Tuesday, November 27, 2007

java cvs functions
Checkout from CVS



public void checkoutFromCVS(String userName, String password, String hostName, String repository) throws ExecutionException{
PServerConnection c = null;
try {
logger.info("entering checkOutImages");

String encryptedPassword = StandardScrambler.getInstance().scramble(password);

CVSRoot root = CVSRoot.parse(":pserver:"+userName+"@"+hostName+":"+SC_PORT+repository);
c = (PServerConnection)ConnectionFactory.getConnection(root);

c.setEncodedPassword(encryptedPassword);

logger.info("open connection....");
c.open();
logger.info("after open connection");

Client client = new Client(c, new StandardAdminHandler());
GlobalOptions options = new GlobalOptions();
options.setCVSRoot(":pserver:"+userName+"@"+hostName+":"+SC_PORT+repository);

client.ensureConnection();

CheckoutCommand checkout = new CheckoutCommand(true,SC_MODULE);
checkout.setPruneDirectories(true);
File f = new File(SC_CVS_HOME);
if(!f.exists())
f.mkdirs();

client.setLocalPath(SC_CVS_HOME);
client.getEventManager().addCVSListener(new LogCVSListener());

boolean success = client.executeCommand(checkout,options);
logger.info("cmd checkout execute success:"+success);
//client.executeCommand(uc, options);
} catch (CommandAbortedException e) {
logger.error("command aborted ex:"+e.getMessage());
throw new ExecutionException(e.getMessage());
} catch (AuthenticationException e) {
logger.error("authenticate ex:"+e.getMessage());
throw new ExecutionException(e.getMessage());
}catch (CommandException e) {
logger.error("command ex:"+e.getCause());
throw new ExecutionException(e.getMessage());
} finally {
if(null != c) {
try {
c.close();
} catch (IOException e) {
logger.error(e.getMessage());
}
}
}
}



Add to CVS


public void addToCVS(List filesToAdd, File fileToAdd, String userName, String password, String hostName, String repository)throws ExecutionException{
logger.info("entering addToCVS");
PServerConnection c = null;
try {
String[] children;
// It is also possible to filter the list of returned files.
// This example does not return any files that end with `.txt'.
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String name) {
if(dir.getName().equals("CVS")){
return false;
}

return true;
}
};
children = fileToAdd.list(filter);
File f = null;

for (int i=0; i < children.length; i++) {

f = new File(fileToAdd.getAbsoluteFile()+"/"+children[i]);

try {
logger.info("file:"+f.getCanonicalFile());
logger.info("is file:"+f.isFile()+" is dir:"+f.isDirectory());
if(f.isDirectory() ) {
if(!f.getName().equals("CVS")){
logger.info("recursive...");
filesToAdd.add(f);
addToCVS(filesToAdd, f, userName, password, hostName, repository);
}
}else {
filesToAdd.add(f);
}
}catch(IOException e) {
throw new ExecutionException(e.getMessage());
}
}

if(filesToAdd.size() == 0) {
logger.info("nothing to add....");
return;
}

String encryptedPassword = StandardScrambler.getInstance().scramble(password);

CVSRoot root = CVSRoot.parse(":pserver:"+userName+"@"+hostName+":"+SC_PORT+repository);
c = (PServerConnection)ConnectionFactory.getConnection(root);

c.setEncodedPassword(encryptedPassword);

logger.info("open connection....");
c.open();
logger.info("after open connection");

Client client = new Client(c, new StandardAdminHandler());

GlobalOptions options = new GlobalOptions();
options.setCVSRoot(":pserver:"+userName+"@"+hostName+":"+SC_PORT+repository);


AddCommand add = new AddCommand();
add.setMessage("adding images for site portal...");
add.setKeywordSubst(KeywordSubstitutionOptions.BINARY);
logger.info("file path:"+fileToAdd.getPath());
logger.info("file parent:"+fileToAdd.getParent());
client.setLocalPath(SC_DIR_TO_SAVE);
client.ensureConnection();

add.setFiles((File[])filesToAdd.toArray(new File[filesToAdd.size()]));
client.getEventManager().addCVSListener(new LogCVSListener());

