Announcement Announcement Module
Collapse
No announcement yet.
Using web service gateways (ws:inbound-gateway and ws:outbound-gateway) with JMS Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using web service gateways (ws:inbound-gateway and ws:outbound-gateway) with JMS

    Is there any way to use jms as a transport with spring-integration support for web services (ws:inbound-gateway and ws:outbound-gateway)?

    I am trying following configuration but it is not working as the publish-subscribe-channel doesn't use the outbound-gateway to send message.


    Code:
    <ws:outbound-gateway id="wsClientGateway" 
      uri="jms:${jndi.config.topic}?messageType=TEXT_MESSAGE
      message-factory="messageFactory"
      marshaller="marshaller" unmarshaller="marshaller"
      request-channel="requestChannel"/>
    
    <int-jms:publish-subscribe-channel 
      id="requestChannel" 
      destination-resolver="destinationResolver"
      topic-name="${jndi.config.topic}"				
      connection-factory="connectionFactory"			
      acknowledge="auto"/>
    
    <bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory" />
    Can someone please share your experience?

    Thanks
    Last edited by fazahid; Jul 31st, 2012, 01:05 PM.

  • #2
    I may be missing something, but here is the question.
    In the configuration above WS Outbound Gateway expects a message from 'configServiceChannel' (not the other way around).

    Also, you are inquiring about a non-working solution to a use case which you didn't share
    Could you please elaborate on your requirement at the high level? What are you trying to accomplish?

    Comment


    • #3
      I am sorry if my explanation was not quite clear. Basically I need to implement a webservice client (and after that a webservice server). I have already worked with the samples given by spring-integration team. That implementation uses HTTP as a transport layer. The client is making a HTTP request and server is sending back HTTP response. Instead of using HTTP I would like to use JMS as a transport layer. In this case client sends a SOAP-Request to a Queue (the server is listening to this queue) and while sending it also creates a temporary Queue and set that in the RepyTo in the JMS message header. Server gets receives the request from the Queue process it and then send back a SOAP-Response using the ReplyTo queue. I know we can do it using spring-ws and spring-jms libraries. I would like to do it using spring-integration support for ws and jms:

      client sending request: java object -> Soap Message -> JMS message (payload is the SOAP xml)
      server receiving request: JMS message (payload is the SOAP xml) -> Soap Message -> java object
      server sending back response: java object -> Soap Message -> JMS message (payload is the SOAP xml)

      FYI- for marshalling and unmarshalling (java object to xml and xml to java object) I am using JAXB

      Let me now if you need more information.

      Thanks

      Comment


      • #4
        The underlying foundation for Spring Integration's Web Service adapters is Spring-WS, so you can configure the transports in the typical Spring-WS way. Basically the "entry point" to the Spring Integration gateway is at the "endpoint"-level in Spring-WS terminology. The Spring-WS MessageDispatcher can still be configured as normal (so, for example, you can rely on alternate transports instead of HTTP).

        Hope that helps.
        -Mark

        Comment


        • #5
          Mark,

          Thanks for your confirmation. I have already implemented this usecase using spring-ws and spring-jms support and now trying to implement the same usecase using spring-integration. For example I am giving xml configuration for webservice client that I am trying right now. Can you please check what I am missing?

          Code:
          <bean id="jndiEnvironment" class="java.util.Properties">
          		<constructor-arg>
          			<map>
          				<entry key="java.naming.factory.initial" value="value" />
          				<entry key="java.naming.provider.url" value="value" />
          				<entry key="java.naming.security.principal" value="value" />
          				<entry key="java.naming.security.credentials" value="value" />	
          			</map>
          		</constructor-arg>
          	</bean>
          	
          	<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
          		<property name="jndiName" value="/my/jndi/name" />
          		<property name="jndiEnvironment" ref="jndiEnvironment" />
          	</bean>	
          	
          	<bean id="marshaller" class="org.springframework.oxm.jibx.JibxMarshaller">
          		<property name="targetClass" value="zahid.play.si.ws.jms.GetCountryDescriptionRequest" />
          	</bean>
          	
          	<bean id="destinationResolver"
          		class="org.springframework.jms.support.destination.JndiDestinationResolver">
          		<property name="jndiEnvironment" ref="jndiEnvironment" />
          	</bean>
          	
          	<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory" />
          	
          	<bean id="messageSender" class="org.springframework.ws.transport.jms.JmsMessageSender">
          		<property name="connectionFactory" ref="connectionFactory" />
          		<property name="destinationResolver" ref="destinationResolver" />
          	</bean>
          	
          	<bean id="messageTemplate" class="org.springframework.integration.core.MessagingTemplate"> 
          		<property name="defaultChannel" ref="requestChannel" /> 
          	</bean>	
          
          	<int:channel id="requestChannel" />
          	
          	<ws:outbound-gateway id="wsClientGateway"
          		uri="jms:MY.TOPIC?messageType=TEXT_MESSAGE&amp;deliveryMode=NON_PERSISTENT"				
          		message-factory="messageFactory" marshaller="marshaller" unmarshaller="marshaller"	
          		message-sender="messageSender"	
          		request-channel="requestChannel" />
          In the java code I am using
          Code:
          messagingTemplate.convertSendAndReceive(MessageBuilder.withPayload(request).build())
          to send a request.

          I am getting this error: [jms:MY.TOPIC?messageType=TEXT_MESSAGE&deliveryMode =NON_PERSISTENT] is not a valid HTTP URL
          Last edited by fazahid; Jul 31st, 2012, 01:06 PM.

          Comment


          • #6
            Solved the problem Here is the solution:

            1) Define a destination provider for your Jms Uri:

            Code:
            public class JmsDestinationProvider implements DestinationProvider {	
            	private String jmsUri;	
            	public URI getDestination() {
            		if(StringUtils.hasText(jmsUri)){
            			try {
            				return new URI(jmsUri);
            			} catch (URISyntaxException e) {
            			}
            		}
                            return null; 
            	}
            	public void setJmsUri(String jmsUri) {
            		this.jmsUri = jmsUri;
            	}
            }
            2) In the spring xml file add a bean for this destination provider and use that bean in ws:outbound-gateway

            Code:
            	<bean id="jmsDestinationProvider" class="play.zahid.springint.activemq.ws.JmsDestinationProvider">
            		<property name="jmsUri" value="jms:test_queue?messageType=TEXT_MESSAGE&amp;deliveryMode=NON_PERSISTENT" />
            	</bean>
            
            	<ws:outbound-gateway id="wsClientGateway"
            		destination-provider="jmsDestinationProvider"
            		message-factory="messageFactory" marshaller="marshaller" unmarshaller="marshaller"	
            		message-sender="messageSender"	
            		request-channel="requestChannel" />
            Thanks for the pointer and confirmation ...

            Comment


            • #7
              Glad you solved it! If you don't mind, could you please add an issue in JIRA (https://jira.springsource.org/browse/INT) indicating that we should add a brief note in our documentation about the role of the DestinationProvider when using non-HTTP transports with the Web Service gateways?

              Thanks,
              Mark

              Comment


              • #8
                Raised an issue in JIRA: https://jira.springsource.org/browse/INT-2695

                Thanks

                Comment

                Working...
                X