You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Eric Le Goff <el...@gmail.com> on 2007/12/18 17:34:02 UTC

JAXB Unmarshalling

I am going on playing with the restful_jaxrs sample demo


In the Client.java there are these lines

...
URL url = new URL("http://localhost:9000/customerservice/customers/123");
        InputStream in = url.openStream();
        System.out.println(getStringFromInputStream(in));
....


What if I did not want to display the XML content (ie the XML
representation of customer whose Id is 123)
But rather I would like to get the actual instance of Customer with id is 123

Is there some Unmarshalling method to do that , something like

...
URL url = new URL("http://localhost:9000/customerservice/customers/123");
        InputStream in = url.openStream();

// Hypothetic code
Customer customer = (Customer) getObjectFromInputStream(in);
...

How would I implement this

Object getObjectFromInputStream(InputStream in)

method ?

I guess I would have to get a JaxbContext before I can get an Unmarshaller ?


Thanks for your help

Eric




-- 
Eric Le Goff

Re: JAXB Unmarshalling

Posted by Sergey Beryozkin <se...@iona.com>.
Hi

I'm wondering, are you actually asking for a code generation be done on a client side with the help of a description language like WSDL 2.0 or WADL ?

Cheers, Sergey


----- Original Message ----- 
From: "Eric Le Goff" <el...@gmail.com>
To: <cx...@incubator.apache.org>
Sent: Tuesday, December 18, 2007 4:34 PM
Subject: JAXB Unmarshalling


>I am going on playing with the restful_jaxrs sample demo
> 
> 
> In the Client.java there are these lines
> 
> ...
> URL url = new URL("http://localhost:9000/customerservice/customers/123");
>        InputStream in = url.openStream();
>        System.out.println(getStringFromInputStream(in));
> ....
> 
> 
> What if I did not want to display the XML content (ie the XML
> representation of customer whose Id is 123)
> But rather I would like to get the actual instance of Customer with id is 123
> 
> Is there some Unmarshalling method to do that , something like
> 
> ...
> URL url = new URL("http://localhost:9000/customerservice/customers/123");
>        InputStream in = url.openStream();
> 
> // Hypothetic code
> Customer customer = (Customer) getObjectFromInputStream(in);
> ...
> 
> How would I implement this
> 
> Object getObjectFromInputStream(InputStream in)
> 
> method ?
> 
> I guess I would have to get a JaxbContext before I can get an Unmarshaller ?
> 
> 
> Thanks for your help
> 
> Eric
> 
> 
> 
> 
> -- 
> Eric Le Goff

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

Re: JAXB Unmarshalling

Posted by Sergey Beryozkin <se...@iona.com>.
This is a nice refactoring effort and indeed the code looks simplier.

My point was not really to do with the fact that the code in your original proposal was a bit verbose.

IMHO it's kind of trying to catch 2 rabbits at the same time : attempt to write just a simple HTTP code and still expect the
runtime to nicely map the incoming data into classes like Customer. 
In the end one does not get the flexibilty the client code can get from technologies like XPath (as far as writing a robust cliend code is concerned). And one needs to write manually some utility code which will map the in XMl to *generated* types like Customer. What's the point ?

I'd either go for a pure XML approach or would use a description language to do all the client bootsrapping stuff for me.

Cheers, Sergey



