java: December 2005 Archives

Web Services II

| | Comments (0) | TrackBacks (0)

leaving my work with this not very dynamic axis solution, i contuined experimenting with this topic.

WSDL4J and WSIF seemed to bring me to another stage.
my idea for experimenting was, to insert the url of a wsdl-file in a html-form, read its service-definitions and present the contents with the possibility of invoking single operations along with their parameters.

and this the result of my thoughts:

1. input.html: basic and uncomfortable form:

Enter URL to your favourite WSDL:

<input type="text" name="wsdluri" size="150 ″button type="submit">Explore it !

2. the requests finishes in the arms of a servlet. here the url-string is forwarded to some methods which use the wsdl4j-api.
basically this:

WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
Definition def = reader.readWSDL(wsdlurl);
session.setAttribute("services",def.getServices().values().iterator());
String target = response.encodeRedirectURL("listing.jsp");
response.sendRedirect(target);

3. the jsp processes the iterator and presents all available operations and so on.
this also implements wsdl4j-api. i moved code to a wsdl-helper class which i use on the jsp. i know... java code on jsp = bad style, but in experimental-mode, who cares

that is the main part without out.println´s of the listing.jsp:

Iterator iterator = (Iterator)session.getAttribute("services");
while (iterator.hasNext())
{
Service service = (Service)iterator.next();
QName qname = service.getQName();
Port[] ports = util.getPortsFromService(service);
for (int i = 0; i < ports.length; i++)
{
Port port = ports[i];
Operation [] ops = util.getOperationsForPort(port);
for (int j = 0; j < ops.length; j++)
{
Operation op = ops[j];
List order = op.getParameterOrdering();
if (order!=null && order.size()>0)
{
Iterator orderit = order.iterator();
while(orderit.hasNext())
{
String param = (String)orderit.next();
}
}
//here onclick: set hidden fields
document.forms[0].porttype.value='util.getPorttype(port).getQName().getLocalPart()';document.forms[0].porttypeNS.value='util.getPorttype(port).getQName().getNamespaceURI()';document.forms[0].service.value='qname.getLocalPart()';document.forms[0].serviceNS.value='qname.getNamespaceURI()';document.forms[0].operation.value='op.getName()';document.forms[0].actionparam.value='invoke';document.forms[0].submit();


the setting of some hidden fields is at the moment required for getting the proper ws.
this form also gets handled from the servlet mentioned above.

4. the servlet know calls the part with the wsif stuff

important code snips are:

create wsif-connection:


WSIFService wsifService = WSIFServiceFactory.newInstance().getService(def,serviceNS,service,porttypeNS,porttype);
WSIFPort wsifPort = wsifService.getPort();
WSIFOperation wsifOp = wsifPort.createOperation(operation,inputName,outputName);
WSIFMessage inMsg = wsifOp.createInputMessage();
WSIFMessage ouMsg = wsifOp.createOutputMessage();
WSIFMessage fault = wsifOp.createFaultMessage();

set parameters if needed

inMsg.setObjectPart(part.getName(),paramMap.get(part.getName()));

execute:


if (wsifOp.executeRequestResponseOperation(inMsg,ouMsg,fault))
{
java.util.Iterator iter = ouMsg.getPartNames();
while(iter.hasNext())
{
String name = (String)iter.next();
return (String)ouMsg.getObjectPart(name);
}
}

the returned string is presented on a jsp again.

Web Services I

| | Comments (0) | TrackBacks (0)

started some web services experience with axis, wsdl4j and wsif.
i decided to do some try and error on this topic after downloading the eclipse WTP project and clicking through the various wizards. generating a service and a serviceclient with axis and wtp was very easy, i just followed this !
this is the simple class i used to create a service.


public class Answer
{

public String getGoodbye()
{
return "So long and thanks for all the fish";
}

}

next step was to get the client working.i used wsdl2java wizard to created the client stubs. Then used the code on a jsp


AnswerProxy proxy = new AnswerProxy();
Answer answer = proxy.getAnswer();
out.println(answer.getGoodbye());

last step was to deploy both on tomcat5 and watch the output in the browser.
very easy so far. but not very dynamically.

About this Archive

This page is a archive of entries in the java category from December 2005.

java: November 2006 is the next archive.

Find recent content on the main index or look in the archives to find all content.

java: December 2005: Monthly Archives

Powered by Movable Type 4.0