Showing posts with label jax-ws. Show all posts
Showing posts with label jax-ws. Show all posts

Thursday, September 20, 2012

Calling Web Service with wget

Wget - "The non-interactive network downloader." (from the man page) could be used to call web service if a request XML is available. This is useful to quickly test a web service.
1. First step is to capture the SOAP request in XML format. Wireshark could be used for this. Below is a sample of a request which is used to test the failover setup for application server connection when RAC is used. The request will send the client's machine name as the input and will respond with the instance connected at the back end.
<?xml version='1.0' encoding='UTF-8'?>
  <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
      <ns2:getAppAndDBServerNames xmlns:ns2="http://asanga/">
        <arg0>pc120</arg0>
      </ns2:getAppAndDBServerNames>
    </S:Body>
</S:Envelope>
2. Save the XML request in a file. This file will be used as the input to the wget.
3. Execute the wget command as shown below
wget http://192.168.0.66:8080/FailOverTest/FailOverTestPort --post-file=input.xml 
--header="Content-Type: text/xml" --output-document=soapResponse.xml
input.xml is the file with xml request created in step 2 above. Response from the WS will be saved into soapResponse.xml. 192.168.0.66:8080 is the IP and port of the server where web service is deployed and /FailOverTest/FailOverTestPort is the service called.
$ wget http://192.168.0.66:8080/FailOverTest/FailOverTestPort --post-file=input.xml --header="Content-Type: text/xml" --output-document=soapResponse.xml
--2012-09-20 11:47:08--  http://192.168.0.66:8080/FailOverTest/FailOverTestPort
Connecting to 192.168.0.66:8080... connected.
HTTP request sent, awaiting response... 200 OK
Length: 331 [text/xml]
Saving to: `soapResponse.xml'

100%[============================================================================================================>] 331         --.-K/s   in 0s

2012-09-20 11:47:08 (35.1 MB/s) - `soapResponse.xml' saved [331/331]
4. The soapResponse.xml will have the output in XML format.
<?xml version="1.0" ?>
  <S:Envelopexmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
      <ns2:getAppAndDBServerNamesResponse xmlns:ns2="http://asanga/">
        <return>
          Connected to ent11g2 DB Server hpc1.domain.net Application Server on Thu Sep 20 11:34:02 BST 2012
        </return>
      </ns2:getAppAndDBServerNamesResponse>
    </S:Body>
  </S:Envelope>

Tuesday, May 25, 2010

Tomcat 6 with JAX-WS 2.1

Foremost get the latest JDK (Anything after JDK 1.6 update 4 or later) as this would not require to configure/create additional "endorsed" directory (since rt.jar contains jax-ws 2.1 api).

