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.

Categories

,

0 TrackBacks

Listed below are links to blogs that reference this entry: Web Services II.

TrackBack URL for this entry: http://www.innoq.com/mt4/mt-tb.cgi/2453

Leave a comment

About this Entry

This page contains a single entry by Christian Albrecht published on December 21, 2005 9:00 AM.

Web Services I was the previous entry in this blog.

Spring Discussion is the next entry in this blog.

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

Powered by Movable Type 4.0