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.local;
038:
039: import com.sun.istack.NotNull;
040: import com.sun.xml.ws.api.pipe.ClientTubeAssemblerContext;
041: import com.sun.xml.ws.api.pipe.TransportPipeFactory;
042: import com.sun.xml.ws.api.pipe.TransportTubeFactory;
043: import com.sun.xml.ws.api.pipe.Tube;
044: import com.sun.xml.ws.api.server.WSEndpoint;
045: import com.sun.xml.ws.transport.http.DeploymentDescriptorParser;
046: import com.sun.xml.ws.transport.http.DeploymentDescriptorParser.AdapterFactory;
047:
048: import java.io.File;
049: import java.io.IOException;
050: import java.net.URI;
051: import java.util.List;
052:
053: /**
054: * {@link TransportPipeFactory} for the local transport.
055: *
056: * <p>
057: * The syntax of the endpoint address is:
058: * <pre><xmp>
059: * local:///path/to/exploded/war/image?portLocalName
060: * </xmp></pre>
061: *
062: * <p>
063: * If the service only contains one port, the <tt>?portLocalName</tt> portion
064: * can be omitted.
065: *
066: * @author Kohsuke Kawaguchi
067: */
068: public final class LocalTransportFactory extends TransportTubeFactory {
069: public Tube doCreate(@NotNull
070: ClientTubeAssemblerContext context) {
071: URI adrs = context.getAddress().getURI();
072: if (!(adrs.getScheme().equals("local") || adrs.getScheme()
073: .equals("local-async")))
074: return null;
075: return adrs.getScheme().equals("local") ? new LocalTransportTube(
076: adrs, createServerService(adrs), context.getCodec())
077: : new LocalAsyncTransportTube(adrs,
078: createServerService(adrs), context.getCodec());
079: }
080:
081: /**
082: * The local transport works by looking at the exploded war file image on
083: * a file system.
084: * TODO: Currently it expects the PortName to be appended to the endpoint address
085: * This needs to be expanded to take Service and Port QName as well.
086: */
087: protected static WSEndpoint createServerService(URI adrs) {
088: try {
089: String outputDir = adrs.getPath();
090: List<WSEndpoint> endpoints = parseEndpoints(outputDir);
091:
092: WSEndpoint endpoint = endpoints.get(0);
093: if (endpoints.size() > 1) {
094: for (WSEndpoint rei : endpoints) {
095: //TODO: for now just compare local part
096: if (rei.getPort().getName().getLocalPart().equals(
097: adrs.getQuery())) {
098: endpoint = rei;
099: break;
100: }
101: }
102: }
103:
104: return endpoint;
105: } catch (IOException e) {
106: throw new Error(e);
107: }
108: }
109:
110: protected static List<WSEndpoint> parseEndpoints(String outputDir)
111: throws IOException {
112: String riFile = outputDir + "/WEB-INF/sun-jaxws.xml";
113: DeploymentDescriptorParser<WSEndpoint> parser = new DeploymentDescriptorParser<WSEndpoint>(
114: Thread.currentThread().getContextClassLoader(),
115: new FileSystemResourceLoader(new File(outputDir)),
116: null, new AdapterFactory<WSEndpoint>() {
117: public WSEndpoint createAdapter(String name,
118: String urlPattern, WSEndpoint<?> endpoint) {
119: return endpoint;
120: }
121: });
122:
123: return parser.parse(new File(riFile));
124: }
125:
126: }
|