1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/transport/http/server/HttpEndpoint.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,133 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.ws.transport.http.server; 1.30 + 1.31 +import com.sun.net.httpserver.HttpContext; 1.32 +import com.sun.xml.internal.ws.transport.http.HttpAdapter; 1.33 +import com.sun.xml.internal.ws.transport.http.HttpAdapterList; 1.34 +import com.sun.xml.internal.ws.server.ServerRtException; 1.35 +import com.sun.xml.internal.ws.resources.ServerMessages; 1.36 + 1.37 +import javax.xml.ws.EndpointReference; 1.38 +import java.util.concurrent.Executor; 1.39 +import java.net.MalformedURLException; 1.40 +import java.net.URL; 1.41 + 1.42 +import org.w3c.dom.Element; 1.43 + 1.44 +/** 1.45 + * Hides {@link HttpContext} so that {@link EndpointImpl} 1.46 + * may load even without {@link HttpContext}. 1.47 + * 1.48 + * TODO: But what's the point? If Light-weight HTTP server isn't present, 1.49 + * all the publish operations will fail way. Why is it better to defer 1.50 + * the failure, as opposed to cause the failure as earyl as possible? -KK 1.51 + * 1.52 + * @author Jitendra Kotamraju 1.53 + */ 1.54 +public final class HttpEndpoint extends com.sun.xml.internal.ws.api.server.HttpEndpoint { 1.55 + private String address; 1.56 + private HttpContext httpContext; 1.57 + private final HttpAdapter adapter; 1.58 + private final Executor executor; 1.59 + 1.60 + public HttpEndpoint(Executor executor, HttpAdapter adapter) { 1.61 + this.executor = executor; 1.62 + this.adapter = adapter; 1.63 + } 1.64 + 1.65 + public void publish(String address) { 1.66 + this.address = address; 1.67 + httpContext = ServerMgr.getInstance().createContext(address); 1.68 + publish(httpContext); 1.69 + } 1.70 + 1.71 + public void publish(Object serverContext) { 1.72 + if (serverContext instanceof javax.xml.ws.spi.http.HttpContext) { 1.73 + setHandler((javax.xml.ws.spi.http.HttpContext)serverContext); 1.74 + return; 1.75 + } 1.76 + if (serverContext instanceof HttpContext) { 1.77 + this.httpContext = (HttpContext)serverContext; 1.78 + setHandler(httpContext); 1.79 + return; 1.80 + } 1.81 + throw new ServerRtException(ServerMessages.NOT_KNOW_HTTP_CONTEXT_TYPE( 1.82 + serverContext.getClass(), HttpContext.class, 1.83 + javax.xml.ws.spi.http.HttpContext.class)); 1.84 + } 1.85 + 1.86 + HttpAdapterList getAdapterOwner() { 1.87 + return adapter.owner; 1.88 + } 1.89 + 1.90 + /** 1.91 + * This can be called only after publish 1.92 + * @return address of the Endpoint 1.93 + */ 1.94 + private String getEPRAddress() { 1.95 + if (address == null) 1.96 + return httpContext.getServer().getAddress().toString(); 1.97 + try { 1.98 + URL u = new URL(address); 1.99 + if (u.getPort() == 0) { 1.100 + return new URL(u.getProtocol(),u.getHost(), 1.101 + httpContext.getServer().getAddress().getPort(),u.getFile()).toString(); 1.102 + } 1.103 + } catch (MalformedURLException murl) {} 1.104 + return address; 1.105 + } 1.106 + 1.107 + public void stop() { 1.108 + if (httpContext != null) { 1.109 + if (address == null) { 1.110 + // Application created its own HttpContext 1.111 + // httpContext.setHandler(null); 1.112 + httpContext.getServer().removeContext(httpContext); 1.113 + } else { 1.114 + // Remove HttpContext created by JAXWS runtime 1.115 + ServerMgr.getInstance().removeContext(httpContext); 1.116 + } 1.117 + } 1.118 + 1.119 + // Invoke WebService Life cycle method 1.120 + adapter.getEndpoint().dispose(); 1.121 + } 1.122 + 1.123 + private void setHandler(HttpContext context) { 1.124 + context.setHandler(new WSHttpHandler(adapter, executor)); 1.125 + } 1.126 + 1.127 + private void setHandler(javax.xml.ws.spi.http.HttpContext context) { 1.128 + context.setHandler(new PortableHttpHandler(adapter, executor)); 1.129 + } 1.130 + 1.131 + public <T extends EndpointReference> T getEndpointReference(Class<T> clazz, Element...referenceParameters) { 1.132 + String eprAddress = getEPRAddress(); 1.133 + return clazz.cast(adapter.getEndpoint().getEndpointReference(clazz, eprAddress,eprAddress+"?wsdl", referenceParameters)); 1.134 + } 1.135 + 1.136 +}