logger.info("executing command...");
boolean success = client.executeCommand(add,options);
logger.info("cmd add execute success:"+success);

} catch (CommandAbortedException e) {
logger.error("command aborted ex:"+e.getMessage());
throw new ExecutionException(e.getMessage());
} catch (AuthenticationException e) {
logger.error("authenticate ex:"+e.getMessage());
throw new ExecutionException(e.getMessage());
}catch (CommandException e) {
logger.error("command ex:"+e.getMessage());
throw new ExecutionException(e.getMessage());

}finally {

if(null != c) {
try {
c.close();
} catch (IOException e) {
logger.error(e.getMessage());
}
}
}
logger.info("leaving addToCVS");
}



Commit to CVS


public void commitToCVS(File fileToCommit, String userName, String password, String hostName, String repository) throws ExecutionException{
PServerConnection c = null;
try {
logger.info("entering commitToCVS");

String encryptedPassword = StandardScrambler.getInstance().scramble(password);

CVSRoot root = CVSRoot.parse(":pserver:"+userName+"@"+hostName+":"+SC_PORT+repository);
c = (PServerConnection)ConnectionFactory.getConnection(root);

c.setEncodedPassword(encryptedPassword);

logger.info("open connection....");
c.open();
logger.info("after open connection");

Client client = new Client(c, new StandardAdminHandler());
GlobalOptions options = new GlobalOptions();
options.setCVSRoot(":pserver:"+userName+"@"+hostName+":"+SC_PORT+repository);


client.ensureConnection();

client.getEventManager().addCVSListener(new BasicListener());

//File file = new File(SC_CVS_HOME+"\\"+SC_MODULE+"\\resize_needed\\"+SC_TESTER);
File afile[] = new File[] { fileToCommit };

CommitCommand commit = new CommitCommand();
commit.setMessage("auto commit adding to cvs...");
commit.setFiles(afile);


commit.setForceCommit(true);

client.getEventManager().addCVSListener(new LogCVSListener());
client.setLocalPath(SC_DIR_TO_SAVE);

logger.info("executing command...");
boolean success = client.executeCommand(commit,options);
logger.info("cmd commit execute success:"+success);

//client.executeCommand(uc, options);
}catch (CommandAbortedException e) {
logger.error("command aborted ex:"+e.getMessage());
throw new ExecutionException(e.getMessage());
}catch (AuthenticationException e) {
logger.error("authenticate ex:"+e.getMessage());
throw new ExecutionException(e.getMessage());
}catch (CommandException e) {
logger.error("command ex:"+e.getCause());
throw new ExecutionException(e.getMessage());
} finally {
if(null != c) {
try {
c.close();
} catch (IOException e) {
logger.error(e.getMessage());
}
}
}
logger.info("leaving commitToCVS");
}


InnerClass LogCVSListener


