325N/A/*
325N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.ws.transport.http.server;
325N/A
325N/Aimport com.sun.net.httpserver.HttpContext;
325N/Aimport com.sun.xml.internal.ws.transport.http.HttpAdapter;
325N/Aimport com.sun.xml.internal.ws.transport.http.HttpAdapterList;
325N/Aimport com.sun.xml.internal.ws.server.ServerRtException;
325N/Aimport com.sun.xml.internal.ws.server.WSEndpointImpl;
325N/Aimport com.sun.xml.internal.ws.resources.ServerMessages;
325N/A
325N/Aimport javax.xml.ws.EndpointReference;
325N/Aimport java.util.concurrent.Executor;
325N/A
325N/Aimport org.w3c.dom.Element;
325N/A
325N/A/**
325N/A * Hides {@link HttpContext} so that {@link EndpointImpl}
325N/A * may load even without {@link HttpContext}.
325N/A *
325N/A * TODO: But what's the point? If Light-weight HTTP server isn't present,
325N/A * all the publish operations will fail way. Why is it better to defer
325N/A * the failure, as opposed to cause the failure as earyl as possible? -KK
325N/A *
325N/A * @author Jitendra Kotamraju
325N/A */
325N/Apublic final class HttpEndpoint extends com.sun.xml.internal.ws.api.server.HttpEndpoint {
325N/A private String address;
325N/A private HttpContext httpContext;
325N/A private final HttpAdapter adapter;
325N/A private final Executor executor;
325N/A
325N/A public HttpEndpoint(Executor executor, HttpAdapter adapter) {
325N/A this.executor = executor;
325N/A this.adapter = adapter;
325N/A }
325N/A
325N/A public void publish(String address) {
325N/A this.address = address;
325N/A httpContext = ServerMgr.getInstance().createContext(address);
325N/A publish(httpContext);
325N/A }
325N/A
325N/A public void publish(Object serverContext) {
325N/A if (serverContext instanceof javax.xml.ws.spi.http.HttpContext) {
325N/A setHandler((javax.xml.ws.spi.http.HttpContext)serverContext);
325N/A return;
325N/A }
325N/A if (serverContext instanceof HttpContext) {
325N/A this.httpContext = (HttpContext)serverContext;
325N/A setHandler(httpContext);
325N/A return;
325N/A }
325N/A throw new ServerRtException(ServerMessages.NOT_KNOW_HTTP_CONTEXT_TYPE(
325N/A serverContext.getClass(), HttpContext.class,
325N/A javax.xml.ws.spi.http.HttpContext.class));
325N/A }
325N/A
325N/A HttpAdapterList getAdapterOwner() {
325N/A return adapter.owner;
325N/A }
325N/A
325N/A /**
325N/A * This can be called only after publish
325N/A * @return address of the Endpoint
325N/A */
325N/A private String getEPRAddress() {
325N/A if(address == null) {
325N/A // Application created its own HttpContext
325N/A return httpContext.getServer().getAddress().toString();
325N/A } else
325N/A return address;
325N/A }
325N/A
325N/A public void stop() {
325N/A if (httpContext != null) {
325N/A if (address == null) {
325N/A // Application created its own HttpContext
325N/A // httpContext.setHandler(null);
325N/A httpContext.getServer().removeContext(httpContext);
325N/A } else {
325N/A // Remove HttpContext created by JAXWS runtime
325N/A ServerMgr.getInstance().removeContext(httpContext);
325N/A }
325N/A }
325N/A
325N/A // Invoke WebService Life cycle method
325N/A adapter.getEndpoint().dispose();
325N/A }
325N/A
325N/A private void setHandler(HttpContext context) {
325N/A context.setHandler(new WSHttpHandler(adapter, executor));
325N/A }
325N/A
325N/A private void setHandler(javax.xml.ws.spi.http.HttpContext context) {
325N/A context.setHandler(new PortableHttpHandler(adapter, executor));
325N/A }
325N/A
325N/A public <T extends EndpointReference> T getEndpointReference(Class<T> clazz, Element...referenceParameters) {
325N/A WSEndpointImpl endpointImpl = (WSEndpointImpl) adapter.getEndpoint();
325N/A String eprAddress = getEPRAddress();
325N/A return clazz.cast(endpointImpl.getEndpointReference(clazz, eprAddress,eprAddress+"?wsdl", referenceParameters));
325N/A }
325N/A
325N/A}