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 Dhagam Sridhar <ds...@translogicsys.com> on 2003/01/03 07:48:36 UTC

Re: returning an array of beans (or: why i'm going insane)

HI all,
    I too have the same problem using Axis,
    Can we make it work without using java2WSDL and WSDL2java?

thanks in advance,
sridhar.
  ----- Original Message ----- 
  From: Marc Esher 
  To: axis-user@xml.apache.org 
  Sent: Monday, December 30, 2002 5:51 AM
  Subject: RE: returning an array of beans (or: why i'm going insane)


  Thanks a lot, Gene. I'm going to give this a go right now and cross my fingers. I'll report back the results soon.
    -----Original Message-----
    From: Gene Chuang [mailto:genechuang@yahoo.com]
    Sent: Sunday, December 29, 2002 7:12 PM
    To: axis-user@xml.apache.org; jonnycattt@cablespeed.com
    Subject: Re: returning an array of beans (or: why i'm going insane)


    Heh, I went through the same rigamarole last week to get Axis to deploy my service that has an array of JavaBeans. Here's how I attacked this problem: 

    According to the docs, just editing the deploy.wsdd to add JavaBean serialization entries should be good enough.  However, because XML namespace syntax is nearly impossible to understand, and the docs doesn't show a full example of the wsdd, I had to create just this entry manually by doing the Java2WSDL->WSDL2Java roundtripping.  Here are the steps: 

    1)  run Java2WSDL to get the wsdl file
    2) copy this file to a temp directory and run "WSDL2Java -s" to get the deploy.wsdd and not have your classes stomped
    3) Manually edit the new deploy.wsdd, remove all the extraneous elements:  wsdlServiceElement, wsdlServicePort and wsdlPortType.  Change className back to your original service class.  And note there should be at least 2 typeMapping entries, YourJavaBean and ArrayOfYourJavaBean!  The latter is what you're missing, and is not explained in the docs.  Furthurmore, all that complex XML-namespace-to-java-package-mapping are annotated correctly.
    4) Replace your original wsdd with the new one and deploy.

    I'm sure Marc and I aren't the first or last to come across this problem.  I blame it on the following factors:

    - XML Namespace is possibly the most confusing spec I've ever encountered and makes it hard to handcode your own wsdl or wsdd.
    - Axis docs doesn't provide details on array-of-JavaBean serialization, and this practice is very common in the real business world.
    - WSDL2Java is stomping our implementation class!  According to the docs, "When WSDL2Java is asked to generate the implementation template (via the --server-side flag), it will ONLY generate it if it does not already exist.  If this implementation already exists, it will not be overwritten."  This is not the case!

    Apache can't do much about Namespace complexity, but I hope it can rectify its documents and WSDL2Java tool!

    Gene 

    Marc Esher <jo...@cablespeed.com> wrote: 

      Hi all,
      I've been struggling with this for quite some time now, and it's time to
      post as I am about to go insane. Note that I posted this problem to the
      comp.lang.programmer group before receiving my subscription activation for
      this list. Here goes:

      I have a class that returns an array of javabeans (ArticleBean). I want to
      expose this class as a web service using Axis. So far, I've been successful
      publishing/consuming simple web services, but I've had no success with
      anything that returns beans...even the provided sample won't work for me.

      Here's the relevant axis code from the web service client:
      String endpoint =
      "http://localhost:8080/ArticleSearchService/services/ArticleSearchImpl";
      Service service = new Service();
      Call call=null;

      call = (Call) service.createCall();
      call.setTargetEndpointAddress( new java.net.URL(endpoint) );
      QName qn = new QName( "urn:ArticleBean", "ArticleBean" );
      call.registerTypeMapping(ArticleBean.class, qn,
      new
      org.apache.axis.encoding.ser.BeanSerializerFactory(ArticleBean.class, qn),
      new
      org.apache.axis.encoding.ser.BeanDeserializerFactory(ArticleBean.class,
      qn));
      call.setOperationName( new QName("ArticleSearchImpl", "searchByDoi") );
      call.addParameter("doi", XMLType.XSD_STRING, ParameterMode.IN);
      call.setReturnType( XMLType.SOAP_ARRAY );
      ab = (ArticleBean[]) call.invoke( new Object [] {doi});

      And here's the deployment descriptor:

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



      languageSpecificType="java:ArticleBean"/>



      If I view the wsdl at
      http://localhost:8080/ArticleSearchService/services/ArticleSearchImpl?wsdl,
      I get the following error: (snip) The value of the attribute "xmlns:tns1" is
      invalid. Prefixed namespace bindings may not be empty

      If I invoke a the client class (snippet above), I get "no deserializer
      defined for array type" in the error message.

      So.....I tried another approach:

      put my ArticleSearchImpl class into a package (ArticleSearch).
      use java2wsdl on this class; then, use wsdl2java, putting the auto-generated
      files into package ArticleSearch.ws. This worked well. however, it also
      put a new version of my ArticleBean class into this package as well, and the
      deploy.wsdd points to this bean. Then, I use the auto-generated
      ArticleSearchImplSoapBindingImpl to wrap my original class, something like
      this:

      import ArticleSearch.ArticleSearchImpl;
      public class ArticleSearchImplSoapBindingImpl implements
      ArticleSearch.ws.ArticleSearchImpl
      {
      ArticleSearchImpl searcher = new ArticleSearchImpl(); //my original
      class

      public ArticleSearch.ws.ArticleBean[] searchByAuthor(java.lang.String
      author) throws java.rmi.RemoteException {
      return searcher.searchByAuthor(author);
      }
      ....
      }

      The problem is that my original class returns an array of
      ArticleSearch.ArticleBean, not an array of ArticleSearch.ws.ArticleBean.
      Sticking (ArticleSearch.ws.ArticleBean[]) in front of the return value
      didn't help, either, as I suspected it wouldn't. So now I've progressed
      somewhat from my original problem, but i'm still stuck. I cannot believe
      that it's all that difficult to create this sucker, so I know I'm doing
      stupid things wrong.

      Since there is no documentation on the axis site for returning an array of
      beans, I'm appealing to you all for help.

      Thanks.

      Marc


