1 25 26 package org.objectweb.petals.jbi.transport; 27 28 import javax.jbi.JBIException; 29 import javax.jms.JMSException ; 30 import javax.jms.Message ; 31 import javax.jms.ObjectMessage ; 32 import javax.jms.Session ; 33 34 import org.objectweb.petals.jbi.messaging.MessageExchangeImpl; 35 36 45 public class ObjectSerializer implements Serializer { 46 47 public Message jbi2jms(MessageExchangeImpl jbi, Session session) 48 throws TransportException { 49 ObjectMessage jms; 50 try { 51 jms = session.createObjectMessage(jbi); 52 } catch (JMSException e) { 53 if(e.getMessage().indexOf("org.xml.sax.SAXParseException")>0){ 54 if(e.getMessage().indexOf("Content is not allowed in prolog")>0){ 55 throw new TransportException("The Normalized Message is not a valid XML document.",e); 56 }else if (e.getMessage().indexOf("Invalid byte")>0){ 57 throw new TransportException("The Normalized Message contains invalid characters.",e); 58 } 59 } 60 throw new TransportException(e); 61 } 62 return jms; 63 } 64 65 public MessageExchangeImpl jms2jbi(Message jms) throws JBIException { 66 try { 67 return (MessageExchangeImpl) ((ObjectMessage ) jms).getObject(); 68 } catch (JMSException e) { 69 throw new JBIException(e); 70 } 71 72 } 73 74 } 75 | Popular Tags |