2

Using the example provided here https://spring.io/guides/gs/producing-web-service/ I built a web service from a provided WSDL file. The service needed to support SOAP12 as shown in the code, this is done.

@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
    @Bean
    public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);

        servlet.setMessageFactoryBeanName("soap12");

        return new ServletRegistrationBean(servlet, "/myEvents/*");
    }

    @Bean 
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema mySchema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("EventService");
        wsdl11Definition.setLocationUri("/myEvents");
        wsdl11Definition.setTargetNamespace("http://event");
        wsdl11Definition.setSchema(ctipsSchema);

        return wsdl11Definition;
    }
    @Bean
    public XsdSchema mySchema() {
        return new SimpleXsdSchema(new ClassPathResource("mySchema.xsd"));
    }

    @Bean(name = "soap12")
    public SaajSoapMessageFactory soap12MessageFactory() throws SOAPException {
        SaajSoapMessageFactory factory = new SaajSoapMessageFactory(MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL));
        return factory;
    } 


    // -- NO longer needed 
    @Override
    public void addInterceptors(List<EndpointInterceptor> interceptors){
        PayloadValidatingInterceptor validatingInterceptor = new PayloadValidatingInterceptor();
        validatingInterceptor.setXsdSchema(ctipsSchema());
        validatingInterceptor.setValidateRequest(true);
        validatingInterceptor.setValidateResponse(true);
        interceptors.add(validatingInterceptor); 
        try {
            interceptors.add(wss4jSecurityInterceptor());
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }

    @Bean
    public Wss4jSecurityInterceptor wss4jSecurityInterceptor() throws Exception{
        Wss4jSecurityInterceptor interceptor = new Wss4jSecurityInterceptor();
        interceptor.setValidationActions("UsernameToken");
        interceptor.setValidationCallbackHandler(new Wss4jSecurityCallbackImpl());

        return interceptor;
    }
}

The problem I am facing is that the I get an error related to mustUnderstand

SoapMessageDispatcher  : Could not handle mustUnderstand headers: 
{http://www.w3.org/2005/08/addressing}Action,
{http://www.w3.org/2005/08/addressing}To. Returning fault

I was working on the below solution but I cannot get it to work.

public static final String SOAP_HEADER_ACTION = "Action";
public static final String SOAP_HEADER_TO = "To";
public static final String NS_WS_ADDRESSING =    "http://www.w3.org/2005/08/addressing";
public static final String PREFIX = "wsa";

@Bean(name = "soap12")
public SaajSoapMessageFactory soap12MessageFactory() throws SOAPException {

    MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); 
    SOAPMessage request = messageFactory.createMessage();
    SOAPHeaderElement header = request.getSOAPHeader().addHeaderElement(new QName(NS_WS_ADDRESSING, SOAP_HEADER_ACTION, PREFIX));
    header.setMustUnderstand(true);
    header = request.getSOAPHeader().addHeaderElement(new QName(NS_WS_ADDRESSING, SOAP_HEADER_TO, PREFIX));
    header.setMustUnderstand(true);

    SaajSoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory);
    MessageContext context = new DefaultMessageContext(new SaajSoapMessage(request), factory);

    return factory;
}

The Endpoint class is

@Endpoint 
public class HeartbeatEndpoint {
    private static final String NAMESPACE_URI = "http://myevent";

    @Action("http://myevent/Heartbeat") 
    @ResponsePayload
    public HeartbeatResponse Heartbeat(@RequestPayload Heartbeat arg) {
        HeartbeatResponse response = new HeartbeatResponse();
        response.setHeartbeatResult(5);
        return response;
    }
}

Is anyone familiar with how this may be resolved using Spring Boot ?

*** Endpoint updated to be correct ****

Cœur
  • 37,241
  • 25
  • 195
  • 267
user815809
  • 351
  • 5
  • 24
  • Instead of messing around I suggest reading the reference guide, how to use WS-Addressing for a server is explained [here](http://docs.spring.io/spring-ws/site/reference/html/server.html#server-ws-addressing). – M. Deinum Jan 20 '16 at 19:33
  • @M.Deinum not my first day at this. I've been over and over it looking at the interceptors throughout; gotten to the point where I'm reviewing the spring sources in an attempt to find a bean that i can define. If I find a solution, I'll post it to help others. Seems to be widely asked query and its only answers under cxf solutions. I'd rather stick with spring myself – user815809 Jan 20 '16 at 20:33
  • Have you read the documentation? It is explained what you need to do. It is only a matter of annotating the endpoint, it is not a configuration thing... – M. Deinum Jan 20 '16 at 20:41
  • Add your endpoint to the code, your wsdl would be nice to. – M. Deinum Jan 20 '16 at 20:46
  • @M.Deinum Updated to include the endpoint. The annotation of the Endpoint is not that straighforward. If you can help, greatly appreciated but I doubt it can be done – user815809 Jan 20 '16 at 21:54
  • @M.Deinum found a way to add interceptors (which has been my quest for a couple of days now) but I can't figure what is the next step, i get nothing now :( – user815809 Jan 21 '16 at 00:10
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/101238/discussion-between-user815809-and-m-deinum). – user815809 Jan 21 '16 at 00:44
  • As I already stated read the documentation. Your endpoint should be using an `@Action` annotation because you are using WS-Addressing. That is also explained in the reference guide... – M. Deinum Jan 21 '16 at 05:10
  • @M.Deinum thanks. I attempted that but it does not work. Tried @ Action and @ SoapAction. It could be that I am not using these correctly but I dont necessarily see how these can help with WS-Addressing. I do however see "AnnotationActionEndpointMapping : Supporting [WS-Addressing August 2004, WS-Addressing 1.0]" on startup. Would it be possible to change this to the 2005 that is appearing in the error? – user815809 Jan 21 '16 at 09:27
  • Used @Action("http://www.w3.org/2005/08/addressing") but also tried @Action("http://myevent") and @Action("http://myevent/Heartbeat") but it comes to getting an no endpoint found message when its called. – user815809 Jan 21 '16 at 09:50
  • From the spring docs "By default, the AnnotationActionEndpointMapping supports both the 1.0 (May 2006), and the August 2004 editions of WS-Addressing. These two versions are most popular, and are interoperable with Axis 1 and 2, JAX-WS, XFire, Windows Communication Foundation (WCF), and Windows Services Enhancements (WSE) 3.0. If necessary, specific versions of the spec can be injected into the versions property." Our error is related to "http://www.w3.org/2005/08/addressing" which means I need to somehow change the AnnotationActionEndpointMapping – user815809 Jan 21 '16 at 10:16
  • WS-addressing 1.0 is the version you want. So no you don't need to do anything. You should only have a `@Action` which maps to the information in your wsdl (that should contain the headers). – M. Deinum Jan 21 '16 at 12:22
  • Also it is one of `@Action`, `@SoapAction` or `@PayloadRoot` it cannot be a mix of those. Only one of them is for mapping... – M. Deinum Jan 21 '16 at 12:33
  • @M.Deinum that sorted it. Updated the post to show @ Action will resolve but @ ResponsePayload and @ RequestPayload are also needed. Cheers for the guidance. – user815809 Jan 22 '16 at 14:02
  • I nowhere said that you should remove those... I was only mentioning the mapping annotations. – M. Deinum Jan 22 '16 at 14:12
  • Could you please guide me here : https://stackoverflow.com/questions/60260277/could-not-handle-mustunderstand-headers-http-docs-oasis-open-org-wss-2004-01 ? – PAA Feb 19 '20 at 12:08
  • @user815809 - Were you able to solve the issue ? – PAA Feb 19 '20 at 12:21

0 Answers0