Uttakarsh
Uttakarsh

Reputation: 35

Unmarshalling the XML using JAXB

Actually I am very new at spring and currently due to some requirement, I am working with spring-integration, I have made few JAXB classes to convert the data into XML and have to send it through webservices but in response I am getting the XML back with some new element, I want to know how to unmarshall the new XML with same JAXB classes that I have made?

Upvotes: 1

Views: 206

Answers (1)

crm86
crm86

Reputation: 1394

I use the following component to do that (java configuration):

    @Bean
    public Jaxb2Marshaller jaxb2Marshaller() throws Exception {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); 
        /* Packages with root elements (@XmlRootElement). Your JAXB classes  */     
        marshaller.setContextPaths("...");
        return marshaller;
    }   

    @Bean
    @ServiceActivator(inputChannel = "toWebServiceChannel")
    public MessageHandler wsGateway() throws Exception {                    
        ConfigWebServiceURLProvider provider = new ConfigWebServiceURLProvider(isHttps, host, port, endpoint);
        /* marshaller and unmarshaller could be the same */  
        MarshallingWebServiceOutboundGateway gw = new MarshallingWebServiceOutboundGateway(url, jaxb2Marshaller(), jaxb2Marshaller());
        gw.setOutputChannelName( "fromWebServiceChannel" );
        return gw;
    }

Upvotes: 1

Related Questions