Вопрос

I have used Spring OXM and JiBX in my application.

below is my Spring Config file

<context:component-scan base-package="com.controller"/>

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>

<oxm:jibx-marshaller target-class="com.request.RequestClass" id="rqMarshaller"/>
<oxm:jibx-marshaller target-class="com.response.ResponseClass" id="rsMarshaller"/>

<bean id="xmlViewer" class="org.springframework.web.servlet.view.xml.MarshallingView">
    <constructor-arg ref="rsMarshaller" />
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.BeanNameViewResolver"/>

below is controller class

@Controller
public class MyController {
    @Autowired
    private JibxMarshaller rqMarshaller;

    @RequestMapping(value = "/myrequest", method = RequestMethod.POST)
    public ModelAndView searchFlights(@RequestBody String request) {
        System.out.println("Inside");
        System.out.println("request = "+request);
        Source source = new StreamSource(new StringReader(request));

        RequestClass rq = null;
        try {
            rq = (RequestClass) rqMarshaller.unmarshal(source);
        } catch (XmlMappingException e1) {
            e1.printStackTrace();
        } catch (IOException e1) {
            e1.printStackTrace();
        }

        ResponseClass e = new ResponseClass();
        e.setVersion("2.0");

        Orig ond = new Orig();
        ond.setCode("AIT");

        e.getOrig().add(ond);
        return new ModelAndView("xmlViewer","object",e);
    }
}

When i send XML request it marshaled successfully but for response i got following error message.

org.jibx.runtime.JiBXException: No marshaller defined for class com.response.ResponseClass

I have already defined marshaller for ResponseClassin spring config file.

please help. Thanks.

Это было полезно?

Решение

Finally i figured out the solution !!!

Need to specify the bindingName attribute while registering the JiBxMarshaller.

<oxm:jibx-marshaller target-class="com.request.RequestClass" id="rqMarshaller" bindingName="rqBinding"/>
<oxm:jibx-marshaller target-class="com.response.ResponseClass" id="rsMarshaller" bindingName="rsBinding/>

and specify same name in respective binding/mapping file of JiBX.

That's it !

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top