1 22 package org.objectweb.petals.component.common.handleMessagesExchange; 23 24 import java.util.Set ; 25 26 import javax.activation.DataHandler ; 27 import javax.jbi.JBIException; 28 import javax.jbi.messaging.ExchangeStatus; 29 import javax.jbi.messaging.Fault; 30 import javax.jbi.messaging.MessageExchange; 31 import javax.jbi.messaging.MessagingException; 32 import javax.jbi.messaging.NormalizedMessage; 33 import javax.xml.namespace.QName ; 34 import javax.xml.transform.Source ; 35 36 import org.objectweb.petals.component.common.util.SourceHelper; 37 38 45 public class HandleResponses { 46 47 public static void faultMessageExchange(MessageExchange messageExchange, 48 Throwable thr, String code) throws JBIException { 49 Fault fault; 50 try { 51 fault = messageExchange.createFault(); 52 53 Source source = SourceHelper.createContentSource(SourceHelper 55 .createSoapFault(thr, code)); 56 fault.setContent(source); 57 58 messageExchange.setFault(fault); 59 messageExchange.setStatus(ExchangeStatus.ERROR); 60 61 } catch (MessagingException e) { 62 throw new JBIException(e.getMessage()); 63 } 64 } 65 66 public static void buildInMessage(MessageExchange msg, String mailCorps, 67 QName service, String operation, Set <DataHandler > attach) 68 throws JBIException { 69 Source source = null; 70 if (mailCorps != null) 71 source = SourceHelper.createSource(mailCorps); 72 NormalizedMessage nm; 73 try { 74 nm = msg.createMessage(); 75 if (attach != null) { 76 for (DataHandler handler : attach) { 77 nm.addAttachment(handler.getName(), handler); 78 } 79 } 80 81 nm.setContent(source); 82 msg.setMessage(nm, "IN"); 83 msg.setService(service); 84 if (operation != null && !operation.equals("")) { 85 msg.setOperation(new QName (operation)); 86 } 87 88 } catch (javax.jbi.messaging.MessagingException e) { 89 throw new JBIException(e.getMessage()); 90 } 91 } 92 } 93 | Popular Tags |