How to build web services with complex objects

View: New views
3 Messages — Rating Filter:   Alert me  

How to build web services with complex objects

by metro-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hey guys

I have a problem with building a web service that returns a complex object (in my case a Java Bean). My ant-based build file always quits in the wsgen process. Having searched for tutorials and solutions to my case on the internet for a long time without success, I want to ask the experts amongst you.

Example Web Service (simplified):

@WebService
public class MyService {
 
  @WebMethod
  public MyBean getBean() {
    return null;
  }
}


public class MyBean {
  private int value = 1;
  public int getValue() { ..};
  public void setValue(..) { };
}


This should be possible with JAX-WS, right? Do I have to use something special to compile this, some special annotations or something like that?

Ok, I want to build and deploy this WebService with my ANT build file, which looks similar to the following (except from my build file):

...
<target name="apt" depends="compile-server">
  <taskdef name="apt" classname="com.sun.tools.ws.ant.Apt">
      <classpath refid="apt.classpath"/>
  </taskdef>          
  <echo message="Generating webservice"/>
  <apt destdir="${tmp}/classes" sourcedestdir="${tmp}/src/generated" factory="util.APTFactory" sourcepath="${src}">
      <classpath refid="apt.classpath" />
      <source dir="${tmp}/src/service">
      </source>
  </apt>
</target>
       

<target name="wsgen" depends="apt">
        <taskdef name="wsgen" classname="com.sun.tools.ws.ant.WsGen">
                <classpath refid="jaxws.classpath"/>
        </taskdef>
        <wsgen resourcedestdir="${tmp}/webapp/WEB-INF/wsdl"
                sei="${wsName}"
                keep="true"
                sourcedestdir="${tmp}/src/generated"
                destdir="${tmp}/classes"
                genwsdl="true"
                verbose="true">
                <classpath refid="project.classpath"/>
        </wsgen>
</target>
...


When I run this build file it breaks in the wsgen command. Note that it doesn't break whenever I use simple objects, so the build-file in general must be ok.

Do you see any mistakes in it? Do you have any ideas? Or do you know where I can find a complete tutorial/article that describes how to use complex objects and describes how to use wsgen in an ANT task?

If you need a complete zipped example which fails in my environment please let me know.

Thanks a lot for your help,
Andreas
[Message sent by forum member 'a_schwarte' (a_schwarte)]

http://forums.java.net/jive/thread.jspa?messageID=354705

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: How to build web services with complex objects

by Glen Mazza :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

My tutorial (http://www.jroller.com/gmazza/entry/creating_a_wsdl_first_web1) is WSDL-first, but you can add whatever elements you want to the DoubleItRequest object in the WSDL (int value in your case).

Keep in mind web services are implementation-independent--they work with all sorts of programming languages (Java, .Net, Python, etc.) so you can't really return a "Java Bean"(*)--you can however return structures of primitive elements.

HTH,
Glen

(*) You can actually, in one sense, search on JAXBContext in this article for a code sample with the Dispatch interface:  http://www.jroller.com/gmazza/entry/writing_junit_test_cases_for

metro-3 wrote:
Hey guys

I have a problem with building a web service that returns a complex object (in my case a Java Bean). My ant-based build file always quits in the wsgen process. Having searched for tutorials and solutions to my case on the internet for a long time without success, I want to ask the experts amongst you.

Example Web Service (simplified):

@WebService
public class MyService {
 
  @WebMethod
  public MyBean getBean() {
    return null;
  }
}


public class MyBean {
  private int value = 1;
  public int getValue() { ..};
  public void setValue(..) { };
}


This should be possible with JAX-WS, right? Do I have to use something special to compile this, some special annotations or something like that?

Ok, I want to build and deploy this WebService with my ANT build file, which looks similar to the following (except from my build file):

...
<target name="apt" depends="compile-server">
  <taskdef name="apt" classname="com.sun.tools.ws.ant.Apt">
      <classpath refid="apt.classpath"/>
  </taskdef>          
  <echo message="Generating webservice"/>
  <apt destdir="${tmp}/classes" sourcedestdir="${tmp}/src/generated" factory="util.APTFactory" sourcepath="${src}">
      <classpath refid="apt.classpath" />
      <source dir="${tmp}/src/service">
      </source>
  </apt>
</target>
       

<target name="wsgen" depends="apt">
        <taskdef name="wsgen" classname="com.sun.tools.ws.ant.WsGen">
                <classpath refid="jaxws.classpath"/>
        </taskdef>
        <wsgen resourcedestdir="${tmp}/webapp/WEB-INF/wsdl"
                sei="${wsName}"
                keep="true"
                sourcedestdir="${tmp}/src/generated"
                destdir="${tmp}/classes"
                genwsdl="true"
                verbose="true">
                <classpath refid="project.classpath"/>
        </wsgen>
</target>
...


When I run this build file it breaks in the wsgen command. Note that it doesn't break whenever I use simple objects, so the build-file in general must be ok.

Do you see any mistakes in it? Do you have any ideas? Or do you know where I can find a complete tutorial/article that describes how to use complex objects and describes how to use wsgen in an ANT task?

If you need a complete zipped example which fails in my environment please let me know.

Thanks a lot for your help,
Andreas
[Message sent by forum member 'a_schwarte' (a_schwarte)]

http://forums.java.net/jive/thread.jspa?messageID=354705

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@metro.dev.java.net
For additional commands, e-mail: users-help@metro.dev.java.net

Re: How to build web services with complex objects

by metro-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Let me also suggest (in addition to Glen's blog, which is always very helpful) the latest book on the JAX-WS topic by Martin Kalin  - [i]Java Web Services: Up and Running[/i] - http://oreilly.com/catalog/9780596521127/  (he has examples using complex objects)

it is an excellent introduction on the JAX-WS topic (and covers REST / JAX-RS as well)
[Message sent by forum member 'mcs130' (mcs130)]

http://forums.java.net/jive/thread.jspa?messageID=354762

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...