001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)TestUrlConnection.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.wsdl2.impl.test;
030:
031: import com.sun.jbi.wsdl2.Constants;
032:
033: import java.io.ByteArrayInputStream;
034: import java.io.IOException;
035: import java.io.InputStream;
036:
037: import java.net.URL;
038:
039: /**
040: * This class serves as a test URL protocol connection.
041: *
042: * @author Sun Microsystems Inc.
043: */
044: public class TestUrlConnection extends java.net.URLConnection {
045: /** For backward compatibility test (for x2006x01) */
046: private static final String WSDL_NAMESPACE_NAME_2006_01 = "http://www.w3.org/2006/01/wsdl";
047:
048: /**
049: * Construct a test connection to the given URL.
050: *
051: * @param url the URL of the resource to connect to.
052: */
053: TestUrlConnection(URL url) {
054: super (url);
055:
056: this .doInput = true;
057: this .setUseCaches(false);
058: }
059:
060: /**
061: * Opens a communications link to the resource referenced by
062: * this connection's URL, if such a connection has not already been
063: * established.
064: *
065: * @exception IOException if an I/O error occurs while opening the
066: * connection.
067: */
068: public void connect() throws IOException {
069: if (!this .connected) {
070: this .connected = true;
071: }
072: }
073:
074: /** A simple, empty WSDL description document */
075: private static final String TEST1 = "<description xmlns = '"
076: + Constants.WSDL_NAMESPACE_NAME + "'\n"
077: + " targetNamespace='http://foo.com/ns'>\n"
078: + "</description>\n";
079:
080: /** An illegal WSDL definition (wrong namespace) */
081: private static final String TEST2 = "<description xmlns = 'http://wrong-namespace.com/'\n"
082: + " targetNamespace='http://foo.com/ns>'>\n"
083: + "</description>\n";
084:
085: /** An illegal WSDL definition (ill-formed) */
086: private static final String TEST3 = "<description xmlns = '"
087: + Constants.WSDL_NAMESPACE_NAME + "'\n"
088: + " targetNamespace='http://foo.com/ns'>\n"
089: + " <service>\n" + "</description>\n";
090:
091: /** An illegal WSDL definition (invalid) */
092: private static final String TEST4 = "<description xmlns = '"
093: + Constants.WSDL_NAMESPACE_NAME + "'\n"
094: + " targetNamespace='http://foo.com/ns'>\n"
095: + " <operation/>\n" + "</description>\n";
096:
097: /** A simple, empty WSDL description document, but for
098: * backward compatibility test */
099: private static final String TEST5 = "<description xmlns = '"
100: + WSDL_NAMESPACE_NAME_2006_01 + "'\n"
101: + " targetNamespace='http://foo.com/ns'>\n"
102: + "</description>\n";
103:
104: /**
105: * Get an input stream for this connection.
106: *
107: * @return an input stream for this connection.
108: */
109: public InputStream getInputStream() {
110: String file = getURL().getFile();
111: String body = "<bad-test-url/>";
112:
113: if ("/notwsdl.wsdl".equalsIgnoreCase(file)) {
114: body = "<foo/>";
115: } else if ("/test1.wsdl".equalsIgnoreCase(file)) {
116: body = TEST1;
117: } else if ("/test2.wsdl".equalsIgnoreCase(file)) {
118: body = TEST2;
119: } else if ("/test3.wsdl".equalsIgnoreCase(file)) {
120: body = TEST3;
121: } else if ("/test4.wsdl".equalsIgnoreCase(file)) {
122: body = TEST4;
123: } else if ("/test5.wsdl".equalsIgnoreCase(file)) {
124: body = TEST5;
125: }
126:
127: return new ByteArrayInputStream(body.getBytes());
128: }
129: }
|