Author: richard.opalka(a)jboss.com
Date: 2009-10-13 04:36:18 -0400 (Tue, 13 Oct 2009)
New Revision: 10899
Modified:
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/EndpointImpl.java
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyCallbackHandlerImpl.java
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyEndpointRegistryFactory.java
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerAdapter.java
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerConfig.java
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyRequestHandlerFactoryImpl.java
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyRequestHandlerImpl.java
Log:
[JBWS-2674][JBWS-2754] refactoring (WIP)
Modified:
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/EndpointImpl.java
===================================================================
---
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/EndpointImpl.java 2009-10-13
08:13:52 UTC (rev 10898)
+++
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/EndpointImpl.java 2009-10-13
08:36:18 UTC (rev 10899)
@@ -308,11 +308,6 @@
return this.address.getPath();
}
- public String getHost()
- {
- return this.address.getHost();
- }
-
public int getPort()
{
return this.address.getPort();
Modified:
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyCallbackHandlerImpl.java
===================================================================
---
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyCallbackHandlerImpl.java 2009-10-13
08:13:52 UTC (rev 10898)
+++
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyCallbackHandlerImpl.java 2009-10-13
08:36:18 UTC (rev 10899)
@@ -27,7 +27,6 @@
import java.util.LinkedList;
import java.util.List;
-import javax.management.ObjectName;
import javax.xml.ws.WebServiceException;
import org.jboss.logging.Logger;
@@ -35,7 +34,6 @@
import org.jboss.ws.WSException;
import org.jboss.ws.core.server.netty.NettyCallbackHandler;
import org.jboss.ws.extensions.wsrm.transport.backchannel.RMCallbackHandlerImpl;
-import org.jboss.wsf.common.ObjectNameFactory;
import org.jboss.wsf.common.injection.InjectionHelper;
import org.jboss.wsf.common.injection.PreDestroyHolder;
import org.jboss.wsf.spi.SPIProvider;
@@ -50,122 +48,134 @@
import org.jboss.wsf.stack.jbws.WebAppResolver;
/**
- * TODO: javadoc
+ * Netty callback handler operating in JSE environment (replacement for Servlet on J2EE
side).
*
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
final class NettyCallbackHandlerImpl implements NettyCallbackHandler
{
+
+ /** 200 HTTP status code. */
+ public static final int SC_OK = 200;
+
+ /** 500 HTTP status code. */
+ public static final int SC_INTERNAL_SERVER_ERROR = 500;
+
+ /** Logger. */
private static final Logger LOGGER = Logger.getLogger(RMCallbackHandlerImpl.class);
- private final String handledPath;
+ /** SPI provider instance. */
+ private static final SPIProvider SPI_PROVIDER =
SPIProviderResolver.getInstance().getProvider();
- private final SPIProvider spiProvider =
SPIProviderResolver.getInstance().getProvider();
+ /** Endpoints registry. */
+ private static final EndpointRegistry ENDPOINTS_REGISTRY =
NettyCallbackHandlerImpl.SPI_PROVIDER.getSPI(
+ EndpointRegistryFactory.class).getEndpointRegistry();
- private EndpointRegistry epRegistry;
+ /** @PreDestroy registry. */
+ private final List<PreDestroyHolder> preDestroyRegistry = new
LinkedList<PreDestroyHolder>();
+ /** Path this Netty callback operates on. */
+ private final String handledPath;
+
+ /** Endpoint associated with this callback. */
private Endpoint endpoint;
- private List<PreDestroyHolder> preDestroyRegistry = new
LinkedList<PreDestroyHolder>();
-
/**
- * Request path to listen for incomming messages
- * @param handledPath
+ * Constructor.
+ *
+ * @param path this handler operates on
+ * @param context this handler operates on
+ * @param endpointRegistryPath registry id
*/
- public NettyCallbackHandlerImpl(String path, String context, String
endpointRegistryPath)
+ public NettyCallbackHandlerImpl(final String path, final String context, final String
endpointRegistryPath)
{
super();
- this.initRegistry();
this.initEndpoint(context, endpointRegistryPath);
this.handledPath = path;
}
/**
- * Initializes endpoint registry
+ * Initialize the service endpoint and associate it with this callback.
+ *
+ * @param context context path
+ * @param endpointRegistryPath registry id
*/
- private void initRegistry()
- {
- epRegistry =
spiProvider.getSPI(EndpointRegistryFactory.class).getEndpointRegistry();
- }
-
- /**
- * Initialize the service endpoint
- * @param contextPath context path
- * @param servletName servlet name
- */
private void initEndpoint(final String context, final String endpointRegistryPath)
{
final EndpointResolver resolver = new WebAppResolver(context,
endpointRegistryPath);
- this.endpoint = epRegistry.resolve(resolver);
+ this.endpoint = NettyCallbackHandlerImpl.ENDPOINTS_REGISTRY.resolve(resolver);
if (this.endpoint == null)
{
- ObjectName oname = ObjectNameFactory.create(Endpoint.SEPID_DOMAIN +
":" + Endpoint.SEPID_PROPERTY_CONTEXT
- + "=" + context + "," +
Endpoint.SEPID_PROPERTY_ENDPOINT + "=" + endpointRegistryPath);
- throw new WebServiceException("Cannot obtain endpoint for: " +
oname);
+ throw new WebServiceException("Cannot obtain endpoint for: " +
endpointRegistryPath);
}
}
- public int handle(String method, InputStream inputStream, OutputStream outputStream,
InvocationContext invCtx)
- throws IOException
+ /**
+ * Handles either WSDL GET request or endpoint POST invocation.
+ *
+ * @param method only HTTP GET and POST methods are supported
+ * @param is input stream
+ * @param os output stream
+ * @param invCtx invocation context
+ * @return HTTP status code
+ * @throws IOException if some I/O error occurs
+ */
+ public int handle(final String method, final InputStream is, final OutputStream os,
final InvocationContext invCtx)
+ throws IOException
{
Integer statusCode = null;
try
{
+ EndpointAssociation.setEndpoint(this.endpoint);
+ final RequestHandler requestHandler = this.endpoint.getRequestHandler();
+
if (method.equals("POST"))
{
- this.handle(inputStream, outputStream, invCtx, false);
+ requestHandler.handleRequest(this.endpoint, is, os, invCtx);
statusCode = (Integer) invCtx.getProperty(Constants.NETTY_STATUS_CODE);
}
else if (method.equals("GET"))
{
- this.handle(inputStream, outputStream, invCtx, true);
+ requestHandler.handleWSDLRequest(this.endpoint, os, invCtx);
}
else
{
throw new WSException("Unsupported HTTP method: " + method);
}
}
- catch (Exception e)
+ catch (final Exception e)
{
NettyCallbackHandlerImpl.LOGGER.error(e.getMessage(), e);
- statusCode = 500;
+ statusCode = NettyCallbackHandlerImpl.SC_INTERNAL_SERVER_ERROR;
}
+ finally
+ {
+ this.registerForPreDestroy(this.endpoint);
+ EndpointAssociation.removeEndpoint();
+ }
- return statusCode == null ? 200 : statusCode;
+ return statusCode == null ? NettyCallbackHandlerImpl.SC_OK : statusCode;
}
+ /**
+ * Returns request path this callback operates on.
+ *
+ * @return callback path
+ */
public String getPath()
{
return this.handledPath;
}
- private void handle(final InputStream inputStream, final OutputStream outputStream,
final InvocationContext invCtx, final boolean wsdlRequest) throws IOException
+ /**
+ * Registers endpoint for with @PreDestroy registry.
+ *
+ * @param endpoint webservice endpoint
+ */
+ private void registerForPreDestroy(final Endpoint endpoint)
{
- try
- {
- EndpointAssociation.setEndpoint(this.endpoint);
- final RequestHandler requestHandler = this.endpoint.getRequestHandler();
-
- if (wsdlRequest)
- {
- requestHandler.handleWSDLRequest(this.endpoint, outputStream, invCtx);
- }
- else
- {
- requestHandler.handleRequest(this.endpoint, inputStream, outputStream,
invCtx);
- }
- }
- finally
- {
- this.registerForPreDestroy(this.endpoint);
- EndpointAssociation.removeEndpoint();
- }
- }
-
- private void registerForPreDestroy(final Endpoint ep)
- {
- final PreDestroyHolder holder = (PreDestroyHolder)
ep.getAttachment(PreDestroyHolder.class);
+ final PreDestroyHolder holder = (PreDestroyHolder)
endpoint.getAttachment(PreDestroyHolder.class);
if (holder != null)
{
synchronized (this.preDestroyRegistry)
@@ -175,16 +185,22 @@
this.preDestroyRegistry.add(holder);
}
}
- ep.removeAttachment(PreDestroyHolder.class);
+ endpoint.removeAttachment(PreDestroyHolder.class);
}
}
-
- public final void init()
+
+ /**
+ * Template lifecycle method that does nothing in this implementation.
+ */
+ public void init()
{
- // does nothing
+ // Does nothing
}
- public final void destroy()
+ /**
+ * Calls @PreDestroy annotated methods on endpoint bean.
+ */
+ public void destroy()
{
synchronized (this.preDestroyRegistry)
{
@@ -201,7 +217,6 @@
}
}
this.preDestroyRegistry.clear();
- this.preDestroyRegistry = null;
}
}
Modified:
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyEndpointRegistryFactory.java
===================================================================
---
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyEndpointRegistryFactory.java 2009-10-13
08:13:52 UTC (rev 10898)
+++
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyEndpointRegistryFactory.java 2009-10-13
08:36:18 UTC (rev 10899)
@@ -43,7 +43,7 @@
{
super();
}
-
+
/**
* Returns endpoint registry.
*
Modified:
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerAdapter.java
===================================================================
---
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerAdapter.java 2009-10-13
08:13:52 UTC (rev 10898)
+++
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerAdapter.java 2009-10-13
08:36:18 UTC (rev 10899)
@@ -74,7 +74,7 @@
/** Deployment model factory. */
private static final DeploymentModelFactory DEPLOYMENT_FACTORY =
NettyHttpServerAdapter.SPI_PROVIDER
.getSPI(DeploymentModelFactory.class);
-
+
private static final NettyRequestHandlerFactory requestHandlerFactory =
NettyRequestHandlerFactoryImpl.getInstance();
/**
@@ -123,7 +123,7 @@
private String getEndpointRegistryPath(EndpointImpl endpoint)
{
// we need to distinguish ports in endpoints registry in JSE environment
- return endpoint.getPathWithoutContext() + "-port-" + endpoint.getPort();
+ return endpoint.getPath() + "-port-" + endpoint.getPort();
}
private Deployment newDeployment(EndpointImpl epImpl, String contextRoot)
Modified:
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerConfig.java
===================================================================
---
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerConfig.java 2009-10-13
08:13:52 UTC (rev 10898)
+++
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerConfig.java 2009-10-13
08:36:18 UTC (rev 10899)
@@ -111,42 +111,83 @@
// not implemented methods
+ /**
+ * Not implemented.
+ *
+ * @return string
+ */
public String getImplementationTitle()
{
throw new UnsupportedOperationException();
}
+ /**
+ * Not implemented.
+ *
+ * @return string
+ */
public String getImplementationVersion()
{
throw new UnsupportedOperationException();
}
+ /**
+ * Not implemented.
+ *
+ * @return int
+ */
public int getWebServicePort()
{
throw new UnsupportedOperationException();
}
+ /**
+ * Not implemented.
+ *
+ * @return int
+ */
public int getWebServiceSecurePort()
{
throw new UnsupportedOperationException();
}
- public void setModifySOAPAddress(boolean flag)
+ /**
+ * Not implemented.
+ *
+ * @param flag boolean
+ */
+ public void setModifySOAPAddress(final boolean flag)
{
throw new UnsupportedOperationException();
}
- public void setWebServiceHost(String host) throws UnknownHostException
+ /**
+ * Not implemented.
+ *
+ * @param host string
+ * @throws UnknownHostException never thrown
+ */
+ public void setWebServiceHost(final String host) throws UnknownHostException
{
throw new UnsupportedOperationException();
}
- public void setWebServicePort(int port)
+ /**
+ * Not implemented.
+ *
+ * @param port int
+ */
+ public void setWebServicePort(final int port)
{
throw new UnsupportedOperationException();
}
- public void setWebServiceSecurePort(int port)
+ /**
+ * Not implemented.
+ *
+ * @param port int
+ */
+ public void setWebServiceSecurePort(final int port)
{
throw new UnsupportedOperationException();
}
Modified:
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyRequestHandlerFactoryImpl.java
===================================================================
---
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyRequestHandlerFactoryImpl.java 2009-10-13
08:13:52 UTC (rev 10898)
+++
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyRequestHandlerFactoryImpl.java 2009-10-13
08:36:18 UTC (rev 10899)
@@ -30,10 +30,10 @@
*/
final class NettyRequestHandlerFactoryImpl implements
NettyRequestHandlerFactory<NettyRequestHandlerImpl>
{
-
+
/** Factory singleton. */
private static final NettyRequestHandlerFactory<NettyRequestHandlerImpl>
SINGLETON = new NettyRequestHandlerFactoryImpl();
-
+
/**
* Constructor.
*/
@@ -51,7 +51,7 @@
{
return new NettyRequestHandlerImpl();
}
-
+
/**
* Returns factory instance.
*
Modified:
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyRequestHandlerImpl.java
===================================================================
---
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyRequestHandlerImpl.java 2009-10-13
08:13:52 UTC (rev 10898)
+++
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyRequestHandlerImpl.java 2009-10-13
08:36:18 UTC (rev 10899)
@@ -126,15 +126,14 @@
InvocationContext invCtx) throws IOException
{
boolean handlerExists = false;
- String handledPath = null;
requestPath = truncateHostName(requestPath);
- NettyCallbackHandlerImpl handler =
(NettyCallbackHandlerImpl)this.getCallback(requestPath);
+ NettyCallbackHandlerImpl handler = (NettyCallbackHandlerImpl)
this.getCallback(requestPath);
if (handler != null)
{
handlerExists = true;
if (LOG.isDebugEnabled())
LOG.debug("Handling request path: " + requestPath);
-
+
return handler.handle(httpMethod, inputStream, outputStream, invCtx);
}
if (handlerExists == false)