X

Manual Web Service Configuration In From Java Case

As Fabian mentioned in his recent blog entry (http://blogs.sun.com/ritzmann), attaching policy assertions
to webservices created from wsdl could be simply done by inserting the assertions directly into appropriate wsdl document. Today I will show how to attach them in from Java case

Preparation


All you will need is JDK (http://java.sun.com/javase/downloads/index.jsp)
and Java EE Application Server with integrated WSIT.

What follows was tested with

Step 1. Write a Simple Web Service


I will start with a new empty working directory and create a simple java class as follows:
$ mkdir work-wspol ; cd work-wspol ; vim Stock.java
package org.example;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService(serviceName="StockSvc", portName="StockPort", targetNamespace="http://example.org")
public class Stock {
@WebMethod()
public boolean itemAvaiable (String itemId, int amount) {
return Math.random() > 0.6;
}
}

Step 2. Deploy the Service To Make Sure "It Works"


Prepare skeleton for a war archive to deploy:
$ mkdir -p WEB-INF/classes

And compile the web service, your AS_HOME variable must point to glassfish installation/home directory:
$ javac -cp $AS_HOME/lib/javaee.jar -d WEB-INF/classes Stock.java

Then you can bundle and deploy the service in one shot:
$ jar cvf $AS_HOME/domains/domain1/autodeploy/stock.war WEB-INF

Please note that for sake of clarity we have bundled only really necessary files into our war archive. For this sample it should work all right though

After a minute (presuming your glassfish instance is running), you should be able to see the new web service wsdl displaying at http://localhost:8080/stock/StockSvc?wsdl

Step 3. Create WSIT Config File Skeleton


Config file uses the same format as the wsdl. We only need a skeleton -- something which matches our service.
The easiest way to obtain it is to use the one from http://localhost:8080/stock/StockSvc?wsdl.

Another way is to use:

$ $AS_HOME/bin/wsgen -wsdl -cp WEB-INF/classes org.example.Stock 

which should create StockSvc.wsdl file in your work directory.

I will use the latter and copy it to my "war space":

$ mv StockSvc.wsdl WEB-INF/wsit-org.example.Stock.xml

Please note the config file filename. It follows general naming convention wsit-<svcClassName>.xml and is placed in WEB-INF directory.

To get rid of certain unnecessary dependencies I remove following parts of the config file.

$ vim WEB-INF/wsit-org.example.Stock.xml
  <types>
<xsd:schema>
<xsd:import namespace="http://example.org" schemaLocation="StockSvc_schema1.xsd"/>
</xsd:schema>
</types>
<soap:address location="REPLACE_WITH_ACTUAL_URL"/>

I am now ready to attach appropriate policy assertions into the config file.

Step 4. Attach Policy Assertions


For this blog I selected RM policy assertions to be attached to our config file.
Appropriate added text is red.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions
targetNamespace="http://example.org"
name="StockSvc"
xmlns:tns="http://example.org"
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm/policy" 
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"

>
  <message name="itemAvaiable">
<part name="parameters" element="tns:itemAvaiable"/>
</message>
<message name="itemAvaiableResponse">
<part name="parameters" element="tns:itemAvaiableResponse"/>
</message>
<portType name="Stock">
<operation name="itemAvaiable">
<input message="tns:itemAvaiable"/>
<output message="tns:itemAvaiableResponse"/>
</operation>
</portType>
<binding name="StockPortBinding" type="tns:Stock">
 <wsp:Policy>
<wsp:ExactlyOne>
<wsp:All>
<wsaw:UsingAddressing/>
<wsrm:RMAssertion/>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="itemAvaiable">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="StockSvc">
<port name="StockPort" binding="tns:StockPortBinding">
</port>
</service>
</definitions>

Step 5. Redeploy The Service


Now we can redeploy the service. We have to undeploy it first by
$ rm $AS_HOME/domains/domain1/autodeploy/stock.war

And deploy it once again, this time with RM switched on:
$ jar cvf $AS_HOME/domains/domain1/autodeploy/stock.war WEB-INF

Join the discussion

Comments ( 1 )
  • guest Thursday, September 20, 2007

    jj


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.