> Well, if you REALLY want, you can hide the calling of JAXB in an util, for example you can extend HTTP Client to make it aware of a JAXBContext and be able to accept and return a JAXB object, for example following code:
> 
>        String inputFile = client.getClass().getResource("update_customer.txt").getFile();
>        File input = new File(inputFile);
>        PutMethod put = new PutMethod("http://localhost:9000/customerservice/customers");
>        RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
>        put.setRequestEntity(entity);
>        HttpClient httpclient = new HttpClient();
>        int result = httpclient.executeMethod(put);
>        String response = put.getResponseBodyAsString()
> 
> Will become:
> 
>        PutMethod put = new PutMethod("http://localhost:9000/customerservice/customers");
>        Customer customer = new Customer();
>        RequestEntity entity = new JAXBRequestEntity(customer);
>        put.setRequestEntity(entity);
>        HttpClient httpclient = new JAXBHttpClient(jaxbcontext);
>        int result = httpclient.executeMethod(put);
>        Customer updatedCustomer = put.getResponseBodyAsJAXB()
> 
> Of course, you can also add some nice things such as handle checked exception in this HTTP Client extension, so that it becomes:
>      try {
>        int result = httpclient.executeMethod(put);
>        Customer updatedCustomer = put.getResponseBodyAsJAXB()
>       } catch (CustomerNotFoundException e) {
>       } catch (WebServiceException e)  {
>       }
> 
> Does this make sense?
> 
> Cheers,
> Jervis
>> -----Original Message-----
>> From: Sergey Beryozkin [mailto:sergey.beryozkin@iona.com]
>> Sent: 2007年12月20日 17:54
>> To: cxf-user@incubator.apache.org
>> Subject: Re: JAXB Unmarshalling
>> 
>> That's pretty interesting all right.
>> 
>> I would say that there might not be much point in dealing directly with
>> JAXBContext and pretend
>> that your code is so light and free :-)
>> 
>> Cheers, Sergey
>> 
>> ----- Original Message -----
>> From: "Liu, Jervis" <jl...@iona.com>
>> To: <cx...@incubator.apache.org>
>> Sent: Thursday, December 20, 2007 7:18 AM
>> Subject: RE: JAXB Unmarshalling
>> 
>> 
>> >
>> >> -----Original Message-----
>> >> From: Sergey Beryozkin [mailto:sergey.beryozkin@iona.com]
>> >> Sent: 2007年12月19日 22:40
>> >> To: cxf-user@incubator.apache.org
>> >> Subject: Re: JAXB Unmarshalling
>> >>
>> >> By the way, can this approach (which uses JAXBContexts) work for you in
>> >> CXF? :
>> >>
>> >>
>> http://weblogs.java.net/blog/mhadley/archive/2006/03/restful_web_ser_1.
>> >> html
>> >>
>> > [Liu, Jervis] You don’t have to use JAX-WS Dispatch API in this case. Once
>> you grab the InputStream from HTTPClient (or other lightweight http client
>> stack), you can call JAXB to marshal the response to your Customer object.
>> There is no point to use a heavy stack like a JAX-WS runtime to do such a
>> simple task. Following code snippet should do the job:
>> >
>> >    public Object getObjectFromInputStream (Class<Object> type,
>> InputStream is) {
>> >        try {
>> >            JAXBContext context = getJAXBContext(type);
>> >            Unmarshaller unmarshaller = context.createUnmarshaller();
>> >            return unmarshaller.unmarshal(is);
>> >        } catch (JAXBException e) {
>> >            e.printStackTrace();
>> >        }
>> >
>> >        return null;
>> >    }
>> >
>> >    private JAXBContext getJAXBContext(Class type) throws
>> JAXBException {
>> >        synchronized (jaxbContexts) {
>> >            JAXBContext context = jaxbContexts.get(type);
>> >            if (context == null) {
>> >                context = JAXBContext.newInstance(type);
>> >                jaxbContexts.put(type, context);
>> >            }
>> >            return context;
>> >        }
>> >    }
>> >
>> >    static Map<Class, JAXBContext> jaxbContexts = new
>> WeakHashMap<Class, JAXBContext>();
>> >
>> >> You'd still need a schema describing the data like Customer, etc...
>> >> Cheers. Sergey
>> >>
>> >>
>> >>
>> >> ----- Original Message -----
>> >> From: "Eric Le Goff" <el...@gmail.com>
>> >> To: <cx...@incubator.apache.org>
>> >> Sent: Tuesday, December 18, 2007 4:34 PM
>> >> Subject: JAXB Unmarshalling
>> >>
>> >>
>> >> >I am going on playing with the restful_jaxrs sample demo
>> >> >
>> >> >
>> >> > In the Client.java there are these lines
>> >> >
>> >> > ...
>> >> > URL url = new
>> >> URL("http://localhost:9000/customerservice/customers/123");
>> >> >        InputStream in = url.openStream();
>> >> >        System.out.println(getStringFromInputStream(in));
>> >> > ....
>> >> >
>> >> >
>> >> > What if I did not want to display the XML content (ie the XML
>> >> > representation of customer whose Id is 123)
>> >> > But rather I would like to get the actual instance of Customer with id is
>> 123
>> >> >
>> >> > Is there some Unmarshalling method to do that , something like
>> >> >
>> >> > ...
>> >> > URL url = new
>> >> URL("http://localhost:9000/customerservice/customers/123");
>> >> >        InputStream in = url.openStream();
>> >> >
>> >> > // Hypothetic code
>> >> > Customer customer = (Customer) getObjectFromInputStream(in);
>> >> > ...
>> >> >
>> >> > How would I implement this
>> >> >
>> >> > Object getObjectFromInputStream(InputStream in)
>> >> >
>> >> > method ?
>> >> >
>> >> > I guess I would have to get a JaxbContext before I can get an
>> >> Unmarshaller ?
>> >> >
>> >> >
>> >> > Thanks for your help
>> >> >
>> >> > Eric
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > Eric Le Goff
>> >>
>> >> ----------------------------
>> >> IONA Technologies PLC (registered in Ireland)
>> >> Registered Number: 171387
>> >> Registered Address: The IONA Building, Shelbourne Road, Dublin 4,
>> Ireland
>> >
>> > ----------------------------
>> > IONA Technologies PLC (registered in Ireland)
>> > Registered Number: 171387
>> > Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
>> >
>> 
>> ----------------------------
>> IONA Technologies PLC (registered in Ireland)
>> Registered Number: 171387
>> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
> 
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
>

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