Re: returning an array of beans (or: why i'm going insane)

Posted by Jess Sightler <js...@eximtechnologies.com>.
Hmmm, maybe I've missed an important part if this discussion.  I have to
ask, is all of this work necessary for sending an array of a Custom
type?

I know that the documentation isn't clear, but my experience has been
that it is quite simple.  With Axis v1.0, all that I had to do was
define the BeanSerializer for the one custom type itself... Axis was
able to deal with the fact that I was using arrays of that custom type
quite nicely after that.

I did spend some time at first trying to define the mapping for the
Array of Custom types (because I hadn't tried it without it first) and
found it very frustrating, but in the end it wasn't even necessary.

Could that also be the case here?

---
Jess


On Fri, 2003-01-03 at 02:11, Gene Chuang wrote:
> Yeah sure, if you are familiar with XML-namespace syntax and how axis
> maps namespace to java package and vice versa, and how Axis handles
> complex-type and array-type conversion then you can handcode the
> deploy.wsdd to do exactly this. 
> 
> If not, then do the round-trip to create the deploy.wsdd as a template
> for you, and use this in future deployments.  
> 
>  Dhagam Sridhar <ds...@translogicsys.com> wrote: 
>         HI all,
>             I too have the same problem using Axis,
>             Can we make it work without using java2WSDL and WSDL2java?
>          
>         thanks in advance,
>         sridhar.
>                 ----- Original Message ----- 
>                 From: Marc Esher
>                 To: axis-user@xml.apache.org
>                 Sent: Monday, December 30, 2002 5:51 AM
>                 Subject: RE: returning an array of beans (or: why i'm
>                 going insane)
>                 
>                 Thanks a lot, Gene. I'm going to give this a go right
>                 now and cross my fingers. I'll report back the results
>                 soon.
>                         -----Original Message-----
>                         From: Gene Chuang
>                         [mailto:genechuang@yahoo.com]
>                         Sent: Sunday, December 29, 2002 7:12 PM
>                         To: axis-user@xml.apache.org;
>                         jonnycattt@cablespeed.com
>                         Subject: Re: returning an array of beans (or:
>                         why i'm going insane)
>                         
>                         
>                         
>                         Heh, I went through the same rigamarole last
>                         week to get Axis to deploy my service that has
>                         an array of JavaBeans. Here's how I attacked
>                         this problem: 
>                         
>                         According to the docs, just editing the
>                         deploy.wsdd to add JavaBean serialization
>                         entries should be good enough.  However,
>                         because XML namespace syntax is nearly
>                         impossible to understand, and the docs doesn't
>                         show a full example of the wsdd, I had to
>                         create just this entry manually by doing the
>                         Java2WSDL->WSDL2Java roundtripping.  Here are
>                         the steps: 
>                         
>                         1)  run Java2WSDL to get the wsdl file
>                         2) copy this file to a temp directory and run
>                         "WSDL2Java -s" to get the deploy.wsdd and not
>                         have your classes stomped
>                         3) Manually edit the new deploy.wsdd, remove
>                         all the extraneous elements: 
>                         wsdlServiceElement, wsdlServicePort and
>                         wsdlPortType.  Change className back to your
>                         original service class.  And note there should
>                         be at least 2 typeMapping entries,
>                         YourJavaBean and ArrayOfYourJavaBean!  The
>                         latter is what you're missing, and is not
>                         explained in the docs.  Furthurmore, all that
>                         complex XML-namespace-to-java-package-mapping
>                         are annotated correctly.
>                         4) Replace your original wsdd with the new one
>                         and deploy.
>                         
>                         I'm sure Marc and I aren't the first or last
>                         to come across this problem.  I blame it on
>                         the following factors:
>                         
>                         - XML Namespace is possibly the most confusing
>                         spec I've ever encountered and makes it hard
>                         to handcode your own wsdl or wsdd.
>                         - Axis docs doesn't provide details on
>                         array-of-JavaBean serialization, and this
>                         practice is very common in the real business
>                         world.
>                         - WSDL2Java is stomping our implementation
>                         class!  According to the docs, "When WSDL2Java
>                         is asked to generate the implementation
>                         template (via the --server-side flag), it will
>                         ONLY generate it if it does not already
>                         exist.  If this implementation already exists,
>                         it will not be overwritten."  This is not the
>                         case!
>                         
>                         Apache can't do much about Namespace
>                         complexity, but I hope it can rectify its
>                         documents and WSDL2Java tool!
>                         
>                         Gene 
>                         
>                         Marc Esher <jo...@cablespeed.com> wrote: 
>                                 Hi all,
>                                 I've been struggling with this for
>                                 quite some time now, and it's time to
>                                 post as I am about to go insane. Note
>                                 that I posted this problem to the
>                                 comp.lang.programmer group before
>                                 receiving my subscription activation
>                                 for
>                                 this list. Here goes:
>                                 
>                                 I have a class that returns an array
>                                 of javabeans (ArticleBean). I want to
>                                 expose this class as a web service
>                                 using Axis. So far, I've been
>                                 successful
>                                 publishing/consuming simple web
>                                 services, but I've had no success with
>                                 anything that returns beans...even the
>                                 provided sample won't work for me.
>                                 
>                                 Here's the relevant axis code from the
>                                 web service client:
>                                 String endpoint =
>                                 "http://localhost:8080/ArticleSearchService/services/ArticleSearchImpl";
>                                 Service service = new Service();
>                                 Call call=null;
>                                 
>                                 call = (Call) service.createCall();
>                                 call.setTargetEndpointAddress( new
>                                 java.net.URL(endpoint) );
>                                 QName qn = new QName(
>                                 "urn:ArticleBean", "ArticleBean" );
>                                 call.registerTypeMapping(ArticleBean.class, qn,
>                                 new
>                                 org.apache.axis.encoding.ser.BeanSerializerFactory(ArticleBean.class, qn),
>                                 new
>                                 org.apache.axis.encoding.ser.BeanDeserializerFactory(ArticleBean.class,
>                                 qn));
>                                 call.setOperationName( new
>                                 QName("ArticleSearchImpl",
>                                 "searchByDoi") );
>                                 call.addParameter("doi",
>                                 XMLType.XSD_STRING, ParameterMode.IN);
>                                 call.setReturnType( XMLType.SOAP_ARRAY
>                                 );
>                                 ab = (ArticleBean[]) call.invoke( new
>                                 Object [] {doi});
>                                 
>                                 And here's the deployment descriptor:
>                                 
>                                 xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
>                                 
>                                 
>                                 
>                                 languageSpecificType="java:ArticleBean"/>
>                                 
>                                 
>                                 
>                                 If I view the wsdl at
>                                 http://localhost:8080/ArticleSearchService/services/ArticleSearchImpl?wsdl,
>                                 I get the following error: (snip) The
>                                 value of the attribute "xmlns:tns1" is
>                                 invalid. Prefixed namespace bindings
>                                 may not be empty
>                                 
>                                 If I invoke a the client class
>                                 (snippet above), I get "no
>                                 deserializer
>                                 defined for array type" in the error
>                                 message.
>                                 
>                                 So.....I tried another approach:
>                                 
>                                 put my ArticleSearchImpl class into a
>                                 package (ArticleSearch).
>                                 use java2wsdl on this class; then, use
>                                 wsdl2java, putting the auto-generated
>                                 files into package ArticleSearch.ws.
>                                 This worked well. however, it also
>                                 put a new version of my ArticleBean
>                                 class into this package as well, and
>                                 the
>                                 deploy.wsdd points to this bean. Then,
>                                 I use the auto-generated
>                                 ArticleSearchImplSoapBindingImpl to
>                                 wrap my original class, something like
>                                 this:
>                                 
>                                 import
>                                 ArticleSearch.ArticleSearchImpl;
>                                 public class
>                                 ArticleSearchImplSoapBindingImpl
>                                 implements
>                                 ArticleSearch.ws.ArticleSearchImpl
>                                 {
>                                 ArticleSearchImpl searcher = new
>                                 ArticleSearchImpl(); //my original
>                                 class
>                                 
>                                 public ArticleSearch.ws.ArticleBean[]
>                                 searchByAuthor(java.lang.String
>                                 author) throws
>                                 java.rmi.RemoteException {
>                                 return
>                                 searcher.searchByAuthor(author);
>                                 }
>                                 ....
>                                 }
>                                 
>                                 The problem is that my original class
>                                 returns an array of
>                                 ArticleSearch.ArticleBean, not an
>                                 array of ArticleSearch.ws.ArticleBean.
>                                 Sticking
>                                 (ArticleSearch.ws.ArticleBean[]) in
>                                 front of the return value
>                                 didn't help, either, as I suspected it
>                                 wouldn't. So now I've progressed
>                                 somewhat from my original problem, but
>                                 i'm still stuck. I cannot believe
>                                 that it's all that difficult to create
>                                 this sucker, so I know I'm doing
>                                 stupid things wrong.
>                                 
>                                 Since there is no documentation on the
>                                 axis site for returning an array of
>                                 beans, I'm appealing to you all for
>                                 help.
>                                 
>                                 Thanks.
>                                 
>                                 Marc
-- 
=======================================
Jess Sightler
Senior Developer
Exim Technologies
131 Falls Street
Greenville SC 29601
Phone: 864-679-4651
=======================================




