Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Issue with Spring OXM When Unmarshalling XML data(oxm:jaxb2-marshaller)

 
Ranch Hand
Posts: 99
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Im trying to unmarshall the XML data into Object using Spring OXM Marshaller. Please find the code below that we have written for converting the same. In our project, we are using Rest Service to retrieve the data from the database. When I try to run the url in the browser, it fetches the xml data fine. But I getting an issue when Im trying to unmarshall using the Spring OXM Marshaller.



Im receiving a null pointer error when trying to execute the below line

FilterSelectionResponse obj = (FilterSelectionResponse) this.unmarshaller.unmarshal(new StreamSource(is));

Also below is the code that I have included in my appplicationcontext.xml file



Im passing an InputStream Object as an argument to StreamSource constructor. Please help resolve this issue. Thanks in Advance.
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok so what is null the inputStream? It would really help if you posted the stack trace so that we can debug this a bit easier.

While you are working on getting that stack trace for us I will give you a few other alternatives for handling stuff like this:

First of all you can get rid of just about all of that code by using RestTemplate instead of httpClient. RestTemplate can be configured to use HttpClient to do its work but by default it just uses the standard java net stuff.

Read this blog to get acquainted http://blog.springsource.org/2009/03/27/rest-in-spring-3-resttemplate/

Now your rest call and unmarshalling will be reduced to one line:




Also if you are using 3.1.1 they added a packages to scan to org.springframework.oxm.jaxb.Jaxb2Marshaller which makes the oxm namespace useless and removes the need to define the pesky classes to be bound for every single object. To use that just declare a bean of type

org.springframework.oxm.jaxb.Jaxb2Marshaller and set the package(s) to scan for your JaxB annotated objects. After you do this either autowire or wire this bean into any class as you marshaller/unmarshaller. Remember you do need the very latest Spring for this one, RestTemplate has been there since 3.0 though.

 
Varshini Priya
Ranch Hand
Posts: 99
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bill,

Thanks for the response. Please find the stack trace below for the null pointer exception.





Also I tried the restTemplate that you specified in the above section. But I seem to get a Null Pointer error there as well. Any help on resolving is greatly appreciated.Thanks
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok so exactly what is on the lines specified below?

at com.bizdelegate.ReBusinessDelegate.getFilterSelectionList(RepBusinessDelegate.java:91)
at com.managedbeans.DemandManagedBean.getFilterSelectionList(DemandManagedBean.java:306)

Also have you walked through with a debugger to identify exactly what is null?

 
Thank you my well lotioned goddess! Here, have my favorite tiny ad!
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic