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: * TestUtil.java
038: *
039: * Created on April 7, 2006, 12:45 PM
040: *
041: * To change this template, choose Tools | Template Manager
042: * and open the template in the editor.
043: */
044:
045: package com.sun.xml.wss.impl.util;
046:
047: import javax.xml.soap.*;
048: import java.io.*;
049: import java.util.*;
050:
051: /**
052: *
053: * @author ashutosh.shahi@sun.com
054: */
055: public class TestUtil {
056:
057: /** Creates a new instance of TestUtil */
058: public TestUtil() {
059: }
060:
061: public static void saveMimeHeaders(SOAPMessage msg, String fileName)
062: throws IOException {
063:
064: FileOutputStream fos = new FileOutputStream(fileName);
065: ObjectOutputStream oos = new ObjectOutputStream(fos);
066:
067: Hashtable hashTable = new Hashtable();
068: MimeHeaders mimeHeaders = msg.getMimeHeaders();
069: Iterator iterator = mimeHeaders.getAllHeaders();
070:
071: while (iterator.hasNext()) {
072: MimeHeader mimeHeader = (MimeHeader) iterator.next();
073: hashTable.put(mimeHeader.getName(), mimeHeader.getValue());
074: }
075:
076: oos.writeObject(hashTable);
077: oos.flush();
078: oos.close();
079:
080: fos.flush();
081: fos.close();
082: }
083:
084: public static SOAPMessage constructMessage(String mimeHdrsFile,
085: String msgFile) throws Exception {
086: SOAPMessage message;
087:
088: MimeHeaders mimeHeaders = new MimeHeaders();
089: FileInputStream fis = new FileInputStream(msgFile);
090:
091: ObjectInputStream ois = new ObjectInputStream(
092: new FileInputStream(mimeHdrsFile));
093: Hashtable hashTable = (Hashtable) ois.readObject();
094: ois.close();
095:
096: if (hashTable.isEmpty()) {
097: // System.out.println("MimeHeaders Hashtable is empty");
098: } else {
099: for (int i = 0; i < hashTable.size(); i++) {
100: Enumeration keys = hashTable.keys();
101: Enumeration values = hashTable.elements();
102: while (keys.hasMoreElements()
103: && values.hasMoreElements()) {
104: String name = (String) keys.nextElement();
105: String value = (String) values.nextElement();
106: mimeHeaders.addHeader(name, value);
107: }
108: }
109: }
110:
111: MessageFactory messageFactory = MessageFactory.newInstance();
112: message = messageFactory.createMessage(mimeHeaders, fis);
113:
114: message.saveChanges();
115:
116: return message;
117: }
118:
119: }
|