Announcement Announcement Module
Collapse
No announcement yet.
Configuring a Jax-ws client in Spring Integration Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configuring a Jax-ws client in Spring Integration

    Hello,
    I am new on Spring Integration and I have a question which I can't find answer.
    I have created a small project to learn how SI works (from Spring sample), I am using a WSDL which define a "calculator" web service (it have a method which add two numbers).
    This is my config file:
    Code:
    <chain input-channel="addInputChannel" output-channel="addOutputChannel">
    	<ws:header-enricher>
    		<ws:soap-action value="http://www.example.org/calculatrice/add"/>
    	</ws:header-enricher>
    	<ws:outbound-gateway uri="http://localhost:8088/mockcalculatriceSOAP"/>
    </chain>
    
    <!-- The response from the service is logged to the console. -->
    <stream:stdout-channel-adapter id="addOutputChannel"/>
    And my code:
    Code:
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("springWsAccess-Config.xml");
    ChannelResolver channelResolver = new BeanFactoryChannelResolver(context);
    String requestXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\r\n" 
           + "<ns2:add xmlns:ns2=\"http://www.example.org/calculatrice/\">\r\n" 
           + "    <number1>10.0</number1>\r\n" 
           + "    <number2>21.0</number2>\r\n" 
           + "</ns2:add>";
    
    Message<String> message = MessageBuilder.withPayload(requestXml).build();
    
    // Send the Message to the handler's input channel
    MessageChannel channel = channelResolver.resolveChannelName("addInputChannel");
    channel.send(message);
    It works but now, I want using jaxb (I don't want to deal directly with xml) and I don't understand how I will configure Spring to do that, even after googling and reading some tutorials
    I think that I must generate the jaxb client code with wsimport, but how it will be integrated in Spring SI?

  • #2
    I have progressed but...
    This my new config:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    	xmlns:int="http://www.springframework.org/schema/integration"
    	xmlns:ws="http://www.springframework.org/schema/integration/ws"
    	xmlns:file="http://www.springframework.org/schema/integration/file"
    	xmlns:oxm="http://www.springframework.org/schema/oxm"
    	xmlns:stream="http://www.springframework.org/schema/integration/stream"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/integration/ws
    http://www.springframework.org/schema/integration/ws/spring-integration-ws-2.0.xsd
    http://www.springframework.org/schema/integration/file
    http://www.springframework.org/schema/integration/file/spring-integration-file-2.0.xsd
    http://www.springframework.org/schema/integration
    http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
    http://www.springframework.org/schema/oxm
    http://www.springframework.org/schema/oxm/spring-oxm.xsd
    http://www.springframework.org/schema/integration/stream
    http://www.springframework.org/schema/integration/stream/spring-integration-stream-2.0.xsd">
    
    	<bean id="calculatorService" class="com.ccrie.core.CalcServiceImpl">
    		<property name="channel" ref="calcChannel" />
    		
    	</bean>
    	
    	<oxm:jaxb2-marshaller id="jaxb2Marshaller" contextPath="com.ccrie.square"/>
    	
    	<int:channel id="calcChannel" >
    	</int:channel>
    
    	<int:header-value-router input-channel="calcChannel" header-name="operation">
    	  <int:mapping value="add" channel="addObjectChannel" />
    	  <int:mapping value="sub" channel="addObjectChannel" /><!-- Not yet implemented -->
    	</int:header-value-router>
    	
    	<int:transformer input-channel="addObjectChannel" method="transformRequest" output-channel="addHeaderChannel" >
      		<bean class="com.ccrie.square.transfomer.MapAddTransformer"/>
    	</int:transformer>
    	
    	<ws:header-enricher input-channel="addHeaderChannel"  output-channel="wsReply">
    		<ws:soap-action value="http://www.example.org/calculatrice/add"/>
    	</ws:header-enricher>
    	
    	<ws:outbound-gateway  uri="http://localhost:8088/mockcalculatriceSOAP"
    		request-channel="wsReply"
    		reply-channel="addResponseObjectChannel"
    		marshaller="jaxb2Marshaller" 
    		unmarshaller="jaxb2Marshaller"/>
    	
    	<int:channel id="wsReply"/>
    	
    	<int:transformer input-channel="addResponseObjectChannel" method="transformResponse" output-channel="addResponseChannel" >
      		<bean class="com.ccrie.square.transfomer.MapAddTransformer"/>
    	</int:transformer>
    	
    	<stream:stdout-channel-adapter id="addResponseChannel" />
    	
    </beans>
    I use a router which has to select the correct way corresponding to operation selected, a transformer , it convert a Map in a Jaxb object, which will be unmarshalled by the ws:gateway, and a header-enricher which add the soap-action. The response use a simpler mechanism with only one transformer to convert the Jaxb response in a Map.
    It works but result is only display in console, and I don't understand how I can receive the response, help please

    Comment

    Working...
    X