Wed, 27 Apr 2016 01:27:09 +0800
Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/jaxws/
changeset: 657:d47a47f961ee
tag: jdk8u25-b17
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.xml.internal.ws.transport.http.server; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import com.sun.istack.internal.NotNull; |
aoqi@0 | 29 | import com.sun.xml.internal.ws.api.message.Packet; |
aoqi@0 | 30 | import com.sun.xml.internal.ws.api.server.WSEndpoint; |
aoqi@0 | 31 | import com.sun.xml.internal.ws.api.server.WebServiceContextDelegate; |
aoqi@0 | 32 | import com.sun.xml.internal.ws.api.server.PortAddressResolver; |
aoqi@0 | 33 | import com.sun.xml.internal.ws.transport.http.HttpAdapter; |
aoqi@0 | 34 | import com.sun.xml.internal.ws.transport.http.WSHTTPConnection; |
aoqi@0 | 35 | import com.sun.xml.internal.ws.developer.JAXWSProperties; |
aoqi@0 | 36 | import com.sun.xml.internal.ws.resources.WsservletMessages; |
aoqi@0 | 37 | |
aoqi@0 | 38 | import javax.xml.ws.handler.MessageContext; |
aoqi@0 | 39 | import javax.xml.ws.WebServiceException; |
aoqi@0 | 40 | import javax.xml.ws.spi.http.HttpExchange; |
aoqi@0 | 41 | import java.io.IOException; |
aoqi@0 | 42 | import java.io.InputStream; |
aoqi@0 | 43 | import java.io.OutputStream; |
aoqi@0 | 44 | import java.security.Principal; |
aoqi@0 | 45 | import java.util.ArrayList; |
aoqi@0 | 46 | import java.util.List; |
aoqi@0 | 47 | import java.util.Map; |
aoqi@0 | 48 | import java.util.Set; |
aoqi@0 | 49 | |
aoqi@0 | 50 | /** |
aoqi@0 | 51 | * {@link WSHTTPConnection} used with Java SE endpoints. It provides connection |
aoqi@0 | 52 | * implementation using {@link HttpExchange} object. |
aoqi@0 | 53 | * |
aoqi@0 | 54 | * @author Jitendra Kotamraju |
aoqi@0 | 55 | */ |
aoqi@0 | 56 | final class PortableConnectionImpl extends WSHTTPConnection implements WebServiceContextDelegate { |
aoqi@0 | 57 | |
aoqi@0 | 58 | private final HttpExchange httpExchange; |
aoqi@0 | 59 | private int status; |
aoqi@0 | 60 | private final HttpAdapter adapter; |
aoqi@0 | 61 | private boolean outputWritten; |
aoqi@0 | 62 | |
aoqi@0 | 63 | public PortableConnectionImpl(@NotNull HttpAdapter adapter, @NotNull HttpExchange httpExchange) { |
aoqi@0 | 64 | this.adapter = adapter; |
aoqi@0 | 65 | this.httpExchange = httpExchange; |
aoqi@0 | 66 | } |
aoqi@0 | 67 | |
aoqi@0 | 68 | @Override |
aoqi@0 | 69 | @Property(value = {MessageContext.HTTP_REQUEST_HEADERS, Packet.INBOUND_TRANSPORT_HEADERS}) |
aoqi@0 | 70 | public @NotNull Map<String,List<String>> getRequestHeaders() { |
aoqi@0 | 71 | return httpExchange.getRequestHeaders(); |
aoqi@0 | 72 | } |
aoqi@0 | 73 | |
aoqi@0 | 74 | @Override |
aoqi@0 | 75 | public String getRequestHeader(String headerName) { |
aoqi@0 | 76 | return httpExchange.getRequestHeader(headerName); |
aoqi@0 | 77 | } |
aoqi@0 | 78 | |
aoqi@0 | 79 | @Override |
aoqi@0 | 80 | public void setResponseHeaders(Map<String,List<String>> headers) { |
aoqi@0 | 81 | Map<String, List<String>> r = httpExchange.getResponseHeaders(); |
aoqi@0 | 82 | r.clear(); |
aoqi@0 | 83 | for(Map.Entry <String, List<String>> entry : headers.entrySet()) { |
aoqi@0 | 84 | String name = entry.getKey(); |
aoqi@0 | 85 | List<String> values = entry.getValue(); |
aoqi@0 | 86 | // ignore headers that interfere with our correct operations |
aoqi@0 | 87 | if (!name.equalsIgnoreCase("Content-Length") && !name.equalsIgnoreCase("Content-Type")) { |
aoqi@0 | 88 | r.put(name,new ArrayList<String>(values)); |
aoqi@0 | 89 | } |
aoqi@0 | 90 | } |
aoqi@0 | 91 | } |
aoqi@0 | 92 | |
aoqi@0 | 93 | @Override |
aoqi@0 | 94 | public void setResponseHeader(String key, List<String> value) { |
aoqi@0 | 95 | httpExchange.getResponseHeaders().put(key, value); |
aoqi@0 | 96 | } |
aoqi@0 | 97 | |
aoqi@0 | 98 | @Override |
aoqi@0 | 99 | public Set<String> getRequestHeaderNames() { |
aoqi@0 | 100 | return httpExchange.getRequestHeaders().keySet(); |
aoqi@0 | 101 | } |
aoqi@0 | 102 | |
aoqi@0 | 103 | @Override |
aoqi@0 | 104 | public List<String> getRequestHeaderValues(String headerName) { |
aoqi@0 | 105 | return httpExchange.getRequestHeaders().get(headerName); |
aoqi@0 | 106 | } |
aoqi@0 | 107 | |
aoqi@0 | 108 | @Override |
aoqi@0 | 109 | @Property({MessageContext.HTTP_RESPONSE_HEADERS,Packet.OUTBOUND_TRANSPORT_HEADERS}) |
aoqi@0 | 110 | public Map<String,List<String>> getResponseHeaders() { |
aoqi@0 | 111 | return httpExchange.getResponseHeaders(); |
aoqi@0 | 112 | } |
aoqi@0 | 113 | |
aoqi@0 | 114 | @Override |
aoqi@0 | 115 | public void setContentTypeResponseHeader(@NotNull String value) { |
aoqi@0 | 116 | httpExchange.addResponseHeader("Content-Type", value); |
aoqi@0 | 117 | } |
aoqi@0 | 118 | |
aoqi@0 | 119 | @Override |
aoqi@0 | 120 | public void setStatus(int status) { |
aoqi@0 | 121 | this.status = status; |
aoqi@0 | 122 | } |
aoqi@0 | 123 | |
aoqi@0 | 124 | @Override |
aoqi@0 | 125 | @Property(MessageContext.HTTP_RESPONSE_CODE) |
aoqi@0 | 126 | public int getStatus() { |
aoqi@0 | 127 | return status; |
aoqi@0 | 128 | } |
aoqi@0 | 129 | |
aoqi@0 | 130 | public @Override @NotNull InputStream getInput() throws IOException { |
aoqi@0 | 131 | return httpExchange.getRequestBody(); |
aoqi@0 | 132 | } |
aoqi@0 | 133 | |
aoqi@0 | 134 | public @Override @NotNull OutputStream getOutput() throws IOException { |
aoqi@0 | 135 | assert !outputWritten; |
aoqi@0 | 136 | outputWritten = true; |
aoqi@0 | 137 | |
aoqi@0 | 138 | httpExchange.setStatus(getStatus()); |
aoqi@0 | 139 | return httpExchange.getResponseBody(); |
aoqi@0 | 140 | } |
aoqi@0 | 141 | |
aoqi@0 | 142 | public @Override @NotNull WebServiceContextDelegate getWebServiceContextDelegate() { |
aoqi@0 | 143 | return this; |
aoqi@0 | 144 | } |
aoqi@0 | 145 | |
aoqi@0 | 146 | @Override |
aoqi@0 | 147 | public Principal getUserPrincipal(Packet request) { |
aoqi@0 | 148 | return httpExchange.getUserPrincipal(); |
aoqi@0 | 149 | } |
aoqi@0 | 150 | |
aoqi@0 | 151 | @Override |
aoqi@0 | 152 | public boolean isUserInRole(Packet request, String role) { |
aoqi@0 | 153 | return httpExchange.isUserInRole(role); |
aoqi@0 | 154 | } |
aoqi@0 | 155 | |
aoqi@0 | 156 | public @Override @NotNull String getEPRAddress(Packet request, WSEndpoint endpoint) { |
aoqi@0 | 157 | PortAddressResolver resolver = adapter.owner.createPortAddressResolver(getBaseAddress(), endpoint.getImplementationClass()); |
aoqi@0 | 158 | String address = resolver.getAddressFor(endpoint.getServiceName(), endpoint.getPortName().getLocalPart()); |
aoqi@0 | 159 | if(address==null) { |
aoqi@0 | 160 | throw new WebServiceException(WsservletMessages.SERVLET_NO_ADDRESS_AVAILABLE(endpoint.getPortName())); |
aoqi@0 | 161 | } |
aoqi@0 | 162 | return address; |
aoqi@0 | 163 | } |
aoqi@0 | 164 | |
aoqi@0 | 165 | @Property(MessageContext.SERVLET_CONTEXT) |
aoqi@0 | 166 | public Object getServletContext() { |
aoqi@0 | 167 | return httpExchange.getAttribute(MessageContext.SERVLET_CONTEXT); |
aoqi@0 | 168 | } |
aoqi@0 | 169 | |
aoqi@0 | 170 | @Property(MessageContext.SERVLET_RESPONSE) |
aoqi@0 | 171 | public Object getServletResponse() { |
aoqi@0 | 172 | return httpExchange.getAttribute(MessageContext.SERVLET_RESPONSE); |
aoqi@0 | 173 | } |
aoqi@0 | 174 | |
aoqi@0 | 175 | @Property(MessageContext.SERVLET_REQUEST) |
aoqi@0 | 176 | public Object getServletRequest() { |
aoqi@0 | 177 | return httpExchange.getAttribute(MessageContext.SERVLET_REQUEST); |
aoqi@0 | 178 | } |
aoqi@0 | 179 | |
aoqi@0 | 180 | @Override |
aoqi@0 | 181 | public String getWSDLAddress(@NotNull Packet request, @NotNull WSEndpoint endpoint) { |
aoqi@0 | 182 | String eprAddress = getEPRAddress(request,endpoint); |
aoqi@0 | 183 | if(adapter.getEndpoint().getPort() != null) { |
aoqi@0 | 184 | return eprAddress+"?wsdl"; |
aoqi@0 | 185 | } else { |
aoqi@0 | 186 | return null; |
aoqi@0 | 187 | } |
aoqi@0 | 188 | } |
aoqi@0 | 189 | |
aoqi@0 | 190 | @Override |
aoqi@0 | 191 | public boolean isSecure() { |
aoqi@0 | 192 | return httpExchange.getScheme().equals("https"); |
aoqi@0 | 193 | } |
aoqi@0 | 194 | |
aoqi@0 | 195 | @Override |
aoqi@0 | 196 | @Property(MessageContext.HTTP_REQUEST_METHOD) |
aoqi@0 | 197 | public @NotNull String getRequestMethod() { |
aoqi@0 | 198 | return httpExchange.getRequestMethod(); |
aoqi@0 | 199 | } |
aoqi@0 | 200 | |
aoqi@0 | 201 | @Override |
aoqi@0 | 202 | @Property(MessageContext.QUERY_STRING) |
aoqi@0 | 203 | public String getQueryString() { |
aoqi@0 | 204 | return httpExchange.getQueryString(); |
aoqi@0 | 205 | } |
aoqi@0 | 206 | |
aoqi@0 | 207 | @Override |
aoqi@0 | 208 | @Property(MessageContext.PATH_INFO) |
aoqi@0 | 209 | public String getPathInfo() { |
aoqi@0 | 210 | return httpExchange.getPathInfo(); |
aoqi@0 | 211 | } |
aoqi@0 | 212 | |
aoqi@0 | 213 | @Property(JAXWSProperties.HTTP_EXCHANGE) |
aoqi@0 | 214 | public HttpExchange getExchange() { |
aoqi@0 | 215 | return httpExchange; |
aoqi@0 | 216 | } |
aoqi@0 | 217 | |
aoqi@0 | 218 | @Override @NotNull |
aoqi@0 | 219 | public String getBaseAddress() { |
aoqi@0 | 220 | StringBuilder sb = new StringBuilder(); |
aoqi@0 | 221 | sb.append(httpExchange.getScheme()); |
aoqi@0 | 222 | sb.append("://"); |
aoqi@0 | 223 | sb.append(httpExchange.getLocalAddress().getHostName()); |
aoqi@0 | 224 | sb.append(":"); |
aoqi@0 | 225 | sb.append(httpExchange.getLocalAddress().getPort()); |
aoqi@0 | 226 | sb.append(httpExchange.getContextPath()); |
aoqi@0 | 227 | return sb.toString(); |
aoqi@0 | 228 | } |
aoqi@0 | 229 | |
aoqi@0 | 230 | @Override |
aoqi@0 | 231 | public String getProtocol() { |
aoqi@0 | 232 | return httpExchange.getProtocol(); |
aoqi@0 | 233 | } |
aoqi@0 | 234 | |
aoqi@0 | 235 | @Override |
aoqi@0 | 236 | public void setContentLengthResponseHeader(int value) { |
aoqi@0 | 237 | httpExchange.addResponseHeader("Content-Length", ""+value); |
aoqi@0 | 238 | } |
aoqi@0 | 239 | |
aoqi@0 | 240 | @Override |
aoqi@0 | 241 | public String getRequestURI() { |
aoqi@0 | 242 | return httpExchange.getRequestURI().toString(); |
aoqi@0 | 243 | } |
aoqi@0 | 244 | |
aoqi@0 | 245 | @Override |
aoqi@0 | 246 | public String getRequestScheme() { |
aoqi@0 | 247 | return httpExchange.getScheme(); |
aoqi@0 | 248 | } |
aoqi@0 | 249 | |
aoqi@0 | 250 | @Override |
aoqi@0 | 251 | public String getServerName() { |
aoqi@0 | 252 | return httpExchange.getLocalAddress().getHostName(); |
aoqi@0 | 253 | } |
aoqi@0 | 254 | |
aoqi@0 | 255 | @Override |
aoqi@0 | 256 | public int getServerPort() { |
aoqi@0 | 257 | return httpExchange.getLocalAddress().getPort(); |
aoqi@0 | 258 | } |
aoqi@0 | 259 | |
aoqi@0 | 260 | @Override |
aoqi@0 | 261 | protected PropertyMap getPropertyMap() { |
aoqi@0 | 262 | return model; |
aoqi@0 | 263 | } |
aoqi@0 | 264 | |
aoqi@0 | 265 | private static final PropertyMap model; |
aoqi@0 | 266 | |
aoqi@0 | 267 | static { |
aoqi@0 | 268 | model = parse(PortableConnectionImpl.class); |
aoqi@0 | 269 | } |
aoqi@0 | 270 | } |