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: package com.sun.xml.ws.mex.client;
037:
038: import java.io.IOException;
039: import java.io.InputStream;
040: import java.util.logging.Level;
041: import java.util.logging.Logger;
042:
043: import com.sun.xml.ws.api.addressing.AddressingVersion;
044: import com.sun.xml.ws.mex.client.MetadataClient.Protocol;
045:
046: import static com.sun.xml.ws.mex.MetadataConstants.GET_REQUEST;
047: import static com.sun.xml.ws.mex.MetadataConstants.SOAP_1_1;
048: import static com.sun.xml.ws.mex.MetadataConstants.SOAP_1_2;
049: import static com.sun.xml.ws.mex.MetadataConstants.WSA_ANON;
050: import static com.sun.xml.ws.mex.MetadataConstants.WSA_PREFIX;
051:
052: /**
053: * Class for making mex Get requests (which are the same
054: * as ws-transfer Get requests). Currently only http requests
055: * are supported.
056: */
057: public class MetadataUtil {
058:
059: // the transport-specific code is (mostly) here
060: private final HttpPoster postClient;
061:
062: private static final Logger logger = Logger
063: .getLogger(MetadataUtil.class.getName());
064:
065: public MetadataUtil() {
066: postClient = new HttpPoster();
067: }
068:
069: /**
070: * Make a mex/wxf request to a server.
071: *
072: * @param address The address to query for metadata.
073: * @return The full response from the server.
074: */
075: InputStream getMetadata(final String address,
076: final Protocol protocol) throws IOException {
077:
078: final String request = getMexWsdlRequest(address, protocol);
079: if (logger.isLoggable(Level.FINE)) {
080: logger.fine("Request message:\n" + request + "\n");
081: }
082: String contentType = "application/soap+xml"; // soap 1.2
083: if (protocol == Protocol.SOAP_1_1) {
084: contentType = "text/xml; charset=\"utf-8\"";
085: }
086: return postClient.post(request, address, contentType);
087: }
088:
089: private String getMexWsdlRequest(final String address,
090: final Protocol protocol) {
091:
092: // start with soap 1.2
093: String soapPrefix = "s12";
094: String soapNamespace = SOAP_1_2;
095: if (protocol == Protocol.SOAP_1_1) {
096: soapPrefix = "soap-env";
097: soapNamespace = SOAP_1_1;
098: }
099: return "<" + soapPrefix + ":Envelope " + "xmlns:" + soapPrefix
100: + "='" + soapNamespace + "' " + "xmlns:" + WSA_PREFIX
101: + "='" + AddressingVersion.W3C.nsUri + "'>" + "<"
102: + soapPrefix + ":Header>" + "<" + WSA_PREFIX
103: + ":Action>" + GET_REQUEST + "</" + WSA_PREFIX
104: + ":Action>" + "<" + WSA_PREFIX + ":To>" + address
105: + "</" + WSA_PREFIX + ":To>" + "<" + WSA_PREFIX
106: + ":ReplyTo><" + WSA_PREFIX + ":Address>" + WSA_ANON
107: + "</" + WSA_PREFIX + ":Address></" + WSA_PREFIX
108: + ":ReplyTo>" + "<" + WSA_PREFIX + ":MessageID>"
109: + "uuid:778b135f-3fdf-44b2-b53e-ebaab7441e40" + "</"
110: + WSA_PREFIX + ":MessageID>" + "</" + soapPrefix
111: + ":Header>" + "<" + soapPrefix + ":Body/>" + "</"
112: + soapPrefix + ":Envelope>";
113: }
114:
115: }
|