RE: JAXB Unmarshalling

Posted by "Liu, Jervis" <jl...@iona.com>.
Well, if you REALLY want, you can hide the calling of JAXB in an util, for example you can extend HTTP Client to make it aware of a JAXBContext and be able to accept and return a JAXB object, for example following code:

        String inputFile = client.getClass().getResource("update_customer.txt").getFile();
        File input = new File(inputFile);
        PutMethod put = new PutMethod("http://localhost:9000/customerservice/customers");
        RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
        put.setRequestEntity(entity);
        HttpClient httpclient = new HttpClient();
        int result = httpclient.executeMethod(put);
        String response = put.getResponseBodyAsString()

Will become:

        PutMethod put = new PutMethod("http://localhost:9000/customerservice/customers");
        Customer customer = new Customer();
        RequestEntity entity = new JAXBRequestEntity(customer);
        put.setRequestEntity(entity);
        HttpClient httpclient = new JAXBHttpClient(jaxbcontext);
        int result = httpclient.executeMethod(put);
        Customer updatedCustomer = put.getResponseBodyAsJAXB()

Of course, you can also add some nice things such as handle checked exception in this HTTP Client extension, so that it becomes:
      try {
        int result = httpclient.executeMethod(put);
        Customer updatedCustomer = put.getResponseBodyAsJAXB()
       } catch (CustomerNotFoundException e) {
       } catch (WebServiceException e)  {
       }

Does this make sense?

