I have never used any SOAP libraries in java, so I apologize for the newby-ness of this question.
I am trying to take advantage of Tivoli Endpoint Manager's SOAP API. I have generated the necessary classes from the WSDL file provided, using wsimport.exe (provided in the jdk).
Now I am provided with a ton of classes that I assume are packaging the information into xml format, but I am unsure what to do with them. I have read the documentation provided, but it is fuzzy at best.
The classes generated by wsimport are the following:
According to the documentation, the following Perl Code works for querying the Tivoli's API
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";
}
}
Question: What are the equivalent SOAP client libraries in java? (The ones that I googled are so heavy 15mb+)
How would I write the the equivalent java stub code for the Perl above?
EDIT 1
Here is the Stub code I think found the the WebReportsService.java class
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;
}
}
Solution:
This was much simpler than I thought WSDL generation did all the work. Here is how you use those generated classes.
package 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"));
}
Best Answer
There is a maven plugin, the cxf-codegen-plugin, that will auto generate java classes from a WSDL. It will also create a stub client for you if you want to see how to use the generated code.
Edit 2019-11-15
For this example I downloaded the wsdl
located here* and saved it as stockquote.wsdl.* The wsdl is no longer available from where I initially downloaded it. Find the wsdl included in this answer further below.
$ tree
$ cat pom.xml
$ mvn generate-sources
$ tree .
$ cat target/generated/cxf/net/webservicex/StockQuote.java
EDIT 9/11/2017
Here is the content of the wsdl file just in case the website serving it ever goes away.
stockquote.wsdl: