1 17 package org.apache.servicemix.soap.marshalers; 18 19 import java.net.URI ; 20 import java.util.Iterator ; 21 import java.util.Map ; 22 import java.util.Set ; 23 24 import javax.activation.DataHandler ; 25 import javax.jbi.messaging.Fault; 26 import javax.jbi.messaging.NormalizedMessage; 27 import javax.xml.namespace.QName ; 28 29 import org.apache.servicemix.JbiConstants; 30 import org.apache.servicemix.soap.SoapFault; 31 import org.w3c.dom.DocumentFragment ; 32 33 39 public class JBIMarshaler { 40 41 public static final String SOAP_FAULT_CODE = "org.apache.servicemix.soap.fault.code"; 42 public static final String SOAP_FAULT_SUBCODE = "org.apache.servicemix.soap.fault.subcode"; 43 public static final String SOAP_FAULT_REASON = "org.apache.servicemix.soap.fault.reason"; 44 public static final String SOAP_FAULT_NODE = "org.apache.servicemix.soap.fault.node"; 45 public static final String SOAP_FAULT_ROLE = "org.apache.servicemix.soap.fault.role"; 46 47 public void toNMS(NormalizedMessage normalizedMessage, SoapMessage soapMessage) throws Exception { 48 if (soapMessage.hasHeaders()) { 49 normalizedMessage.setProperty(JbiConstants.SOAP_HEADERS, soapMessage.getHeaders()); 50 } 51 if (soapMessage.hasAttachments()) { 52 Map attachments = soapMessage.getAttachments(); 53 for (Iterator it = attachments.entrySet().iterator(); it.hasNext();) { 54 Map.Entry entry = (Map.Entry ) it.next(); 55 normalizedMessage.addAttachment((String ) entry.getKey(), 56 (DataHandler ) entry.getValue()); 57 } 58 } 59 normalizedMessage.setSecuritySubject(soapMessage.getSubject()); 60 if (soapMessage.getFault() != null) { 61 if (normalizedMessage instanceof Fault == false) { 62 throw new IllegalStateException ("The soap message is a fault but the jbi message is not"); 63 } 64 SoapFault fault = soapMessage.getFault(); 65 normalizedMessage.setProperty(SOAP_FAULT_CODE, fault.getCode()); 66 normalizedMessage.setProperty(SOAP_FAULT_SUBCODE, fault.getSubcode()); 67 normalizedMessage.setProperty(SOAP_FAULT_REASON, fault.getReason()); 68 normalizedMessage.setProperty(SOAP_FAULT_NODE, fault.getNode()); 69 normalizedMessage.setProperty(SOAP_FAULT_ROLE, fault.getRole()); 70 normalizedMessage.setContent(fault.getDetails()); 71 } else { 72 normalizedMessage.setContent(soapMessage.getSource()); 73 } 74 } 75 76 public void fromNMS(SoapMessage soapMessage, NormalizedMessage normalizedMessage) { 77 if (normalizedMessage.getProperty(JbiConstants.SOAP_HEADERS) != null) { 78 Map headers = (Map ) normalizedMessage.getProperty(JbiConstants.SOAP_HEADERS); 79 for (Iterator it = headers.entrySet().iterator(); it.hasNext();) { 80 Map.Entry entry = (Map.Entry ) it.next(); 81 soapMessage.addHeader((QName ) entry.getKey(), (DocumentFragment ) entry.getValue()); 82 } 83 } 84 Set attachmentNames = normalizedMessage.getAttachmentNames(); 85 for (Iterator it = attachmentNames.iterator(); it.hasNext();) { 86 String id = (String ) it.next(); 87 DataHandler handler = normalizedMessage.getAttachment(id); 88 soapMessage.addAttachment(id, handler); 89 } 90 if (normalizedMessage instanceof Fault) { 91 QName code = (QName ) normalizedMessage.getProperty(SOAP_FAULT_CODE); 92 QName subcode = (QName ) normalizedMessage.getProperty(SOAP_FAULT_SUBCODE); 93 String reason = (String ) normalizedMessage.getProperty(SOAP_FAULT_REASON); 94 URI node = (URI ) normalizedMessage.getProperty(SOAP_FAULT_NODE); 95 URI role = (URI ) normalizedMessage.getProperty(SOAP_FAULT_ROLE); 96 SoapFault fault = new SoapFault(code, subcode, reason, node, role, normalizedMessage.getContent()); 97 soapMessage.setFault(fault); 98 } else { 99 soapMessage.setSource(normalizedMessage.getContent()); 100 } 101 } 102 103 } 104 | Popular Tags |