Satya
Satya

Reputation: 1

spring(integration) support for xml over http

I need to integrate our application with a legacy system which accepts xml requests(no contract) over http (POST) and sends another xml as response. Does spring or spring integration has any build in function to do so?

UPDATE: From Artem's suggestion I am using following code.

    <int:channel id="RequestChannel"/>
<int:channel id="ResponseChannel"/>
<int:gateway id="Gateway"
    service-interface="<package>.DataBuilder" default-request-channel="RequestHeaderEnricher"  default-reply-channel="ResponseChannel"/>

<int:channel id="RequestHeaderEnricher"/>
<int:header-enricher input-channel="RequestHeaderEnricher" output-channel="RequestChannel">
    <int:header name="Content-Type" value="text/xml" />
    <int:header name="Accept" value="text/xml" />
</int:header-enricher>

<int-http:outbound-gateway id="HttpGateway"
    request-channel="RequestChannel" url="http://<host>:<port>/XML_WS_A"
    http-method="POST"  charset="UTF-8" reply-timeout="6000" reply-channel="ResponseChannel"
    message-converters="messageConverters" request-factory="requestFactory">

</int-http:outbound-gateway>

<util:list id="messageConverters">
    <ref bean="marshallingHttpMessageConverter"/>
</util:list>

<bean id="marshallingHttpMessageConverter"
      class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
  <property name="marshaller" ref="marshaller" />
  <property name="unmarshaller" ref="marshaller" />
</bean>

<oxm:jaxb2-marshaller id="marshaller">
    <oxm:class-to-be-bound name="<package>.ExternalDataRequest"/>
</oxm:jaxb2-marshaller>

<bean id="requestFactory"
      class="org.springframework.http.client.SimpleClientHttpRequestFactory">
    <property name="connectTimeout" value="5000"/>
    <property name="readTimeout"    value="5000"/>
</bean>

Upvotes: 0

Views: 1540

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121177

Spring MVC provides for this case RestTemplate.

Spring integration provides more high abstraction over RestTemplate - <int-http:outbound-gateway>

For HTTP protocol it doesn't matter which type of data you send. So, you can simply send and receive an XML, e.g. as a String representation.

To get deal with some Object XML Mapping you should study: http://docs.spring.io/spring/docs/4.0.1.RELEASE/spring-framework-reference/htmlsingle/#oxm and http://docs.spring.io/spring-integration/docs/3.0.0.RELEASE/reference/html/xml.html.

I don't see yet other ways to help you, as your question is teorethical and abuts to the Docs.

Upvotes: 1

Related Questions