You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Daniel López <D....@uib.es> on 2006/01/18 14:22:38 UTC

Web Service requests dispatcher

Hi all,

First of all, let me say I've been browsing thoroughly the documentation 
and the web looking for some way to do what I want, but I'm new to web 
services, so may be the answer is too simple or that it's not the way 
things should be done. In that case, I apologise in advance ;).

Coming from a web application background and having used the servlet 
controller approach for years, I was looking to do the same sort of 
thing with web services: Meaning that one class handles the requests, 
handling global aspects of the service, and forwards the call to the 
appropriate class or classes that do implement the real business logic.
The reasoning behind that is that I want to be able to make the 
implementation of the service, the name of the methods, classes etc, 
independent of the "interface" so I can change from one class to 
another, add optional parameters, re-use the same method etc and all the 
things we already do in our web apps.

The problem is that no matter how I try, it seems I have to put the real 
name of the methods in the wsdd file because otherwise I get errors, lie 
"java.lang.Exception: Couldn't find a matching Java operation for WSDD 
operation"... I tried playing with operation's name and qname but to no 
avail... I also browsed the samples and all the articles I could find 
and all of them see to follow the same trend of having the name of the 
operation be the name of the method of a Java class... so I started to 
wonder if I'm trying to fit a round peg into a square hole her, so to say.

So, is it possible to describe several operations in an wsdd and then 
have all those operations call the same class and let that class read 
the "request" (be it the document, or the Element[]...) and decide which 
classes to call?

Thanks for your time,
D.
-------------------------------------------
Daniel Lopez Janariz (D.Lopez@uib.es)
Web Services
Centre for Information and Technology
Balearic Islands University
(SPAIN)
-------------------------------------------

Re: Web Service requests dispatcher

Posted by Daniel López <D....@uib.es>.
Hi again,

I understand. The reason why is because I wanted to follow the same 
approach we are using for web applications, so we can leverage our 
knowledge and methodology.
In our web apps, we define a single servlet controller that receives all 
requests and then, depending on the URL decides to call one or more 
classes to perform its job.
So it goes like that:
GetInfor.myapp is sent to the controller that checks the configuration:

<XMLOPERATION
   NAME="GetInfor"
   DESCRIPTION="..."
   CLASSNAME="org.leaf.XMLOperation"
   XSLT_SOURCE="xsl/app.xsl"
 >
   <SOURCES GLOBAL_TAG="XML_APP">
     <SOURCE XML_SOURCE="plsql://DBPool/XML$MyPackage.MyProcedure"/>
     <SOURCE XML_SOURCE="xml/MyFile.xml"/>
   </SOURCES>
</XMLOPERATION>

and then calls a PLSQL procedure, gets the XML, joins that XML with the 
static file and finally converts this to HTML, WML or whatever using the 
specified XSL.

This works very nicely for us and we are able to re-use the "xml 
sources" in different operations, and changing the interface of the 
classes or PLSQL procedures does not affect the URL.

And that was more or less what I was looking for in Web Services. I 
understand I could create a general "dispatch" operation in a global 
class and then add an "action" parameter to specify the configured 
operation I want to perform, but then I would lose the nice thing of 
having a WSDL that can be checked by web service clients to see exactly 
the calls that they can make. Or may be there is a way and I don't know 
it, as I'm a novice in the WS world :). I also wanted to make the 
"idiom" of calling our web services as "common" as possible, and using 
the operation name seems to be the usual way of specifying the request.

All in all, I would like to avoid having to have my WS interface tied to 
the interfaces of my java classes implementing them. As I said, may be 
I'm still thinking about the web app world and that's the problem ;).

Thanks,
D.




Anne Thomas Manes escribió:

