001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.transport.http.servlet;
038:
039: import com.sun.istack.NotNull;
040: import com.sun.xml.ws.api.model.wsdl.WSDLPort;
041: import com.sun.xml.ws.api.server.BoundEndpoint;
042: import com.sun.xml.ws.api.server.Module;
043: import com.sun.xml.ws.api.server.WSEndpoint;
044: import com.sun.xml.ws.api.server.WebModule;
045: import com.sun.xml.ws.transport.http.HttpAdapter;
046: import com.sun.xml.ws.transport.http.WSHTTPConnection;
047:
048: import javax.servlet.ServletContext;
049: import javax.servlet.http.HttpServletRequest;
050: import javax.servlet.http.HttpServletResponse;
051: import javax.xml.namespace.QName;
052: import javax.xml.ws.WebServiceException;
053: import java.io.IOException;
054: import java.net.URI;
055: import java.net.URISyntaxException;
056: import java.util.logging.Logger;
057:
058: /**
059: * {@link HttpAdapter} for servlets.
060: *
061: * <p>
062: * This is a thin wrapper around {@link HttpAdapter} with some description
063: * specified in the deployment (in particular those information are related
064: * to how a request is routed to a {@link ServletAdapter}.
065: *
066: * <p>
067: * This class implements {@link BoundEndpoint} and represent the
068: * servlet-{@link WSEndpoint} association for {@link }
069: *
070: */
071: public final class ServletAdapter extends HttpAdapter implements
072: BoundEndpoint {
073: final String name;
074:
075: protected ServletAdapter(String name, String urlPattern,
076: WSEndpoint endpoint, ServletAdapterList owner) {
077: super (endpoint, owner, urlPattern);
078: this .name = name;
079: // registers itself with the container
080: Module module = endpoint.getContainer().getSPI(Module.class);
081: if (module == null)
082: LOGGER.warning("Container " + endpoint.getContainer()
083: + " doesn't support " + Module.class);
084: else {
085: module.getBoundEndpoints().add(this );
086: }
087:
088: }
089:
090: /**
091: * Gets the name of the endpoint as given in the <tt>sun-jaxws.xml</tt>
092: * deployment descriptor.
093: */
094: public String getName() {
095: return name;
096: }
097:
098: @NotNull
099: public URI getAddress() {
100: WebModule webModule = endpoint.getContainer().getSPI(
101: WebModule.class);
102: if (webModule == null)
103: // this is really a bug in the container implementation
104: throw new WebServiceException("Container "
105: + endpoint.getContainer() + " doesn't support "
106: + WebModule.class);
107:
108: return getAddress(webModule.getContextPath());
109: }
110:
111: public @NotNull
112: URI getAddress(String baseAddress) {
113: String adrs = baseAddress + getValidPath();
114: try {
115: return new URI(adrs);
116: } catch (URISyntaxException e) {
117: // this is really a bug in the container implementation
118: throw new WebServiceException(
119: "Unable to compute address for " + endpoint, e);
120: }
121: }
122:
123: /**
124: * Convenient method to return a port name from {@link WSEndpoint}.
125: *
126: * @return
127: * null if {@link WSEndpoint} isn't tied to any paritcular port.
128: */
129: public QName getPortName() {
130: WSDLPort port = getEndpoint().getPort();
131: if (port == null)
132: return null;
133: else
134: return port.getName();
135: }
136:
137: /**
138: * Version of {@link #handle(WSHTTPConnection)}
139: * that takes convenient parameters for servlet.
140: */
141: public void handle(ServletContext context,
142: HttpServletRequest request, HttpServletResponse response)
143: throws IOException {
144: WSHTTPConnection connection = new ServletConnectionImpl(this ,
145: context, request, response);
146: super .handle(connection);
147: }
148:
149: /**
150: *
151: * @deprecated
152: * Use {@link #handle(ServletContext, HttpServletRequest, HttpServletResponse)}
153: */
154: public void publishWSDL(ServletContext context,
155: HttpServletRequest request, HttpServletResponse response)
156: throws IOException {
157: WSHTTPConnection connection = new ServletConnectionImpl(this ,
158: context, request, response);
159: super .handle(connection);
160: }
161:
162: public String toString() {
163: return super .toString() + "[name=" + name + ']';
164: }
165:
166: private static final Logger LOGGER = Logger
167: .getLogger(ServletAdapter.class.getName());
168: }
|