2015-06-01 69 views
0

它存在一种在处理程序和webmethod之间共享对象的方法吗?JaxWS RI/JaxB - 处理程序和WebMethod之间的共享对象

我之所以问这个问题,是因为我想将原始请求 记录到数据库,在StoredProcedure上(通过ID KEY)处理请求,并在原始响应中记录相同的记录。

为了得到这个,我想在处理程序和webmethod之间共享ID KEY,并要求处理程序的请求和响应原始记录。

tnx。

更新

必须使用setter方法你WS实现。

如果要在消息上下文中设置参数,则必须为参数设置范围应用程序。

默认范围是处理程序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); 
    } 

TNX根本不可见。

回答

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 

} 
+0

是否具有财产请求和响应范围是什么? –

+0

尽管我并不完全确定,但由于为相同的请求和响应保留了'MessageContext',所以该属性对于相同的范围很有用@AntoninoBarila – kolossus