From jbossws-commits at lists.jboss.org Fri Oct 9 09:07:53 2009 Content-Type: multipart/mixed; boundary="===============4768663516406671129==" MIME-Version: 1.0 From: jbossws-commits at lists.jboss.org To: jbossws-commits at lists.jboss.org Subject: [jbossws-commits] JBossWS SVN: r10873 - in stack/native/branches/ropalka/modules: core/src/main/java/org/jboss/ws/core/jaxws/spi/http and 2 other directories. Date: Fri, 09 Oct 2009 09:07:53 -0400 Message-ID: <200910091307.n99D7rPI019620@svn01.web.mwc.hst.phx2.redhat.com> --===============4768663516406671129== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: richard.opalka(a)jboss.com Date: 2009-10-09 09:07:52 -0400 (Fri, 09 Oct 2009) New Revision: 10873 Added: stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/co= re/jaxws/spi/http/NettyHttpServerAdapter.java stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/co= re/jaxws/spi/http/NettyHttpServerCallbackHandler.java Removed: stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/co= re/jaxws/spi/http/NettyCallbackHandler.java stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/co= re/jaxws/spi/http/RealNettyHttpServer.java Modified: stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/co= re/jaxws/spi/EndpointImpl.java stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/co= re/jaxws/spi/http/NettyHttpServer.java stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/co= re/jaxws/spi/http/NettyHttpServerFactory.java stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/co= re/jaxws/spi/http/NettyInvocationHandler.java stack/native/branches/ropalka/modules/testsuite/native-tests/src/test/ja= va/org/jboss/test/ws/jaxws/endpoint/jse/UsecasesTestCase.java stack/native/branches/ropalka/modules/testsuite/native-tests/src/test/ja= va/org/jboss/test/ws/jaxws/endpoint/jse/endpoints/Endpoint1Impl.java Log: [JBWS-2674][JBWS-2754] removing useless start method, extending test + othe= r refactorings (WIP) Modified: stack/native/branches/ropalka/modules/core/src/main/java/org/jbos= s/ws/core/jaxws/spi/EndpointImpl.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/c= ore/jaxws/spi/EndpointImpl.java 2009-10-09 12:44:26 UTC (rev 10872) +++ stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/c= ore/jaxws/spi/EndpointImpl.java 2009-10-09 13:07:52 UTC (rev 10873) @@ -45,7 +45,7 @@ import org.jboss.ws.core.jaxws.wsaddressing.EndpointReferenceUtil; import org.jboss.wsf.spi.SPIProvider; import org.jboss.wsf.spi.SPIProviderResolver; -import org.jboss.wsf.spi.deployment.ArchiveDeployment; +import org.jboss.wsf.spi.deployment.Deployment; import org.jboss.wsf.spi.http.HttpContext; import org.jboss.wsf.spi.http.HttpServer; import org.jboss.wsf.spi.http.HttpServerFactory; @@ -56,15 +56,13 @@ /** * A Web service endpoint implementation. * = - * @author Thomas.Diesler(a)jboss.com - * @since 07-Jul-2006 + * @author Thomas Diesler + * @author Richard Opalka */ public class EndpointImpl extends Endpoint { - // provide logging - private final Logger log =3D Logger.getLogger(EndpointImpl.class); = - // The permission to publish an endpoint + private static final Logger log =3D Logger.getLogger(EndpointImpl.class= ); private static final WebServicePermission ENDPOINT_PUBLISH_PERMISSION = =3D new WebServicePermission("publishEndpoint"); = private Object implementor; @@ -77,7 +75,7 @@ private boolean isPublished; private boolean isDestroyed; private URI address; - private ArchiveDeployment dep; + private Deployment dep; = public EndpointImpl(String bindingId, Object implementor, WebServiceFea= ture[] features) { @@ -128,8 +126,6 @@ // Create and start the HTTP server SPIProvider spiProvider =3D SPIProviderResolver.getInstance().getPro= vider(); HttpServer httpServer =3D spiProvider.getSPI(HttpServerFactory.class= ).getHttpServer(); - httpServer.setProperties(properties); - httpServer.start(); = String path =3D address.getPath(); String contextRoot =3D "/" + new StringTokenizer(path, "/").nextToke= n(); @@ -148,7 +144,10 @@ @Override public void publish(Object context) { - log.debug("publish: " + context); + if (context =3D=3D null) + throw new IllegalArgumentException("Null context"); + = + log.debug("publishing endpoint " + this + " to " + context); = if (isDestroyed) throw new IllegalStateException("Endpoint already destroyed"); @@ -156,24 +155,6 @@ // Check with the security manger checkPublishEndpointPermission(); = - /* Check if we are standalone - boolean isStandalone; - try - { - SPIProvider spiProvider =3D SPIProviderResolver.getInstance().get= Provider(); - spiProvider.getSPI(ServerConfigFactory.class).getServerConfig(); - isStandalone =3D false; - } - catch (Exception ex) - { - // ignore, there should be no ServerConfigFactory in VM - isStandalone =3D true; - } - - if (isStandalone =3D=3D false) - throw new IllegalStateException("Cannot publish endpoint from wit= hin server"); - */ - if (context instanceof HttpContext) { serverContext =3D (HttpContext)context; @@ -185,6 +166,10 @@ httpServer.publish(serverContext, this); isPublished =3D true; } + else + { + throw new UnsupportedOperationException("Cannot handle contexts o= f type: " + context); + } } = private static URI getAddressFromConfigAndContext(HttpContext context) @@ -245,7 +230,7 @@ @Override public void setMetadata(List list) { - log.info("Ignore metadata, not implemented"); + log.info("Ignore metadata, not implemented"); // TODO: this.metadata =3D list; } = @@ -258,7 +243,7 @@ @Override public void setExecutor(Executor executor) { - log.info("Ignore executor, not implemented"); + log.info("Ignore executor, not implemented"); // TODO this.executor =3D executor; } = @@ -300,7 +285,8 @@ { if (isDestroyed || !isPublished) throw new WebServiceException("Cannot get EPR for an unpubblished= or already destroyed endpoint!"); - if (getBinding() instanceof HTTPBinding ) + + if (getBinding() instanceof HTTPBinding) { throw new UnsupportedOperationException("Cannot get epr when usin= g the XML/HTTP binding"); } @@ -313,6 +299,7 @@ for (Element el : referenceParameters) builder.referenceParameter(el); } + return EndpointReferenceUtil.transform(clazz, builder.build()); } = @@ -331,8 +318,9 @@ return this.address.getPort(); } = - public String getName() + public String getPathWithoutContext() { + // TODO: optimize this method StringTokenizer st =3D new StringTokenizer(this.getPath(), "/"); st.nextToken(); StringBuilder sb =3D new StringBuilder(); @@ -346,12 +334,15 @@ return sb.toString(); } = - public void setDeployment(ArchiveDeployment dep) + public void setDeployment(final Deployment dep) { - this.dep =3D dep; + if (this.dep =3D=3D null) + { + this.dep =3D dep; + } } = - public ArchiveDeployment getDeployment() + public Deployment getDeployment() { return this.dep; } Deleted: stack/native/branches/ropalka/modules/core/src/main/java/org/jboss= /ws/core/jaxws/spi/http/NettyCallbackHandler.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/c= ore/jaxws/spi/http/NettyCallbackHandler.java 2009-10-09 12:44:26 UTC (rev 1= 0872) +++ stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/c= ore/jaxws/spi/http/NettyCallbackHandler.java 2009-10-09 13:07:52 UTC (rev 1= 0873) @@ -1,204 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * Copyright 2009, 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.ws.core.jaxws.spi.http; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.LinkedList; -import java.util.List; - -import javax.management.ObjectName; -import javax.xml.ws.WebServiceException; - -import org.jboss.logging.Logger; -import org.jboss.ws.Constants; -import org.jboss.ws.WSException; -import org.jboss.ws.extensions.wsrm.transport.backchannel.RMCallbackHandle= rImpl; -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; -import org.jboss.wsf.spi.SPIProviderResolver; -import org.jboss.wsf.spi.deployment.Endpoint; -import org.jboss.wsf.spi.invocation.EndpointAssociation; -import org.jboss.wsf.spi.invocation.InvocationContext; -import org.jboss.wsf.spi.invocation.RequestHandler; -import org.jboss.wsf.spi.management.EndpointRegistry; -import org.jboss.wsf.spi.management.EndpointRegistryFactory; -import org.jboss.wsf.spi.management.EndpointResolver; -import org.jboss.wsf.stack.jbws.WebAppResolver; - -/** - * TODO: javadoc - * - * @author Richard Opalka - */ -final class NettyCallbackHandler -{ - private static final Logger logger =3D Logger.getLogger(RMCallbackHandl= erImpl.class); - private final String handledPath; - private final SPIProvider spiProvider =3D SPIProviderResolver.getInstan= ce().getProvider(); - private EndpointRegistry epRegistry; - private Endpoint endpoint; - private List preDestroyRegistry =3D new LinkedList(); - - /** - * Request path to listen for incomming messages - * @param handledPath - */ - public NettyCallbackHandler(String path, String context, String endpoin= tClass) - { - super(); - this.initRegistry(); - this.initEndpoint(context, endpointClass); - this.handledPath =3D path; - } - - /** - * Initializes endpoint registry - */ - private void initRegistry() - { - epRegistry =3D spiProvider.getSPI(EndpointRegistryFactory.class).get= EndpointRegistry(); - } = - - /** - * Initialize the service endpoint - * @param contextPath context path - * @param servletName servlet name - */ - private void initEndpoint(String contextPath, String servletName) - { - final EndpointResolver resolver =3D new WebAppResolver(contextPath, = servletName); - this.endpoint =3D epRegistry.resolve(resolver); - - if (this.endpoint =3D=3D null) - { - ObjectName oname =3D ObjectNameFactory.create(Endpoint.SEPID_DOMA= IN + ":" + - Endpoint.SEPID_PROPERTY_CONTEXT + "=3D" + contextPath + "," + - Endpoint.SEPID_PROPERTY_ENDPOINT + "=3D" + servletName - ); - throw new WebServiceException("Cannot obtain endpoint for: " + on= ame); - } - } - = - public int handle(String method, InputStream inputStream, OutputStream = outputStream, InvocationContext invCtx) throws IOException - { - Integer statusCode =3D null; - try - { - if (method.equals("POST")) - { - doPost(inputStream, outputStream, invCtx); - statusCode =3D (Integer)invCtx.getProperty(Constants.NETTY_STA= TUS_CODE); - } - else if (method.equals("GET")) - { - doGet(inputStream, outputStream, invCtx); - } - else - { - throw new WSException("Unsupported HTTP method: " + method); - } - } - catch(Exception e) - { - logger.error(e.getMessage(), e); - statusCode =3D 500; - } - = - return statusCode =3D=3D null ? 200 : statusCode; - } - = - public final String getHandledPath() - { - return this.handledPath; - } - = - public void doGet(InputStream inputStream, OutputStream outputStream, I= nvocationContext invCtx) throws IOException - { - try - { - EndpointAssociation.setEndpoint(endpoint); - RequestHandler requestHandler =3D endpoint.getRequestHandler(); - requestHandler.handleWSDLRequest(endpoint, outputStream, invCtx); - } - finally - { - EndpointAssociation.removeEndpoint(); - } - } - - public void doPost(InputStream inputStream, OutputStream outputStream, = InvocationContext invCtx) throws IOException - { - try - { - EndpointAssociation.setEndpoint(endpoint); - RequestHandler requestHandler =3D endpoint.getRequestHandler(); - requestHandler.handleRequest(endpoint, inputStream, outputStream,= invCtx); - } - finally - { - this.registerForPreDestroy(endpoint); - EndpointAssociation.removeEndpoint(); - } - } - - private void registerForPreDestroy(Endpoint ep) - { - PreDestroyHolder holder =3D (PreDestroyHolder)ep.getAttachment(PreDe= stroyHolder.class); - if (holder !=3D null) - { - synchronized(this.preDestroyRegistry) - { - if (!this.preDestroyRegistry.contains(holder)) - { - this.preDestroyRegistry.add(holder); - } - } - ep.removeAttachment(PreDestroyHolder.class); - } - } - - public final void destroy() - { - synchronized(this.preDestroyRegistry) - { - for (final PreDestroyHolder holder : this.preDestroyRegistry) - { - try - { - final Object targetBean =3D holder.getObject(); - InjectionHelper.callPreDestroyMethod(targetBean); - } - catch (Exception exception) - { - logger.error(exception.getMessage(), exception); - } - } - this.preDestroyRegistry.clear(); - this.preDestroyRegistry =3D null; - } - } - -} Modified: stack/native/branches/ropalka/modules/core/src/main/java/org/jbos= s/ws/core/jaxws/spi/http/NettyHttpServer.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/c= ore/jaxws/spi/http/NettyHttpServer.java 2009-10-09 12:44:26 UTC (rev 10872) +++ stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/c= ore/jaxws/spi/http/NettyHttpServer.java 2009-10-09 13:07:52 UTC (rev 10873) @@ -21,144 +21,226 @@ */ package org.jboss.ws.core.jaxws.spi.http; = -import java.util.LinkedList; -import java.util.List; +import java.net.InetSocketAddress; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Executors; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; = -import javax.xml.ws.Endpoint; +import javax.xml.ws.WebServiceException; = -import org.jboss.ws.core.jaxws.spi.EndpointImpl; -import org.jboss.wsf.common.ResourceLoaderAdapter; -import org.jboss.wsf.framework.deployment.BackwardCompatibleContextRootDep= loymentAspect; -import org.jboss.wsf.framework.deployment.DeploymentAspectManagerImpl; -import org.jboss.wsf.framework.deployment.EndpointAddressDeploymentAspect; -import org.jboss.wsf.framework.deployment.EndpointHandlerDeploymentAspect; -import org.jboss.wsf.framework.deployment.EndpointLifecycleDeploymentAspec= t; -import org.jboss.wsf.framework.deployment.EndpointNameDeploymentAspect; -import org.jboss.wsf.framework.deployment.EndpointRegistryDeploymentAspect; -import org.jboss.wsf.framework.deployment.URLPatternDeploymentAspect; -import org.jboss.wsf.spi.SPIProvider; -import org.jboss.wsf.spi.SPIProviderResolver; -import org.jboss.wsf.spi.deployment.AbstractExtensible; -import org.jboss.wsf.spi.deployment.ArchiveDeployment; -import org.jboss.wsf.spi.deployment.DeploymentAspect; -import org.jboss.wsf.spi.deployment.DeploymentModelFactory; -import org.jboss.wsf.spi.deployment.Deployment.DeploymentType; -import org.jboss.wsf.spi.http.HttpContext; -import org.jboss.wsf.spi.http.HttpContextFactory; -import org.jboss.wsf.spi.http.HttpServer; -import org.jboss.wsf.stack.jbws.EagerInitializeDeploymentAspect; -import org.jboss.wsf.stack.jbws.PublishContractDeploymentAspect; -import org.jboss.wsf.stack.jbws.ServiceEndpointInvokerDeploymentAspect; -import org.jboss.wsf.stack.jbws.UnifiedMetaDataDeploymentAspect; +import org.jboss.logging.Logger; +import org.jboss.netty.bootstrap.ServerBootstrap; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelFactory; +import org.jboss.netty.channel.group.ChannelGroup; +import org.jboss.netty.channel.group.DefaultChannelGroup; +import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; +import org.jboss.ws.core.client.transport.WSServerPipelineFactory; = /** * TODO: javadoc * * @author Richard Opalka */ -// TODO: review thread safety -final class NettyHttpServer extends AbstractExtensible implements HttpServ= er +final class NettyHttpServer implements Runnable { + = + private static final Logger LOG =3D Logger.getLogger(NettyHttpServer.cl= ass); + private static final Lock CLASS_LOCK =3D new ReentrantLock(); + private static final long WAIT_PERIOD =3D 100; + private static Map SERVERS =3D new HashMap(); + static final ChannelGroup channelGroup =3D new DefaultChannelGroup("rmB= ackPortsServer"); = - /** JBossWS SPI provider. */ - private static final SPIProvider SPI_PROVIDER =3D SPIProviderResolver.g= etInstance().getProvider(); - /** JBossWS Http Context factory. */ - private static final HttpContextFactory HTTP_CONTEXT_FACTORY =3D NettyH= ttpServer.SPI_PROVIDER.getSPI(HttpContextFactory.class); - /** Deployment model factory. */ - private final DeploymentModelFactory deploymentModelFactory; + private final Object instanceLock =3D 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; = - public NettyHttpServer() + private NettyHttpServer(String scheme, String host, int port) { super(); + this.scheme =3D scheme; + this.host =3D host; + this.port =3D port; + try + { + factory =3D new NioServerSocketChannelFactory(Executors.newCached= ThreadPool(), Executors.newCachedThreadPool()); = - // deployment factory - final SPIProvider spiProvider =3D SPIProviderResolver.getInstance().= getProvider(); - this.deploymentModelFactory =3D spiProvider.getSPI(DeploymentModelFa= ctory.class); + ServerBootstrap bootstrap =3D new ServerBootstrap(factory); + this.handler =3D new NettyInvocationHandler(); + WSServerPipelineFactory channelPipelineFactory =3D new WSServerPi= pelineFactory(); + channelPipelineFactory.setRequestHandler(this.handler); + bootstrap.setPipelineFactory(channelPipelineFactory); + bootstrap.setOption("child.tcpNoDelay", true); + bootstrap.setOption("child.keepAlive", true); + // Bind and start to accept incoming connections. + Channel c =3D bootstrap.bind(new InetSocketAddress(this.port)); + channelGroup.add(c); + if (LOG.isDebugEnabled()) + LOG.debug("Netty http server started on port: " + this.port); + } + catch (Exception e) + { + LOG.warn(e.getMessage(), e); + throw new WebServiceException(e.getMessage(), e); + } } - - public HttpContext createContext(final String contextRoot) + = + public final void registerCallback(NettyHttpServerCallbackHandler callb= ackHandler) { - return NettyHttpServer.HTTP_CONTEXT_FACTORY.newHttpContext(this, con= textRoot); + this.handler.registerCallback(callbackHandler); } - - public void destroy(HttpContext context, Endpoint endpoint) + = + public final void unregisterCallback(NettyHttpServerCallbackHandler cal= lbackHandler) { - EndpointImpl epImpl =3D (EndpointImpl)endpoint; - RealNettyHttpServer server =3D RealNettyHttpServer.getInstance("http= ", "localhost", epImpl.getPort()); - NettyCallbackHandler callback =3D server.getCallback(epImpl.getPath(= )); - server.unregisterCallback(callback); - = - DeploymentAspectManagerImpl daManager =3D new DeploymentAspectManage= rImpl(); = - daManager.setDeploymentAspects(getDeploymentAspects()); - daManager.undeploy(epImpl.getDeployment()); + this.handler.unregisterCallback(callbackHandler); + if (!this.hasMoreCallbacks()) + { + this.terminate(); + } } - - public void publish(HttpContext context, Endpoint ep) + = + public final NettyHttpServerCallbackHandler getCallback(String requestP= ath) { - EndpointImpl epImpl =3D (EndpointImpl)ep; - Class endpointClass =3D this.getEndpointClass(ep); - String contextRoot =3D context.getContextRoot(); - ClassLoader loader =3D endpointClass.getClassLoader(); - // TODO: should we use archive deployment - see META-INF/services ??? - final ArchiveDeployment dep =3D (ArchiveDeployment) this.deploymentM= odelFactory.newDeployment(contextRoot, loader); - final org.jboss.wsf.spi.deployment.Endpoint endpoint =3D this.deploy= mentModelFactory.newEndpoint(endpointClass.getName()); - endpoint.setShortName(epImpl.getName() + "-port-" + epImpl.getPort()= ); // we need to distinguish ports in endpoints registry - endpoint.setURLPattern(epImpl.getName()); // TODO: rename method - dep.getService().addEndpoint(endpoint); - dep.setRootFile(new ResourceLoaderAdapter(loader)); - 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()); - = - DeploymentAspectManagerImpl daManager =3D new DeploymentAspectManage= rImpl(); = - daManager.setDeploymentAspects(getDeploymentAspects()); - daManager.deploy(dep); - epImpl.setDeployment(dep); - - RealNettyHttpServer server =3D RealNettyHttpServer.getInstance("http= ", "localhost", epImpl.getPort()); - NettyCallbackHandler callback =3D new NettyCallbackHandler(epImpl.ge= tPath(), contextRoot, endpoint.getShortName()); - server.registerCallback(callback); + return this.handler.getCallback(requestPath); } = - private List getDeploymentAspects() + public final boolean hasMoreCallbacks() { - List retVal =3D new LinkedList(); - = - // TODO: native stack can't use framework classes directly - retVal.add(new EndpointHandlerDeploymentAspect()); // 13 - retVal.add(new BackwardCompatibleContextRootDeploymentAspect()); // = 14 - retVal.add(new URLPatternDeploymentAspect()); // 15 - retVal.add(new EndpointAddressDeploymentAspect()); // 16 - retVal.add(new EndpointNameDeploymentAspect()); // 17 - retVal.add(new UnifiedMetaDataDeploymentAspect()); // 22 - retVal.add(new ServiceEndpointInvokerDeploymentAspect()); // 23 - retVal.add(new PublishContractDeploymentAspect()); // 24 - retVal.add(new EagerInitializeDeploymentAspect()); // 25 - retVal.add(new EndpointRegistryDeploymentAspect()); // 35 - retVal.add(new EndpointLifecycleDeploymentAspect()); // 37 - = - return retVal; + return this.handler.hasMoreCallbacks(); } = - public void start() + public final String getScheme() { - // does nothing + 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 =3D true; + = + while (this.stopped =3D=3D false) + { + try + { + this.instanceLock.wait(WAIT_PERIOD); + LOG.debug("serving requests"); + } + catch (InterruptedException ie) + { + LOG.warn(ie.getMessage(), ie); + } + } + try + { + //Close all connections and server sockets. + channelGroup.close().awaitUninterruptibly(); + //Shutdown the selector loop (boss and worker). + if (factory !=3D null) + { + factory.releaseExternalResources(); + } + } + finally + { + LOG.debug("terminated"); + this.terminated =3D true; + } + } + } + = + public final void terminate() + { + synchronized (this.instanceLock) + { + if (this.stopped =3D=3D true) + return; + = + this.stopped =3D true; + LOG.debug("termination forced"); + SERVERS.remove(scheme + "://" + host + ":" + port + "/"); + while (this.terminated =3D=3D false) + { + try + { + LOG.debug("waiting for termination"); + this.instanceLock.wait(WAIT_PERIOD); + } + catch (InterruptedException ie) + { + LOG.warn(ie.getMessage(), ie); + } + } + } + } + = /** - * Returns implementor class associated with endpoint. - * - * @param endpoint to get implementor class from - * @return implementor class + * Starts back ports server on the background if method is called for t= he first time + * @param scheme protocol + * @param host hostname + * @param port port + * @return netty http server */ - private Class getEndpointClass(final Endpoint endpoint) + public static NettyHttpServer getInstance(String scheme, String host, i= nt port) { - final Object implementor =3D endpoint.getImplementor(); - return implementor instanceof Class ? (Class) implementor : im= plementor.getClass(); + CLASS_LOCK.lock(); + try + { + String key =3D scheme + "://" + host + ":" + port + "/"; + NettyHttpServer server =3D SERVERS.get(key); + if (server =3D=3D null) + { + server =3D new NettyHttpServer(scheme, host, (port =3D=3D -1) = ? 80 : port); = + SERVERS.put(key, server); + // forking back ports server + Thread t =3D new Thread(server, "NettyHttpServer listening on= " + key); + t.setDaemon(true); + t.start(); + // registering shutdown hook + final NettyHttpServer s =3D server; + Runtime.getRuntime().addShutdownHook(new Thread(new Runnable()= { + public void run() + { + s.terminate(); + } + }, "NettyHttpServerShutdownHook(" + key + ")")); + } + else + { + boolean schemeEquals =3D server.getScheme().equals(scheme); + boolean hostEquals =3D server.getHost().equals(host); + boolean portEquals =3D server.getPort() =3D=3D ((port =3D=3D -= 1) ? 80 : port); + if ((schemeEquals =3D=3D false) || (hostEquals =3D=3D false) |= | (portEquals =3D=3D false)) + throw new IllegalArgumentException(); + } + return server; + } + finally + { + CLASS_LOCK.unlock(); + } } - + = } Added: stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/w= s/core/jaxws/spi/http/NettyHttpServerAdapter.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/c= ore/jaxws/spi/http/NettyHttpServerAdapter.java (rev= 0) +++ stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/c= ore/jaxws/spi/http/NettyHttpServerAdapter.java 2009-10-09 13:07:52 UTC (rev= 10873) @@ -0,0 +1,173 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2009, 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.ws.core.jaxws.spi.http; + +import java.util.LinkedList; +import java.util.List; + +import javax.xml.ws.Endpoint; + +import org.jboss.ws.core.jaxws.spi.EndpointImpl; +import org.jboss.wsf.common.ResourceLoaderAdapter; +import org.jboss.wsf.framework.deployment.BackwardCompatibleContextRootDep= loymentAspect; +import org.jboss.wsf.framework.deployment.DeploymentAspectManagerImpl; +import org.jboss.wsf.framework.deployment.EndpointAddressDeploymentAspect; +import org.jboss.wsf.framework.deployment.EndpointHandlerDeploymentAspect; +import org.jboss.wsf.framework.deployment.EndpointLifecycleDeploymentAspec= t; +import org.jboss.wsf.framework.deployment.EndpointNameDeploymentAspect; +import org.jboss.wsf.framework.deployment.EndpointRegistryDeploymentAspect; +import org.jboss.wsf.framework.deployment.URLPatternDeploymentAspect; +import org.jboss.wsf.spi.SPIProvider; +import org.jboss.wsf.spi.SPIProviderResolver; +import org.jboss.wsf.spi.deployment.ArchiveDeployment; +import org.jboss.wsf.spi.deployment.Deployment; +import org.jboss.wsf.spi.deployment.DeploymentAspect; +import org.jboss.wsf.spi.deployment.DeploymentModelFactory; +import org.jboss.wsf.spi.deployment.Deployment.DeploymentType; +import org.jboss.wsf.spi.http.HttpContext; +import org.jboss.wsf.spi.http.HttpContextFactory; +import org.jboss.wsf.spi.http.HttpServer; +import org.jboss.wsf.stack.jbws.EagerInitializeDeploymentAspect; +import org.jboss.wsf.stack.jbws.PublishContractDeploymentAspect; +import org.jboss.wsf.stack.jbws.ServiceEndpointInvokerDeploymentAspect; +import org.jboss.wsf.stack.jbws.UnifiedMetaDataDeploymentAspect; + +/** + * TODO: javadoc + * + * @author Richard Opalka + */ +// TODO: review thread safety +final class NettyHttpServerAdapter implements HttpServer +{ + + /** JBossWS SPI provider. */ + private static final SPIProvider SPI_PROVIDER =3D SPIProviderResolver.g= etInstance().getProvider(); + /** JBossWS Http Context factory. */ + private static final HttpContextFactory HTTP_CONTEXT_FACTORY =3D NettyH= ttpServerAdapter.SPI_PROVIDER.getSPI(HttpContextFactory.class); + /** Deployment model factory. */ + private static final DeploymentModelFactory DEPLOYMENT_FACTORY =3D Nett= yHttpServerAdapter.SPI_PROVIDER.getSPI(DeploymentModelFactory.class); + = + /** + * Constructor. + */ + public NettyHttpServerAdapter() + { + super(); + } + + public HttpContext createContext(final String contextRoot) + { + // TODO: check context is not already registered, throw exception ot= herwise + return NettyHttpServerAdapter.HTTP_CONTEXT_FACTORY.newHttpContext(th= is, contextRoot); + } + + public void destroy(HttpContext context, Endpoint endpoint) + { + EndpointImpl epImpl =3D (EndpointImpl)endpoint; + NettyHttpServer server =3D NettyHttpServer.getInstance("http", "loca= lhost", epImpl.getPort()); + NettyHttpServerCallbackHandler callback =3D server.getCallback(epImp= l.getPath()); + server.unregisterCallback(callback); + = + DeploymentAspectManagerImpl daManager =3D new DeploymentAspectManage= rImpl(); = + daManager.setDeploymentAspects(getDeploymentAspects()); + daManager.undeploy(epImpl.getDeployment()); + } + + public void publish(HttpContext context, Endpoint ep) + { + EndpointImpl epImpl =3D (EndpointImpl)ep; + String contextRoot =3D context.getContextRoot(); + Deployment dep =3D this.newDeployment(epImpl, contextRoot); + = + DeploymentAspectManagerImpl daManager =3D new DeploymentAspectManage= rImpl(); = + daManager.setDeploymentAspects(getDeploymentAspects()); + daManager.deploy(dep); + epImpl.setDeployment(dep); + + NettyHttpServer server =3D NettyHttpServer.getInstance("http", "loca= lhost", epImpl.getPort()); + NettyHttpServerCallbackHandler callback =3D new NettyHttpServerCallb= ackHandler(epImpl.getPath(), contextRoot, this.getEndpointRegistryPath(epIm= pl)); + server.registerCallback(callback); + } + = + private String getEndpointRegistryPath(EndpointImpl endpoint) + { + // we need to distinguish ports in endpoints registry in JSE environ= ment + return endpoint.getPathWithoutContext() + "-port-" + endpoint.getPor= t(); + } + = + private Deployment newDeployment(EndpointImpl epImpl, String contextRoo= t) + { + Class endpointClass =3D this.getEndpointClass(epImpl); + ClassLoader loader =3D endpointClass.getClassLoader(); + + final ArchiveDeployment dep =3D (ArchiveDeployment) DEPLOYMENT_FACTO= RY.newDeployment(contextRoot, loader); + final org.jboss.wsf.spi.deployment.Endpoint endpoint =3D DEPLOYMENT_= FACTORY.newEndpoint(endpointClass.getName()); + endpoint.setShortName(this.getEndpointRegistryPath(epImpl)); + endpoint.setURLPattern(epImpl.getPathWithoutContext()); + dep.getService().addEndpoint(endpoint); + dep.setRootFile(new ResourceLoaderAdapter(loader)); + 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 getDeploymentAspects() + { + List retVal =3D new LinkedList(); + = + // TODO: native stack can't use framework classes directly + retVal.add(new EndpointHandlerDeploymentAspect()); // 13 + retVal.add(new BackwardCompatibleContextRootDeploymentAspect()); // = 14 + retVal.add(new URLPatternDeploymentAspect()); // 15 + retVal.add(new EndpointAddressDeploymentAspect()); // 16 + retVal.add(new EndpointNameDeploymentAspect()); // 17 + retVal.add(new UnifiedMetaDataDeploymentAspect()); // 22 + retVal.add(new ServiceEndpointInvokerDeploymentAspect()); // 23 + retVal.add(new PublishContractDeploymentAspect()); // 24 + retVal.add(new EagerInitializeDeploymentAspect()); // 25 + retVal.add(new EndpointRegistryDeploymentAspect()); // 35 + retVal.add(new EndpointLifecycleDeploymentAspect()); // 37 + = + return retVal; + } + + /** + * Returns implementor class associated with endpoint. + * + * @param endpoint to get implementor class from + * @return implementor class + */ + private Class getEndpointClass(final Endpoint endpoint) + { + final Object implementor =3D endpoint.getImplementor(); + return implementor instanceof Class ? (Class) implementor : im= plementor.getClass(); + } + +} Added: stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/w= s/core/jaxws/spi/http/NettyHttpServerCallbackHandler.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/c= ore/jaxws/spi/http/NettyHttpServerCallbackHandler.java = (rev 0) +++ stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/c= ore/jaxws/spi/http/NettyHttpServerCallbackHandler.java 2009-10-09 13:07:52 = UTC (rev 10873) @@ -0,0 +1,205 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2009, 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.ws.core.jaxws.spi.http; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.LinkedList; +import java.util.List; + +import javax.management.ObjectName; +import javax.xml.ws.WebServiceException; + +import org.jboss.logging.Logger; +import org.jboss.ws.Constants; +import org.jboss.ws.WSException; +import org.jboss.ws.extensions.wsrm.transport.backchannel.RMCallbackHandle= rImpl; +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; +import org.jboss.wsf.spi.SPIProviderResolver; +import org.jboss.wsf.spi.deployment.Endpoint; +import org.jboss.wsf.spi.invocation.EndpointAssociation; +import org.jboss.wsf.spi.invocation.InvocationContext; +import org.jboss.wsf.spi.invocation.RequestHandler; +import org.jboss.wsf.spi.management.EndpointRegistry; +import org.jboss.wsf.spi.management.EndpointRegistryFactory; +import org.jboss.wsf.spi.management.EndpointResolver; +import org.jboss.wsf.stack.jbws.WebAppResolver; + +/** + * TODO: javadoc + * + * @author Richard Opalka + */ +final class NettyHttpServerCallbackHandler +{ + private static final Logger logger =3D Logger.getLogger(RMCallbackHandl= erImpl.class); + private final String handledPath; + private final SPIProvider spiProvider =3D SPIProviderResolver.getInstan= ce().getProvider(); + private EndpointRegistry epRegistry; + private Endpoint endpoint; + private List preDestroyRegistry =3D new LinkedList(); + + /** + * Request path to listen for incomming messages + * @param handledPath + */ + public NettyHttpServerCallbackHandler(String path, String context, Stri= ng endpointRegistryPath) + { + super(); + this.initRegistry(); + this.initEndpoint(context, endpointRegistryPath); + this.handledPath =3D path; + } + + /** + * Initializes endpoint registry + */ + private void initRegistry() + { + epRegistry =3D spiProvider.getSPI(EndpointRegistryFactory.class).get= EndpointRegistry(); + } = + + /** + * Initialize the service endpoint + * @param contextPath context path + * @param servletName servlet name + */ + private void initEndpoint(final String context, final String endpointRe= gistryPath) + { + final EndpointResolver resolver =3D new WebAppResolver(context, endp= ointRegistryPath); + this.endpoint =3D epRegistry.resolve(resolver); + + if (this.endpoint =3D=3D null) + { + ObjectName oname =3D ObjectNameFactory.create(Endpoint.SEPID_DOMA= IN + ":" + + Endpoint.SEPID_PROPERTY_CONTEXT + "=3D" + context + "," + + Endpoint.SEPID_PROPERTY_ENDPOINT + "=3D" + endpointRegistryPath + ); + throw new WebServiceException("Cannot obtain endpoint for: " + on= ame); + } + } + = + public int handle(String method, InputStream inputStream, OutputStream = outputStream, InvocationContext invCtx) throws IOException + { + Integer statusCode =3D null; + try + { + if (method.equals("POST")) + { + doPost(inputStream, outputStream, invCtx); + statusCode =3D (Integer)invCtx.getProperty(Constants.NETTY_STA= TUS_CODE); + } + else if (method.equals("GET")) + { + doGet(inputStream, outputStream, invCtx); + } + else + { + throw new WSException("Unsupported HTTP method: " + method); + } + } + catch(Exception e) + { + logger.error(e.getMessage(), e); + statusCode =3D 500; + } + = + return statusCode =3D=3D null ? 200 : statusCode; + } + = + public final String getHandledPath() + { + return this.handledPath; + } + = + public void doGet(InputStream inputStream, OutputStream outputStream, I= nvocationContext invCtx) throws IOException + { + try + { + EndpointAssociation.setEndpoint(endpoint); + RequestHandler requestHandler =3D endpoint.getRequestHandler(); + requestHandler.handleWSDLRequest(endpoint, outputStream, invCtx); + } + finally + { + EndpointAssociation.removeEndpoint(); + } + } + + public void doPost(InputStream inputStream, OutputStream outputStream, = InvocationContext invCtx) throws IOException + { + try + { + EndpointAssociation.setEndpoint(endpoint); + RequestHandler requestHandler =3D endpoint.getRequestHandler(); + requestHandler.handleRequest(endpoint, inputStream, outputStream,= invCtx); + } + finally + { + this.registerForPreDestroy(endpoint); + EndpointAssociation.removeEndpoint(); + } + } + + private void registerForPreDestroy(Endpoint ep) + { + PreDestroyHolder holder =3D (PreDestroyHolder)ep.getAttachment(PreDe= stroyHolder.class); + if (holder !=3D null) + { + synchronized(this.preDestroyRegistry) + { + if (!this.preDestroyRegistry.contains(holder)) + { + this.preDestroyRegistry.add(holder); + } + } + ep.removeAttachment(PreDestroyHolder.class); + } + } + + public final void destroy() + { + synchronized(this.preDestroyRegistry) + { + for (final PreDestroyHolder holder : this.preDestroyRegistry) + { + try + { + final Object targetBean =3D holder.getObject(); + InjectionHelper.callPreDestroyMethod(targetBean); + } + catch (Exception exception) + { + logger.error(exception.getMessage(), exception); + } + } + this.preDestroyRegistry.clear(); + this.preDestroyRegistry =3D null; + } + } + +} + = \ No newline at end of file Modified: stack/native/branches/ropalka/modules/core/src/main/java/org/jbos= s/ws/core/jaxws/spi/http/NettyHttpServerFactory.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/c= ore/jaxws/spi/http/NettyHttpServerFactory.java 2009-10-09 12:44:26 UTC (rev= 10872) +++ stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/c= ore/jaxws/spi/http/NettyHttpServerFactory.java 2009-10-09 13:07:52 UTC (rev= 10873) @@ -32,7 +32,7 @@ public final class NettyHttpServerFactory extends HttpServerFactory { = - private static final HttpServer NETTY_HTTP_SERVER =3D new NettyHttpServ= er(); + private static final HttpServer NETTY_HTTP_SERVER =3D new NettyHttpServ= erAdapter(); = /** * Constructor. Modified: stack/native/branches/ropalka/modules/core/src/main/java/org/jbos= s/ws/core/jaxws/spi/http/NettyInvocationHandler.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/c= ore/jaxws/spi/http/NettyInvocationHandler.java 2009-10-09 12:44:26 UTC (rev= 10872) +++ stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/c= ore/jaxws/spi/http/NettyInvocationHandler.java 2009-10-09 13:07:52 UTC (rev= 10873) @@ -69,7 +69,7 @@ final class NettyInvocationHandler extends SimpleChannelUpstreamHandler { private static final Logger LOG =3D Logger.getLogger(NettyInvocationHan= dler.class); - private final List callbacks =3D new LinkedList(); + private final List callbacks =3D new Li= nkedList(); private final Lock lock =3D new ReentrantLock(); = public NettyInvocationHandler() @@ -84,7 +84,7 @@ // so that they are closed properly on shutdown // If the added channel is closed before shutdown, // it will be removed from the group automatically. - RealNettyHttpServer.channelGroup.add(ctx.getChannel()); + NettyHttpServer.channelGroup.add(ctx.getChannel()); } = = public boolean hasMoreCallbacks() @@ -143,7 +143,7 @@ boolean handlerExists =3D false; String handledPath =3D null; requestPath =3D truncateHostName(requestPath); - for (NettyCallbackHandler handler : this.callbacks) + for (NettyHttpServerCallbackHandler handler : this.callbacks) { handledPath =3D truncateHostName(handler.getHandledPath()); if (requestPath.equals(handledPath)) @@ -279,12 +279,12 @@ e.getChannel().close(); } = - public NettyCallbackHandler getCallback(String requestPath) + public NettyHttpServerCallbackHandler getCallback(String requestPath) { this.lock.lock(); try { - for (NettyCallbackHandler handler : this.callbacks) + for (NettyHttpServerCallbackHandler handler : this.callbacks) { if (handler.getHandledPath().equals(requestPath)) return handler; @@ -298,7 +298,7 @@ return null; } = - public void registerCallback(NettyCallbackHandler callbackHandler) + public void registerCallback(NettyHttpServerCallbackHandler callbackHan= dler) { this.lock.lock(); try @@ -311,7 +311,7 @@ } } = - public void unregisterCallback(NettyCallbackHandler callbackHandler) + public void unregisterCallback(NettyHttpServerCallbackHandler callbackH= andler) { this.lock.lock(); try Deleted: stack/native/branches/ropalka/modules/core/src/main/java/org/jboss= /ws/core/jaxws/spi/http/RealNettyHttpServer.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/c= ore/jaxws/spi/http/RealNettyHttpServer.java 2009-10-09 12:44:26 UTC (rev 10= 872) +++ stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/c= ore/jaxws/spi/http/RealNettyHttpServer.java 2009-10-09 13:07:52 UTC (rev 10= 873) @@ -1,246 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * Copyright 2009, 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.ws.core.jaxws.spi.http; - -import java.net.InetSocketAddress; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.Executors; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -import javax.xml.ws.WebServiceException; - -import org.jboss.logging.Logger; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelFactory; -import org.jboss.netty.channel.group.ChannelGroup; -import org.jboss.netty.channel.group.DefaultChannelGroup; -import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; -import org.jboss.ws.core.client.transport.WSServerPipelineFactory; - -/** - * TODO: javadoc - * - * @author Richard Opalka - */ -final class RealNettyHttpServer implements Runnable -{ - = - private static final Logger LOG =3D Logger.getLogger(RealNettyHttpServe= r.class); - private static final Lock CLASS_LOCK =3D new ReentrantLock(); - private static final long WAIT_PERIOD =3D 100; - private static Map SERVERS =3D new HashMap= (); - static final ChannelGroup channelGroup =3D new DefaultChannelGroup("rmB= ackPortsServer"); - - private final Object instanceLock =3D 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 RealNettyHttpServer(String scheme, String host, int port) - { - super(); - this.scheme =3D scheme; - this.host =3D host; - this.port =3D port; - try - { - factory =3D new NioServerSocketChannelFactory(Executors.newCached= ThreadPool(), Executors.newCachedThreadPool()); - - ServerBootstrap bootstrap =3D new ServerBootstrap(factory); - this.handler =3D new NettyInvocationHandler(); - WSServerPipelineFactory channelPipelineFactory =3D new WSServerPi= pelineFactory(); - channelPipelineFactory.setRequestHandler(this.handler); - bootstrap.setPipelineFactory(channelPipelineFactory); - bootstrap.setOption("child.tcpNoDelay", true); - bootstrap.setOption("child.keepAlive", true); - // Bind and start to accept incoming connections. - Channel c =3D bootstrap.bind(new InetSocketAddress(this.port)); - channelGroup.add(c); - if (LOG.isDebugEnabled()) - LOG.debug("Netty http server started on port: " + this.port); - } - catch (Exception e) - { - LOG.warn(e.getMessage(), e); - throw new WebServiceException(e.getMessage(), e); - } - } - = - public final void registerCallback(NettyCallbackHandler callbackHandler) - { - this.handler.registerCallback(callbackHandler); - } - = - public final void unregisterCallback(NettyCallbackHandler callbackHandl= er) - { - this.handler.unregisterCallback(callbackHandler); - if (!this.hasMoreCallbacks()) - { - this.terminate(); - } - } - = - public final NettyCallbackHandler getCallback(String requestPath) - { - return this.handler.getCallback(requestPath); - } - = - public final boolean hasMoreCallbacks() - { - return this.handler.hasMoreCallbacks(); - } - - public final String getScheme() - { - 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 =3D true; - = - while (this.stopped =3D=3D false) - { - try - { - this.instanceLock.wait(WAIT_PERIOD); - LOG.debug("serving requests"); - } - catch (InterruptedException ie) - { - LOG.warn(ie.getMessage(), ie); - } - } - try - { - //Close all connections and server sockets. - channelGroup.close().awaitUninterruptibly(); - //Shutdown the selector loop (boss and worker). - if (factory !=3D null) - { - factory.releaseExternalResources(); - } - } - finally - { - LOG.debug("terminated"); - this.terminated =3D true; - } - } - } - = - public final void terminate() - { - synchronized (this.instanceLock) - { - if (this.stopped =3D=3D true) - return; - = - this.stopped =3D true; - LOG.debug("termination forced"); - SERVERS.remove(scheme + "://" + host + ":" + port + "/"); - while (this.terminated =3D=3D false) - { - try - { - LOG.debug("waiting for termination"); - this.instanceLock.wait(WAIT_PERIOD); - } - catch (InterruptedException ie) - { - LOG.warn(ie.getMessage(), ie); - } - } - } - } - = - /** - * Starts back ports server on the background if method is called for t= he first time - * @param scheme protocol - * @param host hostname - * @param port port - * @return netty http server - */ - public static RealNettyHttpServer getInstance(String scheme, String hos= t, int port) - { - CLASS_LOCK.lock(); - try - { - String key =3D scheme + "://" + host + ":" + port + "/"; - RealNettyHttpServer server =3D SERVERS.get(key); - if (server =3D=3D null) - { - server =3D new RealNettyHttpServer(scheme, host, (port =3D=3D = -1) ? 80 : port); = - SERVERS.put(key, server); - // forking back ports server - Thread t =3D new Thread(server, "NettyHttpServer listening on= " + key); - t.setDaemon(true); - t.start(); - // registering shutdown hook - final RealNettyHttpServer s =3D server; - Runtime.getRuntime().addShutdownHook(new Thread(new Runnable()= { - public void run() - { - s.terminate(); - } - }, "NettyHttpServerShutdownHook(" + key + ")")); - } - else - { - boolean schemeEquals =3D server.getScheme().equals(scheme); - boolean hostEquals =3D server.getHost().equals(host); - boolean portEquals =3D server.getPort() =3D=3D ((port =3D=3D -= 1) ? 80 : port); - if ((schemeEquals =3D=3D false) || (hostEquals =3D=3D false) |= | (portEquals =3D=3D false)) - throw new IllegalArgumentException(); - } - return server; - } - finally - { - CLASS_LOCK.unlock(); - } - } - = -} Modified: stack/native/branches/ropalka/modules/testsuite/native-tests/src/= test/java/org/jboss/test/ws/jaxws/endpoint/jse/UsecasesTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- stack/native/branches/ropalka/modules/testsuite/native-tests/src/test/j= ava/org/jboss/test/ws/jaxws/endpoint/jse/UsecasesTestCase.java 2009-10-09 1= 2:44:26 UTC (rev 10872) +++ stack/native/branches/ropalka/modules/testsuite/native-tests/src/test/j= ava/org/jboss/test/ws/jaxws/endpoint/jse/UsecasesTestCase.java 2009-10-09 1= 3:07:52 UTC (rev 10873) @@ -188,7 +188,7 @@ } catch (Exception e) { - log.debug(e.getMessage()); + assertEquals("Ooops", e.getMessage()); } } = Modified: stack/native/branches/ropalka/modules/testsuite/native-tests/src/= test/java/org/jboss/test/ws/jaxws/endpoint/jse/endpoints/Endpoint1Impl.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- stack/native/branches/ropalka/modules/testsuite/native-tests/src/test/j= ava/org/jboss/test/ws/jaxws/endpoint/jse/endpoints/Endpoint1Impl.java 2009-= 10-09 12:44:26 UTC (rev 10872) +++ stack/native/branches/ropalka/modules/testsuite/native-tests/src/test/j= ava/org/jboss/test/ws/jaxws/endpoint/jse/endpoints/Endpoint1Impl.java 2009-= 10-09 13:07:52 UTC (rev 10873) @@ -24,6 +24,8 @@ import java.io.IOException; = import javax.activation.DataHandler; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; import javax.jws.WebService; import javax.xml.ws.WebServiceException; import javax.xml.ws.soap.MTOM; @@ -44,25 +46,42 @@ { = private int count; + private boolean initialized; = public String echo(String input) { count++; return input; } + = + @PostConstruct + public void init() + { + System.out.println("Endpoint initialized: " + this); + this.initialized =3D true; + } = + @PreDestroy + public void destroy() + { + System.out.println("Endpoint destroyed: " + this); + } + public int getCount() { + this.ensureInit(); return count; } = public void getException() { + this.ensureInit(); throw new WebServiceException("Ooops"); } = public DHResponse echoDataHandler(DHRequest request) { + this.ensureInit(); DataHandler dataHandler =3D request.getDataHandler(); = try @@ -84,5 +103,11 @@ DataHandler responseData =3D new DataHandler("Server data", "text/pl= ain"); return new DHResponse(responseData); } + = + private void ensureInit() + { + if (!this.initialized) + throw new IllegalStateException(); + } = } --===============4768663516406671129==--