Non ho mai usato alcuna libreria SOAP in java, quindi mi scuso per la novita di questa domanda.Creazione di un client SOAP in java dato un file WSDL
Sto cercando di sfruttare l'API SOAP di Tivoli Endpoint Manager. Ho generato le classi necessarie dal file WSDL fornito, utilizzando wsimport.exe (fornito in jdk).
Ora mi viene fornita una tonnellata di classi che presumo stiano confezionando le informazioni in formato xml, ma non sono sicuro di cosa farne. Ho letto la documentazione fornita, ma è al massimo sfocata.
Le classi generate dal wsimport sono i seguenti:
Secondo la documentazione, il seguente codice Perl lavora per l'interrogazione API del Tivoli
use SOAP::Lite;
#arguments: [hostname] [username] [password] [relevance expression]
#hostname only, e.g. ’example.com’ rather than ’http://example.com/webreports’
my $host = $ARGV[0];
my $username = SOAP::Data->name(’username’ => $ARGV[1]);
my $password = SOAP::Data->name(’password’ => $ARGV[2]);
my $expr = SOAP::Data->name(’relevanceExpr’ => $ARGV[3]);
my $service = SOAP::Lite -> uri(’http://’ . $host . ’/webreports?wsdl’)
-> proxy($host);
my $result = $service -> GetRelevanceResult($expr, $username, $password);
if($result->fault) {
print "faultcode: " . $result->faultcode . "\n";
print "faultstring: " . $result->faultstring . "\n";
}
else {
foreach my $answer ($result->valueof("//GetRelevanceResultResponse/a")) {
print $answer . "\n";
}
}
Domanda: Quali sono le librerie client SOAP equivalenti in java? (Quelli che ho cercato su go sono così pesanti 15mb +)
Come scrivere il codice stub java equivalente per il Perl sopra?
EDIT 1
ecco il codice stub Penso trovato la classe del WebReportsService.java
package connect.tivoli;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceFeature;
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.2.4-b01
* Generated source version: 2.2
*
*/
@WebServiceClient(name = "WebReportsService", targetNamespace = "http://schemas.bigfix.com/Relevance", wsdlLocation = "http://temwebreports/webreports?wsdl")
public class WebReportsService
extends Service
{
private final static URL WEBREPORTSSERVICE_WSDL_LOCATION;
private final static WebServiceException WEBREPORTSSERVICE_EXCEPTION;
private final static QName WEBREPORTSSERVICE_QNAME = new QName("http://schemas.bigfix.com/Relevance", "WebReportsService");
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("http://temwebreports/webreports?wsdl");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
WEBREPORTSSERVICE_WSDL_LOCATION = url;
WEBREPORTSSERVICE_EXCEPTION = e;
}
public WebReportsService() {
super(__getWsdlLocation(), WEBREPORTSSERVICE_QNAME);
}
public WebReportsService(WebServiceFeature... features) {
super(__getWsdlLocation(), WEBREPORTSSERVICE_QNAME, features);
}
public WebReportsService(URL wsdlLocation) {
super(wsdlLocation, WEBREPORTSSERVICE_QNAME);
}
public WebReportsService(URL wsdlLocation, WebServiceFeature... features) {
super(wsdlLocation, WEBREPORTSSERVICE_QNAME, features);
}
public WebReportsService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public WebReportsService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
super(wsdlLocation, serviceName, features);
}
/**
*
* @return
* returns RelevancePortType
*/
@WebEndpoint(name = "RelevancePort")
public RelevancePortType getRelevancePort() {
return super.getPort(new QName("http://schemas.bigfix.com/Relevance", "RelevancePort"), RelevancePortType.class);
}
/**
*
* @param features
* A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
* @return
* returns RelevancePortType
*/
@WebEndpoint(name = "RelevancePort")
public RelevancePortType getRelevancePort(WebServiceFeature... features) {
return super.getPort(new QName("http://schemas.bigfix.com/Relevance", "RelevancePort"), RelevancePortType.class, features);
}
/**
*
* @return
* returns UserManagementPortType
*/
@WebEndpoint(name = "UserManagementPort")
public UserManagementPortType getUserManagementPort() {
return super.getPort(new QName("http://schemas.bigfix.com/Relevance", "UserManagementPort"), UserManagementPortType.class);
}
/**
*
* @param features
* A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
* @return
* returns UserManagementPortType
*/
@WebEndpoint(name = "UserManagementPort")
public UserManagementPortType getUserManagementPort(WebServiceFeature... features) {
return super.getPort(new QName("http://schemas.bigfix.com/Relevance", "UserManagementPort"), UserManagementPortType.class, features);
}
/**
*
* @return
* returns DashboardVariablePortType
*/
@WebEndpoint(name = "DashboardVariablePort")
public DashboardVariablePortType getDashboardVariablePort() {
return super.getPort(new QName("http://schemas.bigfix.com/Relevance", "DashboardVariablePort"), DashboardVariablePortType.class);
}
/**
*
* @param features
* A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
* @return
* returns DashboardVariablePortType
*/
@WebEndpoint(name = "DashboardVariablePort")
public DashboardVariablePortType getDashboardVariablePort(WebServiceFeature... features) {
return super.getPort(new QName("http://schemas.bigfix.com/Relevance", "DashboardVariablePort"), DashboardVariablePortType.class, features);
}
private static URL __getWsdlLocation() {
if (WEBREPORTSSERVICE_EXCEPTION!= null) {
throw WEBREPORTSSERVICE_EXCEPTION;
}
return WEBREPORTSSERVICE_WSDL_LOCATION;
}
}
Soluzione:
Questo è stato molto più semplice di quanto mi pensavo che la generazione WSDL abbia fatto tutto il lavoro. Ecco come usi quelle classi generate.
pacchetto connect.tivoli;
public class testMain {
public static void main(String[] args) {
String relevanceQuery ="names of bes computers ";
WebReportsService wr = new WebReportsService();
RelevancePortType client;
client = wr.getPort(RelevancePortType.class);
System.out.println(client.getRelevanceResult(relevanceQuery, "ad\\username", "password"));
}
Si dovrebbe ottenere ballo di fine anno porta il servizio di' class (WebReportsService credo) utilizzando il metodo getPort(), poi quando si arriva porta (ad esempio endpoint) oggetto applicazione sarà in grado di chiamare qualsiasi metodo di endpoint del servizio Web. Utilizzare ObjectFactory per creare oggetti necessari. Le librerie client più diffuse sono JAX-WS (incluso in JRE6 +) o CXF (da Apache). –
Mi piacerebbe sapere di un client SOAP leggero in Java. Apache CXF è quello che usiamo, ed è un bloatware totale. – dnault
Hai visto? –
deepakborania