Java
This section contains notes to help in accessing ProphetX Web Services from a standalone program written in Java.
The steps to prepare the access to the web services can be summarized as follows:
- Create the proxy.
- Create the main program.
- Execute.
The proxy is the piece of code that does the actual access to the web services on behalf of the client application. This proxy can be generated automatically using tools that read and analyze the WSDL to create the needed code.
The version 6 of Java SE already includes the wsimport tool to create the proxy in Java.
Example (DTO)
XML Element in Response
A basic method for creating the proxy that returns an XML element is the following:
wsimport -b bindings.xml -extension 'https://pxweb.dtn.com/PXWebSvc/PXServiceDtoXml.svc?wsdl'
The above call creates and compiles the proxy and support Java classes that give the access to the web services. The code is stored in a directory called "com".
The file bindings.xml is needed to ensure that the support classes are generated with String parameters. The file needs to be created manually with the following content:
<jaxb:bindings version="2.1" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <jaxb:globalBindings generateElementProperty="false"/> </jaxb:bindings>
An example of the code of a basic main program is the following:
import com.telvent.dtn.pxweb.*; import org.w3c.dom.*; // Test class class Test { // Main program public static void main( String[] args ) { // Get proxy to access PXWeb PXServiceDtoXml service = new PXServiceDtoXml(); IPXServiceDtoXml client = service.getBasicHttp(); // Prepare request object GetQuoteSnapDto request = new GetQuoteSnapDto(); request.setUserID( "user" ); request.setPassword( "pswd" ); request.setType( "F" ); request.setSymbol( "UIS,MSFT,IBM" ); // Call GetQuoteSnap and get an XML element GetQuoteSnapResponse.GetQuoteSnapResult response = client.getQuoteSnap( request ); Element xml = (Element) response.getAny(); ... } }
To compile and execute use the Java compiler as follows:
javac Test.java java Test
XML String in Response
A basic method for creating the proxy that returns an XML string is the following:
wsimport -b bindings.xml -extension 'https://pxweb.dtn.com/PXWebSvc/PXServiceDto.svc?wsdl'
The previous code example can be modified to access the URL that returns an XML string by just replacing all references to PXServiceDtoXml with PXServiceDto and, of course, modify the code to handle the XML string returned. The call to PXWeb would look like this:
... // Call GetQuoteSnap and print response as a string String xml = client.getQuoteSnap( request ); System.out.println( xml ); ...
Example (STD)
XML Element in Response
A basic method for creating the proxy that returns an XML element is the following:
wsimport -extension 'https://pxweb.dtn.com/PXWebSvc/PXServiceStdXml.svc?wsdl'
The above call creates and compiles the proxy and support Java classes that give the access to the web services. The code is stored in a directory called "com".
An example of the code of a basic main program is the following:
import com.telvent.dtn.pxweb.*; import org.w3c.dom.*; // Test class class Test { // Main program public static void main( String[] args ) { // Get proxy to access PXWeb PXServiceStdXml service = new PXServiceStdXml(); IPXServiceStdXml client = service.getBasicHttp(); // Call GetQuoteSnap and get an XML element GetQuoteSnapResponse.GetQuoteSnapResult response = client.getQuoteSnap( "user", "pswd", "F", "UIS,MSFT,IBM" ); Element xml = (Element) response.getAny(); ... } }
To compile and execute use the Java compiler as follows:
javac Test.java java Test
XML String in Response
A basic method for creating the proxy that returns an XML string is the following:
wsimport -b bindings.xml -extension 'https://pxweb.dtn.com/PXWebSvc/PXServiceStdXml.svc?wsdl'
The previous code example can be modified to access the URL that returns an XML string by just replacing all references to PXServiceStd with PXServiceStdXml and, of course, modify the code to handle the XML string returned. The call to PXWeb would look like this:
... // Call GetQuoteSnap and print response as a string String xml = client.getQuoteSnap( "user", "pswd", "F", "UIS,MSFT,IBM" ); System.out.println( xml ); ...