Cheers,
Jervis
> -----Original Message-----
> From: Sergey Beryozkin [mailto:sergey.beryozkin@iona.com]
> Sent: 2007年12月20日 17:54
> To: cxf-user@incubator.apache.org
> Subject: Re: JAXB Unmarshalling
> 
> That's pretty interesting all right.
> 
> I would say that there might not be much point in dealing directly with
> JAXBContext and pretend
> that your code is so light and free :-)
> 
> Cheers, Sergey
> 
> ----- Original Message -----
> From: "Liu, Jervis" <jl...@iona.com>
> To: <cx...@incubator.apache.org>
> Sent: Thursday, December 20, 2007 7:18 AM
> Subject: RE: JAXB Unmarshalling
> 
> 
> >
> >> -----Original Message-----
> >> From: Sergey Beryozkin [mailto:sergey.beryozkin@iona.com]
> >> Sent: 2007年12月19日 22:40
> >> To: cxf-user@incubator.apache.org
> >> Subject: Re: JAXB Unmarshalling
> >>
> >> By the way, can this approach (which uses JAXBContexts) work for you in
> >> CXF? :
> >>
> >>
> http://weblogs.java.net/blog/mhadley/archive/2006/03/restful_web_ser_1.
> >> html
> >>
> > [Liu, Jervis] You don’t have to use JAX-WS Dispatch API in this case. Once
> you grab the InputStream from HTTPClient (or other lightweight http client
> stack), you can call JAXB to marshal the response to your Customer object.
> There is no point to use a heavy stack like a JAX-WS runtime to do such a
> simple task. Following code snippet should do the job:
> >
> >    public Object getObjectFromInputStream (Class<Object> type,
> InputStream is) {
> >        try {
> >            JAXBContext context = getJAXBContext(type);
> >            Unmarshaller unmarshaller = context.createUnmarshaller();
> >            return unmarshaller.unmarshal(is);
> >        } catch (JAXBException e) {
> >            e.printStackTrace();
> >        }
> >
> >        return null;
> >    }
> >
> >    private JAXBContext getJAXBContext(Class type) throws
> JAXBException {
> >        synchronized (jaxbContexts) {
> >            JAXBContext context = jaxbContexts.get(type);
> >            if (context == null) {
> >                context = JAXBContext.newInstance(type);
> >                jaxbContexts.put(type, context);
> >            }
> >            return context;
> >        }
> >    }
> >
> >    static Map<Class, JAXBContext> jaxbContexts = new
> WeakHashMap<Class, JAXBContext>();
> >
> >> You'd still need a schema describing the data like Customer, etc...
> >> Cheers. Sergey
> >>
> >>
> >>
> >> ----- Original Message -----
> >> From: "Eric Le Goff" <el...@gmail.com>
> >> To: <cx...@incubator.apache.org>
> >> Sent: Tuesday, December 18, 2007 4:34 PM
> >> Subject: JAXB Unmarshalling
> >>
> >>
> >> >I am going on playing with the restful_jaxrs sample demo
> >> >
> >> >
> >> > In the Client.java there are these lines
> >> >
> >> > ...
> >> > URL url = new
> >> URL("http://localhost:9000/customerservice/customers/123");
> >> >        InputStream in = url.openStream();
> >> >        System.out.println(getStringFromInputStream(in));
> >> > ....
> >> >
> >> >
> >> > What if I did not want to display the XML content (ie the XML
> >> > representation of customer whose Id is 123)
> >> > But rather I would like to get the actual instance of Customer with id is
> 123
> >> >
> >> > Is there some Unmarshalling method to do that , something like
> >> >
> >> > ...
> >> > URL url = new
> >> URL("http://localhost:9000/customerservice/customers/123");
> >> >        InputStream in = url.openStream();
> >> >
> >> > // Hypothetic code
> >> > Customer customer = (Customer) getObjectFromInputStream(in);
> >> > ...
> >> >
> >> > How would I implement this
> >> >
> >> > Object getObjectFromInputStream(InputStream in)
> >> >
> >> > method ?
> >> >
> >> > I guess I would have to get a JaxbContext before I can get an
> >> Unmarshaller ?
> >> >
> >> >
> >> > Thanks for your help
> >> >
> >> > Eric
> >> >
> >> >
> >> >
> >> >
> >> > --
> >> > Eric Le Goff
> >>
> >> ----------------------------
> >> IONA Technologies PLC (registered in Ireland)
> >> Registered Number: 171387
> >> Registered Address: The IONA Building, Shelbourne Road, Dublin 4,
> Ireland
> >
> > ----------------------------
> > IONA Technologies PLC (registered in Ireland)
> > Registered Number: 171387
> > Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
> >
> 
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

Re: JAXB Unmarshalling

Posted by Sergey Beryozkin <se...@iona.com>.
That's pretty interesting all right.

I would say that there might not be much point in dealing directly with JAXBContext and pretend
that your code is so light and free :-)

Cheers, Sergey

----- Original Message ----- 
From: "Liu, Jervis" <jl...@iona.com>
To: <cx...@incubator.apache.org>
Sent: Thursday, December 20, 2007 7:18 AM
Subject: RE: JAXB Unmarshalling


