i'm using axis 2 call ws methods using stub called channelconnectservicestub.
generating stub , 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 } }
and i'm using loghandler log message requests , responses.
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; } }
i want pass property ("testid") point creating , calling stub loghandler class. have mentioned 2 approaches i've taken.
both passing value. problem is, there multiple client threads using same testwsclient use service. so, different values setting different clients getting interchange when came loghandler. (but invokestr, axisservice , action don't have issue).
- is there way pass properties messagecontext before stub invoked?
- can property stub loghandler without interchanging values in multi-threaded environment.
i tried below 1 failed since 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()); } }
make sure singleton instance of configurationcontext.
when setproperty , getproperty servicecontext note obtaining shared copy of property object per jvm, instead of "testid" key, use unique key,
ex: in client side code after stub initialization instead of,
channelconnectservicestub._getserviceclient().getservicecontext() .setproperty("testid","testidval");
try
channelconnectservicestub._getserviceclient().getservicecontext() .setproperty(stub._getserviceclient().getservicecontext().getname(), "testidval");
and retrieve property, in loghandler use same key (the msgcontext.getservicecontext().getname()
unique per flow)
instead of
messagecontext.getservicecontext().getproperty("testid");
try
messagecontext.getservicecontext() .getproperty(msgcontext.getservicecontext().getname());
also note storing values on jvm shared property object, avoid memory growth remove value once no longer needed.
messagecontext.getservicecontext() .removeproperty(msgcontext.getservicecontext().getname();
Comments
Post a Comment