Tue, 09 Apr 2013 14:51:13 +0100
8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com
1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
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 */
26 package com.sun.xml.internal.ws.transport.http.server;
28 import com.sun.istack.internal.NotNull;
29 import com.sun.istack.internal.Nullable;
30 import com.sun.xml.internal.ws.resources.HttpserverMessages;
31 import com.sun.xml.internal.ws.transport.http.HttpAdapter;
32 import com.sun.xml.internal.ws.transport.http.WSHTTPConnection;
34 import javax.xml.ws.spi.http.HttpHandler;
35 import javax.xml.ws.spi.http.HttpExchange;
36 import java.io.IOException;
37 import java.util.concurrent.Executor;
38 import java.util.logging.Level;
39 import java.util.logging.Logger;
41 /**
42 * {@link HttpHandler} implementation that serves the actual request.
43 *
44 * @author Jitendra Kotamraju
45 */
46 final class PortableHttpHandler extends HttpHandler {
48 private static final String GET_METHOD = "GET";
49 private static final String POST_METHOD = "POST";
50 private static final String HEAD_METHOD = "HEAD";
51 private static final String PUT_METHOD = "PUT";
52 private static final String DELETE_METHOD = "DELETE";
54 private static final Logger logger =
55 Logger.getLogger(
56 com.sun.xml.internal.ws.util.Constants.LoggingDomain + ".server.http");
58 private final HttpAdapter adapter;
59 private final Executor executor;
61 public PortableHttpHandler(@NotNull HttpAdapter adapter, @Nullable Executor executor) {
62 assert adapter!=null;
63 this.adapter = adapter;
64 this.executor = executor;
65 }
67 /**
68 * Called by HttpServer when there is a matching request for the context
69 */
70 @Override
71 public void handle(HttpExchange msg) {
72 try {
73 if (logger.isLoggable(Level.FINE)) {
74 logger.log(Level.FINE, "Received HTTP request:{0}", msg.getRequestURI());
75 }
76 if (executor != null) {
77 // Use application's Executor to handle request. Application may
78 // have set an executor using Endpoint.setExecutor().
79 executor.execute(new HttpHandlerRunnable(msg));
80 } else {
81 handleExchange(msg);
82 }
83 } catch (Throwable e) {
84 // Dont't propagate the exception otherwise it kills the httpserver
85 logger.log(Level.SEVERE, null, e);
86 }
87 }
89 public void handleExchange(HttpExchange msg) throws IOException {
90 WSHTTPConnection con = new PortableConnectionImpl(adapter,msg);
91 try {
92 if (logger.isLoggable(Level.FINE)) {
93 logger.log(Level.FINE, "Received HTTP request:{0}", msg.getRequestURI());
94 }
95 String method = msg.getRequestMethod();
96 if(method.equals(GET_METHOD) || method.equals(POST_METHOD) || method.equals(HEAD_METHOD)
97 || method.equals(PUT_METHOD) || method.equals(DELETE_METHOD)) {
98 adapter.handle(con);
99 } else {
100 logger.warning(HttpserverMessages.UNEXPECTED_HTTP_METHOD(method));
101 }
102 } finally {
103 msg.close();
104 }
105 }
107 /**
108 * Wrapping the processing of request in a Runnable so that it can be
109 * executed in Executor.
110 */
111 class HttpHandlerRunnable implements Runnable {
112 final HttpExchange msg;
114 HttpHandlerRunnable(HttpExchange msg) {
115 this.msg = msg;
116 }
118 @Override
119 @SuppressWarnings("CallToThreadDumpStack")
120 public void run() {
121 try {
122 handleExchange(msg);
123 } catch (Throwable e) {
124 // Does application's executor handle this exception ?
125 e.printStackTrace();
126 }
127 }
128 }
130 }