Announcement Announcement Module
Collapse
No announcement yet.
Getting NoSuchMethodError with RestTemplate in Spring MVC+SWF client app Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Getting NoSuchMethodError with RestTemplate in Spring MVC+SWF client app

    Hi,

    Im a newbie to Spring. Im trying to build a client app which can consume Restful services from our internal API's to populate data in the client. (The API's are RESTful CXF JAX-RS in nature)

    Im using the booking-mvc sample from Spring downloads and Im working off on this. Everything was working fine until I switched the datasource from using some test data to web api response.

    I read about RestTemplate support in Spring 3.0 and thought this might be the solution.Unfortunately, I have hit a dead-end and Im unable to figure out if Im looking at the right technologies to use or if Im doing something drastically wrong.

    Im just trying to get RestTemplate to work with a static xml file at : /WEB-INF/hotels/test.xml file.

    Im trying to implement the code from this tutorial : http://www.thekspace.com/home/compon...-spring-3.html

    I dont get any compile time errors , but when I run the app from Tomcat and hit the url that directs to the controller which in turn uses the RestTemplate instantiation, I get the following error:


    SEVERE: Servlet.service() for servlet Spring MVC Dispatcher Servlet threw exception
    java.lang.NoSuchMethodError: org.springframework.oxm.Unmarshaller.supports(Ljav a/lang/ClassZ
    at org.springframework.http.converter.xml.Marshalling HttpMessageConverter.supports(MarshallingHttpMessa geConverter.java:109)
    at org.springframework.http.converter.AbstractHttpMes sageConverter.canRead(AbstractHttpMessageConverter .java:97)
    at org.springframework.web.client.RestTemplate$Accept HeaderRequestCallback.doWithRequest(RestTemplate.j ava:506)
    at org.springframework.web.client.RestTemplate.doExec ute(RestTemplate.java:436)
    at org.springframework.web.client.RestTemplate.execut e(RestTemplate.java:401)
    at org.springframework.web.client.RestTemplate.getFor Object(RestTemplate.java:199)
    at org.springframework.webflow.samples.booking.JpaBoo kingService.findProgramDetailsById(JpaBookingServi ce.java:255)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:309)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:196)
    at $Proxy14.findProgramDetailsById(Unknown Source)
    at org.springframework.webflow.samples.booking.Hotels Controller.pshow(HotelsController.java:53)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.web.bind.annotation.support.Ha ndlerMethodInvoker.invokeHandlerMethod(HandlerMeth odInvoker.java:176)
    at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.invokeHandlerMethod(An notationMethodHandlerAdapter.java:426)
    at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.handle(AnnotationMetho dHandlerAdapter.java:414)
    at org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:790)
    at org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:719)
    at org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:644)
    at org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServlet.java:549)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:575)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:668)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 343)
    at org.springframework.security.web.access.intercept. FilterSecurityInterceptor.invoke(FilterSecurityInt erceptor.java:109)
    at org.springframework.security.web.access.intercept. FilterSecurityInterceptor.doFilter(FilterSecurityI nterceptor.java:83)
    at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 355)
    at org.springframework.security.web.access.ExceptionT ranslationFilter.doFilter(ExceptionTranslationFilt er.java:97)
    at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 355)
    at org.springframework.security.web.session.SessionMa nagementFilter.doFilter(SessionManagementFilter.ja va:100)
    at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 355)
    at org.springframework.security.web.authentication.An onymousAuthenticationFilter.doFilter(AnonymousAuth enticationFilter.java:78)
    at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 355)
    at org.springframework.security.web.servletapi.Securi tyContextHolderAwareRequestFilter.doFilter(Securit yContextHolderAwareRequestFilter.java:54)
    at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 355)
    at org.springframework.security.web.savedrequest.Requ estCacheAwareFilter.doFilter(RequestCacheAwareFilt er.java:35)
    at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 355)
    at org.springframework.security.web.authentication.http://www.BasicAuthenticationFilter...lter.java:177)
    at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 355)
    at org.springframework.security.web.authentication.Ab stractAuthenticationProcessingFilter.doFilter(Abst ractAuthenticationProcessingFilter.java:188)
    at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 355)
    at org.springframework.security.web.authentication.lo gout.LogoutFilter.doFilter(LogoutFilter.java:105)
    at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 355)
    at org.springframework.security.web.context.SecurityC ontextPersistenceFilter.doFilter(SecurityContextPe rsistenceFilter.java:79)
    at org.springframework.security.web.FilterChainProxy$ VirtualFilterChain.doFilter(FilterChainProxy.java: 355)
    at org.springframework.security.web.FilterChainProxy. doFilter(FilterChainProxy.java:149)
    at org.springframework.web.filter.DelegatingFilterPro xy.invokeDelegate(DelegatingFilterProxy.java:237)
    at org.springframework.web.filter.DelegatingFilterPro xy.doFilter(DelegatingFilterProxy.java:167)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.HiddenHttpMethodFil ter.doFilterInternal(HiddenHttpMethodFilter.java:7 7)
    at org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:680)




    I would greatly appreciate any help or advice on what technologies/libraries to use to consume CXF JAX-RS services which are outside of my stand alone client app. Is this possible using RestTemplate , if so , please let me know what is the right way to integrate this into my app.

    Thanks in advance
    Shilpa

  • #2
    Please use [ code][/code ] tags when posting code.

    You are either mixing spring versions or you have spring in different class loaders... Judging by the stack trace you are mixing versions.

    Comment


    • #3
      Sorry about that, I wasnt sure what formatting was required. Thanks for the tip

      I did notice that I was including some spring 3.0.5 jars in my tomcat classpath for older projects, I went ahead and removed those.
      But, I still get the same error and the same stack trace.(I did a text compare and found no stark difference)

      My application class path has the following jars which were downloaded using maven.
      spring3.0.5
      spring-webflow2.3.1
      spring-security3.0.2
      xstream-1.4.2

      I also see maven downloaded jaxb-api-2.1.ar ( Im not sure if xstream plays along well with this)

      The rest of the application however, runs just fine until the controller switches to the method where I have implemented the RestTemplate code. I am using XStream library for marshalling.

      Here's the code fragment:

      Code:
      ApplicationContext applicationContext = new ClassPathXmlApplicationContext("appContext.xml",
      		JpaBookingService.class);
      RestTemplate restTemplate = applicationContext.getBean("restTemplate", RestTemplate.class);
      try {
      	    // retrieve a particular customer
      	    String url = "http://localhost:8080/hotels/test.xml";
      	    List<Customer> customers = (List) restTemplate.getForObject(url, List.class);
      	    for (Customer customer : customers) {
      		System.out.println("customer - id:" + customer.getId() + ", name:" + customer.getName());
      	    }
      The project uses a static file (test.xml) which is a list of customers with id and name tags. There is a Customer class. I have configured the restTemplate bean in the appContext.xml

      Please let me know if this is still an issue with project set-up or if it has to specifically with the method implementing restTemplate.

      Comment


      • #4
        After talking to my team, they said they had trouble unmarshalling with xstream library and suggested that I use jaxb.
        After making the changes in the code and reading sample tutorials for implementing Jaxb2Marshaller, Im able to get restTemplate to work in my project.

        Thank you for helping out but it would be great to know why the above error was thrown, so I can get a complete understanding of the scenario. Im still completely new to Spring and still trying the ropes. So, Im sure I might have missed something in the above experiment.


        Thanks
        Shilpa

        Comment

        Working...
        X