001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the "License"). You may not use this file except
005: * in compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://jwsdp.dev.java.net/CDDLv1.0.html
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * HEADER in each file and include the License file at
014: * https://jwsdp.dev.java.net/CDDLv1.0.html If applicable,
015: * add the following below this CDDL HEADER, with the
016: * fields enclosed by brackets "[]" replaced with your
017: * own identifying information: Portions Copyright [yyyy]
018: * [name of copyright owner]
019: */
020: /*
021: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
022: *
023: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
024: *
025: * The contents of this file are subject to the terms of either the GNU
026: * General Public License Version 2 only ("GPL") or the Common Development
027: * and Distribution License("CDDL") (collectively, the "License"). You
028: * may not use this file except in compliance with the License. You can obtain
029: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
030: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
031: * language governing permissions and limitations under the License.
032: *
033: * When distributing the software, include this License Header Notice in each
034: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
035: * Sun designates this particular file as subject to the "Classpath" exception
036: * as provided by Sun in the GPL Version 2 section of the License file that
037: * accompanied this code. If applicable, add the following below the License
038: * Header, with the fields enclosed by brackets [] replaced by your own
039: * identifying information: "Portions Copyrighted [year]
040: * [name of copyright owner]"
041: *
042: * Contributor(s):
043: *
044: * If you wish your version of this file to be governed by only the CDDL or
045: * only the GPL Version 2, indicate your decision by adding "[Contributor]
046: * elects to include this software in this distribution under the [CDDL or GPL
047: * Version 2] license." If you don't indicate a single choice of license, a
048: * recipient has the option to distribute your version of this file under
049: * either the CDDL, the GPL Version 2 or to extend the choice of license to
050: * its licensees as provided above. However, if you add GPL Version 2 code
051: * and therefore, elected the GPL Version 2 license, then the option applies
052: * only if the new code is made subject to such option by the copyright
053: * holder.
054: */
055:
056: package soap;
057:
058: import java.io.ByteArrayInputStream;
059: import java.io.StringWriter;
060: import javax.xml.soap.*;
061: import javax.xml.transform.Transformer;
062: import javax.xml.transform.TransformerFactory;
063: import javax.xml.transform.dom.DOMSource;
064: import javax.xml.transform.stream.StreamResult;
065: import javax.xml.transform.stream.StreamSource;
066: import junit.framework.TestCase;
067:
068: public class DetailTest extends TestCase {
069:
070: /** Creates a new instance of Test1 */
071: public DetailTest(String name) {
072: super (name);
073: }
074:
075: public void testDetailImpl() {
076: try {
077: doit1();
078: } catch (Throwable t) {
079: System.out.println("Exception: " + t);
080: t.printStackTrace();
081: fail();
082: }
083: }
084:
085: public void doit1() throws Exception {
086: String testDoc = "<?xml version='1.0' encoding='UTF-8'?>\n"
087: + "<D:Envelope xmlns:D='http://schemas.xmlsoap.org/soap/envelope/'>\n"
088: + " <D:Body>\n"
089: + " <D:Fault>\n"
090: + " <D:faultcode>Client.invalidSignature</D:faultcode>\n"
091: + " <D:faultstring>invalid signature</D:faultstring>\n"
092: + " <D:detail>\n" + " 27: Invalid Signature\n"
093: + " </D:detail>\n" + " </D:Fault>\n"
094: + " </D:Body>\n" + "</D:Envelope>\n";
095: byte[] testDocBytes = testDoc.getBytes("UTF-8");
096: ByteArrayInputStream bais = new ByteArrayInputStream(
097: testDocBytes);
098: StreamSource strSource = new StreamSource(bais);
099:
100: MessageFactory msgFactory = MessageFactory.newInstance();
101: SOAPMessage message = msgFactory.createMessage();
102: SOAPPart soapPart = message.getSOAPPart();
103:
104: soapPart.setContent(strSource);
105: message.saveChanges();
106: SOAPEnvelope envelope = soapPart.getEnvelope();
107: SOAPBody body = envelope.getBody();
108: SOAPFault fault = body.getFault();
109: Detail detail = fault.getDetail();
110: assertTrue(detail.getPrefix().length() > 0);
111: }
112:
113: public String nodeToString(org.w3c.dom.Node node) throws Exception {
114: // Use a Transformer for output
115: TransformerFactory tFactory = new com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl();
116: Transformer transformer = tFactory.newTransformer();
117: StringWriter stringWriter = new StringWriter();
118:
119: DOMSource source = new DOMSource(node);
120: StreamResult result = new StreamResult(stringWriter);
121: transformer.transform(source, result);
122: return stringWriter.toString();
123: }
124:
125: public void testDetailEntryCR6581434() {
126: try {
127: MessageFactory mf = MessageFactory.newInstance();
128: SOAPMessage m = mf.createMessage();
129: SOAPEnvelope se = m.getSOAPPart().getEnvelope();
130: Name codeName = se.createName("ErrorCode", "as", null);
131: SOAPFault fault = m.getSOAPBody().addFault();
132: Detail detail = fault.addDetail();
133: detail.addNamespaceDeclaration("as", "http://abc.com/test");
134: DetailEntry codeDetail = detail.addDetailEntry(codeName);
135: } catch (Exception e) {
136: e.printStackTrace();
137: fail();
138: }
139:
140: }
141: }
|