Announcement Announcement Module
Collapse
No announcement yet.
Client WS-Addressing Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Client WS-Addressing

    Hi,

    I've created web service with ws-security and next client to support ws-security. Next step to improve this web service is to add support for WS-Addressing and I did it.

    Code:
    @Endpoint
    public class MarshallingHypertensionEndpoint {
    
    
    	@PayloadRoot(localPart = "HypertensionRequest", namespace = "http://cp.wat.edu.pl/hypertension")
    	@Action("http://cp.wat.edu.pl/HypertensionRequest")
    	public HypertensionResponse requestHypertension(HypertensionRequest hypertensionRequest) throws Exception {
    Code:
    <bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping" >
    		<property name="interceptors">
                <list>
                	<bean class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor" />
    				<bean class="org.springframework.ws.soap.server.endpoint.interceptor.SoapEnvelopeLoggingInterceptor" />
                    <ref bean="wsSecurityInterceptor"/>
                </list>
            </property>
    	</bean>  
    	
    	<!-- WS-Addressing -->
    	<bean class="org.springframework.ws.soap.addressing.server.AnnotationActionEndpointMapping" >
    		<property name="preInterceptors">
    			<list>
    				<bean class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor" />
    				<bean class="org.springframework.ws.soap.server.endpoint.interceptor.SoapEnvelopeLoggingInterceptor" />
                    <ref bean="wsSecurityInterceptor"/>
    			</list>
    		</property>
    	</bean>

    I have client with support to WS-Security but now I don't know how can I add WS-Addressing header to message.

    This is very simple client code which works with ws-security:

    Code:
    public class ActionHypertensionClient extends WebServiceGatewaySupport 
    {
    	private Resource request;
    	
    	private static XWSSProcessor cprocessor;  
    	private static ProcessingContext context;
    	
    
        public void setRequest(Resource request) {
            this.request = request;
        }
    
        public void echo() throws IOException, XWSSecurityException {
        	Resource xwssConfig = new ClassPathResource("wss-client-config.xml", ActionHypertensionClient.class);
        	XWSSProcessorFactory factory = XWSSProcessorFactory.newInstance();  
        	cprocessor = factory.createProcessorForSecurityConfiguration(xwssConfig.getInputStream(), null);
        	context = new ProcessingContext();
        	
        	Source requestSource = new ResourceSource(request);
            StringResult result = new StringResult();
            getWebServiceTemplate().sendSourceAndReceiveToResult(requestSource,new WebServiceMessageCallback() {  
            	    public void doWithMessage(WebServiceMessage message) throws IOException {  
            	      // We can cast safely to SaajSoapMessage  
            	      SaajSoapMessage saajSoapMessage = (SaajSoapMessage) message;  
            	      
            	      SOAPMessage saajMessage = saajSoapMessage.getSaajMessage();
            	      try {  
            	        context.setSOAPMessage(saajMessage);  
            	        SOAPMessage securedMessage = cprocessor.secureOutboundMessage(context);  
            	        saajSoapMessage.setSaajMessage(securedMessage);
            	      }  
            	      catch (XWSSecurityException e) {  
            	        throw new XwsSecuritySecurementException(e.getMessage());  
            	      }
            	    }
            	 }, result);
            System.out.println(result);
        }
    
        public static void main(String[] args) throws IOException, XWSSecurityException {
            ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml", ActionHypertensionClient.class);
            ActionHypertensionClient hypertensionClient = (ActionHypertensionClient) applicationContext.getBean("actionHypertensionClient");
            hypertensionClient.echo();
        }
    
    }
    What should I do to add ws-addressing support for this client ?

    I can't change callback to org.springframework.ws.soap.addressing.client.Acti onCallback becouse of ws-security.

    What should I do ?

    Thanks in advance,
    Michał

  • #2
    I found a solution in org.springframework.ws.soap.addressing.client.Acti onCallback.doWithMessage.

    Just have to add :
    Code:
    action = new URI("http://cp.wat.edu.pl/HypertensionRequest");
            	      
    messageIdStrategy = new UuidMessageIdStrategy();
    URI messageId = messageIdStrategy.newMessageId(saajSoapMessage);
    MessageAddressingProperties map = new MessageAddressingProperties(to, from, replyTo, faultTo, action, messageId);
    version = new Addressing10();
    version.addAddressingHeaders(saajSoapMessage, map);
    and it works :>

    Thanks to Arjen for clean implementation.

    Comment


    • #3
      There is a one small BUG in org.springframework.ws.soap.addressing.server.Anno tationActionEndpointMapping.

      There is no "order" property.

      When I set up org.springframework.ws.soap.addressing.server.Anno tationActionEndpointMapping and org.springframework.ws.server.endpoint.mapping.Pay loadRootAnnotationMethodEndpointMapping then PayloadRootAnnotationMethodEndpoint is always "ordered" with highest priority.

      Even if in message is wsa action property. I think if in message is wsa action propety then AnnotationActionEndpointMapping should have highest priority.


      Is there any option to set order ?

      Comment


      • #4
        You can provide the endpoint adapters in the order you want by defining the bean soapmessagedispatcher. By default it uses the adapters in the properties file located in the same directory as the SoapMessageDispatcher.

        Comment


        • #5
          Yes, it works. Thanks a lot.

          Comment

          Working...
          X