1
我們有一個帶有攔截器的webservice出站網關,它執行一些預處理和後處理,我們需要動態設置攔截器的屬性,與此非常相似how to pass values through http headers dynamically using spring integration情況,我們試圖實現建議的解決方案,但是我們在運行時遇到異常。如何在彈簧集成上動態地在攔截器上設置屬性
這裏的相關代碼:
攔截器相關的代碼
public class WebServiceClientInterceptor implements ClientInterceptor {
private final ThreadLocal<HashMap<String, String>> customHeaders = new ThreadLocal<HashMap<String, String>>();
.....
public GenericMessage setCustomHeaders(GenericMessage message, String property, String value) {
log.info("Adding header");
if (customHeaders.get() == null) {
log.info("map was null");
customHeaders.set(new HashMap<String, String>());
}
log.info("set " + property + ": " + value);
customHeaders.get().put(property, value);
return message;
}
上下文定義
<int:chain id="getOperatorTynTecCallChain"
input-channel="inspector.getoperator.tyntec.enricher.input.channel"
output-channel="inspector.getoperator.results.enricher.output.channel">
<int:service-activator expression="@webServiceClientInterceptor.setCustomHeaders(#root, 'mcc' , headers.mcc.getFirst())" />
<int:transformer method="transformRequest" ref="tynTecInspectorPartnerImpl" />
<int-ws:header-enricher id="getOperatorTynTecHeaderEnricher">
<int-ws:soap-action value="urn:SyncSuperQueryService" />
</int-ws:header-enricher>
<int-ws:outbound-gateway id="getOperatorTynTecOutboundHttpGateway"
marshaller="xmlBeansMarshaller" unmarshaller="xmlBeansTynTecUnmarshaller"
requires-reply="true" message-sender="httpComponentsMessageSender"
uri="${scoretools.inspector.tyntec.url}">
<interceptor="webServiceClientInterceptor">
</int-ws:outbound-gateway>
<int:service-activator expression="@tynTecInspectorPartnerImpl.transformResponse(payload, headers.msisdn, headers.mcc)" />
</int:chain>
<bean id="webServiceClientInterceptor" name="webServiceClientInterceptor"
class="com.cliqdigital.inspector.util.WebServiceClientInterceptor" />
異常
16:23:56,338 DEBUG [org.springframework.integration.handler.ExpressionEvaluatingMessageProcessor] (default task-1) SpEL Expression evaluation failed with EvaluationException.: org.springframework.expression.spel.SpelEvaluationException: EL1004E:(pos 29): Method call: Method setCustomHeaders() cannot be found on com.sun.proxy.$Proxy52 type
看起來當攔截器被包裹在代理的方法setCustoHeaders丟失,任何想法是怎樣的?
我愛你,我其實希望你能挑出這個問題,和往常一樣,你做得很快,很有效。 我們會嘗試你的建議是什麼,告訴你患得患失,順便說一句,我不知道爲什麼攔截器被代理,但我想我們會花更少的時間找到一個解決方法(即用接口的方法),比研究它爲什麼代理並使其不被代理。 謝謝,Andrea –
是的,它現在真的有效 –