Re: returning an array of beans (or: why i'm going insane)

Posted by Gene Chuang <ge...@yahoo.com>.
Yeah sure, if you are familiar with XML-namespace syntax and how axis maps namespace to java package and vice versa, and how Axis handles complex-type and array-type conversion then you can handcode the deploy.wsdd to do exactly this.
If not, then do the round-trip to create the deploy.wsdd as a template for you, and use this in future deployments. 
 Dhagam Sridhar <ds...@translogicsys.com> wrote:HI all,    I too have the same problem using Axis,    Can we make it work without using java2WSDL and WSDL2java? thanks in advance,sridhar.----- Original Message ----- From: Marc Esher To: axis-user@xml.apache.org Sent: Monday, December 30, 2002 5:51 AMSubject: RE: returning an array of beans (or: why i'm going insane)
Thanks a lot, Gene. I'm going to give this a go right now and cross my fingers. I'll report back the results soon.-----Original Message-----
From: Gene Chuang [mailto:genechuang@yahoo.com]
Sent: Sunday, December 29, 2002 7:12 PM
To: axis-user@xml.apache.org; jonnycattt@cablespeed.com
Subject: Re: returning an array of beans (or: why i'm going insane)


Heh, I went through the same rigamarole last week to get Axis to deploy my service that has an array of JavaBeans. Here's how I attacked this problem: 
According to the docs, just editing the deploy.wsdd to add JavaBean serialization entries should be good enough.  However, because XML namespace syntax is nearly impossible to understand, and the docs doesn't show a full example of the wsdd, I had to create just this entry manually by doing the Java2WSDL->WSDL2Java roundtripping.  Here are the steps: 
1)  run Java2WSDL to get the wsdl file
2) copy this file to a temp directory and run "WSDL2Java -s" to get the deploy.wsdd and not have your classes stomped
3) Manually edit the new deploy.wsdd, remove all the extraneous elements:  wsdlServiceElement, wsdlServicePort and wsdlPortType.  Change className back to your original service class.  And note there should be at least 2 typeMapping entries, YourJavaBean and ArrayOfYourJavaBean!  The latter is what you're missing, and is not explained in the docs.  Furthurmore, all that complex XML-namespace-to-java-package-mapping are annotated correctly.
4) Replace your original wsdd with the new one and deploy.

