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: * @(#)Payload.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package testengine;
030:
031: import org.w3c.dom.Document;
032:
033: import java.io.StringReader;
034:
035: import javax.jbi.messaging.NormalizedMessage;
036:
037: import javax.xml.parsers.DocumentBuilder;
038: import javax.xml.parsers.DocumentBuilderFactory;
039: import javax.xml.transform.dom.DOMSource;
040: import javax.xml.transform.stream.StreamSource;
041:
042: /**
043: * Simple utility class used to load a dummy DOM document.
044: *
045: * @author Sun Microsystems, Inc.
046: */
047: public class Payload {
048: /**
049: *
050: */
051: public static String mDefaultPath;
052: public static String mDefaultOutPath;
053: /**
054: *
055: */
056: private static Document mDefaultDoc;
057:
058: private static Document mDefaultOutDoc;
059:
060: /**
061: *
062: */
063: private static DocumentBuilder mBuilder;
064:
065: /**
066: *
067: *
068: * @param msg NOT YET DOCUMENTED
069: *
070: * @throws Exception
071: */
072: public static synchronized void setBadPayload(NormalizedMessage msg)
073: throws Exception {
074: try {
075: StringReader reader = new StringReader(
076: "<xmlstart>aim not a good xml <ddd>");
077: msg.setContent(new StreamSource(reader));
078: } catch (Exception e) {
079: e.printStackTrace();
080: throw e;
081: }
082: }
083:
084: /**
085: *
086: *
087: * @param msg NOT YET DOCUMENTED
088: *
089: * @throws Exception
090: */
091: public static synchronized void setPayload(NormalizedMessage msg)
092: throws Exception {
093: if (mBuilder == null) {
094: init();
095: }
096:
097: msg.setContent(new DOMSource(mDefaultDoc));
098: }
099:
100: /**
101: *
102: *
103: * @param msg NOT YET DOCUMENTED
104: *
105: * @throws Exception
106: */
107: public static synchronized void setResponse(NormalizedMessage msg)
108: throws Exception {
109: if (mBuilder == null) {
110: init();
111: }
112:
113: msg.setContent(new DOMSource(mDefaultOutDoc));
114: }
115:
116: /**
117: *
118: *
119: * @throws Exception
120: */
121: private static void init() throws Exception {
122: DocumentBuilderFactory factory;
123:
124: factory = DocumentBuilderFactory.newInstance();
125: factory.setNamespaceAware(true);
126: mBuilder = factory.newDocumentBuilder();
127: mDefaultDoc = mBuilder.parse(mDefaultPath);
128: mDefaultOutDoc = mBuilder.parse(mDefaultOutPath);
129: }
130: }
|