static public class LogCVSListener implements CVSListener {
protected CVSCommandResult result = new CVSCommandResult();
protected Logger logger = Logger.getLogger(LogCVSListener.class.getName());
public LogCVSListener() {
}

/***
* @return Returns the result.
*/
public CVSCommandResult getResult() {
return this.result;
}

/*
* (non-Javadoc)
*
* @see org.netbeans.lib.cvsclient.event.CVSListener#messageSent(org.netbeans.lib.cvsclient.event.MessageEvent)
*/
public void messageSent(MessageEvent e) {
if (e.isError()) {
logger.error(e.getMessage());
// permet de stocker les traces
result.getTrace().append(e.getMessage() + "\n");
} else {
logger.info(e.getMessage());
}
}

/*
* (non-Javadoc)
*
* @see org.netbeans.lib.cvsclient.event.CVSListener#messageSent(org.netbeans.lib.cvsclient.event.BinaryMessageEvent)
*/
public void messageSent(BinaryMessageEvent e) {
logger.info(e.getMessage());
}

/*
* (non-Javadoc)
*
* @see org.netbeans.lib.cvsclient.event.CVSListener#fileAdded(org.netbeans.lib.cvsclient.event.FileAddedEvent)
*/
public void fileAdded(FileAddedEvent e) {
logger.debug("File has been added.");
result.getFileAdded().add(e.getFilePath());
}

/* (non-Javadoc)
* @see org.netbeans.lib.cvsclient.event.CVSListener#fileToRemove(org.netbeans.lib.cvsclient.event.FileToRemoveEvent)
*/
public void fileToRemove(FileToRemoveEvent e) {
logger.debug("File to remove: " + e.getFilePath());
//result.getFileToRemove().add(e.getFilePath());

}

/*
* (non-Javadoc)
*
* @see org.netbeans.lib.cvsclient.event.CVSListener#fileRemoved(org.netbeans.lib.cvsclient.event.FileRemovedEvent)
*/
public void fileRemoved(FileRemovedEvent e) {
logger.debug("File is removed: " + e.getFilePath());
}

/*
* (non-Javadoc)
*
* @see org.netbeans.lib.cvsclient.event.CVSListener#fileUpdated(org.netbeans.lib.cvsclient.event.FileUpdatedEvent)
*/
public void fileUpdated(FileUpdatedEvent e) {
logger.debug("File has been updated");
result.getFileUpdated().add(e.getFilePath());
}

/*
* (non-Javadoc)
*
* @see org.netbeans.lib.cvsclient.event.CVSListener#fileInfoGenerated(org.netbeans.lib.cvsclient.event.FileInfoEvent)
*/
public void fileInfoGenerated(FileInfoEvent fileInfoEvent) {
logger.debug("File status information has been received");
// Avec le diffInfo, possibilité de gestion plus fine des différences.
// DiffInformation diffInfo =
// ((SimpleDiffBuilder)fileInfoEvent.getSource()).createDiffInformation();
result.getFileInfo().add(fileInfoEvent.getInfoContainer());
}

/*
* (non-Javadoc)
*
* @see org.netbeans.lib.cvsclient.event.CVSListener#commandTerminated(org.netbeans.lib.cvsclient.event.TerminationEvent)
*/
public void commandTerminated(TerminationEvent e) {
if (e.isError()) {
logger.error("Server responses has error");
result.setError(true);
} else {
logger.debug("Server responses has OK");
}
}

/*
* (non-Javadoc)
*
* @see org.netbeans.lib.cvsclient.event.CVSListener#moduleExpanded(org.netbeans.lib.cvsclient.event.ModuleExpansionEvent)
*/
public void moduleExpanded(ModuleExpansionEvent e) {
// ne fait rien
}

}
typical keytool implementation



C:\jboss-4.0.3SP1\server\default\conf>keytool -genkey -dname "cn=actwskey, ou=Comira, o=CatsTest, c=US" -alias actwskey -keypass ###### -keystore d:\jboss-4.0.3SP1\server\default\conf\keys\actwskey.keystore -storepass ###### validity 180 -keysize 1024 -keyalg RSA



view the contents of a keystore



keytool -list -v -keystore keys\actwskey.keystore

Monday, November 26, 2007

Example calling axis endpoint and jwsdp endpoint




private void doAxisImpl(){
try {

Service service = new Service();
Call call = (Call) service.createCall();
String url = "http://cwcdev.corporate.act.org/schedule/ALMVTC.WSDL";
call.setTargetEndpointAddress(new java.net.URL(url));

org.apache.axis.message.SOAPEnvelope env = new org.apache.axis.message.SOAPEnvelope();
org.apache.axis.message.SOAPBodyElement sbe
//= new org.apache.axis.message.SOAPBodyElement(XMLUtils.StringToElement("http://cwcdev.corporate.act.org/schedule/ALMVTC.WSDL", "getVersion", ""));
= new org.apache.axis.message.SOAPBodyElement(XMLUtils.StringToElement("http://actcenters.com/ALMVTC/message/", "sayHello", ""));
SOAPFactory factory = SOAPFactoryImpl.newInstance();
Name name = factory.createName("name");
SOAPElement param = sbe.addChildElement(name);
param.addTextNode("James Zhang");

call.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean(true));
call.setProperty(Call.SOAPACTION_URI_PROPERTY, "http://actcenters.com/ALMVTC/action/Schedule.sayHello");
call.addParameter("name", Constants.XSD_STRING, ParameterMode.IN);

env.addBodyElement(sbe);

//XMLUtils.PrettyElementToStream(env.getAsDOM(), System.out);
//env = new SignedSOAPEnvelope(env, "http://cwcdev.corporate.act.org");

System.out.println("\n============= Request ==============");
XMLUtils.PrettyElementToStream(env.getAsDOM(), System.out);

call.invoke(env);

MessageContext mc = call.getMessageContext();
System.out.println("\n============= Response ==============");
XMLUtils.PrettyElementToStream(mc.getResponseMessage().getSOAPEnvelope().getAsDOM(), System.out);
}
catch (Exception e) {
e.printStackTrace();
}
}

