Author: alessio.soldano(a)jboss.com
Date: 2009-07-17 04:02:58 -0400 (Fri, 17 Jul 2009)
New Revision: 10329
Added:
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/HttpServletResponseExt.java
Modified:
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/RequestHandlerImpl.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/ServletControllerExt.java
Log:
[JBWS-2669] Implement missing endpoint metrics update for JBossWS-CXF
Added:
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/HttpServletResponseExt.java
===================================================================
---
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/HttpServletResponseExt.java
(rev 0)
+++
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/HttpServletResponseExt.java 2009-07-17
08:02:58 UTC (rev 10329)
@@ -0,0 +1,225 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * 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 GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Locale;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * A HttpServletResponse delegate that externalizes fields.
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 17-Jul-2009
+ */
+public class HttpServletResponseExt implements HttpServletResponse
+{
+ private HttpServletResponse delegate;
+ private int sc;
+
+ public HttpServletResponseExt(HttpServletResponse delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ /**
+ * Get the status currently set in the HttpServletResponse
+ *
+ * @return the http status
+ */
+ public int getStatus()
+ {
+ return this.sc;
+ }
+
+ /* HttpServletResponse API */
+
+ public void addCookie(Cookie cookie)
+ {
+ delegate.addCookie(cookie);
+ }
+
+ public void addDateHeader(String name, long date)
+ {
+ delegate.addDateHeader(name, date);
+ }
+
+ public void addHeader(String name, String value)
+ {
+ delegate.addHeader(name, value);
+ }
+
+ public void addIntHeader(String name, int value)
+ {
+ delegate.addIntHeader(name, value);
+ }
+
+ public boolean containsHeader(String name)
+ {
+ return delegate.containsHeader(name);
+ }
+
+ public String encodeRedirectURL(String url)
+ {
+ return delegate.encodeRedirectURL(url);
+ }
+
+ @Deprecated
+ public String encodeRedirectUrl(String url)
+ {
+ return delegate.encodeRedirectUrl(url);
+ }
+
+ public String encodeURL(String url)
+ {
+ return delegate.encodeURL(url);
+ }
+
+ @Deprecated
+ public String encodeUrl(String url)
+ {
+ return delegate.encodeUrl(url);
+ }
+
+ public void sendError(int sc) throws IOException
+ {
+ delegate.sendError(sc);
+ }
+
+ public void sendError(int sc, String msg) throws IOException
+ {
+ delegate.sendError(sc, msg);
+ }
+
+ public void sendRedirect(String location) throws IOException
+ {
+ delegate.sendRedirect(location);
+ }
+
+ public void setDateHeader(String name, long date)
+ {
+ delegate.setDateHeader(name, date);
+ }
+
+ public void setHeader(String name, String value)
+ {
+ delegate.setHeader(name, value);
+ }
+
+ public void setIntHeader(String name, int value)
+ {
+ delegate.setIntHeader(name, value);
+ }
+
+ public void setStatus(int sc)
+ {
+ delegate.setStatus(sc);
+ this.sc = sc;
+ }
+
+ @Deprecated
+ public void setStatus(int sc, String sm)
+ {
+ delegate.setStatus(sc, sm);
+ this.sc = sc;
+ }
+
+ public void flushBuffer() throws IOException
+ {
+ delegate.flushBuffer();
+ }
+
+ public int getBufferSize()
+ {
+ return delegate.getBufferSize();
+ }
+
+ public String getCharacterEncoding()
+ {
+ return delegate.getCharacterEncoding();
+ }
+
+ public String getContentType()
+ {
+ return delegate.getContentType();
+ }
+
+ public Locale getLocale()
+ {
+ return delegate.getLocale();
+ }
+
+ public ServletOutputStream getOutputStream() throws IOException
+ {
+ return delegate.getOutputStream();
+ }
+
+ public PrintWriter getWriter() throws IOException
+ {
+ return delegate.getWriter();
+ }
+
+ public boolean isCommitted()
+ {
+ return delegate.isCommitted();
+ }
+
+ public void reset()
+ {
+ delegate.reset();
+ }
+
+ public void resetBuffer()
+ {
+ delegate.resetBuffer();
+ }
+
+ public void setBufferSize(int size)
+ {
+ delegate.setBufferSize(size);
+ }
+
+ public void setCharacterEncoding(String charset)
+ {
+ delegate.setCharacterEncoding(charset);
+ }
+
+ public void setContentLength(int len)
+ {
+ delegate.setContentLength(len);
+ }
+
+ public void setContentType(String type)
+ {
+ delegate.setContentType(type);
+ }
+
+ public void setLocale(Locale loc)
+ {
+ delegate.setLocale(loc);
+ }
+
+}
Property changes on:
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/HttpServletResponseExt.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified:
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/RequestHandlerImpl.java
===================================================================
---
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/RequestHandlerImpl.java 2009-07-16
16:34:38 UTC (rev 10328)
+++
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/RequestHandlerImpl.java 2009-07-17
08:02:58 UTC (rev 10329)
@@ -54,11 +54,11 @@
public void handleHttpRequest(Endpoint ep, HttpServletRequest req, HttpServletResponse
res, ServletContext context) throws ServletException, IOException
{
- ServletController controller =
(ServletController)context.getAttribute(ServletController.class.getName());
+ ServletControllerExt controller =
(ServletControllerExt)context.getAttribute(ServletController.class.getName());
if (controller == null)
throw new IllegalStateException("Cannot obtain servlet controller");
- controller.invoke(req, res);
+ controller.invoke(req, res, ep);
}
public void handleRequest(Endpoint endpoint, InputStream inStream, OutputStream
outStream, InvocationContext context)
Modified:
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/ServletControllerExt.java
===================================================================
---
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/ServletControllerExt.java 2009-07-16
16:34:38 UTC (rev 10328)
+++
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/ServletControllerExt.java 2009-07-17
08:02:58 UTC (rev 10329)
@@ -39,6 +39,8 @@
import org.apache.cxf.transport.servlet.ServletTransportFactory;
import org.apache.cxf.transports.http.QueryHandler;
import org.apache.cxf.transports.http.QueryHandlerRegistry;
+import org.jboss.wsf.spi.deployment.Endpoint;
+import org.jboss.wsf.spi.management.EndpointMetrics;
/**
* An extension to the CXF servlet controller
@@ -150,14 +152,50 @@
return false;
}
- public void invoke(HttpServletRequest req, HttpServletResponse res) throws
ServletException
+ public void invoke(HttpServletRequest req, HttpServletResponse res, Endpoint ep)
throws ServletException
{
ServletDestination dest = findDestination(req);
boolean requestHandled = handleQuery(req, res, dest);
if (false == requestHandled)
{
- invokeDestination(req, res, dest);
+ Long beginTime = initRequestMetrics(ep);
+ HttpServletResponseExt response = new HttpServletResponseExt(res);
+ invokeDestination(req, response, dest);
+ if (response.getStatus() < 500)
+ {
+ processResponseMetrics(ep, beginTime);
+ }
+ else
+ {
+ processFaultMetrics(ep, beginTime);
+ }
}
}
+
+ private long initRequestMetrics(Endpoint endpoint)
+ {
+ long beginTime = 0;
+
+ EndpointMetrics metrics = endpoint.getEndpointMetrics();
+ if (metrics != null)
+ beginTime = metrics.processRequestMessage();
+
+ return beginTime;
+ }
+
+ private void processResponseMetrics(Endpoint endpoint, long beginTime)
+ {
+ EndpointMetrics metrics = endpoint.getEndpointMetrics();
+ if (metrics != null)
+ metrics.processResponseMessage(beginTime);
+ }
+
+ private void processFaultMetrics(Endpoint endpoint, long beginTime)
+ {
+ EndpointMetrics metrics = endpoint.getEndpointMetrics();
+ if (metrics != null)
+ metrics.processFaultMessage(beginTime);
+ }
+
}