> Daniel,
> 
> The operation name and the method name do not need to be the same. You 
> use the <operation> definition in the WSDD to map the method name to an 
> operation name (qname). But you can map a method to only one operation.
> 
> Also note that when using the java:MSG provider, your operation may have 
> only one input parameter and one return value. It assumes you are using 
> document/literal style, and it always converts the input and output 
> messages into DOM. If you want Axis to perform XML to Java mapping for 
> you, then you want to use the java:RPC provider.
> 
> Can you explain to us why you want to be able to define the input and 
> output parameters, but you don't want to let Axis perform your dispatching?
> 
> May I also suggest that given the amount of control you want, you should 
> be defining your service using WSDL rather than WSDD.
> 
> Anne
> 


Re: Web Service requests dispatcher

Posted by Anne Thomas Manes <at...@gmail.com>.
Daniel,

The operation name and the method name do not need to be the same. You use
the <operation> definition in the WSDD to map the method name to an
operation name (qname). But you can map a method to only one operation.

Also note that when using the java:MSG provider, your operation may have
only one input parameter and one return value. It assumes you are using
document/literal style, and it always converts the input and output messages
into DOM. If you want Axis to perform XML to Java mapping for you, then you
want to use the java:RPC provider.

Can you explain to us why you want to be able to define the input and output
parameters, but you don't want to let Axis perform your dispatching?

May I also suggest that given the amount of control you want, you should be
defining your service using WSDL rather than WSDD.

Anne

On 1/19/06, Daniel López <D....@uib.es> wrote:
>
> Hi Anne,
> Thanks for your suggestions, I tried the java:MSG provider and even
> though it goes one step further towards what I want to accomplish, I'm
> still limited to make it so the name of the operation and method in the
> Java class are the same, which I want to avoid if possible. Is there any
> way I can change that?
>
> I also had already considered the workaround you suggest with the
> submitRequest generic operation, but then I would lose the extra
> features that I can get from defining each operation separatedly in the
> wsdd, each one with its parameters and types specified etc.
>
> So I would like to be able to do something like...
> ...
> <service name="TestWebService" provider="java:MSG">
>    <parameter name="className" value="test.TestWS" />
>    <parameter name="scope" value="Application" />
>    <parameter name="allowedMethods" value="process" />
>    <operation
>      name="getInfo"
>      qname="ns:getInfo"
>      returnQName="return"
>      returnType="rtns:normalizedString"
>      xmlns:rtns="http://www.w3.org/2001/XMLSchema"
>      xmlns:ns="http://soapinterop.org/xsd"
>     >
>       <parameter name="id" type="tns:string"
>                  xmlns:tns="http://www.w3.org/2001/XMLSchema"
>       />
>    </operation>
>    <operation
>      name="getMoreInfo"
>      qname="ns:getMoreInfo"
>      returnQName="return"
>      returnType="rtns:normalizedString"
>      xmlns:rtns="http://www.w3.org/2001/XMLSchema"
>      xmlns:ns="http://soapinterop.org/xsd"
>     >
>       <parameter name="id" type="tns:string"
>                  xmlns:tns="http://www.w3.org/2001/XMLSchema"
>       />
>       <parameter name="anotherParam" type="tns:string"
>                  xmlns:tns="http://www.w3.org/2001/XMLSchema"
>       />
>    </operation>
>    ...
>   </service>
> ...
> But have both the operations,"getInfo" and "getMoreInfo" be implemented
> in a single Java method like
> /**
> *
> */
> public Element [] dispath(Element [] elems)
> {
>    // Parse elems and see if the requested operation is getInfo
>    // or getMoreInfo...
> }
>
> Is this possible at all?
> Thanks,
> D.
>
>
> Anne Thomas Manes escribió:
> > You can have complete control over dispatching if you use a message
> > style service with the java:MSG provider. Alternatively, you can define
> > a generic operation (something like "submitRequest") which will always
> > be dispatched to your controller.
> >
> > Anne
>
>

Re: Web Service requests dispatcher

Posted by Daniel López <D....@uib.es>.
Hi Anne,
Thanks for your suggestions, I tried the java:MSG provider and even
though it goes one step further towards what I want to accomplish, I'm
still limited to make it so the name of the operation and method in the
Java class are the same, which I want to avoid if possible. Is there any
way I can change that?

