The Holy Java

Building the right thing, building it right, fast

Posts Tagged ‘webservice’

Howto: JAX-WS service with XML Source input instead of JAXB-produced POJOs (similar to JAX-RPC with SOAPElement input)

Posted by Jakub Holý on December 29, 2010

Sometimes you may want to create a JAX-WS webservice with its input defined by a proper, structured XSD yet accessing the input as raw XML object and not as POJOs produced by JAXB, similarly as with a JAX-RPC webservice having input of the type SOAPElement. This is possible using @WebServiceProvider with

Read the rest of this entry »

Posted in j2ee, Languages | Tagged: , , , | 3 Comments »

Tip: Multiple webservice implementation classes available at the same time under WAS7

Posted by Jakub Holý on December 29, 2010

If you want to experiment with webservices by providing several alternative implementations of the same webservice (represented by the <wsdl:service> element), each having its own URL, and you’re using Websphere 7 and JAX-WS, then:

  1. For each alternative implementation, add <wsdl:port> with a unique name under the <wsdl:service> element in the WSDL file. Beware: This is essential to enable multiple implementations.
  2. For each alternative implementation, define a servlet and servlet mapping in web.xml like this:
    <servlet id="$IMPLEMENTATION_CLASS_NAME$">
  3. Create the implementations – likely as POJOs denoted with the @WebService annotation – and set the corresponding portName for each of them (@WebService(portName=”<unique port name>”, …))
  4. Deploy and use Read the rest of this entry »

Posted in j2ee, Languages, WebSphere | Tagged: , , , | Comments Off on Tip: Multiple webservice implementation classes available at the same time under WAS7

Webservice testing with JMeter: Passing data from a response to another request

Posted by Jakub Holý on June 4, 2010

JMeter is great for functional and performance testing of many things, including web services (and to my surprise also LDAP). It also provides means for extracting data from a response and passing them to a subsequent request, which is exactly what I needed. There is already a good tutorial on testing a WS with JMeter, so I won’t repeat the basic setup here. The steps are:

  1. Create a webservice (WS) test plan, as described in the tutorial (in my case it contains two WS calls)
  2. Add the User Defined Variables config element to the test plan and define there a variable for transferring the response data
  3. Add an XPath Extractor Post Processor to the first WS call to extract the value of interest into the user defined variable (beware namespaces!)
  4. Add a BeanShell Pre Processor to the second call, which will replace a placeholder in the WS call’s XML data with the value of that variable

Read the rest of this entry »

Posted in Languages, Testing | Tagged: , , , | 10 Comments »

Sending a SOAP request to a Web Service via URLConnection

Posted by Jakub Holý on May 25, 2006

You may want to test you web service by sending it a manually composed request and reading the XML returned. Here’s how to do it (e.g. using BeanShell in jEdit):

The SOAP request

<?xml version="1.0" encoding="utf-16"?>
<soap:Envelope xmlns:soap="" xmlns:xsi="" xmlns:xsd="">
    <getUserByEmail xmlns="">

The Java code

String soapXml =   // jEdit: = buffer.getText(0,buffer.getLength()) url = new"http://localhost:9081/myServiceWAR/services/MyService"); conn = url.openConnection();
// Set the necessary header fields
conn.setRequestProperty("SOAPAction", "http://localhost:9081/myServiceWAR/services/MyService");
// Send the request wr = new;
// Read the response rd = new;
String line;
while ((line = rd.readLine()) != null) { System.out.println(line); /*jEdit: print(line); */ }

Posted in j2ee, Languages | Tagged: , , , | 2 Comments »