use of org.glassfish.webservices.monitoring.ThreadLocalInfo in project Payara by payara.
the class JAXRPCServlet method doPost.
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
WebServiceEngineImpl wsEngine = WebServiceEngineImpl.getInstance();
if ("Tester".equalsIgnoreCase(request.getQueryString())) {
Endpoint endpt = wsEngine.getEndpoint(request.getServletPath());
if (endpt != null && Boolean.parseBoolean(endpt.getDescriptor().getDebugging())) {
WebServiceTesterServlet.invoke(request, response, endpt.getDescriptor());
return;
}
}
if (delegate != null) {
// check if we need to trace this...
String messageId = null;
if (wsEngine.getGlobalMessageListener() != null) {
Endpoint endpt = wsEngine.getEndpoint(request.getServletPath());
messageId = wsEngine.preProcessRequest(endpt);
if (messageId != null) {
ThreadLocalInfo config = new ThreadLocalInfo(messageId, request);
wsEngine.getThreadLocal().set(config);
}
}
delegate.doPost(request, response);
if (messageId != null) {
wsEngine.postProcessResponse(messageId, new HttpResponseInfoImpl(response));
}
}
}
use of org.glassfish.webservices.monitoring.ThreadLocalInfo in project Payara by payara.
the class EjbWebServiceDispatcher method handlePost.
private void handlePost(HttpServletRequest req, HttpServletResponse resp, EjbRuntimeEndpointInfo endpointInfo) throws IOException, SOAPException {
JAXRPCEndpointImpl endpoint = null;
String messageID = null;
SOAPMessageContext msgContext = null;
try {
MimeHeaders headers = wsUtil.getHeaders(req);
if (!wsUtil.hasTextXmlContentType(headers)) {
wsUtil.writeInvalidContentType(resp);
return;
}
msgContext = jaxRpcObjectFactory.createSOAPMessageContext();
SOAPMessage message = createSOAPMessage(req, headers);
boolean wssSucceded = true;
if (message != null) {
msgContext.setMessage(message);
// get the endpoint info
endpoint = (JAXRPCEndpointImpl) endpointInfo.getEndpoint().getExtraAttribute(EndpointImpl.NAME);
if (endpoint != null) {
// first global notification
if (wsEngine.hasGlobalMessageListener()) {
messageID = wsEngine.preProcessRequest(endpoint);
}
} else {
if (logger.isLoggable(FINE)) {
logger.log(FINE, MISSING_MONITORING_INFO, req.getRequestURI());
}
}
AdapterInvocationInfo adapterInvocationInfo = null;
if (!(endpointInfo instanceof Ejb2RuntimeEndpointInfo)) {
throw new IllegalArgumentException(endpointInfo + "is not instance of Ejb2RuntimeEndpointInfo.");
}
try {
Ejb2RuntimeEndpointInfo endpointInfo2 = (Ejb2RuntimeEndpointInfo) endpointInfo;
// Do ejb container pre-invocation and pre-handler logic
adapterInvocationInfo = endpointInfo2.getHandlerImplementor();
// Set message context in invocation
EJBInvocation.class.cast(adapterInvocationInfo.getInv()).setMessageContext(msgContext);
// Set http response object so one-way operations will
// response before actual business method invocation.
msgContext.setProperty(HTTP_SERVLET_RESPONSE, resp);
if (securityService != null) {
wssSucceded = securityService.validateRequest(endpointInfo2.getServerAuthConfig(), (StreamingHandler) adapterInvocationInfo.getHandler(), msgContext);
}
// Trace if necessary
if (messageID != null || (endpoint != null && endpoint.hasListeners())) {
// create the thread local
ThreadLocalInfo threadLocalInfo = new ThreadLocalInfo(messageID, req);
wsEngine.getThreadLocal().set(threadLocalInfo);
if (endpoint != null) {
endpoint.processRequest(msgContext);
} else {
if (logger.isLoggable(FINE)) {
logger.log(FINE, MISSING_MONITORING_INFO, req.getRequestURI());
}
}
}
// which will be flow back into the EJB container.
if (wssSucceded) {
adapterInvocationInfo.getHandler().handle(msgContext);
}
} finally {
// preInvoke steps might have occurred. It's ok if implementor is null.
if (adapterInvocationInfo != null) {
endpointInfo.releaseImplementor(adapterInvocationInfo.getInv());
}
}
} else {
String errorMsg = MessageFormat.format(logger.getResourceBundle().getString(NULL_MESSAGE), endpointInfo.getEndpoint().getEndpointName(), endpointInfo.getEndpointAddressUri());
if (logger.isLoggable(Level.FINE)) {
logger.fine(errorMsg);
}
msgContext.writeSimpleErrorResponse(FAULT_CODE_CLIENT, errorMsg);
}
if (messageID != null || endpoint != null) {
endpoint.processResponse(msgContext);
}
SOAPMessage reply = msgContext.getMessage();
if (securityService != null && wssSucceded) {
if (!(endpointInfo instanceof Ejb2RuntimeEndpointInfo)) {
throw new IllegalArgumentException(endpointInfo + "is not instance of Ejb2RuntimeEndpointInfo.");
}
Ejb2RuntimeEndpointInfo endpointInfo2 = (Ejb2RuntimeEndpointInfo) endpointInfo;
securityService.secureResponse(endpointInfo2.getServerAuthConfig(), (StreamingHandler) endpointInfo2.getHandlerImplementor().getHandler(), msgContext);
}
if (reply.saveRequired()) {
reply.saveChanges();
}
wsUtil.writeReply(resp, msgContext);
} catch (Throwable e) {
String errorMessage = MessageFormat.format(logger.getResourceBundle().getString(ERROR_ON_EJB), new Object[] { endpointInfo.getEndpoint().getEndpointName(), endpointInfo.getEndpointAddressUri(), e.getMessage() });
logger.log(WARNING, errorMessage, e);
SOAPMessageContext errorMsgContext = jaxRpcObjectFactory.createSOAPMessageContext();
errorMsgContext.writeSimpleErrorResponse(FAULT_CODE_SERVER, errorMessage);
resp.setStatus(SC_INTERNAL_SERVER_ERROR);
if (messageID != null || endpoint != null) {
endpoint.processResponse(errorMsgContext);
}
wsUtil.writeReply(resp, errorMsgContext);
}
// Final tracing notification
if (messageID != null) {
HttpResponseInfoImpl response = new HttpResponseInfoImpl(resp);
wsEngine.postProcessResponse(messageID, response);
}
}
use of org.glassfish.webservices.monitoring.ThreadLocalInfo in project Payara by payara.
the class MonitoringPipe method firePreInvocation.
private void firePreInvocation(HttpServletRequest httpRequest, Packet pipeRequest, JAXWSEndpointImpl endpointTracer, SOAPMessageContextImpl soapMessageContext, JavaCallInfo javaCallInfo) {
if (seiModel instanceof SOAPSEIModel) {
SOAPSEIModel soapSEIModel = (SOAPSEIModel) seiModel;
Globals.get(MonitorFilter.class).filterRequest(pipeRequest, new MonitorContextImpl(javaCallInfo, soapSEIModel, wsdlModel, ownerEndpoint, endpoint));
}
// Invoke preProcessRequest on global listeners. If there's a global listener we get
// a trace ID back to trace this message
String messageTraceId = wsMonitor.preProcessRequest(endpointTracer);
if (messageTraceId != null) {
soapMessageContext.put(MESSAGE_ID, messageTraceId);
wsMonitor.getThreadLocal().set(new ThreadLocalInfo(messageTraceId, httpRequest));
}
try {
// Invoke processRequest on global listeners
endpointTracer.processRequest(soapMessageContext);
} catch (Exception e) {
// temporary - need to send back SOAP fault message
}
}
Aggregations