> 
>> -----Original Message-----
>> From: Sergey Beryozkin [mailto:sergey.beryozkin@iona.com]
>> Sent: 2007年12月19日 22:40
>> To: cxf-user@incubator.apache.org
>> Subject: Re: JAXB Unmarshalling
>> 
>> By the way, can this approach (which uses JAXBContexts) work for you in
>> CXF? :
>> 
>> http://weblogs.java.net/blog/mhadley/archive/2006/03/restful_web_ser_1.
>> html
>> 
> [Liu, Jervis] You don’t have to use JAX-WS Dispatch API in this case. Once you grab the InputStream from HTTPClient (or other lightweight http client stack), you can call JAXB to marshal the response to your Customer object. There is no point to use a heavy stack like a JAX-WS runtime to do such a simple task. Following code snippet should do the job: 
> 
>    public Object getObjectFromInputStream (Class<Object> type,  InputStream is) {
>        try {
>            JAXBContext context = getJAXBContext(type);
>            Unmarshaller unmarshaller = context.createUnmarshaller();
>            return unmarshaller.unmarshal(is);
>        } catch (JAXBException e) {
>            e.printStackTrace();         
>        }
> 
>        return null;
>    }
> 
>    private JAXBContext getJAXBContext(Class type) throws JAXBException {
>        synchronized (jaxbContexts) {
>            JAXBContext context = jaxbContexts.get(type);
>            if (context == null) {
>                context = JAXBContext.newInstance(type);
>                jaxbContexts.put(type, context);
>            }
>            return context;
>        }
>    }
> 
>    static Map<Class, JAXBContext> jaxbContexts = new WeakHashMap<Class, JAXBContext>();
> 
>> You'd still need a schema describing the data like Customer, etc...
>> Cheers. Sergey
>> 
>> 
>> 
>> ----- Original Message -----
>> From: "Eric Le Goff" <el...@gmail.com>
>> To: <cx...@incubator.apache.org>
>> Sent: Tuesday, December 18, 2007 4:34 PM
>> Subject: JAXB Unmarshalling
>> 
>> 
>> >I am going on playing with the restful_jaxrs sample demo
>> >
>> >
>> > In the Client.java there are these lines
>> >
>> > ...
>> > URL url = new
>> URL("http://localhost:9000/customerservice/customers/123");
>> >        InputStream in = url.openStream();
>> >        System.out.println(getStringFromInputStream(in));
>> > ....
>> >
>> >
>> > What if I did not want to display the XML content (ie the XML
>> > representation of customer whose Id is 123)
>> > But rather I would like to get the actual instance of Customer with id is 123
>> >
>> > Is there some Unmarshalling method to do that , something like
>> >
>> > ...
>> > URL url = new
>> URL("http://localhost:9000/customerservice/customers/123");
>> >        InputStream in = url.openStream();
>> >
>> > // Hypothetic code
>> > Customer customer = (Customer) getObjectFromInputStream(in);
>> > ...
>> >
>> > How would I implement this
>> >
>> > Object getObjectFromInputStream(InputStream in)
>> >
>> > method ?
>> >
>> > I guess I would have to get a JaxbContext before I can get an
>> Unmarshaller ?
>> >
>> >
>> > Thanks for your help
>> >
>> > Eric
>> >
>> >
>> >
>> >
>> > --
>> > Eric Le Goff
>> 
>> ----------------------------
>> IONA Technologies PLC (registered in Ireland)
>> Registered Number: 171387
>> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
> 
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
>

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

Re: JAXB Unmarshalling

Posted by Eric Le Goff <er...@babelgum.com>.
Jervis,

Thanks for the tips which was exactly what I had been expecting

