src/share/jaxws_classes/com/sun/xml/internal/ws/transport/http/server/PortableConnectionImpl.java

Tue, 09 Apr 2013 14:51:13 +0100

author
alanb
date
Tue, 09 Apr 2013 14:51:13 +0100
changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
permissions
-rw-r--r--

8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com

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

mercurial