I also had already considered the workaround you suggest with the
submitRequest generic operation, but then I would lose the extra
features that I can get from defining each operation separatedly in the
wsdd, each one with its parameters and types specified etc.

So I would like to be able to do something like...
...
<service name="TestWebService" provider="java:MSG">
   <parameter name="className" value="test.TestWS" />
   <parameter name="scope" value="Application" />
   <parameter name="allowedMethods" value="process" />
   <operation
     name="getInfo"
     qname="ns:getInfo"
     returnQName="return"
     returnType="rtns:normalizedString"
     xmlns:rtns="http://www.w3.org/2001/XMLSchema"
     xmlns:ns="http://soapinterop.org/xsd"
    >
      <parameter name="id" type="tns:string"
                 xmlns:tns="http://www.w3.org/2001/XMLSchema"
      />
   </operation>
   <operation
     name="getMoreInfo"
     qname="ns:getMoreInfo"
     returnQName="return"
     returnType="rtns:normalizedString"
     xmlns:rtns="http://www.w3.org/2001/XMLSchema"
     xmlns:ns="http://soapinterop.org/xsd"
    >
      <parameter name="id" type="tns:string"
                 xmlns:tns="http://www.w3.org/2001/XMLSchema"
      />
      <parameter name="anotherParam" type="tns:string"
                 xmlns:tns="http://www.w3.org/2001/XMLSchema"
      />
   </operation>
   ...
  </service>
...
But have both the operations,"getInfo" and "getMoreInfo" be implemented
in a single Java method like
/**
*
*/
public Element [] dispath(Element [] elems)
{
   // Parse elems and see if the requested operation is getInfo
   // or getMoreInfo...
}

Is this possible at all?
Thanks,
D.


Anne Thomas Manes escribió:
> You can have complete control over dispatching if you use a message 
> style service with the java:MSG provider. Alternatively, you can define 
> a generic operation (something like "submitRequest") which will always 
> be dispatched to your controller.
> 
> Anne


Re: Web Service requests dispatcher

Posted by Anne Thomas Manes <at...@gmail.com>.
You can have complete control over dispatching if you use a message style
service with the java:MSG provider. Alternatively, you can define a generic
operation (something like "submitRequest") which will always be dispatched
to your controller.

Anne

On 1/18/06, Daniel López <D....@uib.es> wrote:
>
> Hi all,
>
> First of all, let me say I've been browsing thoroughly the documentation
> and the web looking for some way to do what I want, but I'm new to web
> services, so may be the answer is too simple or that it's not the way
> things should be done. In that case, I apologise in advance ;).
>
> Coming from a web application background and having used the servlet
> controller approach for years, I was looking to do the same sort of
> thing with web services: Meaning that one class handles the requests,
> handling global aspects of the service, and forwards the call to the
> appropriate class or classes that do implement the real business logic.
> The reasoning behind that is that I want to be able to make the
> implementation of the service, the name of the methods, classes etc,
> independent of the "interface" so I can change from one class to
> another, add optional parameters, re-use the same method etc and all the
> things we already do in our web apps.
>
> The problem is that no matter how I try, it seems I have to put the real
> name of the methods in the wsdd file because otherwise I get errors, lie
> "java.lang.Exception: Couldn't find a matching Java operation for WSDD
> operation"... I tried playing with operation's name and qname but to no
> avail... I also browsed the samples and all the articles I could find
> and all of them see to follow the same trend of having the name of the
> operation be the name of the method of a Java class... so I started to
> wonder if I'm trying to fit a round peg into a square hole her, so to say.
>
> So, is it possible to describe several operations in an wsdd and then
> have all those operations call the same class and let that class read
> the "request" (be it the document, or the Element[]...) and decide which
> classes to call?
>
> Thanks for your time,
> D.
> -------------------------------------------
> Daniel Lopez Janariz (D.Lopez@uib.es)
> Web Services
> Centre for Information and Technology
> Balearic Islands University
> (SPAIN)
> -------------------------------------------
>