geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lucian <luc...@dudeinthemirror.com>
Subject PrefixedQName incompatible with javax.xml.soap.SOAPHeaderElement
Date Tue, 19 Sep 2006 22:35:03 GMT
Hi , I am trying to decompose a SOAP message and
I am getting the following exception :

Exception in thread "main" java.lang.ClassCastException:
org.apache.axis.message.PrefixedQName incompatible with
javax.xml.soap.SOAPHeaderElement
	at com.acme.dw.tri.MessageReader.displayAttributes(MessageReader.java:128)
	at com.acme.dw.tri.MessageReader.unmarshallMessage(MessageReader.java:106)
	at com.acme.dw.tri.MessageReader.main(MessageReader.java:155)


Here is the code :

package com.acme.dw.tri;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.StringReader;
import java.util.Iterator;

import javax.xml.soap.MessageFactory;
import javax.xml.soap.Name;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPHeaderElement;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;


import com.acme.dw.util.FileIO;
import com.acme.dw.util.JWhich;

/**
 * @author l
 *
 */
public class MessageReader {

	/**
	 * 
	 */
	public MessageReader () {
		
	}
	
	/**
         * Read a SOAP message from a flat file
	 * @param _message_file
	 * @return
	 */
	public SOAPMessage readSOAPMessageFromFile (String _message_file) {
		String msg = "";
		SOAPMessage soap_msg = null;
		try {
			msg = FileIO.readFileIntoStr(_message_file);
		} catch (FileNotFoundException fnfe) {
			System.out.println("Can not read " + _message_file);
			fnfe.getMessage();
			fnfe.printStackTrace();
		} catch (IOException e) {
			System.out.println("Other exception in readSOAPMessageFromFile");
			e.getMessage();
			e.printStackTrace();
		}
		
		// If you don't have the FileIO package read from the file like this:
		// FileInputStream fis= new FileInputStream(_message_file);		 
		// StreamSource src = new StreamSource(fis); 
		
	    
		// Make the string into a javax.xml.soap.SOAPMessage
		try {
            MessageFactory factory = MessageFactory.newInstance();
            soap_msg = factory.createMessage();
            SOAPPart sp = soap_msg.getSOAPPart();
            
            StringReader char_stream = new StringReader(msg);            
            Source src = new StreamSource(char_stream);

            sp.setContent(src);
            
            soap_msg.saveChanges();
		}
		catch (SOAPException se) {
			System.out.println("SOAPException in readSOAPMessageFromFile");
			se.getMessage();
			se.printStackTrace();
		    return null;
		}
	    
		return soap_msg;
	}
	
	/**
	 * Given a SOAP message in a string, it displays all the elements and attributes
	 * @param _tag
	 * @return
	 */
	public String unmarshallMessage (SOAPMessage _soap_msg) {
        SOAPEnvelope envelope = null;
		try {
			envelope = _soap_msg.getSOAPPart().getEnvelope();		
			SOAPHeader header = envelope.getHeader();
			SOAPBody body = envelope.getBody();
							
			Iterator<SOAPHeaderElement> allhe =
(Iterator<SOAPHeaderElement>)header.examineAllHeaderElements();
			
			SOAPHeaderElement she = null;
			while(allhe.hasNext()) {
				she = (SOAPHeaderElement)allhe.next();
				Iterator attr = she.getAllAttributes();
				displayAttributes(attr);
				
				boolean mu = she.getMustUnderstand();
				System.out.println("mustUnderstand is : " + mu);
			}
			

	        
	    } catch (SOAPException se) {
			System.out.println("SOAPException in unmarshallMessage");
			se.getMessage();
			se.printStackTrace();
			
		}
		return null;
	}
	

	private void displayAttributes (Iterator<SOAPHeaderElement> _attr) {

        while (_attr.hasNext()) {

        	SOAPElement se = (SOAPHeaderElement)_attr.next();
        	
        	Name se_name = se.getElementName();
        	System.out.println("Attribute name  : " + se_name);
        	System.out.println("Attribute text	 : " +
se.getAttributeValue(se_name));       	
        }	
	}

	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		if (args.length < 1) {
            System.out.println("USAGE : " + FileIO.class.getName() + "<file_name>");
            System.out.println("<file_name> is the file that contains the SOAP
message");
            return;
        }
		
		// where is the class loaded from
		JWhich.which ("javax.xml.soap.MessageFactory");
		// JWhich.which("javax.xml.soap.SOAPHeaderElement");
		
		String _file = args[0];
		MessageReader mr = new MessageReader();
		SOAPMessage sm = mr.readSOAPMessageFromFile(_file);
		mr.unmarshallMessage(sm);
		
	}

}

And here is the list under the "Order and Export" tab
in Eclipse --> Project --> Properties --> Java Build Path

tri/src
util
Geronimo v1.1 Runtime
commons-discovery-0.2.jar
axis-1.4.jar
jdom-1.0.jar
JRE System Library [ibm_jdk_15]


I've tried to use the JRE 1.4.2 from Sun instead, I'm getting
exactly the same exception (according to the Geronimo doc
one can use 1.5 as long as CORBA support is not needed)


Thanks in advance for your help. 
Of course, if you know of a better / simpler way to do this, that
would help as well.




Mime
View raw message