2015-06-01 66 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