The Holy Java

Building the right thing, building it right, fast

Archive for May, 2006

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="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <getUserByEmail xmlns="http://service.w3.ibm.com">
      <iuser>jholy@example.com</iuser>
    </getUserByEmail>
  </soap:Body>
</soap:Envelope>

The Java code


String soapXml =   // jEdit: = buffer.getText(0,buffer.getLength())
java.net.URL url = new java.net.URL("http://localhost:9081/myServiceWAR/services/MyService");
java.net.URLConnection conn = url.openConnection();
// Set the necessary header fields
conn.setRequestProperty("SOAPAction", "http://localhost:9081/myServiceWAR/services/MyService");
conn.setDoOutput(true);
// Send the request
java.io.OutputStreamWriter wr = new java.io.OutputStreamWriter(conn.getOutputStream());
wr.write(soapXml);
wr.flush();
// Read the response
java.io.BufferedReader rd = new java.io.BufferedReader(new java.io.InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) { System.out.println(line); /*jEdit: print(line); */ }

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

RAD, WebSphere and changing the classloader mode

Posted by Jakub Holý on May 4, 2006

I’ve spent hours trying to change the classloader mode for a .war include in an .ear application and deployed to the WebSphere Portal v5.1 Test Environment by means of Rational Application Developer’s server configuration editor. I was able to change to for the EAR, but when I changed the mode for a WAR of the EAR from PARENT_FIRST to PARENT_LAST and saved the configuration, I was required to republish, after doing this RAD promted me to reload the configuration from the disk because it has changed. I did so – and my change to parent_last was gone.

Finally i discovered that if I stop the server, remove the application (EAR), republish (?), add the application, change the classloader mode of all WARs in question (and perhaps the EAR as well), save the config. and republish, the change will really apply.

I’m looking forward to have even more fun with WebSphere and RAD… ;-)

RAD 6.0
WebSphere Portal v5.1 Test Environment

Posted in WebSphere | Comments Off