Using Jax-B with Jax-WS to Return Complex Types

I’m sure you have a lot of questions about this, but none of the answers that I found seem to cope with the problem that I encountered, so I was hoping I could get some specific answers.

I have a project consisting of a client and a server. The server connects to the database, and the client can call methods on the server through the wsdl file. This works fine, but the server can only return simple types and lists. I looked at how to handle custom types, and I was directed to JaxB, which seems to be exactly what I'm looking for. Unfortunately, I am a little confused about how I should use it. I use NetBeans IDE (6.9.1), which makes working with wsdl files easier, although I read that passing complex classes is pretty trivial from the command line, once you have the wsdl-end of things working correctly?

What I want to do is return a class to the server - it will only contain data that the client can read and use.

I did the following, but obviously I'm wrong somewhere!

  • I have a class called Server-side Customer, which is designed and returned when the client invokes a specific method.
  • The client obviously cannot correctly interpret this class.
  • I used a schema to create an XML schema from the Customer class. Then I use the netbeans wizard to bind the schema to a class on the client.
  • I guess this is where I got confused. I want to cancel the xml response from the server and use it to create a new object on the client. I use the "jaxbu" netbeans shortcut, which extends into some code, but I'm not sure how to put the returned object in unmarshaller. If that makes sense?

The code generated by "jaxbu" is similar to the one below, inside the try block:

javax.xml.bind.JAXBContext jaxbCtx = javax.xml.bind.JAXBContext.newInstance(c.getClass().getPackage().getName()); javax.xml.bind.Unmarshaller unmarshaller = jaxbCtx.createUnmarshaller(); c = (CustomerInfo) unmarshaller.unmarshal(new java.io.File("File path")); 

Any help would be greatly appreciated and if you require further information. please feel free to ask.

Thanks Mathew

+4
source share
2 answers

I am not going to be the best help with a definitive answer, but I asked a similar question a while ago and was pointed out in useful directions in this question. as Blaise Dohan said that you need to use something to navigate the XML document and find the fragments you need, then debug them from there.

JAXB unmarshaling Ignoring SOAP Envelope / Header Tags

+2
source

you should not do jaxb things directly. instead, you put all complex types in the schema associated with your wsdl (assuming you are working from wsdl). then you use various jaxws tools (wsgen, wsimport) to create stub classes and jaxb classes from wsdl (both for the client and for the server).

To a large extent, all of this is described in the jaxws tutorials (metro is the reference jaxws implementation).

+1
source

Source: https://habr.com/ru/post/1348115/


All Articles