jwsdp ex




private void doSOAPImpl(){

/**/

SOAPConnection soapConn = null;
try {
MessageFactory msgFactory = MessageFactory.newInstance();
SOAPMessage msg = msgFactory.createMessage();
msg.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true");
msg.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, "utf-8");
msg.getMimeHeaders().addHeader("SOAPAction", "http://actcenters.com/ALMVTC/action/Schedule.sayHello");
// SOAPPart soapPart = msg.getSOAPPart();
// SOAPEnvelope soapEnvelope = soapPart.getEnvelope();

// for the tutorial web service, we don't have any headers,
// so get the "free" one and detach it:
//SOAPHeader soapHeader = soapEnvelope.getHeader();
//soapHeader.detachNode();

// to the body, add the document we want to send to the
// ping request web service:
SOAPBody body = msg.getSOAPBody();
SOAPFactory soapFactory = SOAPFactory.newInstance();
Name bodyName = soapFactory.createName("sayHello", "wsdlns", "http://actcenters.com/ALMVTC/message/"
);



SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
Name paramName = soapFactory.createName("name");
SOAPElement param = bodyElement.addChildElement(paramName);
param.addTextNode("James Zhang");

// echo the document first:
System.out.println("\nAbout to send the following SOAPMessage:\n");
msg.writeTo(System.out);
String url = "http://cwcdev.corporate.act.org/schedule/ALMVTC.WSDL";
System.out.println("\nto endpoint URL "+url+"\n");

// ...then send it, and echo the response:
SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance();
soapConn = soapConnFactory.createConnection();

SOAPMessage responseMsg = soapConn.call(msg, url);
System.out.println("\nGot the following SOAPMessage in response:\n");
responseMsg.writeTo(System.out);

} catch (UnsupportedOperationException e) {
logger.error(e.getMessage());
} catch (SOAPException e) {
logger.error(e.getMessage());
} catch (IOException e) {
logger.error(e.getMessage());
}finally{
try {
soapConn.close();
} catch (SOAPException e) {
e.printStackTrace();
}
}
}

Wednesday, November 21, 2007

WS-Security using JBoss-4.0.3SP1 and jwsdp-1.6

http://www.devx.com/Java/Article/28816/1954?pf=true
http://xfire.codehaus.org/WS-Security
A more detailed description of key generation can be found here:
http://www.churchillobjects.com/c/11201e.html
http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/keytool.html

How to create a production certificate can be found here:
http://support.globalsign.net/en/objectsign/java.cfm

Thursday, November 08, 2007

Using NetBeans java_cvs library:

NetBeans JavaCVS library

Thursday, October 18, 2007

Adding Web-Service support to JBoss-4.0.5.GA
download the web services kit from jboss - jbossws-native-2.0.0.GA
follow the install instructions.
- 2.0.0.GA is missing the wstx.jar. get it from 2.0.1 and put it in jboss_home\client

- would have used 2.0.1 but there were problems in the deployment

to execute wscompile use wsconsume


C:\projects-cal-ws\act-ws-scheduler\client>wsconsume -k -p com.comira -o ./WebContent/WEB-INF/classes -s ./src -w http://cwcdev.corporate.act.org/schedule/ALMVTC.WSDL ./WebContent/WEB-INF/wsdl/ALMVTC.WSDL


I have also added WSCONSUME_CLASSPATH to my system variables. Not sure if this is needed. It points to my JBOSSWS2.0.0.GA\lib dir


anyType a huge pain with rpc/encoded documents


deploy jbossws using the following:


C:\jbossws-native-2.0.0.GA>ant deploy-jboss40

Monday, September 10, 2007

Found this to be of excellent use: A scheduled timer task that runs daily. Good to use for those mundane tasks that must be executed without fail. http://www.ibm.com/developerworks/java/library/j-schedule.html

Wednesday, August 29, 2007

New Addition to the Scheduling Widgets

Schedule Checker


