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 */ 25 26 package com.sun.xml.internal.ws.transport.http.server; 27 28 import com.sun.istack.internal.NotNull; 29 import com.sun.xml.internal.ws.api.server.BoundEndpoint; 30 import com.sun.xml.internal.ws.api.server.Module; 31 import com.sun.xml.internal.ws.api.server.WSEndpoint; 32 import com.sun.xml.internal.ws.api.server.WebModule; 33 import com.sun.xml.internal.ws.transport.http.HttpAdapter; 34 35 import javax.xml.ws.WebServiceException; 36 import java.net.URI; 37 import java.net.URISyntaxException; 38 import java.util.logging.Level; 39 import java.util.logging.Logger; 40 41 /** 42 * {@link HttpAdapter} for Endpoint API. 43 * 44 * <p> 45 * This is a thin wrapper around {@link HttpAdapter} 46 * with some description specified in the deployment (in particular those 47 * information are related to how a request is routed to a {@link ServerAdapter}. 48 * 49 * <p> 50 * This class implements {@link BoundEndpoint} and represent the 51 * server-{@link WSEndpoint} association for Endpoint API's transport 52 * 53 * @author Jitendra Kotamraju 54 */ 55 public final class ServerAdapter extends HttpAdapter implements BoundEndpoint { 56 final String name; 57 58 protected ServerAdapter(String name, String urlPattern, WSEndpoint endpoint, ServerAdapterList owner) { 59 super(endpoint, owner, urlPattern); 60 this.name = name; 61 // registers itself with the container 62 Module module = endpoint.getContainer().getSPI(Module.class); 63 if(module==null) 64 LOGGER.log(Level.WARNING, "Container {0} doesn''t support {1}", 65 new Object[]{endpoint.getContainer(), Module.class}); 66 else { 67 module.getBoundEndpoints().add(this); 68 } 69 } 70 71 /** 72 * Gets the name of the endpoint as given in the {@code sun-jaxws.xml} 73 * deployment descriptor. 74 */ 75 public String getName() { 76 return name; 77 } 78 79 80 @Override 81 public @NotNull URI getAddress() { 82 WebModule webModule = endpoint.getContainer().getSPI(WebModule.class); 83 if(webModule==null) 84 // this is really a bug in the container implementation 85 throw new WebServiceException("Container "+endpoint.getContainer()+" doesn't support "+WebModule.class); 86 87 return getAddress(webModule.getContextPath()); 88 } 89 90 @Override 91 public @NotNull URI getAddress(String baseAddress) { 92 String adrs = baseAddress+getValidPath(); 93 try { 94 return new URI(adrs); 95 } catch (URISyntaxException e) { 96 // this is really a bug in the container implementation 97 throw new WebServiceException("Unable to compute address for "+endpoint,e); 98 } 99 } 100 101 public void dispose() { 102 endpoint.dispose(); 103 } 104 105 public String getUrlPattern() { 106 return urlPattern; 107 } 108 109 @Override 110 public String toString() { 111 return super.toString()+"[name="+name+']'; 112 } 113 114 private static final Logger LOGGER = Logger.getLogger(ServerAdapter.class.getName()); 115 }