geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Jencks <david_jen...@yahoo.com>
Subject Re: PrefixedQName incompatible with javax.xml.soap.SOAPHeaderElement
Date Tue, 19 Sep 2006 22:46:03 GMT
Does this happen when you run geronimo standalone unrelated to  
eclipse? On both 1.4.2 and 1.5 jdks?

I haven't examined the inheritance hierarchy of the classes involved  
but your eclipse listing makes me suspect that either QName or axis  
classes are being loaded in at least 2 classloaders.  Geronimo should  
include the appropriate axis jar for use of j2ee 1.4 web services.   
Use of another axis jar may risk classloading conflicts.

thanks
david jencks

On Sep 19, 2006, at 3:35 PM, lucian wrote:

> 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