I'm sure Marc and I aren't the first or last to come across this problem.  I blame it on the following factors:

- XML Namespace is possibly the most confusing spec I've ever encountered and makes it hard to handcode your own wsdl or wsdd.
- Axis docs doesn't provide details on array-of-JavaBean serialization, and this practice is very common in the real business world.
- WSDL2Java is stomping our implementation class!  According to the docs, "When WSDL2Java is asked to generate the implementation template (via the --server-side flag), it will ONLY generate it if it does not already exist.  If this implementation already exists, it will not be overwritten."  This is not the case!

Apache can't do much about Namespace complexity, but I hope it can rectify its documents and WSDL2Java tool!

Gene 

Marc Esher <jo...@cablespeed.com> wrote: Hi all,
I've been struggling with this for quite some time now, and it's time to
post as I am about to go insane. Note that I posted this problem to the
comp.lang.programmer group before receiving my subscription activation for
this list. Here goes:

I have a class that returns an array of javabeans (ArticleBean). I want to
expose this class as a web service using Axis. So far, I've been successful
publishing/consuming simple web services, but I've had no success with
anything that returns beans...even the provided sample won't work for me.

Here's the relevant axis code from the web service client:
String endpoint =
"http://localhost:8080/ArticleSearchService/services/ArticleSearchImpl";
Service service = new Service();
Call call=null;