> [Liu, Jervis] You don't have to use JAX-WS Dispatch API in this case. Once you grab the InputStream from HTTPClient (or other lightweight http client stack), you can call JAXB to marshal the response to your Customer object. There is no point to use a heavy stack like a JAX-WS runtime to do such a simple task. Following code snippet should do the job:
>
>     public Object getObjectFromInputStream (Class<Object> type,  InputStream is) {


BTW I had to replace with
public Object getObjectFromInputStream (Class<?> type,  InputStream is) {
so that I could call a getObjectFromInputStream(Customer.class, is)


Would not it be nice if this piece of code was part of CXF , because I
guess I am not the only one who needs this



-- 
Eric Le Goff

RE: JAXB Unmarshalling

Posted by "Liu, Jervis" <jl...@iona.com>.
> -----Original Message-----
> From: Sergey Beryozkin [mailto:sergey.beryozkin@iona.com]
> Sent: 2007年12月19日 22:40
> To: cxf-user@incubator.apache.org
> Subject: Re: JAXB Unmarshalling
> 
> By the way, can this approach (which uses JAXBContexts) work for you in
> CXF? :
> 
> http://weblogs.java.net/blog/mhadley/archive/2006/03/restful_web_ser_1.
> html
> 
[Liu, Jervis] You don’t have to use JAX-WS Dispatch API in this case. Once you grab the InputStream from HTTPClient (or other lightweight http client stack), you can call JAXB to marshal the response to your Customer object. There is no point to use a heavy stack like a JAX-WS runtime to do such a simple task. Following code snippet should do the job: 

    public Object getObjectFromInputStream (Class<Object> type,  InputStream is) {
        try {
            JAXBContext context = getJAXBContext(type);
            Unmarshaller unmarshaller = context.createUnmarshaller();
            return unmarshaller.unmarshal(is);
        } catch (JAXBException e) {
            e.printStackTrace();         
        }

        return null;
    }

    private JAXBContext getJAXBContext(Class type) throws JAXBException {
        synchronized (jaxbContexts) {
            JAXBContext context = jaxbContexts.get(type);
            if (context == null) {
                context = JAXBContext.newInstance(type);
                jaxbContexts.put(type, context);
            }
            return context;
        }
    }

    static Map<Class, JAXBContext> jaxbContexts = new WeakHashMap<Class, JAXBContext>();

> You'd still need a schema describing the data like Customer, etc...
> Cheers. Sergey
> 
> 
> 
> ----- Original Message -----
> From: "Eric Le Goff" <el...@gmail.com>
> To: <cx...@incubator.apache.org>
> Sent: Tuesday, December 18, 2007 4:34 PM
> Subject: JAXB Unmarshalling
> 
> 
> >I am going on playing with the restful_jaxrs sample demo
> >
> >
> > In the Client.java there are these lines
> >
> > ...
> > URL url = new
> URL("http://localhost:9000/customerservice/customers/123");
> >        InputStream in = url.openStream();
> >        System.out.println(getStringFromInputStream(in));
> > ....
> >
> >
> > What if I did not want to display the XML content (ie the XML
> > representation of customer whose Id is 123)
> > But rather I would like to get the actual instance of Customer with id is 123
> >
> > Is there some Unmarshalling method to do that , something like
> >
> > ...
> > URL url = new
> URL("http://localhost:9000/customerservice/customers/123");
> >        InputStream in = url.openStream();
> >
> > // Hypothetic code
> > Customer customer = (Customer) getObjectFromInputStream(in);
> > ...
> >
> > How would I implement this
> >
> > Object getObjectFromInputStream(InputStream in)
> >
> > method ?
> >
> > I guess I would have to get a JaxbContext before I can get an
> Unmarshaller ?
> >
> >
> > Thanks for your help
> >
> > Eric
> >
> >
> >
> >
> > --
> > Eric Le Goff
> 
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

Re: JAXB Unmarshalling

Posted by Sergey Beryozkin <se...@iona.com>.
By the way, can this approach (which uses JAXBContexts) work for you in CXF? :

http://weblogs.java.net/blog/mhadley/archive/2006/03/restful_web_ser_1.html

You'd still need a schema describing the data like Customer, etc...
Cheers. Sergey



----- Original Message ----- 
From: "Eric Le Goff" <el...@gmail.com>
To: <cx...@incubator.apache.org>
Sent: Tuesday, December 18, 2007 4:34 PM
Subject: JAXB Unmarshalling


>I am going on playing with the restful_jaxrs sample demo
> 
> 
> In the Client.java there are these lines
> 
> ...
> URL url = new URL("http://localhost:9000/customerservice/customers/123");
>        InputStream in = url.openStream();
>        System.out.println(getStringFromInputStream(in));
> ....
> 
> 
> What if I did not want to display the XML content (ie the XML
> representation of customer whose Id is 123)
> But rather I would like to get the actual instance of Customer with id is 123
> 
> Is there some Unmarshalling method to do that , something like
> 
> ...
> URL url = new URL("http://localhost:9000/customerservice/customers/123");
>        InputStream in = url.openStream();
> 
> // Hypothetic code
> Customer customer = (Customer) getObjectFromInputStream(in);
> ...
> 
> How would I implement this
> 
> Object getObjectFromInputStream(InputStream in)
> 
> method ?
> 
> I guess I would have to get a JaxbContext before I can get an Unmarshaller ?
> 
> 
> Thanks for your help
> 
> Eric
> 
> 
> 
> 
> -- 
> Eric Le Goff

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland