Hi

See comments inline please

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



Hello,

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
(commons-httpclient-3.1jar)

WSDL (trimmed) looks like this:
...
<wsdl:types>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema";
targetNamespace="http://mynamespace";
elementFormDefault="qualified" xmlns:msg="http://myothernamespace";
xmlns:emailbus="http://mythirdnamespace";>
<xsd:import schemaLocation="myothernamespace.xsd"
namespace="http://myothernamespace"; />
<xsd:import schemaLocation="mythirdnamespace.xsd"
namespace="http://mythirdnamespace"; />
<xsd:element name="sendEmail">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="msgCtx" type="msg:ServiceMessageContext"
minOccurs="1" />
<xsd:element name="emailMessage" type="emailbus:EmailMessage"
minOccurs="1" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>

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

msgCtx (trimmed) looks like this:
<complexType name="ServiceMessageContext">
<sequence>
<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" />
</sequence>
</complexType>

emailMessage, like this:
<complexType name="EmailMessage">
<sequence>
<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" />
</sequence>
</complexType>
<complexType name="Body">
<sequence>
<element name="content" type="xsd:base64Binary"
xmime:expectedContentTypes="text/html" />
</sequence>
</complexType>
<complexType name="Attachment">
<sequence>
<element name="content" type="xsd:base64Binary" />
</sequence>
</complexType>

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

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

<model xlmns="http://cxf.apache.org/jaxrs";>
<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;
</operation>
</resource>
</model>

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

cheers
Reinis
--
View this message in context: 
http://old.nabble.com/no-annotations-RESTfull-webservice---a-complex-use-case-tp27685209p27685209.html
Sent from the cxf-user mailing list archive at Nabble.com.

Reply via email to