1 10 11 package org.mule.providers.soap.axis; 12 13 import java.util.Iterator ; 14 15 import javax.activation.DataHandler ; 16 import javax.xml.soap.SOAPException ; 17 import javax.xml.soap.SOAPMessage ; 18 19 import org.apache.axis.MessageContext; 20 import org.apache.axis.attachments.AttachmentPart; 21 import org.apache.commons.lang.StringUtils; 22 import org.mule.config.i18n.Message; 23 import org.mule.providers.AbstractMessageAdapter; 24 import org.mule.providers.soap.MuleSoapHeaders; 25 import org.mule.transformers.simple.SerializableToByteArray; 26 import org.mule.umo.MessagingException; 27 import org.mule.umo.transformer.UMOTransformer; 28 29 34 public class AxisMessageAdapter extends AbstractMessageAdapter 35 { 36 39 private static final long serialVersionUID = -923205879581370143L; 40 41 private final Object payload; 42 private final SOAPMessage message; 43 private UMOTransformer trans = new SerializableToByteArray(); 44 45 public AxisMessageAdapter(Object message) throws MessagingException 46 { 47 this.payload = message; 48 try 49 { 50 MessageContext ctx = MessageContext.getCurrentContext(); 51 52 if (ctx != null) 53 { 54 MuleSoapHeaders header = new MuleSoapHeaders(ctx.getMessage().getSOAPPart().getEnvelope() 55 .getHeader()); 56 57 if (StringUtils.isNotBlank(header.getReplyTo())) 58 { 59 setReplyTo(header.getReplyTo()); 60 } 61 62 if (StringUtils.isNotBlank(header.getCorrelationGroup())) 63 { 64 setCorrelationGroupSize(Integer.parseInt(header.getCorrelationGroup())); 65 } 66 if (StringUtils.isNotBlank(header.getCorrelationSequence())) 67 { 68 setCorrelationSequence(Integer.parseInt(header.getCorrelationSequence())); 69 } 70 if (StringUtils.isNotBlank(header.getCorrelationId())) 71 { 72 setCorrelationId(header.getCorrelationId()); 73 } 74 75 this.message = ctx.getMessage(); 76 int x = 1; 77 try 78 { 79 for (Iterator i = this.message.getAttachments(); i.hasNext(); x++) 80 { 81 super.addAttachment(String.valueOf(x), ((AttachmentPart)i.next()) 82 .getActivationDataHandler()); 83 } 84 } 85 catch (Exception e) 86 { 87 logger.fatal("Failed to read attachments", e); 89 } 90 } 91 else 92 { 93 this.message = null; 94 } 95 } 96 catch (SOAPException e) 97 { 98 throw new MessagingException(new Message ("soap", 5), message, e); 99 } 100 } 101 102 110 public String getPayloadAsString(String encoding) throws Exception 111 { 112 return new String (getPayloadAsBytes(), encoding); 113 } 114 115 121 public byte[] getPayloadAsBytes() throws Exception 122 { 123 return (byte[])trans.transform(payload); 124 } 125 126 129 public Object getPayload() 130 { 131 return payload; 132 } 133 134 public SOAPMessage getSoapMessage() 135 { 136 return message; 137 } 138 139 public void addAttachment(String name, DataHandler dataHandler) throws Exception 140 { 141 message.addAttachmentPart(new AttachmentPart(dataHandler)); 142 super.addAttachment(name, dataHandler); 143 } 144 145 public void removeAttachment(String name) throws Exception 146 { 147 if ("all".equalsIgnoreCase(name)) 148 { 149 message.removeAllAttachments(); 150 attachments.clear(); 151 } 152 else 153 { 154 throw new SOAPException (new Message ("soap", 6).toString()); 155 } 156 } 157 } 158 | Popular Tags |