Announcement Announcement Module
Collapse
No announcement yet.
Empty SOAPAction Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Empty SOAPAction

    Hello,

    I have written the following ws:outbound-gateway, which connects to
    www.w3schools.com/webservices/tempconvert.asmx and converts Celsius degrees to Fahrenheit,
    as a learning exercise:

    Code:
    <int:channel id="w3RequestsOutputChannel"/>
        <int-ws:outbound-gateway
            id="w3schoolsGateway"
            request-channel="w3RequestsOutputChannel"
            uri="http://www.w3schools.com/webservices/tempconvert.asmx"
        />
    Here's my Main class:

    Code:
    public final class Main {
    	
    	private static String bodyTemplate0 =
    					"<CelsiusToFahrenheit xmlns=\"http://tempuri.org/\">"
    					+ "<Celsius>%s</Celsius>"
    					+ "</CelsiusToFahrenheit>"
    	
    	public static void main(final String... args) {
    		ClassPathXmlApplicationContext ctx = 
    				new ClassPathXmlApplicationContext("classpath*:META-INF/spring/integration/spring-integration-context.xml");
    	
    		MessageChannel channel = ctx.getBean("w3RequestsOutputChannel", MessageChannel.class);
    		
    		String body = String.format(bodyTemplate0, "20");
    		System.out.println(body);
    		MessagingTemplate messagingTemplate  = new MessagingTemplate();
    		
    		MessageBuilder<String> mb = MessageBuilder.withPayload(body);
    		Message<?> message = messagingTemplate.
    				sendAndReceive(channel,
    				mb.build()
    		);
    		
    		System.out.println(message.getPayload());
    		
    	}  // end main
    	
    }
    Unfortunately, I get an error from the w3schools server saying that the SOAPAction header cannot be read.
    Using tcpdump, I have determined that the SOAPAction header is actually empty. As a result, I have added
    a SOAP Header Mapper to my channel, which sets the SOAPAction, as follows:

    Code:
    <int:channel id="w3RequestsOutputChannel"/>
        <int-ws:outbound-gateway
            id="w3schoolsGateway"
            request-channel="w3RequestsOutputChannel"
            uri="$http://www.w3schools.com/webservices/tempconvert.asmx"
            header-mapper="soapHeaderMapper"
        />
    
     
     public class SoapHeaderMapper extends DefaultSoapHeaderMapper {
    	
    	    @Override
    	    public void populateStandardHeaders(java.util.Map<java.lang.String,java.lang.Object> headers,
                    org.springframework.ws.soap.SoapMessage target) {
    	        target.setSoapAction("http://tempuri.org/CelsiusToFahrenheit");
    	    }
    
    }
    The SOAP request now works. However, it seems silly to have to hard-code the SOAP Action. Is there a way to send a SOAP request without manually setting the SOAP Action?

    Many thanks.

    Philroc

  • #2
    Hi!

    How about this one:
    HTML Code:
    <ws:header-enricher input-channel="literalValueInput">
    	<ws:soap-action expression=""/>
    </ws:header-enricher>
    before WS-outbound-gateway?
    Unfortunately we don't have a description of this component, but it is the same as core one: http://static.springsource.org/sprin...eader-enricher

    Take care,
    Artem

    Comment

    Working...
    X