Utworzenie klienta SOAP w java z plikiem WSDL
Nigdy nie korzystałem z żadnych bibliotek SOAP w Javie, więc przepraszam za nowość tego pytania.
Próbuję wykorzystać interfejs API SOAP Tivoli Endpoint Manager. Wygenerowałem niezbędne klasy z dostarczonego pliku WSDL za pomocą narzędzia wsimport.exe (udostępnionego w jdk).
Teraz mam mnóstwo klas, które zakładam, że pakują informacje do formatu xml, ale nie jestem pewien, co z nimi zrobić. Przeczytałem dostarczoną dokumentację, ale w najlepszym razie jest ona rozmyta.
Klasy generowane przez wsimport są następujące:
Zgodnie z dokumentacją następujący kod Perla działa w celu wysyłania zapytań do interfejsu API 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";
}
}
Pytanie: Jakie są równoważne biblioteki klienta SOAP w Javie? (Te, które przeszedłem na Google są tak ciężkie 15mb +)
Jak napisałbym odpowiednik kodu zastępczego Java dla powyższego Perla?
EDYTUJ 1
Oto kod StubMyślę znaleziono klasę 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;
}
}
Rozwiązanie:
Było to znacznie prostsze niż myślałem, że pokolenie WSDL wykonało całą pracę. Oto sposób korzystania z wygenerowanych klas.
pakiet 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"));
}