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

Fri, 04 Oct 2013 16:21:34 +0100

author
mkos
date
Fri, 04 Oct 2013 16:21:34 +0100
changeset 408
b0610cd08440
parent 368
0989ad8c0860
child 637
9c07ef4934dd
permissions
-rw-r--r--

8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
Reviewed-by: chegar

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;
ohair@286 27
alanb@368 28 import com.oracle.webservices.internal.api.message.BasePropertySet;
alanb@368 29 import com.oracle.webservices.internal.api.message.PropertySet;
ohair@286 30 import com.sun.istack.internal.NotNull;
ohair@286 31 import com.sun.istack.internal.Nullable;
ohair@286 32 import com.sun.xml.internal.ws.api.message.Packet;
ohair@286 33 import com.sun.xml.internal.ws.api.server.WebServiceContextDelegate;
ohair@286 34
ohair@286 35 import javax.xml.ws.WebServiceContext;
ohair@286 36 import java.io.IOException;
ohair@286 37 import java.io.InputStream;
ohair@286 38 import java.io.OutputStream;
ohair@286 39 import java.net.HttpURLConnection;
ohair@286 40 import java.security.Principal;
ohair@286 41 import java.util.Collections;
ohair@286 42 import java.util.List;
ohair@286 43 import java.util.Map;
ohair@286 44 import java.util.Set;
ohair@286 45
ohair@286 46
ohair@286 47 /**
ohair@286 48 * The view of an HTTP exchange from the point of view of JAX-WS.
ohair@286 49 *
ohair@286 50 * <p>
ohair@286 51 * Different HTTP server layer uses different implementations of this class
ohair@286 52 * so that JAX-WS can be shielded from individuality of such layers.
ohair@286 53 * This is an interface implemented as an abstract class, so that
ohair@286 54 * future versions of the JAX-WS RI can add new methods.
ohair@286 55 *
ohair@286 56 * <p>
ohair@286 57 * This class extends {@link PropertySet} so that a transport can
alanb@368 58 * expose its properties to the application and pipes. (This object
ohair@286 59 * will be added to {@link Packet#addSatellite(PropertySet)}.)
ohair@286 60 *
ohair@286 61 * @author Jitendra Kotamraju
ohair@286 62 */
alanb@368 63 public abstract class WSHTTPConnection extends BasePropertySet {
ohair@286 64
ohair@286 65 public static final int OK=200;
ohair@286 66 public static final int ONEWAY=202;
ohair@286 67 public static final int UNSUPPORTED_MEDIA=415;
ohair@286 68 public static final int MALFORMED_XML=400;
ohair@286 69 public static final int INTERNAL_ERR=500;
ohair@286 70
ohair@286 71 /**
ohair@286 72 * Overwrites all the HTTP response headers written thus far.
ohair@286 73 *
ohair@286 74 * <p>
ohair@286 75 * The implementation should copy the contents of the {@link Map},
ohair@286 76 * rather than retaining a reference. The {@link Map} passed as a
ohair@286 77 * parameter may change after this method is invoked.
ohair@286 78 *
ohair@286 79 * <p>
ohair@286 80 * This method may be called repeatedly, although in normal use
ohair@286 81 * case that's rare (so the implementation is encourage to take
ohair@286 82 * advantage of this usage pattern to improve performance, if possible.)
ohair@286 83 *
ohair@286 84 * <p>
ohair@286 85 * Initially, no header is set.
ohair@286 86 *
ohair@286 87 * <p>
ohair@286 88 * This parameter is usually exposed to {@link WebServiceContext}
ohair@286 89 * as {@link Packet#OUTBOUND_TRANSPORT_HEADERS}, and thus it
ohair@286 90 * should ignore <tt>Content-Type</tt> and <tt>Content-Length</tt> headers.
ohair@286 91 *
ohair@286 92 * @param headers
ohair@286 93 * See {@link HttpURLConnection#getHeaderFields()} for the format.
ohair@286 94 * This parameter may not be null, but since the user application
ohair@286 95 * code may invoke this method, a graceful error checking with
ohair@286 96 * an helpful error message should be provided if it's actually null.
ohair@286 97 * @see #setContentTypeResponseHeader(String)
ohair@286 98 */
ohair@286 99 public abstract void setResponseHeaders(@NotNull Map<String,List<String>> headers);
ohair@286 100
ohair@286 101 public void setResponseHeader(String key, String value) {
ohair@286 102 setResponseHeader(key, Collections.singletonList(value));
ohair@286 103 }
ohair@286 104
ohair@286 105 public abstract void setResponseHeader(String key, List<String> value);
ohair@286 106
ohair@286 107 /**
ohair@286 108 * Sets the <tt>"Content-Type"</tt> header.
ohair@286 109 *
ohair@286 110 * <p>
ohair@286 111 * If the Content-Type header has already been set, this method will overwrite
ohair@286 112 * the previously set value. If not, this method adds it.
ohair@286 113 *
ohair@286 114 * <p>
alanb@368 115 * Note that this method and {@link #setResponseHeaders(java.util.Map)}
ohair@286 116 * may be invoked in any arbitrary order.
ohair@286 117 *
ohair@286 118 * @param value
ohair@286 119 * strings like <tt>"application/xml; charset=UTF-8"</tt> or
ohair@286 120 * <tt>"image/jpeg"</tt>.
ohair@286 121 */
ohair@286 122 public abstract void setContentTypeResponseHeader(@NotNull String value);
ohair@286 123
ohair@286 124 /**
ohair@286 125 * Sets the HTTP response code like {@link #OK}.
ohair@286 126 *
ohair@286 127 * <p>
ohair@286 128 * While JAX-WS processes a {@link WSHTTPConnection}, it
ohair@286 129 * will at least call this method once to set a valid HTTP response code.
ohair@286 130 * Note that this method may be invoked multiple times (from user code),
ohair@286 131 * so do not consider the value to be final until {@link #getOutput()}
ohair@286 132 * is invoked.
ohair@286 133 */
ohair@286 134
ohair@286 135 public abstract void setStatus(int status);
ohair@286 136
ohair@286 137 /**
ohair@286 138 * Gets the last value set by {@link #setStatus(int)}.
ohair@286 139 *
ohair@286 140 * @return
ohair@286 141 * if {@link #setStatus(int)} has not been invoked yet,
ohair@286 142 * return 0.
ohair@286 143 */
ohair@286 144 // I know this is ugly method!
ohair@286 145 public abstract int getStatus();
ohair@286 146
ohair@286 147 /**
ohair@286 148 * Transport's underlying input stream.
ohair@286 149 *
ohair@286 150 * <p>
ohair@286 151 * This method will be invoked at most once by the JAX-WS RI to
ohair@286 152 * read the request body. If there's no request body, this method
ohair@286 153 * should return an empty {@link InputStream}.
ohair@286 154 *
ohair@286 155 * @return
ohair@286 156 * the stream from which the request body will be read.
ohair@286 157 */
ohair@286 158 public abstract @NotNull InputStream getInput() throws IOException;
ohair@286 159
ohair@286 160 /**
ohair@286 161 * Transport's underlying output stream
ohair@286 162 *
ohair@286 163 * <p>
ohair@286 164 * This method will be invoked exactly once by the JAX-WS RI
ohair@286 165 * to start writing the response body (unless the processing aborts abnormally.)
ohair@286 166 * Even if there's no response body to write, this method will
ohair@286 167 * still be invoked only to be closed immediately.
ohair@286 168 *
ohair@286 169 * <p>
ohair@286 170 * Once this method is called, the status code and response
ohair@286 171 * headers will never change (IOW {@link #setStatus(int)},
ohair@286 172 * {@link #setResponseHeaders}, and {@link #setContentTypeResponseHeader(String)}
ohair@286 173 * will never be invoked.
ohair@286 174 */
ohair@286 175 public abstract @NotNull OutputStream getOutput() throws IOException;
ohair@286 176
ohair@286 177 /**
ohair@286 178 * Returns the {@link WebServiceContextDelegate} for this connection.
ohair@286 179 */
ohair@286 180 public abstract @NotNull WebServiceContextDelegate getWebServiceContextDelegate();
ohair@286 181
ohair@286 182 /**
ohair@286 183 * HTTP request method, such as "GET" or "POST".
ohair@286 184 */
ohair@286 185 public abstract @NotNull String getRequestMethod();
ohair@286 186
ohair@286 187 /**
ohair@286 188 * HTTP request headers.
ohair@286 189 *
ohair@286 190 * @deprecated
ohair@286 191 * This is a potentially expensive operation.
ohair@286 192 * Programs that want to access HTTP headers should consider using
ohair@286 193 * other methods such as {@link #getRequestHeader(String)}.
ohair@286 194 *
ohair@286 195 * @return
ohair@286 196 * can be empty but never null.
ohair@286 197 */
ohair@286 198 public abstract @NotNull Map<String,List<String>> getRequestHeaders();
ohair@286 199
ohair@286 200 /**
ohair@286 201 * HTTP request header names.
ohair@286 202 *
ohair@286 203 * @deprecated
ohair@286 204 * This is a potentially expensive operation.
ohair@286 205 * Programs that want to access HTTP headers should consider using
ohair@286 206 * other methods such as {@link #getRequestHeader(String)}.
ohair@286 207 *
ohair@286 208 * @return
ohair@286 209 * can be empty but never null.
ohair@286 210 */
ohair@286 211 public abstract @NotNull Set<String> getRequestHeaderNames();
ohair@286 212
ohair@286 213 /**
ohair@286 214 * @return
ohair@286 215 * HTTP response headers.
ohair@286 216 */
ohair@286 217 public abstract Map<String,List<String>> getResponseHeaders();
ohair@286 218
ohair@286 219 /**
ohair@286 220 * Gets an HTTP request header.
ohair@286 221 *
ohair@286 222 * <p>
ohair@286 223 * if multiple headers are present, this method returns one of them.
ohair@286 224 * (The implementation is free to choose which one it returns.)
ohair@286 225 *
ohair@286 226 * @return
ohair@286 227 * null if no header exists.
ohair@286 228 */
ohair@286 229 public abstract @Nullable String getRequestHeader(@NotNull String headerName);
ohair@286 230
ohair@286 231 /**
ohair@286 232 * Gets an HTTP request header.
ohair@286 233 *
ohair@286 234 * @return
ohair@286 235 * null if no header exists.
ohair@286 236 */
ohair@286 237 public abstract @Nullable List<String> getRequestHeaderValues(@NotNull String headerName);
ohair@286 238
ohair@286 239 /**
ohair@286 240 * HTTP Query string, such as "foo=bar", or null if none exists.
ohair@286 241 */
ohair@286 242 public abstract @Nullable String getQueryString();
ohair@286 243
ohair@286 244 /**
ohair@286 245 * Extra portion of the request URI after the end of the expected address of the service
ohair@286 246 * but before the query string
ohair@286 247 */
ohair@286 248 public abstract @Nullable String getPathInfo();
ohair@286 249
ohair@286 250 /**
ohair@286 251 * Requested path. A string like "/foo/bar/baz"
ohair@286 252 */
ohair@286 253 public abstract @NotNull String getRequestURI();
ohair@286 254
ohair@286 255 /**
ohair@286 256 * Requested scheme, e.g. "http" or "https"
ohair@286 257 */
ohair@286 258 public abstract @NotNull String getRequestScheme();
ohair@286 259
ohair@286 260 /**
ohair@286 261 * Server name
ohair@286 262 */
ohair@286 263 public abstract @NotNull String getServerName();
ohair@286 264
ohair@286 265 /**
ohair@286 266 * Server port
ohair@286 267 */
ohair@286 268 public abstract int getServerPort();
ohair@286 269
ohair@286 270 /**
ohair@286 271 * Portion of the request URI that groups related service addresses. The value, if non-empty, will
ohair@286 272 * always begin with '/', but will never end with '/'. Environments that do not support
ohair@286 273 * context paths must return an empty string.
ohair@286 274 */
ohair@286 275 public @NotNull String getContextPath() {
ohair@286 276 return "";
ohair@286 277 }
ohair@286 278
ohair@286 279 /**
ohair@286 280 * Environment specific context , if available
ohair@286 281 */
ohair@286 282 public Object getContext() {
ohair@286 283 return null;
ohair@286 284 }
ohair@286 285
ohair@286 286 /**
ohair@286 287 * Gets the absolute URL up to the context path.
ohair@286 288 * @return
ohair@286 289 * String like "http://myhost/myapp"
ohair@286 290 * @since 2.1.2
ohair@286 291 */
ohair@286 292 public @NotNull String getBaseAddress() {
ohair@286 293 throw new UnsupportedOperationException();
ohair@286 294 }
ohair@286 295
ohair@286 296 /**
ohair@286 297 * Whether connection is HTTPS or not
ohair@286 298 *
ohair@286 299 * @return if the received request is on HTTPS, return true
ohair@286 300 * else false
ohair@286 301 */
ohair@286 302 public abstract boolean isSecure();
ohair@286 303
ohair@286 304 /**
ohair@286 305 * User principal associated with the request
ohair@286 306 *
ohair@286 307 * @return user principal
ohair@286 308 */
ohair@286 309 public Principal getUserPrincipal() {
ohair@286 310 return null;
ohair@286 311 }
ohair@286 312
ohair@286 313 /**
ohair@286 314 * Whether user associated with the request holds the given role
ohair@286 315 *
ohair@286 316 * @param role Role to check
ohair@286 317 * @return if the caller holds the role
ohair@286 318 */
ohair@286 319 public boolean isUserInRole(String role) {
ohair@286 320 return false;
ohair@286 321 }
ohair@286 322
ohair@286 323 /**
ohair@286 324 * Gets request metadata attribute
ohair@286 325 * @param key Request metadata key
ohair@286 326 * @return Value of metadata attribute or null, if no value present
ohair@286 327 */
ohair@286 328 public Object getRequestAttribute(String key) {
ohair@286 329 return null;
ohair@286 330 }
ohair@286 331
ohair@286 332 private volatile boolean closed;
ohair@286 333
ohair@286 334 /**
ohair@286 335 * Close the connection
ohair@286 336 */
ohair@286 337 public void close() {
ohair@286 338 this.closed = true;
ohair@286 339 }
ohair@286 340
ohair@286 341 /**
ohair@286 342 * Retuns whether connection is closed or not.
ohair@286 343 */
ohair@286 344 public boolean isClosed() {
ohair@286 345 return closed;
ohair@286 346 }
ohair@286 347
ohair@286 348 /**
ohair@286 349 * Subclasses are expected to override
ohair@286 350 *
alanb@368 351 * @return a {@link String} containing the protocol name and version number
ohair@286 352 */
ohair@286 353 public String getProtocol() {
ohair@286 354 return "HTTP/1.1";
ohair@286 355 }
ohair@286 356
ohair@286 357 /**
ohair@286 358 * Subclasses are expected to override
ohair@286 359 *
ohair@286 360 * @since JAX-WS RI 2.2.2
alanb@368 361 * @return value of given cookie
ohair@286 362 */
ohair@286 363 public String getCookie(String name) {
ohair@286 364 return null;
ohair@286 365 }
ohair@286 366
ohair@286 367 /**
ohair@286 368 * Subclasses are expected to override
ohair@286 369 *
ohair@286 370 *
ohair@286 371 * @since JAX-WS RI 2.2.2
ohair@286 372 */
ohair@286 373 public void setCookie(String name, String value) {
ohair@286 374 }
ohair@286 375
ohair@286 376 /**
ohair@286 377 * Subclasses are expected to override
ohair@286 378 */
ohair@286 379 public void setContentLengthResponseHeader(int value) {
ohair@286 380 }
ohair@286 381
ohair@286 382 }

mercurial