David Blevins

Greenhorn
+ Follow
since May 03, 2010
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
3
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by David Blevins

Passing a String back and forth will work. The contents of the String will simply be wrapped in a CDATA block.

The bigger question is if that is really what you want. If you intend to manipulate these xml documents as java objects on either the client or server then I recommend taking a day or two and learning about JAXB.

This is a really large example, but the related xml should be quite familiar. This class is annotated with JAXB annotations and is capable of reading and writing web.xml files. Most the fields and elements should be fairly intuitive:

http://svn.apache.org/repos/asf/openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/WebApp.java

This ties into JAX-WS in the following way. Say your doService method actually looked like this:



What would happen is the JAX-WS engine would see that the WebApp class was annotated with JAXB annotations and would then create a web.xml "file" from that object and pass it back to the client in the SOAP response. I put "file" in quotes as of course there is no file, you'd simply get the contents of what would be the web.xml file version of the WebApp object you return.

So you have the choice to handle your requests and responses as Strings or Java classes of your making. It's up to you. I'd probably put the time into learning JAXB.
8 years ago

only in my case, the XML will be more complex (up to 7 levels deep). how do you construct the soap message for this case? also what's the type in the parameter of the activated method in the server side to receive the XML?
I notice that if the wsdl is automatically generated (in my case using eclipse), third party lib must be used (like axis). or am I wrong?
If I'm not wrong, is there any way to construct and receive the soap message using java 6 built-in libs? more preferrably the one providing a template for the soap message so I just need to somehow embed the client's XML inside the template message. thanks



JAXB 2 is what is used by default in JAX-WS to marshal objects to/from xml when sending receiving SOAP. The @WebService method returns an object annotated with JAXB annotations, it will be marshalled to xml and sent as the response.

JAXB iss built into the VM in Java 6, so you could potentially have a "real" server and a "fake" client that doesn't truly understand all of SOAP and just creates messages by hand. You'd just need a set of JAXB objects to match the xml you plan to send back and forth and construct soap messages by hand in a client.

Are you attempting to create a client for an existing webservice or are you creating both the client and the server?
8 years ago
EJB not required, works fine with the @Stateless annotation removed and deployed in a .war file into a Java EE 6 certified server such as TomEE, JBoss or GlassFish.

8 years ago
I might suggest REST (JAX-RS) instead of JAX-WS (or both -- you can do both from the same class if you use an EJB).

This is a fairly comprehensive "getting started" doc for JAX-WS and shows all the code, all the WSDL and all the SOAP messages sent back an forth.

It's attempting to expose as much of the "guts" as possible to give you enough of a comfort level that if you wanted to do something different (like use a different stack) you'll be better prepared:

http://tomee.apache.org/examples-trunk/simple-webservice/README.html

Note all of the above can work in Java SE provided you use the Embeddable EJB Container API part of EJB 3.1 (also shown in that example). You just need the right libraries in the classpath.
8 years ago

What type of exceptions are appropriate?



Simply put, you need to catch the exceptions that are declared in the method you are calling:

Using the String class as an example, it has the following method:



If you want to call that method on a String you need to catch what is listed in the throws clause. In this case you must catch(UnsupportedEncodingException e)

It's a minor detail at this stage in your learning, but understand that any exception that is a direct or indirect subclass of RuntimeException is optional. You can catch it or not, up to you. Your teacher will probably give you extra points if you catch any RuntimeExceptions the javadoc mentions for the given method.

How to instantiate the threads?



Sounds like the teacher wants you to override the run method, in which case you need to learn how to create a subclass. You'll subclass Thread and override the run method. Then you need to instantiate the subclass with the new keyword and choosing the appropriate constructor.

Here's an example of subclassing Object and overriding toString



8 years ago
For the Eclipse support, you should use the JavaEE version of Eclipse. Assuming the server you plan to use supports Java EE 6 (all the major ones do at this point) then you can just create what Eclipse calls a 'Dynamic Web Project'.

You can add Servlets, EJBs and more to a Dynamic Web Project and it will work fine provided the server supports them. As of Java EE 6 all these things work in plain .war files.

Here's a video of creating a simple Dynamic Web Project in Eclipse and creating and deploying a Servlet, EJB and CDI bean using the Java EE version of Tomcat (TomEE):

http://www.youtube.com/watch?v=Lr8pxEACVRI

There are also a lot of EJB (and more) examples here:

http://tomee.apache.org/examples-trunk/
It's been a while since anyone has tried it, but this Eclipse plugin does have some ability to convert EJB 2.x xml metadata to the equivalent EJB 3.x annotations:

http://www.apache.org/dist/openejb/eclipse-plugin/

It will read the ejb-jar.xml and actually insert the annotations in the code. Note this is maybe 1/3 of the effort. Converting Home and LocalHome to be business interfaces will take some work. As well if you have heavy use of CMP 2.x that will be quite a lot more work to convert to JPA.
Thanks for the OpenEJB mentions in this thread. The stack formerly known as "OpenEJB/Tomcat" morphed into Apache TomEE which is a Java EE 6 certified version of Tomcat. We're pretty excited to give Tomcat users the option to use Java EE features without having to leave Tomcat.
You could try Apache TomEE. It a Java EE 6 certified version of Apache Tomcat that has JMS support already integrated using Apache ActiveMQ.
Alternate approach would be to use Apache TomEE, which is a version of Tomcat with EJB support already added.
Also note that Apache TomEE, the Java EE version of Apache Tomcat, has ActiveMQ already included and integrated.

Was just announced and released by Apache at JavaOne this last October.
In October at JavaOne, Apache released Apache TomEE which is a Java EE 6 certified version of Apache Tomcat. It supports EJB 3.1, CDI 1.0, etc. and includes Apache OpenEJB, Apache OpenWebBeans, Apache OpenJPA, Apache MyFaces, etc. All added and integrated into Tomcat and officially certified like JBoss or GlassFish.