author | mkos |
Mon, 18 Jan 2016 15:28:46 +0100 | |
changeset 35341 | 6e00d8d01e71 |
parent 25871 | b80b84e87032 |
permissions | -rw-r--r-- |
12009 | 1 |
/* |
22679
d785acd84a14
8032639: Update copyright year to match last edit in jaxws repository for 2013
mkos
parents:
16791
diff
changeset
|
2 |
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
12009 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.xml.internal.ws.transport.http.server; |
|
27 |
||
28 |
import com.sun.net.httpserver.HttpContext; |
|
29 |
import com.sun.xml.internal.ws.transport.http.HttpAdapter; |
|
30 |
import com.sun.xml.internal.ws.transport.http.HttpAdapterList; |
|
31 |
import com.sun.xml.internal.ws.server.ServerRtException; |
|
32 |
import com.sun.xml.internal.ws.resources.ServerMessages; |
|
33 |
||
34 |
import javax.xml.ws.EndpointReference; |
|
35 |
import java.util.concurrent.Executor; |
|
36 |
import java.net.MalformedURLException; |
|
37 |
import java.net.URL; |
|
38 |
||
39 |
import org.w3c.dom.Element; |
|
40 |
||
41 |
/** |
|
42 |
* Hides {@link HttpContext} so that {@link EndpointImpl} |
|
43 |
* may load even without {@link HttpContext}. |
|
44 |
* |
|
45 |
* TODO: But what's the point? If Light-weight HTTP server isn't present, |
|
46 |
* all the publish operations will fail way. Why is it better to defer |
|
47 |
* the failure, as opposed to cause the failure as earyl as possible? -KK |
|
48 |
* |
|
49 |
* @author Jitendra Kotamraju |
|
50 |
*/ |
|
51 |
public final class HttpEndpoint extends com.sun.xml.internal.ws.api.server.HttpEndpoint { |
|
52 |
private String address; |
|
53 |
private HttpContext httpContext; |
|
54 |
private final HttpAdapter adapter; |
|
55 |
private final Executor executor; |
|
56 |
||
57 |
public HttpEndpoint(Executor executor, HttpAdapter adapter) { |
|
58 |
this.executor = executor; |
|
59 |
this.adapter = adapter; |
|
60 |
} |
|
61 |
||
62 |
public void publish(String address) { |
|
63 |
this.address = address; |
|
64 |
httpContext = ServerMgr.getInstance().createContext(address); |
|
65 |
publish(httpContext); |
|
66 |
} |
|
67 |
||
68 |
public void publish(Object serverContext) { |
|
69 |
if (serverContext instanceof javax.xml.ws.spi.http.HttpContext) { |
|
70 |
setHandler((javax.xml.ws.spi.http.HttpContext)serverContext); |
|
71 |
return; |
|
72 |
} |
|
73 |
if (serverContext instanceof HttpContext) { |
|
74 |
this.httpContext = (HttpContext)serverContext; |
|
75 |
setHandler(httpContext); |
|
76 |
return; |
|
77 |
} |
|
78 |
throw new ServerRtException(ServerMessages.NOT_KNOW_HTTP_CONTEXT_TYPE( |
|
79 |
serverContext.getClass(), HttpContext.class, |
|
80 |
javax.xml.ws.spi.http.HttpContext.class)); |
|
81 |
} |
|
82 |
||
83 |
HttpAdapterList getAdapterOwner() { |
|
84 |
return adapter.owner; |
|
85 |
} |
|
86 |
||
87 |
/** |
|
88 |
* This can be called only after publish |
|
89 |
* @return address of the Endpoint |
|
90 |
*/ |
|
91 |
private String getEPRAddress() { |
|
92 |
if (address == null) |
|
93 |
return httpContext.getServer().getAddress().toString(); |
|
94 |
try { |
|
95 |
URL u = new URL(address); |
|
96 |
if (u.getPort() == 0) { |
|
97 |
return new URL(u.getProtocol(),u.getHost(), |
|
98 |
httpContext.getServer().getAddress().getPort(),u.getFile()).toString(); |
|
99 |
} |
|
100 |
} catch (MalformedURLException murl) {} |
|
101 |
return address; |
|
102 |
} |
|
103 |
||
104 |
public void stop() { |
|
105 |
if (httpContext != null) { |
|
106 |
if (address == null) { |
|
107 |
// Application created its own HttpContext |
|
108 |
// httpContext.setHandler(null); |
|
109 |
httpContext.getServer().removeContext(httpContext); |
|
110 |
} else { |
|
111 |
// Remove HttpContext created by JAXWS runtime |
|
112 |
ServerMgr.getInstance().removeContext(httpContext); |
|
113 |
} |
|
114 |
} |
|
115 |
||
116 |
// Invoke WebService Life cycle method |
|
117 |
adapter.getEndpoint().dispose(); |
|
118 |
} |
|
119 |
||
120 |
private void setHandler(HttpContext context) { |
|
121 |
context.setHandler(new WSHttpHandler(adapter, executor)); |
|
122 |
} |
|
123 |
||
124 |
private void setHandler(javax.xml.ws.spi.http.HttpContext context) { |
|
125 |
context.setHandler(new PortableHttpHandler(adapter, executor)); |
|
126 |
} |
|
127 |
||
128 |
public <T extends EndpointReference> T getEndpointReference(Class<T> clazz, Element...referenceParameters) { |
|
129 |
String eprAddress = getEPRAddress(); |
|
16791 | 130 |
return clazz.cast(adapter.getEndpoint().getEndpointReference(clazz, eprAddress,eprAddress+"?wsdl", referenceParameters)); |
12009 | 131 |
} |
132 |
||
133 |
} |