Registration Scheduler Updated

Friday, August 10, 2007


Here's the calendar object which is used for scheduling,

Tuesday, February 20, 2007

Struts -> Tiles -> RequestProcessor

I've been battling all day with JBoss and struts and feel that this one is gonna need some documentation in case it ever creeps up and bites me in the ass again.

I switched from jboss-4.0.2 to jboss-4.0.3sp1 and have been gettin hit left and right with things that just don't fucking work. Or perhaps it's the way I've done them that don't fucking work. Well anyways, here's what happened.

The .ear that I deploy requests for a UnifiedClassLoader so as to enjoy the ability to package individual utility classes into reusable components.

Anyways, I had a struts.jar in the .war/lib dir and jboss kept tellin me that the RequestProcessor wasn't compatible with TilesRequestProcessor. Just delete your damn .jar file from the .war next time. NOTE TO SELF - DON'T DO STUPID THINGS!!!!

Wednesday, February 07, 2007


Updated Scheduler
Web Services

server
RPC Server Endpoint
Developing Web Services
Developing Web Services from WSDL
wscompile ant task
wscompile ant init
Model Packaging with Namespace var
wscompile server

(now it's a example of a document end point)


C:\projects\workspace\cal-ws>wscompile -cp ./WebContent/WEB-INF/classes -gen:server -f:documentliteral -mapping ./WebContent/META-INF/jaxrpc-mapping.xml -keep -d ./WebContent/WEB-INF/classes -s ./src -nd ./WebContent/WEB-INF/wsdl config.xml


wscompile needs a configuration file for its operation, we use



<configuration
xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">

<service name="HelloWorldService"
targetNamespace="http://com.comira.cal.ws/samples"
typeNamespace="http://com.comira.cal.ws/samples/types"
packageName="com.comira.cal.ws">
<interface name="com.comira.cal.ws.IHelloWorldWS"/>
</service>

</configuration>

Need the web.xml



<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>HelloWorldService</servlet-name>
<servlet-class>com.comira.cal.ws.HelloWorldWS</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorldService</servlet-name>
<url-pattern>/HelloWorldService</url-pattern>
</servlet-mapping>
</web-app>

One more descriptor is needed that glues everything together. It is called webservices.xml, is placed in WEB-INF, and must also be coded by hand. Here it is:



<webservices
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd"
version="1.1">

<webservice-description>
<webservice-description-name>HelloWorldServiceJSE</webservice-description-name>
<wsdl-file>WEB-INF/wsdl/HelloWorldService.wsdl</wsdl-file>
<jaxrpc-mapping-file>WEB-INF/jaxrpc-mapping.xml</jaxrpc-mapping-file>
<port-component>
<port-component-name>PortComponent</port-component-name>
<wsdl-port>IHelloWorldWSPort</wsdl-port>
<service-endpoint-interface>com.comira.cal.ws.IHelloWorldWS</service-endpoint-interface>
<service-impl-bean>
<servlet-link>HelloWorldService</servlet-link>
</service-impl-bean>
</port-component>
</webservice-description>
</webservices>


Then we package everything together and deploy to JBoss. On the server we should see messages like this



23:12:56,515 INFO [TomcatDeployer] deploy, ctxPath=/ws4ee-samples-server-jse, warUrl=file:/.../ws4ee-samples-server-jse-exp.war/
23:12:57,125 INFO [WSDLFilePublisher] WSDL published to: file:/.../data/wsdl/ws4ee-samples-server-jse.war/OrganizationService.wsdl
23:12:57,546 INFO [AxisService] WSDD published to: ...\data\wsdl\ws4ee-samples-server-jse.war\PortComponent.wsdd
23:12:58,328 INFO [AxisService] Web Service deployed: http://TDDELL:8080/ws4ee-samples-server-jse/Organization


A potential client can access the WSDL from this address

http://zimbob:8080/calws/HelloWorldService?wsdl
This just basically shows the xml rpc config file:



<?xml version="1.0" encoding="UTF-8"?>
<definitions name="HelloWorldService" targetNamespace="http://com.comira.cal.ws/samples" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://com.comira.cal.ws/samples" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<types>
</types>
<message name="IHelloWorldWS_sayHelloResponse">
<part name="result" type="xsd:string"/>
</message>
<message name="IHelloWorldWS_sayHello">
<part name="String_1" type="xsd:string"/>
</message>

<portType name="IHelloWorldWS">
<operation name="sayHello" parameterOrder="String_1">
<input message="tns:IHelloWorldWS_sayHello"/>
<output message="tns:IHelloWorldWS_sayHelloResponse"/>
</operation>
</portType>
<binding name="IHelloWorldWSBinding" type="tns:IHelloWorldWS">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="sayHello">

<soap:operation soapAction=""/>
<input>
<soap:body namespace="http://com.comira.cal.ws/samples" use="literal"/>
</input>
<output>
<soap:body namespace="http://com.comira.cal.ws/samples" use="literal"/>
</output>
</operation>
</binding>

<service name="HelloWorldService">
<port binding="tns:IHelloWorldWSBinding" name="IHelloWorldWSPort">
<soap:address location="http://zimbob:8080/calws/HelloWorldService"/>
</port>
</service>
</definitions>


client
RPC Clent

wscompile client
(now it's a example of a document end point)


C:\projects\workspace\cal-ws\client>wscompile -gen:client -f:documentliteral -mapping ./WebContent/META-INF/jaxrpc-mapping.xml -keep -d ./WebContent/WEB-INF/classes -s ./src -nd ./WebContent/WEB-INF/wsdl config.xml


wscompile needs a config file:



<configuration
xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">

<wsdl location="http://zimbob:8080/calws/HelloWorldService?wsdl"
packageName="com.comira.cal.ws">
</wsdl>

</configuration>


JAX-RPC Mapping Files
The web service client must have access to the same mapping information as described for the EJB service endpoint or the Java service endpoint. The jaxrpc mapping file must be part of the deployment, it cannot be obtained at runtime.

The standard deployment descriptor for web components web.xml, declares the service reference.



<web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<servlet>
<servlet-name>HelloWorldWSServlet</servlet-name>
<servlet-class>com.comira.cal.client.ws.HelloWorldWSServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HelloWorldWSServlet</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>

<service-ref>
<service-ref-name>service/HelloWorldServiceJSE</service-ref-name>
<service-interface>com.comira.cal.ws.HelloWorldService</service-interface>
<wsdl-file>META-INF/HelloWorldService.wsdl</wsdl-file>
<jaxrpc-mapping-file>META-INF/jaxrpc-mapping.xml</jaxrpc-mapping-file>
</service-ref>

</web-app>


Here is a simple example, that shows how a servlet does a lookup of the service interface, then obtains the desired port, and finally invokes sayHello on the service endpoint interface.



/**
* $Header: Exp$
* (c) CATSTesting 2007
*
* Created by: graham
* Feb 7, 2007
*/
package com.comira.cal.client.ws;

import java.io.IOException;
import java.io.PrintWriter;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.comira.cal.ws.HelloWorldService;
import com.comira.cal.ws.IHelloWorldWS;

public class HelloWorldWSServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
processRequest(req, resp);
}

protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
processRequest(req, resp);
}

protected void processRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String name = req.getParameter("name");
String info = getSayHello(name);

PrintWriter out = resp.getWriter();
out.print(info);
out.close();
}

/** Get the contact info from the JSE service */
public String getSayHello(String name) throws ServletException
{
try
{
InitialContext iniCtx = new InitialContext();
HelloWorldService service = (HelloWorldService)iniCtx.lookup("java:comp/env/service/HelloWorldServiceJSE");
IHelloWorldWS endpoint = service.getIHelloWorldWSPort();
String info = endpoint.sayHello(name);
return info;
}
catch (NamingException e)
{
throw new ServletException(e);
}
catch (Exception e)
{
throw new ServletException("Cannot invoke webservice", e);
}
}
}



The client jar breaks down like so:



|---- META-INF
| |
| |- HelloWorldService.wsdl
| |- jaxrpc-mapping.xml
|
|---- WEB-INF
|
|- web.xml
|- /classes


The jaxrpc-mapping.xml is exactly the same as the server endpoint's one and the HelloWorldService.wsdl required the changing of the location of the service.

A call to: http://zimbob:8080/calclientws/hello?name=jay
Resulted in:



Hello World: jay on Wed Feb 07 15:25:52 PST 2007