cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fahman_dude <>
Subject no-annotations RESTfull webservice - a complex use case
Date Mon, 22 Feb 2010 10:21:38 GMT


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
- 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.

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)

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.

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

View raw message