001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.transport.tcp.server;
038:
039: import com.sun.istack.NotNull;
040: import com.sun.xml.ws.transport.http.DeploymentDescriptorParser;
041: import com.sun.xml.ws.transport.tcp.resources.MessagesMessages;
042: import com.sun.xml.ws.transport.tcp.util.WSTCPURI;
043: import com.sun.xml.ws.transport.tcp.grizzly.GrizzlyTCPConnector;
044: import java.io.IOException;
045: import java.net.URI;
046: import java.net.URL;
047: import java.util.List;
048: import java.util.logging.Level;
049: import java.util.logging.Logger;
050:
051: /**
052: * @author Alexey Stashok
053: */
054: public final class WSTCP {
055: private static final Logger logger = Logger
056: .getLogger(com.sun.xml.ws.transport.tcp.util.TCPConstants.LoggingDomain
057: + ".server");
058:
059: private static final String JAXWS_RI_RUNTIME = "WEB-INF/sun-jaxws.xml";
060:
061: private final TCPContext context;
062: private final ClassLoader initClassLoader;
063: private WSTCPDelegate delegate;
064: private WSTCPConnector connector;
065: private final String contextPath;
066:
067: public WSTCP(@NotNull
068: final TCPContext context, @NotNull
069: final ClassLoader initClassLoader, @NotNull
070: final String contextPath) {
071: this .context = context;
072: this .initClassLoader = initClassLoader;
073: this .contextPath = contextPath;
074: }
075:
076: public @NotNull
077: List<TCPAdapter> parseDeploymentDescriptor() throws IOException {
078: final DeploymentDescriptorParser<TCPAdapter> parser = new DeploymentDescriptorParser<TCPAdapter>(
079: initClassLoader, new TCPResourceLoader(context), null,
080: TCPAdapter.FACTORY);
081: final URL sunJaxWsXml = context.getResource(JAXWS_RI_RUNTIME);
082:
083: return parser.parse(sunJaxWsXml.toExternalForm(), sunJaxWsXml
084: .openStream());
085: }
086:
087: public @NotNull
088: WSTCPConnector initialize() throws IOException {
089: final List<TCPAdapter> adapters = parseDeploymentDescriptor();
090: delegate = new WSTCPDelegate();
091: delegate.registerAdapters(contextPath, adapters);
092:
093: final TCPAdapter adapter = adapters.get(0);
094: final URI uri = adapter.getEndpoint().getPort().getAddress()
095: .getURI();
096:
097: final WSTCPURI tcpURI = WSTCPURI.parse(uri);
098:
099: final WSTCPConnector connector = new GrizzlyTCPConnector(
100: tcpURI.host, tcpURI.port, delegate);
101: connector.listen();
102: return connector;
103: }
104:
105: public void process() throws IOException {
106: connector = initialize();
107: }
108:
109: public void close() {
110: if (connector != null) {
111: connector.close();
112: }
113: }
114:
115: public static void main(final String[] args) {
116: if (args.length != 1) {
117: System.out.println(MessagesMessages.STANDALONE_RUN());
118: System.exit(0);
119: }
120:
121: final String contextPath = args[0];
122:
123: final ClassLoader classloader = Thread.currentThread()
124: .getContextClassLoader();
125: final TCPContext context = new TCPStandaloneContext(classloader);
126:
127: final WSTCP wsTCP = new WSTCP(context, classloader, contextPath);
128:
129: try {
130: wsTCP.process();
131: System.out.println(MessagesMessages.STANDALONE_EXIT());
132: System.in.read();
133: } catch (Exception e) {
134: } finally {
135: wsTCP.close();
136: }
137: }
138: }
|