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.http.server;
038:
039: import com.sun.net.httpserver.HttpContext;
040: import com.sun.xml.ws.api.server.WSEndpoint;
041: import com.sun.xml.ws.api.model.wsdl.WSDLPort;
042: import com.sun.xml.ws.transport.http.HttpAdapter;
043: import com.sun.xml.ws.transport.http.HttpAdapterList;
044: import com.sun.xml.ws.server.ServerRtException;
045: import com.sun.xml.ws.server.WSEndpointImpl;
046:
047: import javax.xml.stream.XMLStreamWriter;
048: import javax.xml.stream.XMLStreamException;
049: import javax.xml.ws.EndpointReference;
050: import java.util.concurrent.Executor;
051: import java.io.IOException;
052:
053: import org.w3c.dom.Element;
054:
055: /**
056: * Hides {@link HttpContext} so that {@link EndpointImpl}
057: * may load even without {@link HttpContext}.
058: *
059: * TODO: But what's the point? If Light-weight HTTP server isn't present,
060: * all the publish operations will fail way. Why is it better to defer
061: * the failure, as opposed to cause the failure as earyl as possible? -KK
062: *
063: * @author Jitendra Kotamraju
064: */
065: final class HttpEndpoint {
066: private String address;
067: private HttpContext httpContext;
068: private final HttpAdapter adapter;
069: private final Executor executor;
070:
071: public HttpEndpoint(WSEndpoint endpoint, Executor executor) {
072: this .executor = executor;
073: this .adapter = HttpAdapter.createAlone(endpoint);
074: }
075:
076: public void publish(String address) {
077: this .address = address;
078: httpContext = ServerMgr.getInstance().createContext(address);
079: publish(httpContext);
080: }
081:
082: public void publish(Object serverContext) {
083: if (!(serverContext instanceof HttpContext)) {
084: throw new ServerRtException("not.HttpContext.type",
085: serverContext.getClass());
086: }
087:
088: this .httpContext = (HttpContext) serverContext;
089: publish(httpContext);
090: }
091:
092: /**
093: * This can be called only after publish
094: * @return address of the Endpoint
095: */
096: private String getEPRAddress() {
097: if (address == null) {
098: // Application created its own HttpContext
099: return httpContext.getServer().getAddress().toString();
100: } else
101: return address;
102: }
103:
104: public void stop() {
105: if (address == null) {
106: // Application created its own HttpContext
107: // httpContext.setHandler(null);
108: httpContext.getServer().removeContext(httpContext);
109: } else {
110: // Remove HttpContext created by JAXWS runtime
111: ServerMgr.getInstance().removeContext(httpContext);
112: }
113:
114: // Invoke WebService Life cycle method
115: adapter.getEndpoint().dispose();
116: }
117:
118: private void publish(HttpContext context) {
119: context.setHandler(new WSHttpHandler(adapter, executor));
120: }
121:
122: public <T extends EndpointReference> T getEndpointReference(
123: Class<T> clazz, Element... referenceParameters) {
124: WSEndpointImpl endpointImpl = (WSEndpointImpl) adapter
125: .getEndpoint();
126: String eprAddress = getEPRAddress();
127: return clazz.cast(endpointImpl.getEndpointReference(clazz,
128: eprAddress, eprAddress + "?wsdl", referenceParameters));
129: }
130:
131: }
|