Thanks so much for the response. Maybe I should describe it from the
perspective of a library user. Currently, the user is given a library that,
given a particular consumer request, is returned a fixed-formatted response (in
the form of some flavor of streamed XML-based structure). It is a fixed format
in that the WS is only using the output format(s) (from the finite number of
java output classes in the library) it knows how to serialize as part of a
response.
This is too limited. I want to give the user the opportunity to do the
following:
Class MyCustomProcessor implements CustomProcessor , where the interface
contains 2 method definitions:
public void processInputMessage(String msg); /* the msg is provided to the user
in a structure they are inherently familiar with, and therefore know how to
"process". When they are through processing it, they have created some sort of
structure, presumably as java objects (captured in MyCustomOutputObject after
processing) */
public CustomOutputObject getProcessedMessage();/* the returned object
(probably nested classes, but whatever) gets embedded in the response returned
by the JAXRS method/subresource. Here though, the structure of the
CustomOutputObject is unknown to the library at runtime. */
So, then user's custom processor might look like:
Class MyCustomProcessor implements CustomerProcessor {
Private MyCustomOutputObject so; /* the returned custom output objects */
.
.
public void processInputMessage(String msg);
public CustomOutputObject getProcessedMessage();
.
}
My ideas were:
1) have CustomOutputObject be an abstract class (part of the library) that the
user must extend (MyCustomOutputObject extends CustomOutputObject ) for their
custom output classes. I was hoping to figure out a way via
reflection/introspection or anything convenient, to have the library assemble
those custom output classes at runtime in way that JAXRS/JAXB (whatever) can
figure out how to serialize as part of the response. I made progress on the
above except that the WS apparently didn't know what to do with the
MyCustomOutputObject (it was missing in the response).
2) rather than:
public CustomOutputObject getProcessedMessage();
, have a simpler
public String getProcessedMessage();
Here, the library just has to embed the String blindly in the response. I must
say, I don't know how to do this in JAXRS, and would need to (i.e. how do you
take a java container that the JAXRS/JAXB knows how to serialize a priori as
XML and embed the XML string in it? -> if this was a conventional servlet, I
would know what to do!).
So, I would like to be able to do 1) ( because some day would like to do all
this outside a web environment with EJBs, etc.), but doing 2) would be FINE for
now..
Too much information? Thanks for any response!
-----Original Message-----
From: Sergey Beryozkin [mailto:[email protected]]
Sent: Tuesday, February 08, 2011 5:13 AM
To: [email protected]
Subject: Re: Serialize Custom Class with CXF via Reflection (or similar)
Hi
On Tue, Feb 8, 2011 at 2:40 AM, Tim Clotworthy <
[email protected]> wrote:
> Hello,
> I am involved with a project now where we are trying to provide a (JAX-RS)
> web services library that allows implementers to write their own classes for
> customizing the format of a web service response.
>
> I am trying to do something like the following:
>
> LibraryContainerClass
>
> |
> --- ContainedUserClass
>
> where the JAX-RS - based webservices library can serialize the contained
> user class (i.e. ContainedUserClass) without explicitly knowing its
> structure.
>
> Is LibraryContainerClass mapped to a JAX-RS root resource class which
returns ContainedUserClass instances on demand ?
> Not sure whether this would be a CXF-specific (Aegis?) capability, or a
> more general xml-tool (Aegis/jaxb/dom) capability but, as an example, is
> there some way to have the CXF capability use reflection to derive the
> structure needed by JAX-RS to serialize the output?
>
>
Usually, a custom JAX-RS MessageBodyWriter can serialize the data as needed.
CXF JAX-RS has JAXB and Aegis providers. The question is whether you'd like
to have a custom provider which can control the format of the output or not.
JAXBProvider can be customized a lot...
> I tried having an abstract class that the library user's output class must
> extend, but it didn't work.
>
>
Can you provide more info please ?
Cheers, Sergey
> Any response is appreciated (including even perhaps directing me to someone
> or something else). Thanks for any reply!
>