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 Dan Hobbs <da...@jumar-solutions.com> on 2005/02/08 18:10:53 UTC

Newbie with EJB/web service problem

Hello, I'm new to web services and I'm having real trouble exposing an EJB
as a web service. I'm not sure whether what I'm trying to do is impossible
though, or whether I am approaching this in entirely the wrong way...

I am using Axis 1.2RC2 on Tomcat 4.1.31/Windows 2000 Professional. I am
familiar enough with Tomcat, it's just web services where my head is
spinning because there seem to be so many ways of doing things!

I also have the option of putting Axis within JBoss (I have v4.0.0) (I have
removed the jboss-ws4ee.sar folder and got Axis working OK within JBoss).

All OK so far, but when I try to do something useful...

My task is to expose an EJB (which has been generated by a 3rd party, and I
can't see the source of the runtime helper classes it uses). I successfully
ran Java2WSDL (on the EJB remote interface) to create the .wsdd but received
warnings about some of the objects used for I/O not having default
constructors so not being mappable to XML. I cannot therefore run WSDL2Java
on the .wsdd to create the endpoint stub.

I have considered writing a wrapper EJB whose call method has a similar
signature, but has equivalent classes with default constructors, but I'm not
sure whether that is feasible because I don't know how the clients of the
EJB will be built.

I have also thought about putting a service-endpoint into ejb-jar.xml, but
by now I am so confused I'm not sure which direction I should be heading.

If anyone has any advice on whether this is possible, and what I should be
doing, then it would be greatly appreciated.

Regards,

Dan




Re: Newbie with EJB/web service problem

Posted by Peter Smith <pe...@fast.fujitsu.com.au>.
>I have also thought about putting a service-endpoint into ejb-jar.xml, but
>by now I am so confused I'm not sure which direction I should be heading.
>  
>
I haven't done any more than expose a simple EJB like in the Axis sample 
(I used Interstage EJB container with Axis.war deployed to it). If my 
understanding is correct, the Axis "EJBProvider" is not much more that a 
server-side EJB client program which just gets the EJB Home/Remote etc 
(where the info needed to do this is configured in the wsdd) and calls 
apropriate methods that the SLSB/wsdd exposes.

On the other hand, the <service-endpoint> in the ejb-jar.xml is 
something new for EJB 2.1 (see JSR 921).  So my understanding is 
<service-endpoint> is only going to mean anything for a J2EE1.4 
compliant container. Also, if you have removed the containers own web 
service support jars and substituted Axis, I doubt <service-endpoint> is 
going to work properly.

(Please can somebody correct me if I am wrong!)

Peter.

This is an email from Fujitsu Australia Software Technology Pty Ltd, ABN 27 003 693 481. It is confidential to the ordinary user of the email address to which it was addressed and may contain copyright and/or legally privileged information. No one else may read, print, store, copy or forward all or any of it or its attachments. If you receive this email in error, please return to sender. Thank you.

If you do not wish to receive commercial email messages from Fujitsu Australia Software Technology Pty Ltd, please email unsubscribe@fast.fujitsu.com.au



Re: rpc/literal vs document/literal, and returning a list of objects

Posted by Eugene Shershnev <sh...@gmail.com>.
Just one note here.
If you require interoperability, you shouldn't use rpc/literal since .Net
doesn't support it.
You're better off with wrapped/literal which is "a flavour" of
document/literal.

----- Original Message ----- 
From: "Dan Hobbs" <da...@jumar-solutions.com>
To: <ax...@ws.apache.org>
Sent: Tuesday, February 15, 2005 11:24a
Subject: rpc/literal vs document/literal, and returning a list of objects


> Hello all.
>
> I am really struggling to know whether I am heading in the right direction
> with this project, so any advice would be greatly appreciated.
>
> The requirement: a WS-I-compliant web service to wrap an EJB which returns
a
> java.util.Vector of objects.
>
> Firstly, I think the WS-I compliance bit means I have two choices:
> rpc/literal or document/literal. I read in a mail from Anne Thomas Manes
> that rpc/literal is "not recommended" but I'm not sure why.
>
> Secondly, the List to be returned contains a JavaBean, which itself
contains
> two JavaBeans, one with two double and one String property, the other with
> one String property. I gather there is some issue with returning arrays,
but
> I don't know which message style that applies to. I control the format of
> the response, however, so this can be changed. However, the fact remains
> that either a set of simple arrays or a java.util.Collection must be
> returned somehow.
>
> The method exposed as a web service takes three parameters (Short, String,
> String) and I'm unclear on whether these three need to be kept separate as
> they are, or grouped together into one class (e.g.
> WebsrvcOrderInLmsImportParams).
>
> At this point I am thoroughly confused by reading what seems to be
> conflicting advice. If anyone can see straight away which route I should
be
> taking, or know of a relevant article on the web, please let me know.
>
> I attach my deploy.wsdd and Java client, which have been modified too many
> times now and I've managed to stop the thing working altogether!
>
> Many thanks,
>
> Dan
>
> ---------
>
> Deploy.wsdd:
>
> <deployment xmlns="http://xml.apache.org/axis/wsdd/"
>             xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
>
> <service name="DanWS2" provider="java:RPC">
>          style="rpc"
>          use="literal">
>   <parameter name="className" value="DanWS2"/>
>   <parameter name="allowedMethods" value="*"/>
>
>   <operation name="websrvcOrderInLms"
> returnQname="ns:websrvcOrderInLmsResponse" returnType="ns:java.util.List">
>     <parameter qname="ns:nummer1" type="xsd:short" mode="IN"/>
>     <parameter qname="ns:userIntfNumb" type="xsd:string" mode="IN"/>
>     <parameter qname="ns:dateCrtd" type="xsd:string" mode="IN"/>
>   </operation>
>
>   <beanMapping qname="ns:GrpExp"
xmlns:ns="http://www.jumar-solutions.com/"
>                languageSpecificType="java:GrpExp"/>
>   <beanMapping qname="ns:StorOrdr"
> xmlns:ns="http://www.jumar-solutions.com/"
>                languageSpecificType="java:StorOrdr"/>
>   <beanMapping qname="ns:OrdrStat"
> xmlns:ns="http://www.jumar-solutions.com/"
>                languageSpecificType="java:OrdrStat"/>
>
>  </service>
>
> </deployment>
>
>
> TestClient.java:
>
> import org.apache.axis.client.Call;
> import org.apache.axis.client.Service;
> import javax.xml.namespace.QName;
> import org.apache.axis.Constants;
> import org.apache.axis.MessageContext;
> import org.apache.axis.server.AxisServer;
> import java.util.List;
>
> public class TestClient2
> {
>    public static void main(String [] args) {
>        MessageContext msgContext = new MessageContext(new AxisServer());
>
>      String endpoint =
>         "http://localhost:8080/axis/services/DanWS2";
>      String nameSpaceUri = "http://soapinterop.org";
>      String operation = "websrvcOrderInLms";
>
>        try {
>
>            Service  service = new Service();
>            Call     call    = (Call) service.createCall();
>
>            call.setTargetEndpointAddress( new java.net.URL(endpoint) );
>            call.setOperation(new QName(nameSpaceUri, "DanWS2"),
operation);
>
>            // parameters
>            Short nummer1 = new Short((short)1);
>            String userIntfNumb = "10015";
>            String dateCrtd = "20041230212749000000";
>
>            List ret = (List) call.invoke( new Object[] { nummer1,
> userIntfNumb, dateCrtd } );
>
>            System.out.println("Sent " + nummer1 + "," + userIntfNumb + ","
+
> dateCrtd + ". Got: " + ret);
>        } catch (Exception e) {
>          e.printStackTrace();
>        }
>    }
> }
>
>
>


Re: rpc/literal vs document/literal, and returning a list of objects

Posted by Praveen Peddi <pp...@contextmedia.com>.
But what about the doc/literal issues related to returning array of beans. 
Wouldn't Dan hit the wall at some point. Atleast I hit the wall when I tried 
to move towards doc/literal. We were using rpc/encoded style before and 
everything was working great. When I read that rpc/encoded has permance 
problems I tried to move to doc/literal style (actually wrapped/literal) but 
I was stuck with returning arrays issue. My .NET client doesn't serialize 
the beans at all. I read the Eric's thread and other email threads related 
to this issue but could not really come up with a solution.

Praveen
----- Original Message ----- 
From: "Anne Thomas Manes" <at...@gmail.com>
To: <ax...@ws.apache.org>
Sent: Tuesday, February 15, 2005 12:47 PM
Subject: Re: rpc/literal vs document/literal, and returning a list of 
objects


> And just to clarify...
>
> The difference between doc/literal and wrapped/literal is in the way
> you invoke the service -- the contents on the wire (the structure of
> the SOAP message) will be identical.
>
> In doc/literal, you input an object (javabean), and you return an
> object (javabean). In wrapped/literal, you input parameters, and you
> return an object. Wrapped/literal is a programming convention that
> make doc/literal look like rpc/literal.
>
> Don't use rpc/literal because .NET doesn't support it.
>
> Regards,
> Anne
>
>
> On Tue, 15 Feb 2005 16:55:36 +0000, Tom Oinn <tm...@ebi.ac.uk> wrote:
>> Dan,
>>
>> My suggestion would be to use document / literal style. The data
>> structure you describe is easy to define as an XML schema (by hand if
>> you must, but I'd use something like XMLSpy). You can then create the
>> requisite WSDL file referencing this schema, generate the server side
>> Java classes against this and modify them to call the appropriate
>> methods on your existing EJB.
>>
>> If you're using doc/literal style you'll also have to build a (very
>> simple) XSD type for your three inputs, in this case a simple sequence
>> with minoccurs and maxoccurs attributes set to 1.
>>
>> I would definitely start with WSDL in any case, given that the WSDL
>> defines whether your service is WS-I compliant.
>>
>> HTH,
>>
>> Tom
>>
> 


Re: rpc/literal vs document/literal, and returning a list of objects

Posted by Anne Thomas Manes <at...@gmail.com>.
And just to clarify...

The difference between doc/literal and wrapped/literal is in the way
you invoke the service -- the contents on the wire (the structure of
the SOAP message) will be identical.

In doc/literal, you input an object (javabean), and you return an
object (javabean). In wrapped/literal, you input parameters, and you
return an object. Wrapped/literal is a programming convention that
make doc/literal look like rpc/literal.

Don't use rpc/literal because .NET doesn't support it.

Regards,
Anne


On Tue, 15 Feb 2005 16:55:36 +0000, Tom Oinn <tm...@ebi.ac.uk> wrote:
> Dan,
> 
> My suggestion would be to use document / literal style. The data
> structure you describe is easy to define as an XML schema (by hand if
> you must, but I'd use something like XMLSpy). You can then create the
> requisite WSDL file referencing this schema, generate the server side
> Java classes against this and modify them to call the appropriate
> methods on your existing EJB.
> 
> If you're using doc/literal style you'll also have to build a (very
> simple) XSD type for your three inputs, in this case a simple sequence
> with minoccurs and maxoccurs attributes set to 1.
> 
> I would definitely start with WSDL in any case, given that the WSDL
> defines whether your service is WS-I compliant.
> 
> HTH,
> 
> Tom
>

Re: rpc/literal vs document/literal, and returning a list of objects

Posted by Tom Oinn <tm...@ebi.ac.uk>.
Dan,

My suggestion would be to use document / literal style. The data 
structure you describe is easy to define as an XML schema (by hand if 
you must, but I'd use something like XMLSpy). You can then create the 
requisite WSDL file referencing this schema, generate the server side 
Java classes against this and modify them to call the appropriate 
methods on your existing EJB.

If you're using doc/literal style you'll also have to build a (very 
simple) XSD type for your three inputs, in this case a simple sequence 
with minoccurs and maxoccurs attributes set to 1.

I would definitely start with WSDL in any case, given that the WSDL 
defines whether your service is WS-I compliant.

HTH,

Tom

rpc/literal vs document/literal, and returning a list of objects

Posted by Dan Hobbs <da...@jumar-solutions.com>.
Hello all.

I am really struggling to know whether I am heading in the right direction
with this project, so any advice would be greatly appreciated.

The requirement: a WS-I-compliant web service to wrap an EJB which returns a
java.util.Vector of objects.

Firstly, I think the WS-I compliance bit means I have two choices:
rpc/literal or document/literal. I read in a mail from Anne Thomas Manes
that rpc/literal is "not recommended" but I'm not sure why.

Secondly, the List to be returned contains a JavaBean, which itself contains
two JavaBeans, one with two double and one String property, the other with
one String property. I gather there is some issue with returning arrays, but
I don't know which message style that applies to. I control the format of
the response, however, so this can be changed. However, the fact remains
that either a set of simple arrays or a java.util.Collection must be
returned somehow.

The method exposed as a web service takes three parameters (Short, String,
String) and I'm unclear on whether these three need to be kept separate as
they are, or grouped together into one class (e.g.
WebsrvcOrderInLmsImportParams).

At this point I am thoroughly confused by reading what seems to be
conflicting advice. If anyone can see straight away which route I should be
taking, or know of a relevant article on the web, please let me know.

I attach my deploy.wsdd and Java client, which have been modified too many
times now and I've managed to stop the thing working altogether!

Many thanks,

Dan

---------

Deploy.wsdd:

<deployment xmlns="http://xml.apache.org/axis/wsdd/"
            xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

<service name="DanWS2" provider="java:RPC">
         style="rpc"
         use="literal">
  <parameter name="className" value="DanWS2"/>
  <parameter name="allowedMethods" value="*"/>
  
  <operation name="websrvcOrderInLms"
returnQname="ns:websrvcOrderInLmsResponse" returnType="ns:java.util.List">
    <parameter qname="ns:nummer1" type="xsd:short" mode="IN"/>
    <parameter qname="ns:userIntfNumb" type="xsd:string" mode="IN"/>
    <parameter qname="ns:dateCrtd" type="xsd:string" mode="IN"/>
  </operation>

  <beanMapping qname="ns:GrpExp" xmlns:ns="http://www.jumar-solutions.com/"
               languageSpecificType="java:GrpExp"/>
  <beanMapping qname="ns:StorOrdr"
xmlns:ns="http://www.jumar-solutions.com/"
               languageSpecificType="java:StorOrdr"/>
  <beanMapping qname="ns:OrdrStat"
xmlns:ns="http://www.jumar-solutions.com/"
               languageSpecificType="java:OrdrStat"/>

 </service>

</deployment>


TestClient.java:

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
import org.apache.axis.Constants;
import org.apache.axis.MessageContext;
import org.apache.axis.server.AxisServer;
import java.util.List;

public class TestClient2
{
   public static void main(String [] args) {
       MessageContext msgContext = new MessageContext(new AxisServer());

     String endpoint =
        "http://localhost:8080/axis/services/DanWS2";
     String nameSpaceUri = "http://soapinterop.org";
     String operation = "websrvcOrderInLms";

       try {

           Service  service = new Service();
           Call     call    = (Call) service.createCall();

           call.setTargetEndpointAddress( new java.net.URL(endpoint) );
           call.setOperation(new QName(nameSpaceUri, "DanWS2"), operation);

           // parameters
           Short nummer1 = new Short((short)1);
           String userIntfNumb = "10015";
           String dateCrtd = "20041230212749000000";

           List ret = (List) call.invoke( new Object[] { nummer1,
userIntfNumb, dateCrtd } );

           System.out.println("Sent " + nummer1 + "," + userIntfNumb + "," +
dateCrtd + ". Got: " + ret);
       } catch (Exception e) {
         e.printStackTrace();
       }
   }
}




RE: Newbie with EJB/web service problem

Posted by Dan Hobbs <da...@jumar-solutions.com>.
Hello again. Thanks for your responses.

I have run the samples/ejb exercise, and the EJBs were deployed OK (on the
face of it - they appear in the Axis list of services offered, and I can
look at xxx?wsdl ok) and the SimpleBean said hello back to me no problem. I
couldn't get my client to talk to the NiceThingsBean, though. I think this
is due to either the JNDI name or the namespace given in the .wsdd for the
NiceThingsBean, but I'm not that far with my learning yet that I can fix
it...

Here is the response from Java2WSDL when I run it against the remote
interface of the EJB I want to expose. Please forgive me if I'm being thick
here. :-)

Regards,

Dan

------------------- response from Java2WSDL ----------------------

C:\work\ws>java org.apache.axis.wsdl.Java2WSDL -o sch.wsdl
-l"http://localhost:8080/axis/services/sch" -n "urn:sch" -p"sch" "urn:sch"
sch.WEBSRVC_ORDER_IN_LMS_Remote
17:01:10,736 WARN   - The class com.ca.gen65.vwrt.vdf.VDF does not contain a
default constructor, which is a requirement for a bean class.  The class
cannot beconverted into an xml schema type.  An xml schema anyType will be
used to define this class in the wsdl file.
17:01:10,814 WARN   - The class java.lang.Character is defined in a java or
javax package and cannot be converted into an xml schema type.  An xml
schema anyType will be used to define this class in the wsdl file.
17:01:10,970 WARN   - The class char is not a bean class and cannot be
converted into an xml schema type.  An xml schema anyType will be used to
define this class in the wsdl file.
17:01:11,002 WARN   - The class java.lang.StringBuffer is defined in a java
or javax package and cannot be converted into an xml schema type.  An xml
schema anyType will be used to define this class in the wsdl file.
17:01:11,033 WARN   - The class com.ca.gen65.vwrt.IExportView does not
contain a default constructor, which is a requirement for a bean class.  The
class cannot be converted into an xml schema type.  An xml schema anyType
will be used to define this class in the wsdl file.
17:01:11,033 WARN   - The class javax.ejb.EJBHome is defined in a java or
javaxpackage and cannot be converted into an xml schema type.  An xml schema
anyTypewill be used to define this class in the wsdl file.
17:01:11,033 WARN   - The class javax.ejb.Handle is defined in a java or
javax package and cannot be converted into an xml schema type.  An xml
schema anyType will be used to define this class in the wsdl file.
17:01:11,033 WARN   - The class javax.ejb.EJBObject is defined in a java or
javax package and cannot be converted into an xml schema type.  An xml
schema anyType will be used to define this class in the wsdl file.

C:\work\ws>

> -----Original Message-----
> From: Venkat Reddy [mailto:vreddyp@gmail.com]
> Sent: 09 February 2005 12:07
> To: axis-user@ws.apache.org
> Subject: Re: Newbie with EJB/web service problem
> 
> Just to ensure that the environment is alright, did you try building
> and running the samples/ejb in axis?
> 
> As you mentioned, the issue could be with code generation (java2wsdl,
> wsdl2java). What errors did you get when you ran WSDL2Java? Need to
> resolve issues with the EJB classes to run Java2WSDL and WSDL2Java
> properly.
> 
> In the worst case, you might need to handcraft the WSDL file and run
> WSDL2Java.
> 
> -- Venkat
> 
> 
> 
> On Tue, 8 Feb 2005 17:10:53 -0000, Dan Hobbs
> <da...@jumar-solutions.com> wrote:
> > Hello, I'm new to web services and I'm having real trouble exposing an
> EJB
> > as a web service. I'm not sure whether what I'm trying to do is
> impossible
> > though, or whether I am approaching this in entirely the wrong way...
> >
> > I am using Axis 1.2RC2 on Tomcat 4.1.31/Windows 2000 Professional. I am
> > familiar enough with Tomcat, it's just web services where my head is
> > spinning because there seem to be so many ways of doing things!
> >
> > I also have the option of putting Axis within JBoss (I have v4.0.0) (I
> have
> > removed the jboss-ws4ee.sar folder and got Axis working OK within
> JBoss).
> >
> > All OK so far, but when I try to do something useful...
> >
> > My task is to expose an EJB (which has been generated by a 3rd party,
> and I
> > can't see the source of the runtime helper classes it uses). I
> successfully
> > ran Java2WSDL (on the EJB remote interface) to create the .wsdd but
> received
> > warnings about some of the objects used for I/O not having default
> > constructors so not being mappable to XML. I cannot therefore run
> WSDL2Java
> > on the .wsdd to create the endpoint stub.
> >
> > I have considered writing a wrapper EJB whose call method has a similar
> > signature, but has equivalent classes with default constructors, but I'm
> not
> > sure whether that is feasible because I don't know how the clients of
> the
> > EJB will be built.
> >
> > I have also thought about putting a service-endpoint into ejb-jar.xml,
> but
> > by now I am so confused I'm not sure which direction I should be
> heading.
> >
> > If anyone has any advice on whether this is possible, and what I should
> be
> > doing, then it would be greatly appreciated.
> >
> > Regards,
> >
> > Dan
> >
> >



Re: Newbie with EJB/web service problem

Posted by Venkat Reddy <vr...@gmail.com>.
Just to ensure that the environment is alright, did you try building
and running the samples/ejb in axis?

As you mentioned, the issue could be with code generation (java2wsdl,
wsdl2java). What errors did you get when you ran WSDL2Java? Need to
resolve issues with the EJB classes to run Java2WSDL and WSDL2Java
properly.

In the worst case, you might need to handcraft the WSDL file and run WSDL2Java.

-- Venkat



On Tue, 8 Feb 2005 17:10:53 -0000, Dan Hobbs
<da...@jumar-solutions.com> wrote:
> Hello, I'm new to web services and I'm having real trouble exposing an EJB
> as a web service. I'm not sure whether what I'm trying to do is impossible
> though, or whether I am approaching this in entirely the wrong way...
> 
> I am using Axis 1.2RC2 on Tomcat 4.1.31/Windows 2000 Professional. I am
> familiar enough with Tomcat, it's just web services where my head is
> spinning because there seem to be so many ways of doing things!
> 
> I also have the option of putting Axis within JBoss (I have v4.0.0) (I have
> removed the jboss-ws4ee.sar folder and got Axis working OK within JBoss).
> 
> All OK so far, but when I try to do something useful...
> 
> My task is to expose an EJB (which has been generated by a 3rd party, and I
> can't see the source of the runtime helper classes it uses). I successfully
> ran Java2WSDL (on the EJB remote interface) to create the .wsdd but received
> warnings about some of the objects used for I/O not having default
> constructors so not being mappable to XML. I cannot therefore run WSDL2Java
> on the .wsdd to create the endpoint stub.
> 
> I have considered writing a wrapper EJB whose call method has a similar
> signature, but has equivalent classes with default constructors, but I'm not
> sure whether that is feasible because I don't know how the clients of the
> EJB will be built.
> 
> I have also thought about putting a service-endpoint into ejb-jar.xml, but
> by now I am so confused I'm not sure which direction I should be heading.
> 
> If anyone has any advice on whether this is possible, and what I should be
> doing, then it would be greatly appreciated.
> 
> Regards,
> 
> Dan
> 
>