Author: richard.opalka(a)jboss.com
Date: 2009-10-09 10:03:31 -0400 (Fri, 09 Oct 2009)
New Revision: 10880
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/NettyHttpServer.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/NettyHttpServerCallbackHandler.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/NettyHttpServerConfigFactory.java
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerFactory.java
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyInvocationHandler.java
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyInvocationHandlerFactory.java
Log:
[JBWS-2674][JBWS-2754] refactoring (WIP)
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-09
13:17:05 UTC (rev 10879)
+++
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyEndpointRegistryFactory.java 2009-10-09
14:03:31 UTC (rev 10880)
@@ -26,15 +26,29 @@
import org.jboss.wsf.spi.management.EndpointRegistryFactory;
/**
- * TODO: javadoc
+ * Netty server endpoint registry factory for JSE environment.
*
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
public final class NettyEndpointRegistryFactory extends EndpointRegistryFactory
{
+
+ /** Endpoing registry singleton. */
+ private static final EndpointRegistry ENDPOINT_REGISTRY = new
DefaultEndpointRegistry();
+
+ /**
+ * Constructor.
+ */
+ public NettyEndpointRegistryFactory()
+ {
+ super();
+ }
- private static EndpointRegistry ENDPOINT_REGISTRY = new DefaultEndpointRegistry();
-
+ /**
+ * Returns endpoint registry.
+ *
+ * @return endpoint registry
+ */
@Override
public EndpointRegistry getEndpointRegistry()
{
Modified:
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServer.java
===================================================================
---
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServer.java 2009-10-09
13:17:05 UTC (rev 10879)
+++
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServer.java 2009-10-09
14:03:31 UTC (rev 10880)
@@ -46,23 +46,35 @@
*/
final class NettyHttpServer implements Runnable
{
-
+
private static final Logger LOG = Logger.getLogger(NettyHttpServer.class);
+
private static final Lock CLASS_LOCK = new ReentrantLock();
+
private static final long WAIT_PERIOD = 100;
+
private static Map<String, NettyHttpServer> SERVERS = new HashMap<String,
NettyHttpServer>();
+
static final ChannelGroup channelGroup = new
DefaultChannelGroup("rmBackPortsServer");
private final Object instanceLock = new Object();
+
private final String scheme;
+
private final String host;
+
private final int port;
+
private boolean started;
+
private boolean stopped;
+
private boolean terminated;
+
private ChannelFactory factory;
+
private NettyInvocationHandler handler;
-
+
private NettyHttpServer(String scheme, String host, int port)
{
super();
@@ -92,12 +104,12 @@
throw new WebServiceException(e.getMessage(), e);
}
}
-
+
public final void registerCallback(NettyHttpServerCallbackHandler callbackHandler)
{
this.handler.registerCallback(callbackHandler);
}
-
+
public final void unregisterCallback(NettyHttpServerCallbackHandler callbackHandler)
{
this.handler.unregisterCallback(callbackHandler);
@@ -106,12 +118,12 @@
this.terminate();
}
}
-
+
public final NettyHttpServerCallbackHandler getCallback(String requestPath)
{
return this.handler.getCallback(requestPath);
}
-
+
public final boolean hasMoreCallbacks()
{
return this.handler.hasMoreCallbacks();
@@ -121,26 +133,26 @@
{
return this.scheme;
}
-
+
public final String getHost()
{
return this.host;
}
-
+
public final int getPort()
{
return this.port;
}
-
+
public final void run()
{
synchronized (this.instanceLock)
{
if (this.started)
return;
-
+
this.started = true;
-
+
while (this.stopped == false)
{
try
@@ -170,14 +182,14 @@
}
}
}
-
+
public final void terminate()
{
synchronized (this.instanceLock)
{
if (this.stopped == true)
return;
-
+
this.stopped = true;
LOG.debug("termination forced");
SERVERS.remove(scheme + "://" + host + ":" + port +
"/");
@@ -195,7 +207,7 @@
}
}
}
-
+
/**
* Starts back ports server on the background if method is called for the first time
* @param scheme protocol
@@ -212,15 +224,16 @@
NettyHttpServer server = SERVERS.get(key);
if (server == null)
{
- server = new NettyHttpServer(scheme, host, (port == -1) ? 80 : port);
+ server = new NettyHttpServer(scheme, host, (port == -1) ? 80 : port);
SERVERS.put(key, server);
// forking back ports server
- Thread t = new Thread(server, "NettyHttpServer listening on " +
key);
+ Thread t = new Thread(server, "NettyHttpServer listening on " +
key);
t.setDaemon(true);
t.start();
// registering shutdown hook
final NettyHttpServer s = server;
- Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
+ Runtime.getRuntime().addShutdownHook(new Thread(new Runnable()
+ {
public void run()
{
s.terminate();
@@ -242,5 +255,5 @@
CLASS_LOCK.unlock();
}
}
-
+
}
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-09
13:17:05 UTC (rev 10879)
+++
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerAdapter.java 2009-10-09
14:03:31 UTC (rev 10880)
@@ -62,11 +62,15 @@
/** JBossWS SPI provider. */
private static final SPIProvider SPI_PROVIDER =
SPIProviderResolver.getInstance().getProvider();
+
/** JBossWS Http Context factory. */
- private static final HttpContextFactory HTTP_CONTEXT_FACTORY =
NettyHttpServerAdapter.SPI_PROVIDER.getSPI(HttpContextFactory.class);
+ private static final HttpContextFactory HTTP_CONTEXT_FACTORY =
NettyHttpServerAdapter.SPI_PROVIDER
+ .getSPI(HttpContextFactory.class);
+
/** Deployment model factory. */
- private static final DeploymentModelFactory DEPLOYMENT_FACTORY =
NettyHttpServerAdapter.SPI_PROVIDER.getSPI(DeploymentModelFactory.class);
-
+ private static final DeploymentModelFactory DEPLOYMENT_FACTORY =
NettyHttpServerAdapter.SPI_PROVIDER
+ .getSPI(DeploymentModelFactory.class);
+
/**
* Constructor.
*/
@@ -83,38 +87,39 @@
public void destroy(HttpContext context, Endpoint endpoint)
{
- EndpointImpl epImpl = (EndpointImpl)endpoint;
+ EndpointImpl epImpl = (EndpointImpl) endpoint;
NettyHttpServer server = NettyHttpServer.getInstance("http",
"localhost", epImpl.getPort());
NettyHttpServerCallbackHandler callback = server.getCallback(epImpl.getPath());
server.unregisterCallback(callback);
-
- DeploymentAspectManagerImpl daManager = new DeploymentAspectManagerImpl();
+
+ DeploymentAspectManagerImpl daManager = new DeploymentAspectManagerImpl();
daManager.setDeploymentAspects(getDeploymentAspects());
daManager.undeploy(epImpl.getDeployment());
}
public void publish(HttpContext context, Endpoint ep)
{
- EndpointImpl epImpl = (EndpointImpl)ep;
+ EndpointImpl epImpl = (EndpointImpl) ep;
String contextRoot = context.getContextRoot();
Deployment dep = this.newDeployment(epImpl, contextRoot);
-
- DeploymentAspectManagerImpl daManager = new DeploymentAspectManagerImpl();
+
+ DeploymentAspectManagerImpl daManager = new DeploymentAspectManagerImpl();
daManager.setDeploymentAspects(getDeploymentAspects());
daManager.deploy(dep);
epImpl.setDeployment(dep);
NettyHttpServer server = NettyHttpServer.getInstance("http",
"localhost", epImpl.getPort());
- NettyHttpServerCallbackHandler callback = new
NettyHttpServerCallbackHandler(epImpl.getPath(), contextRoot,
this.getEndpointRegistryPath(epImpl));
+ NettyHttpServerCallbackHandler callback = new
NettyHttpServerCallbackHandler(epImpl.getPath(), contextRoot, this
+ .getEndpointRegistryPath(epImpl));
server.registerCallback(callback);
}
-
+
private String getEndpointRegistryPath(EndpointImpl endpoint)
{
// we need to distinguish ports in endpoints registry in JSE environment
return endpoint.getPathWithoutContext() + "-port-" + endpoint.getPort();
}
-
+
private Deployment newDeployment(EndpointImpl epImpl, String contextRoot)
{
Class<?> endpointClass = this.getEndpointClass(epImpl);
@@ -129,19 +134,19 @@
dep.setRuntimeClassLoader(loader);
dep.setType(DeploymentType.JAXWS_JSE);
dep.getService().setContextRoot(contextRoot);
-
+
// TODO: remove this properties hack
dep.getService().setProperty("protocol", "http");
dep.getService().setProperty("host", "127.0.0.1");
dep.getService().setProperty("port", epImpl.getPort());
-
+
return dep;
}
-
+
private List<DeploymentAspect> getDeploymentAspects()
{
List<DeploymentAspect> retVal = new LinkedList<DeploymentAspect>();
-
+
// TODO: native stack can't use framework classes directly
retVal.add(new EndpointHandlerDeploymentAspect()); // 13
retVal.add(new BackwardCompatibleContextRootDeploymentAspect()); // 14
@@ -154,7 +159,7 @@
retVal.add(new EagerInitializeDeploymentAspect()); // 25
retVal.add(new EndpointRegistryDeploymentAspect()); // 35
retVal.add(new EndpointLifecycleDeploymentAspect()); // 37
-
+
return retVal;
}
Modified:
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerCallbackHandler.java
===================================================================
---
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerCallbackHandler.java 2009-10-09
13:17:05 UTC (rev 10879)
+++
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerCallbackHandler.java 2009-10-09
14:03:31 UTC (rev 10880)
@@ -53,13 +53,18 @@
*
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
-final class NettyHttpServerCallbackHandler
+final class NettyHttpServerCallbackHandler // TODO: review class name
{
- private static final Logger logger = Logger.getLogger(RMCallbackHandlerImpl.class);
+ private static final Logger LOGGER = Logger.getLogger(RMCallbackHandlerImpl.class);
+
private final String handledPath;
+
private final SPIProvider spiProvider =
SPIProviderResolver.getInstance().getProvider();
+
private EndpointRegistry epRegistry;
+
private Endpoint endpoint;
+
private List<PreDestroyHolder> preDestroyRegistry = new
LinkedList<PreDestroyHolder>();
/**
@@ -80,7 +85,7 @@
private void initRegistry()
{
epRegistry =
spiProvider.getSPI(EndpointRegistryFactory.class).getEndpointRegistry();
- }
+ }
/**
* Initialize the service endpoint
@@ -94,82 +99,75 @@
if (this.endpoint == null)
{
- ObjectName oname = ObjectNameFactory.create(Endpoint.SEPID_DOMAIN +
":" +
- Endpoint.SEPID_PROPERTY_CONTEXT + "=" + context + "," +
- Endpoint.SEPID_PROPERTY_ENDPOINT + "=" + endpointRegistryPath
- );
+ 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);
}
}
-
- public int handle(String method, InputStream inputStream, OutputStream outputStream,
InvocationContext invCtx) throws IOException
+
+ public int handle(String method, InputStream inputStream, OutputStream outputStream,
InvocationContext invCtx)
+ throws IOException
{
Integer statusCode = null;
try
{
if (method.equals("POST"))
{
- doPost(inputStream, outputStream, invCtx);
- statusCode = (Integer)invCtx.getProperty(Constants.NETTY_STATUS_CODE);
+ this.handle(inputStream, outputStream, invCtx, false);
+ statusCode = (Integer) invCtx.getProperty(Constants.NETTY_STATUS_CODE);
}
else if (method.equals("GET"))
{
- doGet(inputStream, outputStream, invCtx);
+ this.handle(inputStream, outputStream, invCtx, true);
}
else
{
throw new WSException("Unsupported HTTP method: " + method);
}
}
- catch(Exception e)
+ catch (Exception e)
{
- logger.error(e.getMessage(), e);
+ NettyHttpServerCallbackHandler.LOGGER.error(e.getMessage(), e);
statusCode = 500;
}
-
+
return statusCode == null ? 200 : statusCode;
}
-
- public final String getHandledPath()
+
+ public String getHandledPath()
{
return this.handledPath;
}
-
- public void doGet(InputStream inputStream, OutputStream outputStream,
InvocationContext invCtx) throws IOException
- {
- try
- {
- EndpointAssociation.setEndpoint(endpoint);
- RequestHandler requestHandler = endpoint.getRequestHandler();
- requestHandler.handleWSDLRequest(endpoint, outputStream, invCtx);
- }
- finally
- {
- EndpointAssociation.removeEndpoint();
- }
- }
- public void doPost(InputStream inputStream, OutputStream outputStream,
InvocationContext invCtx) throws IOException
+ private void handle(final InputStream inputStream, final OutputStream outputStream,
final InvocationContext invCtx, final boolean wsdlRequest) throws IOException
{
try
{
- EndpointAssociation.setEndpoint(endpoint);
- RequestHandler requestHandler = endpoint.getRequestHandler();
- requestHandler.handleRequest(endpoint, inputStream, outputStream, invCtx);
+ 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(endpoint);
+ this.registerForPreDestroy(this.endpoint);
EndpointAssociation.removeEndpoint();
}
}
- private void registerForPreDestroy(Endpoint ep)
+ private void registerForPreDestroy(final Endpoint ep)
{
- PreDestroyHolder holder =
(PreDestroyHolder)ep.getAttachment(PreDestroyHolder.class);
+ final PreDestroyHolder holder = (PreDestroyHolder)
ep.getAttachment(PreDestroyHolder.class);
if (holder != null)
{
- synchronized(this.preDestroyRegistry)
+ synchronized (this.preDestroyRegistry)
{
if (!this.preDestroyRegistry.contains(holder))
{
@@ -182,7 +180,7 @@
public final void destroy()
{
- synchronized(this.preDestroyRegistry)
+ synchronized (this.preDestroyRegistry)
{
for (final PreDestroyHolder holder : this.preDestroyRegistry)
{
@@ -193,7 +191,7 @@
}
catch (Exception exception)
{
- logger.error(exception.getMessage(), exception);
+ NettyHttpServerCallbackHandler.LOGGER.error(exception.getMessage(),
exception);
}
}
this.preDestroyRegistry.clear();
@@ -202,4 +200,3 @@
}
}
-
\ No newline at end of file
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-09
13:17:05 UTC (rev 10879)
+++
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerConfig.java 2009-10-09
14:03:31 UTC (rev 10880)
@@ -28,21 +28,22 @@
import org.jboss.wsf.spi.management.ServerConfig;
/**
- * TODO: javadoc
+ * Netty HTTP server config that configures user temp
+ * directory to be used for contract publishing.
*
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
final class NettyHttpServerConfig implements ServerConfig
{
- // TODO: count with security manager enabled
- private static File TMP_DIR;
-
+ /** Temporary directory location. */
+ private static File tmpDir;
+
static
{
try
{
- TMP_DIR = new File(System.getProperty("java.io.tmpdir"));
+ NettyHttpServerConfig.tmpDir = new
File(System.getProperty("java.io.tmpdir"));
}
catch (SecurityException se)
{
@@ -50,21 +51,41 @@
}
}
+ /**
+ * Constructor.
+ */
+ public NettyHttpServerConfig()
+ {
+ super();
+ }
+
public File getHomeDir()
{
- return NettyHttpServerConfig.TMP_DIR;
+ return NettyHttpServerConfig.tmpDir;
}
public File getServerDataDir()
{
- return NettyHttpServerConfig.TMP_DIR;
+ return NettyHttpServerConfig.tmpDir;
}
public File getServerTempDir()
{
- return NettyHttpServerConfig.TMP_DIR;
+ return NettyHttpServerConfig.tmpDir;
}
+ public String getWebServiceHost()
+ {
+ return "localhost";
+ }
+
+ public boolean isModifySOAPAddress()
+ {
+ return false;
+ }
+
+ // not implemented methods
+
public String getImplementationTitle()
{
throw new UnsupportedOperationException();
@@ -75,28 +96,16 @@
throw new UnsupportedOperationException();
}
- public String getWebServiceHost()
- {
- return "localhost";
- }
-
public int getWebServicePort()
{
throw new UnsupportedOperationException();
- //return 8878;
}
public int getWebServiceSecurePort()
{
throw new UnsupportedOperationException();
- //return 8879;
}
- public boolean isModifySOAPAddress()
- {
- return false;
- }
-
public void setModifySOAPAddress(boolean flag)
{
throw new UnsupportedOperationException();
@@ -116,5 +125,5 @@
{
throw new UnsupportedOperationException();
}
-
+
}
Modified:
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerConfigFactory.java
===================================================================
---
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerConfigFactory.java 2009-10-09
13:17:05 UTC (rev 10879)
+++
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerConfigFactory.java 2009-10-09
14:03:31 UTC (rev 10880)
@@ -25,15 +25,16 @@
import org.jboss.wsf.spi.management.ServerConfigFactory;
/**
- * TODO: javadoc
+ * Netty server configuration factory.
*
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
public final class NettyHttpServerConfigFactory extends ServerConfigFactory
{
- private static ServerConfig NETTY_CONFIG = new NettyHttpServerConfig();
-
+ /** Netty config singleton. */
+ private static final ServerConfig NETTY_CONFIG_SINGLETON = new
NettyHttpServerConfig();
+
/**
* Constructor.
*/
@@ -42,10 +43,15 @@
super();
}
+ /**
+ * Provides Netty server configuration.
+ *
+ * @return Netty server configuration
+ */
@Override
public ServerConfig getServerConfig()
{
- return NettyHttpServerConfigFactory.NETTY_CONFIG;
+ return NettyHttpServerConfigFactory.NETTY_CONFIG_SINGLETON;
}
-
+
}
Modified:
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerFactory.java
===================================================================
---
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerFactory.java 2009-10-09
13:17:05 UTC (rev 10879)
+++
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerFactory.java 2009-10-09
14:03:31 UTC (rev 10880)
@@ -32,8 +32,9 @@
public final class NettyHttpServerFactory extends HttpServerFactory
{
- private static final HttpServer NETTY_HTTP_SERVER = new NettyHttpServerAdapter();
-
+ /** Netty HTTP server adapter singleton. */
+ private static final HttpServer NETTY_SERVER_ADAPTER_SINGLETON = new
NettyHttpServerAdapter();
+
/**
* Constructor.
*/
@@ -41,16 +42,16 @@
{
super();
}
-
+
/**
- * Returns Netty based http server.
+ * Returns Netty based http server adapter.
*
- * @return Netty based http server
+ * @return Netty based http server adapter
*/
@Override
public HttpServer getHttpServer()
{
- return NettyHttpServerFactory.NETTY_HTTP_SERVER;
+ return NettyHttpServerFactory.NETTY_SERVER_ADAPTER_SINGLETON;
}
}
Modified:
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyInvocationHandler.java
===================================================================
---
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyInvocationHandler.java 2009-10-09
13:17:05 UTC (rev 10879)
+++
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyInvocationHandler.java 2009-10-09
14:03:31 UTC (rev 10880)
@@ -69,14 +69,16 @@
final class NettyInvocationHandler extends SimpleChannelUpstreamHandler
{
private static final Logger LOG = Logger.getLogger(NettyInvocationHandler.class);
+
private final List<NettyHttpServerCallbackHandler> callbacks = new
LinkedList<NettyHttpServerCallbackHandler>();
+
private final Lock lock = new ReentrantLock();
public NettyInvocationHandler()
{
super();
}
-
+
@Override
public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e)
{
@@ -85,7 +87,7 @@
// If the added channel is closed before shutdown,
// it will be removed from the group automatically.
NettyHttpServer.channelGroup.add(ctx.getChannel());
- }
+ }
public boolean hasMoreCallbacks()
{
@@ -95,12 +97,12 @@
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws
Exception
{
- HttpRequest request = (HttpRequest)e.getMessage();
+ HttpRequest request = (HttpRequest) e.getMessage();
ChannelBuffer content = request.getContent();
OutputStream baos = new ByteArrayOutputStream();
OutputStream outputStream = new BufferedOutputStream(baos);
Integer statusCode = null;
-
+
InvocationContext invCtx = new InvocationContext();
Map<String, List<String>> requestHeaders = new HashMap<String,
List<String>>();
Map<String, List<String>> responseHeaders = new HashMap<String,
List<String>>();
@@ -131,14 +133,14 @@
writeResponse(e, request, baos.toString(), statusCode, responseHeaders,
ctx.getChannel());
}
}
-
+
private InputStream getInputStream(ChannelBuffer content)
{
return new ChannelBufferInputStream(content);
}
-
- private int handle(String requestPath, String httpMethod, InputStream inputStream,
OutputStream outputStream,
- InvocationContext invCtx) throws IOException
+
+ private int handle(String requestPath, String httpMethod, InputStream inputStream,
OutputStream outputStream,
+ InvocationContext invCtx) throws IOException
{
boolean handlerExists = false;
String handledPath = null;
@@ -156,10 +158,10 @@
}
if (handlerExists == false)
LOG.warn("No callback handler registered for path: " + requestPath);
-
+
return 500;
}
-
+
private String truncateHostName(String s)
{
String retVal = s;
@@ -174,20 +176,20 @@
LOG.error(mue.getMessage(), mue);
}
}
-
+
while (retVal.endsWith("/"))
{
retVal = retVal.substring(0, retVal.length() - 1);
}
return retVal;
}
-
- private void writeResponse(MessageEvent e, HttpRequest request, String content, int
statusCode, Map<String,
- List<String>> responseHeaders, Channel channel) throws IOException
+
+ private void writeResponse(MessageEvent e, HttpRequest request, String content, int
statusCode,
+ Map<String, List<String>> responseHeaders, Channel channel) throws
IOException
{
// Build the response object.
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1,
getResponseStatus(statusCode));
-
+
Iterator<String> iterator = responseHeaders.keySet().iterator();
String key = null;
List<String> values = null;
@@ -240,7 +242,7 @@
cf.awaitUninterruptibly();
}
}
-
+
private List<String> removeProhibitedCharacters(List<String> values)
{
List<String> retVal = new LinkedList<String>();
@@ -248,27 +250,30 @@
{
retVal.add(i, removeProhibitedCharacters(values.get(i)));
}
-
+
return retVal;
}
-
+
private String removeProhibitedCharacters(String s)
{
String retVal = s;
-
+
retVal = retVal.replace('\r', ' ');
retVal = retVal.replace('\n', ' ');
-
+
return retVal;
}
private HttpResponseStatus getResponseStatus(int statusCode)
{
// TODO:
https://jira.jboss.org/jira/browse/NETTY-233
- if (statusCode == 500) return HttpResponseStatus.INTERNAL_SERVER_ERROR;
- if (statusCode == 202) return HttpResponseStatus.ACCEPTED;
- if (statusCode == 204) return HttpResponseStatus.NO_CONTENT;
-
+ if (statusCode == 500)
+ return HttpResponseStatus.INTERNAL_SERVER_ERROR;
+ if (statusCode == 202)
+ return HttpResponseStatus.ACCEPTED;
+ if (statusCode == 204)
+ return HttpResponseStatus.NO_CONTENT;
+
return HttpResponseStatus.OK;
}
@@ -324,5 +329,5 @@
this.lock.unlock();
}
}
-
+
}
Modified:
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyInvocationHandlerFactory.java
===================================================================
---
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyInvocationHandlerFactory.java 2009-10-09
13:17:05 UTC (rev 10879)
+++
stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyInvocationHandlerFactory.java 2009-10-09
14:03:31 UTC (rev 10880)
@@ -27,15 +27,29 @@
import org.jboss.wsf.spi.invocation.InvocationType;
/**
- * TODO: javadoc
+ * Netty invocation handler factory that supports JAXWS JSE invocation only.
*
* @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
public final class NettyInvocationHandlerFactory extends InvocationHandlerFactory
{
+ /**
+ * Constructor.
+ */
+ public NettyInvocationHandlerFactory()
+ {
+ super();
+ }
+
+ /**
+ * Returns invocation handler for specified invocation type.
+ *
+ * @param type invocation type
+ * @return invocation handler
+ */
@Override
- public InvocationHandler newInvocationHandler(InvocationType type)
+ public InvocationHandler newInvocationHandler(final InvocationType type)
{
InvocationHandler handler = null;
@@ -45,7 +59,7 @@
handler = new InvocationHandlerJAXWS();
break;
default :
- throw new IllegalArgumentException("Unable to resolve
spi.invocation.InvocationHandler for type " + type);
+ throw new IllegalArgumentException("Unable to resolve
spi.invocation.InvocationHandler for type: " + type);
}
return handler;