call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
QName qn = new QName( "urn:ArticleBean", "ArticleBean" );
call.registerTypeMapping(ArticleBean.class, qn,
new
org.apache.axis.encoding.ser.BeanSerializerFactory(ArticleBean.class, qn),
new
org.apache.axis.encoding.ser.BeanDeserializerFactory(ArticleBean.class,
qn));
call.setOperationName( new QName("ArticleSearchImpl", "searchByDoi") );
call.addParameter("doi", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType( XMLType.SOAP_ARRAY );
ab = (ArticleBean[]) call.invoke( new Object [] {doi});

And here's the deployment descriptor:

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





languageSpecificType="java:ArticleBean"/>



If I view the wsdl at
http://localhost:8080/ArticleSearchService/services/ArticleSearchImpl?wsdl,
I get the following error: (snip) The value of the attribute "xmlns:tns1" is
invalid. Prefixed namespace bindings may not be empty

If I invoke a the client class (snippet above), I get "no deserializer
defined for array type" in the error message.

So.....I tried another approach:

put my ArticleSearchImpl class into a package (ArticleSearch).
use java2wsdl on this class; then, use wsdl2java, putting the auto-generated
files into package ArticleSearch.ws. This worked well. however, it also
put a new version of my ArticleBean class into this package as well, and the
deploy.wsdd points to this bean. Then, I use the auto-generated
ArticleSearchImplSoapBindingImpl to wrap my original class, something like
this:

import ArticleSearch.ArticleSearchImpl;
public class ArticleSearchImplSoapBindingImpl implements
ArticleSearch.ws.ArticleSearchImpl
{
ArticleSearchImpl searcher = new ArticleSearchImpl(); //my original
class

public ArticleSearch.ws.ArticleBean[] searchByAuthor(java.lang.String
author) throws java.rmi.RemoteException {
return searcher.searchByAuthor(author);
}
....
}

The problem is that my original class returns an array of
ArticleSearch.ArticleBean, not an array of ArticleSearch.ws.ArticleBean.
Sticking (ArticleSearch.ws.ArticleBean[]) in front of the return value
didn't help, either, as I suspected it wouldn't. So now I've progressed
somewhat from my original problem, but i'm still stuck. I cannot believe
that it's all that difficult to create this sucker, so I know I'm doing
stupid things wrong.

Since there is no documentation on the axis site for returning an array of
beans, I'm appealing to you all for help.

Thanks.

Marc