![]() |
Table of Contents
JAX-WSIntroductionThe JAX-WS 1) standard is implemented by a number of SOAP toolkits. In most cases when we talk about JAX-WS we are referring to the JAX-WS Reference Implementation 2) rather than the standard itself. Note: JAX-WS does not support RPC/encoded style SOAP services and so cannot be used with some EMBL-EBI web services. See the SOAP and WSDL sections of the guide for more information about SOAP styles. InstallationJAX-WS is included as part of the Java 6 platform and thus is available if Java 6 or later is installed. If using Java 5 JAX-WS is available for download from http://jax-ws.java.net/. EMBL-EBI Sample Client Dependencies
For the JAX-WS based sample clients we provide an archive containing additional required dependencies (e.g. Apache commons-cli 3) ):
This can be used via the java -Djava.ext.dirs=lib -jar WSDbfetch_JAXWS.jar Creating Stubs Using wsimport
The For details of the WSDL documents available for EBI Web Services see the service page for the service of interest. Specific Apache ant 4) and Apache Maven 5) tasks for generating stubs from WSDL documents are available, see the JAX-WS documentation for details. Command-line
To generate stubs from a WSDL, in this case for EB-eye, use the wsimport -d bin -p uk.ac.ebi.webservices.ebeye -keep -s src http://www.ebi.ac.uk/ebisearch/service.ebi?wsdl
In this case the stubs are generated in the Apache ant: generic taskTo build stubs using the Apache ant build tool, without having to install additional tasks, a generic target can be defined which generates code stubs from a WSDL document: <!-- Generate JAX-WS stubs from a WSDL --> <!-- Using the wsimport command: wsimport -d bin -p uk.ac.ebi.webservices.ebeye -keep -s src http://www.ebi.ac.uk/ebisearch/service.ebi?wsdl NB: assumes wsimport is on the current PATH. --> <target name="genJaxwsStubs" description="JAX-WS RI: generate stubs from a WSDL using wsimport command"> <echo message="${stubPkg}" /> <echo message="${wsdlUrl}" /> <exec executable="wsimport"> <arg value="-d" /> <arg value="${build.dir}" /> <arg value="-p" /> <arg value="${stubPkg}" /> <arg value="-keep" /> <arg value="-s" /> <arg value="${src.dir}" /> <arg value="-Xnocompile" /> <arg value="${wsdlUrl}" /> </exec> </target>
This assumes that the
The <!-- Generate JAX-WS stubs for WSDbfetch --> <target name="jaxws-stubs-wsdbfetch" description="JAX-WS RI: generate stubs for WSDbfetch (document/literal SOAP)"> <antcall target="genJaxwsStubs"> <param name="stubPkg" value="uk.ac.ebi.webservices.jaxws.stubs.wsdbfetch" /> <param name="wsdlUrl" value="http://www.ebi.ac.uk/ws/services/WSDbfetchDoclit?wsdl" /> </antcall> </target> The target can then be referenced when invoking ant to generate the stubs: ant jaxws-stubs-wsdbfetch
An Apache ant Exercise 1: Generate the service stubs.
Examine the Apache ant build file (
To run the tasks described in the ant build file in Eclipse right-click on the To build the JAX-WS examples we need to run two targets:
To run these in Eclipse:
To run these targets from the command-line: ant jaxws-stubs ant jaxws-compile Apache ant: WsImport taskApache ant allows the addition of specific tasks via a plug-in mechanism. The WsImport task (http://jax-ws.java.net/nonav/2.2.5/docs/UsersGuide.html#3.1.2.1_Generate_a_Service_Endpoint_Interface_) supports the generation of JAX-WS stubs from a WSDL document and, if installed, can be used as an alternative to the generic task above. Apache mavenA Maven plug-in is also available to generate JAX-WS code stubs from a WSDL document, see http://jax-ws-commons.java.net/jaxws-maven-plugin/ for details. Using the Stubs
The stubs generated by
Import the generated classes into the program (assuming the import uk.ac.ebi.webservices.wsdbfetch.*; To create a service proxy, with which you can interact with the service: WSDBFetchDoclitServerService service = new WSDBFetchDoclitServerService(); WSDBFetchServer srvProxy = service.getWSDbfetchDoclit();
The methods of the service proxy ( String result = srvProxy.fetchData("UNIPROT:ADH1A_HUMAN", "default", "raw");
The System.out.println(result); Then compile in the usual way:
And then run the program, to check it works:
Exercise 2: WSDbfetch (document/literal SOAP)The WSDbfetch web service (http://www.ebi.ac.uk/Tools/webservices/services/dbfetch) provides the same basic functionality as dbfetch, but through a collection of SOAP interfaces. Since JAX-WS does not support RPC/encoded SOAP services, the document/literal SOAP service has to be used. Using the example WSDbfetch client (examples/soap/jaxws/Dbfetch.java) as a guide, use the service to fetch the UniProtKB entries with the accessions: P13569, P26361 and P35071, in fasta sequence format. Sample solution: solutions/soap/jaxws/Q4Dbfetch.java Exercise 3: WSDbfetch meta-dataThe WSDbfetch service includes a number of meta-data methods which provide information about the service such as the names of the databases available, and the formats and styles which can be used with each database (see http://www.ebi.ac.uk/Tools/webservices/services/dbfetch).
Starting from the example client (examples/soap/jaxws/Dbfetch.java), use the Sample solution: solutions/soap/jaxws/Q5Dbfetch.java Complex Data Structures
The methods in the WSDbfetch service all use simple string parameters. Many of the other EBI services use more complex input structures. For example NCBI BLAST (SOAP) requires a structure containing the various parameters and the input sequence to be passed to the // Object factory for creating objects to be exchanged with the web service. ObjectFactory objFactory = new ObjectFactory(); // Populate input parameters structure InputParameters params = new InputParameters(); params.setProgram("blastp"); ArrayOfString databaseList = new ArrayOfString(); databaseList.getString().add("uniprotkb_swissprot"); params.setDatabase(databaseList); params.setStype("protein"); params.setSequence(objFactory.createInputParametersSequence(">Seq1 Example search sequence\n" + "MKFLILLFNILCLFPVLAADNHGVGPQGASGVDPITFDINSNQTGPAFLTAVEMAGV")); String email = "email@example.org"; // Your e-mail address // Get the NCBI BLAST (SOAP) service proxy JDispatcherService_Service service = new JDispatcherService_Service(); JDispatcherService ncbiblast = service.getJDispatcherServiceHttpPort(); // Submit the job String jobid = ncbiblast.run(email, "", params); System.out.println("Job Id: " + jobid);
Note: due to the
See Customizations for WCF Service WSDL section of the The WSIT Tutorial for details of how to modify this behavior by using a customized binding with
The // Poll until job has finished String status = "RUNNING"; while (status.equals("RUNNING")) { Thread.sleep(3000); // Wait 3 seconds status = ncbiblast.getStatus(jobid); // check job status System.out.println(status); } // If the job completed successfully... if (status.equals("FINISHED")) { // Get the text result byte[] resultbytes = ncbiblast.getResult(jobid, "out", null); String result = new String(resultbytes); // Output the result System.out.println(result); } Exercise 4: NCBI BLAST (SOAP)So far all the services we have looked at have been able to return the result in a relatively short period of time. This is not the case when running analytical tools, which in extreme cases may take days to return a result. So for these tools asynchronous methods have to be used, where the submission returns a job identifier which can be then used to check on the status of the job, and once it completes retrieve the results. The NCBI BLAST (SOAP) service, uses the NCBI BLAST suite to perform a sequence similarity search requires this approach. Examine the example client (examples/soap/jaxws/NcbiBlastSoap.java) and note the “run”, “getStatus” and “getResult” work flow.
Using the example client as a guide, perform an NCBI BLAST search with UniProtKB CFTR_MOUSE ( Sample solution: solutions/soap/jaxws/Q8NcbiBlastSoap.java Exercise 5: NCBI BLAST (SOAP) meta-data
The NCBI BLAST (SOAP) service can return the result in a number of formats, modify your client to use the Sample solution: solutions/soap/jaxws/Q9NcbiBlastSoap.java ProxiesIn some environments it is necessary to configure an HTTP proxy before a client can connect to external services. JAX-WS supports the normal Java mechanisms for the configuration of proxies:
For details and examples see:
User-Agent
HTTP clients usually provide information about what they are, allowing services to handle specific clients differently if necessary, and giving service providers some information about how their services are being used. By default JAX-WS sets the HTTP User-Agent header (see RFC2616 section 14.43) to something like ” // Modify the user-agent to add a more specific prefix (see RFC2616 section 14.43) String clientUserAgent = "Example-Client/1.0 (" + System.getProperty("os.name") + ")"; ((BindingProvider)srvProxy).getRequestContext().put( MessageContext.HTTP_REQUEST_HEADERS, Collections.singletonMap("User-Agent",Collections.singletonList(clientUserAgent)) );
Where Note: while the HTTP specification does not define a limit on the size of HTTP headers, web server implementations often do limit the maximum size of an HTTP header to 8KB or 16KB. If the server limit for an HTTP header is exceeded a “400 Bad Request” will be returned by the server. Service End-point and NamespaceIn cases where access is required to alternative instance of the web service, the end-point address for the service and possibly the XML namespace used for the SOAP messages will need to be modified. In JAX-WS these can be overridden when getting the service proxy object by specifying the a WSDL document describing the required end-point address and the required service XML namespace: String srvWsdl = "http://wwwdev.ebi.ac.uk/ws/services/WSDbfetchDoclit?wsdl"; String srvXmlNamespaceUri = "http://www.ebi.ac.uk/ws/services/WSDbfetchDoclit"; String srvServiceName = "WSDBFetchDoclitServerService"; WSDBFetchDoclitServerService service = new WSDBFetchDoclitServerService( new java.net.URL(srvWsdl), new javax.xml.namespace.QName(srvXmlNamespaceUri, srvServiceName)); WSDBFetchServer srvProxy = service.getWSDbfetchDoclit(); Sample ClientsMost SOAP Web Services at EMBL-EBI have sample clients which provide command-line access to the service and example code. For Java some of the clients are based on JAX-WS. Document/literal SOAP
1)
JAX-WS - http://jcp.org/en/jsr/detail?id=224
2)
JAX-WS Reference Implementation - http://jax-ws.java.net/
3)
Apache commons-cli - http://commons.apache.org/cli/
4)
Apache ant - http://ant.apache.org/
5)
Apache Maven - http://maven.apache.org/
![]() |