1

I have a web service which contains getEmployeeList method and i need to log request and response in a database like;

***Column** **Id Request Response ResponseTime*** 1 Request1 Response1 600ms 2 Request2 Response2 400ms 

My employee service class;

@WebService @HandlerChain(file="employeehandler-chain.xml") public interface EmployeeWS { @WebMethod List<Employee> getEmployeeList( @WebParam(name = " EmployeeReq") EmployeeReq employeeReq); 

My custom handler class ;

public class EmployeeHandler implements SOAPHandler<SOAPMessageContext> { @Override public boolean handleMessage(SOAPMessageContext context) { Boolean outBound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); try { SOAPMessage soapMsg = context.getMessage(); 

Is there a way to correlate the request and response in my handler ?

1 Answer 1

2

You can create an id when you are handling an inbound message and save into the SOAPMessageContext and get it when you are handling the response:

Boolean outBound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY); if (!outbound) { Long messageId = createId(); context.put("messageId", messageId); saveRequestToDatabase(context.getMessage(), messageId); } else { saveResponseToDatabase(context.getMessage(), context.get("messageId")); } 

Each request creates a new SOAPMessageContext which is kept alive until the end of the response process, so even if there are various requests being executed concurrently each context will be different.

Sign up to request clarification or add additional context in comments.

1 Comment

You're right. MessageContext interface extends Map<String, Object>, Thank you so much..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.