1

I'm trying to add a Custom Interceptors to the interceptors List in my EndPoint Config, but i have a problem where PayloadRootSmartSoapEndpointInterceptor intercepts 2 of my Endpoints instead of one, I have Defined 2 SOAP EndPoints using spring-ws.

@EnableWs
@Configuration
@Order(1)
public class Config extends WsConfigurerAdapter {

private String namespaceBti = "http://tarim.bull.ro/BullTarimWS/BTIService";

private String namespaceBtiLst = "http://tarim.bull.ro/BullTarimWS/BTILSTService";

@Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
    MessageDispatcherServlet servlet = new MessageDispatcherServlet();
    servlet.setApplicationContext(applicationContext);
    servlet.setTransformWsdlLocations(true);
    return new ServletRegistrationBean(servlet, "/public/btiWS/*");
}

//Service 1
@Bean(name = "BTIService") 
public DefaultWsdl11Definition defaultWsdl11DefinitionBti(@Qualifier("BTISchema") XsdSchema certificateSchema) {
    DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
    wsdl11Definition.setPortTypeName("BtiPort");
    wsdl11Definition.setLocationUri("/public/btiWS"); //<context-path>
    wsdl11Definition.setTargetNamespace(namespaceBti);
    wsdl11Definition.setRequestSuffix("Input");
    wsdl11Definition.setResponseSuffix("Output");
    wsdl11Definition.setSchema(certificateSchema);
    return wsdl11Definition;
}

@Bean(name="BTISchema")
public XsdSchema certificateSchemaBti() {
    return new SimpleXsdSchema(new ClassPathResource("xml-resources/GETBTI.xsd"));
}

// Service 2
@Bean(name = "BTILSTService") //name of the wsdl in the URL
public DefaultWsdl11Definition defaultWsdl11DefinitionBtiLst(@Qualifier("BTILSTSchema") XsdSchema certificateSchema) {
    DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
    wsdl11Definition.setPortTypeName("BtiLstPort");
    wsdl11Definition.setLocationUri("/public/btiWS"); //<context-path>
    wsdl11Definition.setTargetNamespace(namespaceBtiLst);
    wsdl11Definition.setRequestSuffix("Input");
    wsdl11Definition.setResponseSuffix("Output");
    wsdl11Definition.setSchema(certificateSchema);
    return wsdl11Definition;
}

@Bean(name="BTILSTSchema")
public XsdSchema certificateSchemaBtiLst() {
    return new SimpleXsdSchema(new ClassPathResource("xml-resources/GETBTILST.xsd"));
}

@Autowired
private WriteBtiDto writeBtiDto;

Adding a Custom Interceptor to the list>

@Override
public void addInterceptors(List<EndpointInterceptor> interceptors) {


    interceptors.add(new PayloadRootSmartSoapEndpointInterceptor(
            new BtiEndpointInterceptor(), //let Spring Build and Manage The Bean, not me
            BtiEndpoint.getNamespaceUri(),
            BtiEndpoint.getLocalPart()
    ));

}

BTI EndPoint

@Endpoint()
public class BtiEndpoint {

private static final String NAMESPACE_URI="http://tarim.bull.ro/BullTarimWS/BTIService";
private static final String LOCAL_PART = "CXMLTYPE-GETBTIInput";


@PayloadRoot(namespace = NAMESPACE_URI, localPart = LOCAL_PART) 
@ResponsePayload 
public CXMLTYPEGETBTIOutput getBTI(@RequestPayload CXMLTYPEGETBTIInput request){
    CXMLTYPEGETBTIOutput response = new CXMLTYPEGETBTIOutput();
    return response;
}
// GETTERS AND SETTER FOR NAMESPACE AND LOCAL PART

BTILST EndPoint

@Endpoint()
public class BtiLstEndpoint {

private static final String NAMESPACE_URI="http://tarim.bull.ro/BullTarimWS/BTILSTService";
private static final String LOCAL_PART = "CXMLTYPE-GETBTILSTInput";


@PayloadRoot(namespace = NAMESPACE_URI, localPart = LOCAL_PART) 
@ResponsePayload 
public CXMLTYPEGETBTILSTOutput getBTI(@RequestPayload CXMLTYPEGETBTILSTInput request){
    CXMLTYPEGETBTILSTOutput response = new CXMLTYPEGETBTILSTOutput();
    return response;
}
// GETTERS AND SETTER FOR NAMESPACE AND LOCAL PART

EndpointInterceptor

@Component
public class BtiEndpointInterceptor implements EndpointInterceptor {


private static final Log LOG = LogFactory.getLog(BtiEndpointInterceptor.class);

@Override
public boolean handleRequest(MessageContext messageContext, Object o) throws Exception {
    LOG.info("1. Global Request Handling");
    return true;
}

@Override
public boolean handleResponse(MessageContext messageContext, Object o) throws Exception {
    LOG.info("2. Global Response Handling");
    return true;
}

@Override
public boolean handleFault(MessageContext messageContext, Object o) throws Exception {
    LOG.info("Global Exception Handling");
    return true;
}

@Override
public void afterCompletion(MessageContext messageContext, Object endpoint, Exception ex) {
    
}
jakijunior
  • 39
  • 6
  • https://stackoverflow.com/questions/32771333/spring-ws-how-to-apply-interceptor-to-a-specific-endpoint – WLebedev Jan 19 '21 at 08:36

0 Answers0