cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <>
Subject Re: no-annotations RESTfull webservice - a complex use case
Date Mon, 22 Feb 2010 11:58:12 GMT

See comments inline please

----- Original Message ----- 
From: "fahman_dude" <>
To: <>
Sent: Monday, February 22, 2010 10:21 AM
Subject: no-annotations RESTfull webservice - a complex use case


I have the use case where I have to provide a RESTfull webservice. This use
case has a number of constraints:
- contract-first (as in, first - definition (WSDL for SOAP, user model for
REST), then - implementation (ws implementation and JAXB generated stuff))
- same webservice implementation class for both - SOAP and REST

> S.B : I'm wondering, should we start thinking about supporting WSDL2 for cases like this
one be supported ?

- no manual modifications to the generated classes since they can be
re-generated at any time upon contract change
- REST service will be called by a simple httpclient

WSDL (trimmed) looks like this:
<xsd:schema xmlns=""
elementFormDefault="qualified" xmlns:msg="http://myothernamespace"
<xsd:import schemaLocation="myothernamespace.xsd"
namespace="http://myothernamespace" />
<xsd:import schemaLocation="mythirdnamespace.xsd"
namespace="http://mythirdnamespace" />
<xsd:element name="sendEmail">
<xsd:element name="msgCtx" type="msg:ServiceMessageContext"
minOccurs="1" />
<xsd:element name="emailMessage" type="emailbus:EmailMessage"
minOccurs="1" />

<wsdl:message name="sendEmailIn">
<wsdl:part element="tns:sendEmail" name="data" />

msgCtx (trimmed) looks like this:
<complexType name="ServiceMessageContext">
<element maxOccurs="1" minOccurs="1" name="messageId" type="string" />
<element maxOccurs="1" minOccurs="0" name="requestId" type="string" />
<element maxOccurs="1" minOccurs="0" name="correlationId" type="string" />

emailMessage, like this:
<complexType name="EmailMessage">
<element name="from" type="xsd:string" />
<element name="to" type="xsd:string" />
<element name="subject" type="xsd:string" />
<element name="body" type="tns:Body" />
<element name="attachments" type="tns:Attachment" minOccurs="0"
maxOccurs="unbounded" />
<complexType name="Body">
<element name="content" type="xsd:base64Binary"
xmime:expectedContentTypes="text/html" />
<complexType name="Attachment">
<element name="content" type="xsd:base64Binary" />

Webservice implementation has this single method:
public class EmailServiceImpl implements EmailService {
 public void sendEmail(ServiceMessageContext msgCtx, EmailMessage
emailMessage) {

Now, I can easily generate JAX-WS stuff first (wsdl2java). And it works just
fine (even with mtom and fastinfoset). But when it comes to JAX-RS I am

My plan was to define user model and apply it to "EmailService" and
"EmailServiceImpl" like this:

<model xlmns="">
<resource name="somepackages.EmailService" path="emailservice"
produces="application/json" consumes="multipart/form-data">
<operation name="sendEmail" verb="POST" path="/sendemail">
&lt;param name="msgCtx" type="REQUEST_BODY" /&gt;
&lt;param name="emailMessage" type="REQUEST_BODY" /&gt;

This worked aswell atleast to the point where I was able to succesfully
create a JAX-RS server based on the definition and classes.

Then, I intended to use HttpClient to perform a multipart post by means of
JAXB marshaling both parameters ("msgCtx" and "emailMessage"), attaching
them as Parts to MultipartRequestEntity and posting them over.

> S.B Note that it is very easy to post attachments with CXF JAXRS on the client side too,
the only thing which has not been 
> impemented yet is the recursive multiparts (that is, when individual multipart/form-data
parts contains multiple parts of its own) 
> but this works on the server.

Currently I am facing a number of understanding issues even after weekend of
searching and reading on the web.

1. @XmlRootElement is neither "msgCtx" nor "emailMessage" but rather
wsdl2java-generated wrapper class "SendEmail". This kinda makes sense for
JAX-WS but I guess it will not work for JAX-RS (as I understand it, I have
to marshal "msgCtx" and "emailMessage" separatelly and add them to
MultipartRequestEntity as two separate Parts that can be identified later by
JAX-RS server). Can anyone enlighten me on what's wrong with my idea here or
is it really so that I have to configure JAXB so that it is able to marshall
"msgCtx" and "emailMessage" separatelly (I'd greatly appretiate, if anyone
could write me how to do that)

> S.B I'm a little bit confused here. What is the value of  ServiceMessageContext and EmailMessage'
XmlRootElements ? As far as I 
> understand, there's a single SendEmail wrapper instance which is being sent in case of
SOAP and it is unwrapped at the server side 
> into two individual parts, msgCtx and emailMessage. But in case of JAXRS you're sending
a multipart/form-data request, with one 
> part containing the ServiceMessageContext instance and the other part containing an email
If you could attach a sample request message which you're sending with the http client (plus
the generated ServiceMessageContext and 
EmailMessage) then it could help as well, I may be able to do some testing on my side...

2. "emailMessage" alone consists of multiple parts - there's xml with
primitives, "body" which is xsd:base64Binary and the collection of
"attachments" each of which is xsd:base64Binary. Now, for JAX-WS CXF handles
and hides this complexity and I see a beautifull "multipart/related" message
on the wire. How do I achieve this for REST service? When I marshal instance
of "SendEmail" I see only one part with serialized SendEmail and all the
base64 stuff is inline. Again, can anyone give me a hint on what would be
the solution here that would actually work.

> S.B I'd like to have a look at the sample multipart/form-data request message.
cheers, Sergey

View this message in context:
Sent from the cxf-user mailing list archive at

View raw message