是否存在在处理程序和webmethod之间共享对象的方法?
我之所以要问它是因为我想记录原始请求 到数据库,在StoredProcedure上处理请求(按ID KEY)并在原始响应中记录相同的记录。
为了得到这个,我希望在处理程序和webmethod之间共享ID KEY,并要求处理程序的请求和响应原始日志。
TNX。
更新
您必须在WS实施中使用Setter方法。
如果要在消息上下文中设置参数,则必须为参数设置范围应用程序。
默认范围是处理程序在WS实现中不可见
SoapHandler
public boolean handleMessage(SOAPMessageContext smc) {
smc.put("ID_MESSAGGIO",message.getId());
smc.setScope("ID_MESSAGGIO", MessageContext.Scope.APPLICATION);
}
WS实施
WebServiceContext context;
@Resource
public void setContext(WebServiceContext context) {
this.context = context;
}
@Override
public CreateAndStartRequestByValueResponse createAndStartRequestByValue(CreateAndStartRequestByValueRequest parameters) throws CreateAndStartRequestByValueException {
MessageContext messageContext = context.getMessageContext();
Long theValue = (Long) messageContext.get("ID_MESSAGGIO");
return controller.startCreateAndStartRequestByValue(parameters);
}
总而言之。
答案 0 :(得分:0)
JAX-WS为此目的提供了MessageContext
。
在你的经纪人中:
@Override
public boolean handleMessage(SOAPMessageContext context) {
//This property checks whether the handler is being invoked for a service response
boolean request= ((Boolean) context.get(SOAPMessageContext.MESSAGE_INBOUND_PROPERTY)).booleanValue();
if (request) { //check to make sure the handler is operating on an inbound message
context.setProperty("propertyName","propertyValue");
}
return true;
}
在您的服务实施中:
@Resource
WebServiceContext wsCtxt;
@WebMethod
public YourServiceResponse operation(YourServiceRequest req){
MessageContext msgCtxt = wsCtxt.getMessageContext();
String theValue = msgCtxt.getProperty("propertyName").toString(); //obligatory null check
}