The Source for Java Technology Collaboration

Home » java.net Forums » GlassFish » Metro and JAXB

Thread: Binding a single ComplexType parameter into a java String containing xml?

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
This question is not answered. Helpful answers available: 2. Correct answers available: 1.

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 6 - Last Post: Sep 3, 2008 7:22 PM by: Clive Brettingh...
jimpo

Posts: 5
Binding a single ComplexType parameter into a java String containing xml?
Posted: Aug 29, 2008 4:19 AM
 
  Click to reply to this thread Reply

I am using JAX-WS to implement my web services. I start with a WSDL and then create the stubs and data objects using jbossws 2.0's wscompile tool. I have bunch of service operations A,B, and C that work like this, 'normally'.

Now I would like to have a different kind of operation D which takes two parameter's D1 and D2. I want to have D1 mapped into a Java object 'normally'. But, D2 should map into a String containing the xml representation of the parameter.

As an example, web service request that contains

<vac:archiveDecision>
<vac:employeeNumber>123</vac:employeeNumber>
<vac:decision>
<foo>
dsadsa
</foo>
<bar>
<baz>asdasd</baz>
<baz2>asdasd</baz2>
</bar>
</vac:decision>
</vac:archiveDecision>

Should be mapped into Java object

class Some {
int employeeNumber;
String decision
}

with values employeeNumber = 123, decision = "<vac:decision><foo>dsadsa</foo><bar><baz>asdasd</baz><baz2>asdasd</baz2></bar></vac:decision>"

How can I do this with JAX-WS? I can supply wscompile with a binding file, but looking at

https://jax-ws.dev.java.net/jax-ws-20-fcs/docs/customizations.html

it seems all I can do is change the parameter name, not type?

jimpo

Posts: 5
Re: Binding a single ComplexType parameter into a java String containing xm
Posted: Aug 29, 2008 5:10 AM   in response to: jimpo
 
  Click to reply to this thread Reply

I guess I should give wscompile a JAXB binding xml that defines this kind of mapping.

I can't figure out how to construct this binding.xml. How do I define a mapping which maps ComplexType 'archiveDecisionType's element 'decision' into a String containing the element's xml? Any examples?

Clive Brettingh...
Re: Binding a single ComplexType parameter into a java String containing
xm

Posted: Aug 29, 2008 6:14 AM   in response to: jimpo
  Click to reply to this thread Reply

a) make really sure you want a string (why undo all that parsing, DOM,
or even StAX/SAX is higher up the food chain)
b) the binding customizations are pretty much useless for adapting
complex types.
c) but if you really must you can doctor the generated code to get
custom unmarshaling, see these threads:
http://forums.java.net/jive/thread.jspa?messageID=258280
http://forums.java.net/jive/message.jspa?messageID=293434

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


jimpo

Posts: 5
Re: Binding a single ComplexType parameter into a java String containing
Posted: Sep 1, 2008 1:16 AM   in response to: Clive Brettingh...
 
  Click to reply to this thread Reply

> a) make really sure you want a string (why undo all
> that parsing, DOM,
> or even StAX/SAX is higher up the food chain)
> b) the binding customizations are pretty much useless
> for adapting
> complex types.
> c) but if you really must you can doctor the
> generated code to get
> custom unmarshaling, see these threads:
> http://forums.java.net/jive/thread.jspa?messageID=2582
> 80
> http://forums.java.net/jive/message.jspa?messageID=293
> 434
>
> ------------------------------------------------------
> ---------------
> To unsubscribe, e-mail:
> users-unsubscribe@metro.dev.java.net
> For additional commands, e-mail:
> users-help@metro.dev.java.net

When I think about it, binding to a String is not a necessity. I could bind to a Document or an Element as well. As long as I can extract the xml for this specific parameter easily, ie. not binding into a large number of different java objects.

I wonder if this is possible with JAXB bindings, or does your comment b) still hold?

Clive Brettingh...
Re: Binding a single ComplexType parameter into a java String containing
Posted: Sep 1, 2008 5:06 PM   in response to: jimpo
  Click to reply to this thread Reply

You are safe from b, adapting to DOM Element is the one thing that can
be done directly with bindings (and if the schema specifies any then it
is the default).
Look at the jaxb:dom binding customisation element for JAXB, you should
be able to just apply if to the relevant schema component in the normal way.

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


jimpo

Posts: 5
Re: Binding a single ComplexType parameter into a java String containing
Posted: Sep 3, 2008 8:05 AM   in response to: Clive Brettingh...
 
  Click to reply to this thread Reply

I am having trouble getting the binding to work. Probably because I've never created binding definitions before. I use a bind.xml:

<jxb:bindings version="2.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:bindings schemaLocation="wsdl/schema/FooService.xsd" node="/xs:schema">
<jxb:bindings node="//xs:element[@name='archiveDecision']">
<jxb:dom/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>

FooService.xsd looks like:

<complexType name="archiveDecisionType">
<sequence>
<element name="foo" type="unsignedLong"
maxOccurs="unbounded" minOccurs="1">
</element>
<element name="bar" type="decision:xyzType" />
</sequence>
</complexType>

<element name="archiveDecision"
type="tns:archiveDecisionType">
</element>

When I try to create the files, I get:

>wsconsume -k -b bind.xml --source=source2 wsdl\FooService.wsdl

parsing WSDL...


[ERROR] compiler was unable to honor this dom customization. It is attached to a wrong place, or its inconsistent with o
ther bindings.
line 7 of file:/bind.xml

[ERROR] (the above customization is attached to the following location in the schema)
line 32 of file:/D:/projects/soapoc/jaxws-gener/vacation/wsdl/schema/FooService.xsd

I also tried mapping to the element's type, but got the same error.

Clive Brettingh...
Re: Binding a single ComplexType parameter into a java String containing
Posted: Sep 3, 2008 7:22 PM   in response to: jimpo
  Click to reply to this thread Reply

You shouldn't have both node and schemaLocation set on a single bindings
element (but this is not the cause of your problem, and your binding
should work just as well with the node="/xs:schema" removed).
I think the root of the problem is that the dom customisation can only
have an effect on properties in the final generated code (so if
customising a top level element it will only effect useage via an
element ref).
This error is probably a bad way of telling you that the customisation
can have no effect.
Since you are getting the error I assume you are not using the element
in this way (either it is being used implicitly in an xs:any (then use
customisation on the xs:any), or as top level of the message).
(Similar for the complexType - I assume it is not being used explicitly
as the type of a non-top-level element).

If you are using the element at the top level then there isn't anything
JAXB can do for you (since you are in effect opting out of JAXB
entirely). While you can use JAX-WS to create web services that use raw
XML (javax.xml.ws.Provider) this would apply to the whole endpoint.



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





 XML java.net RSS