To use JAX-WS 2.1 with Tomcat
1. Downloadthe JAX-WS libraries
2. Install (or Extract) the downloaded file with
java -jar JAXWS2.1.2-20070917.jar
3. Assuming the libraries were installed on $CATALINA_HOME/jaxws-ri, edit shared.loader property in $CATALINA_HOME/conf/catalina.properties as follows
shared.loader=$CATALINA_HOME/jaxws-ri/lib/*.jar
If $CATALINA_HOME is not defined on the environment edit catalina.properties as
shared.loader=${catalina.home}/jaxws-ri/lib/*.jar
That's all!

Be sure to have the web.xml and sun-jaxws.xml files in the WS deployment .war, unlike glassfish and weblogic, this tomcat configuration doesn't auto create them and wsdl won't be exposed.

Friday, February 5, 2010

Nokia N900 (Maemo) and JAX-WS

There are various jre that could be used on Nokia N900's Maemo OS to run java applications. All of them have pros and cons. Jalimo and Sun's own jre are few that could be used.

Here is a Jalimo example

This blog is about running a simple JAX-WS client.

Several application should be downloaded and installed from the meamo web site which makes things much easier. Below is the list of applications needed (give list is the name of the application)

1. Update the OS to Maemo 5.
2. rootsh (allows to gain root access)
3. Install OpenSSH Server and OpenSSH Client
4. Personal IP Address

Once the above applications are installed download Java SE for Embedded 6u10 (Build 39) Early Access. The link is given above. Need to do some registering beforehand.

When the registration is completed and confirmation email is received, download the headful version 10 ARMv6 Linux. Full name given on the download page
Java SE for Embedded 6.0 Update 10 ARMv6 Linux (Build 39) Early Access - Headful, EABI, glibc 2.5, Hard Float (VFP), Little Endian


(Not sure if headless version would have a problem with JAX-WS but it had some problems when it came to running swing applications).

Using the X Terminal on the phone gain access to the linux shell on the N900. simply type root on the shell to gain root access. (need the rootsh application installed).

If not already started, then start the SSH server with the following
/etc/init.d/ssh start


Create an additional user and give a password. Use this additional user to sftp the download jre into the phone. Find out the phone's IP with the personal IP Address widget.



Other folders may have restrictions so ftp might only work on /home/user/MyDocs.
Once ftp has finished as root user copy the gzip file into /home/user and unzip.
Create a symbolic link in /usr/bin to /home/user/ejre1.6.0_10/bin/java

cd /usr/bin
ln -s /home/user/ejre1.6.0_10/bin/java java

run java version command to verify installation is successfull.

java -version
java version "1.6.0_10-ea"
Java(TM) 2 Runtime Environment, Standard Edition for Embedded (build 1.6.0_10-ea-b39)
Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode)
Evaluation version, 84 days remain in evaluation period


Copy the following .jar files into the lib directory of the jre installation (ejre1.6.0_10/lib)

FastInfoset.jar
activation.jar
http.jar
javaee.jar
jaxb-api.jar
jaxb-impl.jar
jaxb-xjc.jar
jaxws-api.jar
jaxws-rt.jar
jaxws-tools.jar
jsr173_api.jar
jsr181-api.jar
jsr250-api.jar
mimepull.jar
saaj-api.jar
saaj-impl.jar
sjsxp.jar
stax-ex.jar
streambuffer.jar


That's it!.
Since there's no javac compile the java application and scp the client code or application jar into the phone and run it as a normal java application from the command shell.

Swing application that were developed desktop environment will also run as it is with Sun jre, whereas Jalimo only support SWT.

Screenshot of ADMon 2.0 on Nokia N900



Below is sample java code for testing.

Service class. (Bundle it and deploy into application container)

import javax.jws.WebMethod;
import javax.jws.WebService;


@WebService
public class MoJAXWS {


@WebMethod
public String helloFromServer(String name){

return "Hello "+name;
}

}


Client class (compile this and copy the class file into the phone and run from there)


import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
import mojax.MoJAXWS;
import mojax.MoJAXWSService;


public class Client {

public static void main(String[] args) {
try {
MoJAXWSService service = new MoJAXWSService(new URL("http://serverIP:8080/MobileJAXWS/MoJAXWSService"), new QName("http://mojax/", "MoJAXWSService"));
MoJAXWS port = service.getMoJAXWSPort();
System.out.println(port.helloFromServer("World"));
} catch (MalformedURLException ex) {
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
}


}

}



Monday, October 5, 2009

Java Code Sinppet: JAX-WS & MTOM

To enable MTOM (Message Transmission Optimization Mechanism) there are several things need to be done and in a nutshell

1. add the MTOM annotation on the services class

@javax.xml.ws.soap.MTOM
@WebService(serviceName =


2. Following table list the relationship between MIME type and java type

MIME type Java type
image/gif java.awt.Image
image/jpeg java.awt.Image
text/plain java.lang.String
text/xml javax.xml.transform.Source
application/xml javax.xml.transform.Source
*/* javax.activation.DataHandler


3. Edit the WSDL to and list the correct mime type which will change the schema from

<xs:sequence>
<xs:element name="return" type="xs:base64Binary" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>

to

<xs:sequence>
<xs:element name="return" type="xs:base64Binary" minOccurs="0" maxOccurs="unbounded"
xmime:expectedContentTypes="image/jpeg" xmlns:xmime="http://www.w3.org/2005/05/xmlmime"/>
</xs:sequence>


4. Make the container use the edited WSDL than generated one

@WebService(serviceName = ...., wsdlLocation="WEB-INF/wsdl/edited.wsdl")


5. Deploy the new service

for more info netbeans tutorial pages 1, page 2, page 3



To do the above without any modification to wsdl (using annotation on the java class)

1. Set the @MTOM as above on the service
@MTOM
@WebService
public class NewWebService {

2. Annotate the data type on the web method as follows
@WebMethod
public void setImage(@XmlMimeType("image/gif")Image img){

3. Can also annotate a return type
@WebMethod
public @XmlMimeType("image/gif")Image getImage( String name){

4. All kind of data types could be used
@WebMethod
public @XmlMimeType("*/*")Image getFiles