diff --git a/tools.descartes.prisma.agent.wildfly/src/main/java/tools/descartes/prisma/agent/wildfly/interceptors/WebServiceOutgoingCallInterceptor.java b/tools.descartes.prisma.agent.wildfly/src/main/java/tools/descartes/prisma/agent/wildfly/interceptors/WebServiceOutgoingCallInterceptor.java new file mode 100644 index 0000000000000000000000000000000000000000..0b405d1920ba740e5c5f45bea809934f7ba9d4c7 --- /dev/null +++ b/tools.descartes.prisma.agent.wildfly/src/main/java/tools/descartes/prisma/agent/wildfly/interceptors/WebServiceOutgoingCallInterceptor.java @@ -0,0 +1,74 @@ +/** + * ============================================== + * LibReDE : Library for Resource Demand Estimation + * ============================================== + * + * (c) Copyright 2013-2014, by Simon Spinner and Contributors. + * + * Project Info: http://www.descartes-research.net/ + * + * All rights reserved. This software is made available under the terms of the + * Eclipse Public License (EPL) v1.0 as published by the Eclipse Foundation + * http://www.eclipse.org/legal/epl-v10.html + * + * This software is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Eclipse Public License (EPL) + * for more details. + * + * You should have received a copy of the Eclipse Public License (EPL) + * along with this software; if not visit http://www.eclipse.org or write to + * Eclipse Foundation, Inc., 308 SW First Avenue, Suite 110, Portland, 97204 USA + * Email: license (at) eclipse.org + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + */ +package tools.descartes.prisma.agent.wildfly.interceptors; + +import java.lang.reflect.Method; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Deque; + +import javax.servlet.http.HttpServletRequest; +import javax.xml.namespace.QName; +import javax.xml.ws.handler.MessageContext; + +import org.jboss.logging.Logger; +import org.jboss.ws.api.handler.GenericSOAPHandler; + +import tools.descartes.prisma.agent.wildfly.callstack.ComponentRecord; +import tools.descartes.prisma.agent.wildfly.callstack.InvocationRecord; +import tools.descartes.prisma.agent.wildfly.callstack.OperationRecord; +import tools.descartes.prisma.agent.wildfly.service.MonitoringService; + +/** + * @author Simon Spinner (simon.spinner@uni-wuerzburg.de) + * + */ +public class WebServiceOutgoingCallInterceptor extends GenericSOAPHandler { + + protected final Logger log = Logger.getLogger(this.getClass()); + + @Override + protected boolean handleOutbound(MessageContext msgContext) { + Deque<InvocationRecord> threadCallStack = MonitoringService.INSTANCE.getCallStack(); + InvocationRecord currentInvocation = threadCallStack.peek(); + if (currentInvocation != null) { + URL url; + try { + url = new URL((String)msgContext.get("javax.xml.ws.service.endpoint.address")); + Method caller = (Method)msgContext.get("java.lang.reflect.Method"); + ComponentRecord component = MonitoringService.INSTANCE.requireComponent(url.getHost(), "", "", url.getPath()); + OperationRecord currentOperation = currentInvocation.requireEndpoint(component, caller.getDeclaringClass().getName(), "http", caller.getName()); + // TODO: We currently support only one-way messages. Inbound messages are ignored. + InvocationRecord outgoingInvocation = currentOperation.startInvocation(); + outgoingInvocation.finishInvocation(0, 0, 0); + } catch (MalformedURLException e) { + log.error("Error reading message data.", e); + } + } + return true; + } +}