0
votes

I have spring integration outbound gateway that makes web service call. I have a interceptor that intercepts soap request and logs to log file. Now I want to pass a parameter to handleRequest method of interceptor class so that I can associate each logged soap request to an id in database.

The value id I need to pass to interceptor is stored in headers with name id code looks something like below.

<int-ws:outbound-gateway  uri="${soap.url} interceptor="interceptor"  >
</int-ws:outbound-gateway>

Below is interceptor.

public class Interceptor implements ClientInterceptor {

@Override
public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {

//id below is parameter that needs to be passed.

    LOGGER.info("soap request for "+id +" is " +messageContext.getRequest().getDocument().toString());

    return true;
}

}

I thought of setting a property to Interface in the bean definition.

<bean id="interceptor" class="com.services.Interceptor" >
    <property name="id" value="#{headers['id']}" />
</bean>

But this is not working as I am unable to access headers here somehow. getting exception during server start up .. Even if I get this exception resolved, this will have issues as object is singleton.Any other pointers here ?

    Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Property or field 'headers' cannot be found on object of type 'org.spri
ngframework.beans.factory.config.BeanExpressionContext' - maybe not public?
        at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:224)
        at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:94)
        at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:81)
        at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:51)
        at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:87)
        at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:120)
        at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:242)
1

1 Answers

0
votes

See my answer to your other question for why you can't do what you are trying.

To pass an argument to your interceptor, you could use a ThreadLocal - add a service upstream of the gateway to set your value and then retrieve/remove it in the interceptor.