AXIS 2 を使用して、ChannelConnectServiceStub というスタブを使用して WS メソッドを呼び出しています。
スタブと ConfigurationContext の生成:
public class TestWSClient {
private void init() throws Exception {
String proxyUrl = "http://subdom.dom.com/testpath/TestConnect.asmx";
ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("/rootFolder/Axis2/axis2-1.4.1/repository", "/rootFolder/Axis2/axis2-1.4.1/conf/axis2.xml");
ChannelConnectServiceStub channelConnectServiceStub = new ChannelConnectServiceStub(ctx,proxyUrl);
ctx.setProperty("testid", "testidval"); // Approach 1
channelConnectServiceStub._getServiceClient().getServiceContext().setProperty("testid", "testidval"); // Approach 2
}
}
また、LogHandler を使用してメッセージの要求と応答をログに記録しています。
LogHandler :
class LogHandler extends AbstractHandler implements Handler {
@Override
public InvocationResponse invoke(MessageContext messageContext) throws AxisFault {
String testID = null;
String invokeStr = null;
String axisService = null;
String action = null;
invokeStr = messageContext.getEnvelope().toString();
axisService = messageContext.getAxisService().getName();
action = messageContext.getAxisMessage().getAxisOperation().getInputAction();
testID = (String) messageContext.getProperty("testid");// Approach 1
testID = (String) messageContext.getServiceContext().getProperty("testid");// Approach 2
return InvocationResponse.CONTINUE;
}
}
スタブを作成して呼び出した時点から、プロパティ (「testid」) を LogHandler クラスに渡したいと考えています。私が取った2つのアプローチについて言及しました。
どちらも値を渡しています。しかし問題は、同じ TestWSClient を使用してサービスを使用する複数のクライアント スレッドがあることです。そのため、LogHandler に関しては、異なるクライアントによって設定されている異なる値が交換されています。(ただし、invokeStr、AxisService、およびアクションにはこの問題はありません)。
- スタブが呼び出される前にプロパティを MessageContext に渡す方法はありますか?
- マルチスレッド環境で値を交換せずに、スタブから LogHandler にプロパティを取得するのを手伝ってくれる人はいますか?
以下も試しましたが、operationContext
NULLなので失敗しました。
OperationContext operationContext = stub._getServiceClient().getLastOperationContext();
logger.info("operationContext : " + operationContext);
if (operationContext != null) {
MessageContext outMessageContext = operationContext.getMessageContext("Out");
if (outMessageContext != null) {
logger.info("outMessageContext.getEnvelope().toString() : " + outMessageContext.getEnvelope().toString());
outMessageContext.setProperty("Portal", getPortal());
}
MessageContext inMessageContext = operationContext.getMessageContext("In");
logger.info("inMessageContext : " + inMessageContext);
if (inMessageContext != null) {
logger.info("inMessageContext.getEnvelope().toString() : " + inMessageContext.getEnvelope().toString());
inMessageContext.setProperty("Portal", getPortal());
}
}