1 10 11 package org.mule.providers.soap.glue; 12 13 import electric.glue.context.ThreadContext; 14 import electric.service.IService; 15 16 import org.apache.commons.collections.IteratorUtils; 17 import org.mule.config.MuleProperties; 18 import org.mule.providers.AbstractMessageAdapter; 19 import org.mule.transformers.simple.SerializableToByteArray; 20 import org.mule.umo.transformer.UMOTransformer; 21 22 import java.util.Iterator ; 23 24 30 public class GlueMessageAdapter extends AbstractMessageAdapter 31 { 32 35 private static final long serialVersionUID = 7330508491857055854L; 36 37 private static final UMOTransformer transformer = new SerializableToByteArray(); 38 39 private final Object message; 40 41 public GlueMessageAdapter(Object message) 42 { 43 if (message instanceof GlueMessageHolder) 44 { 45 GlueMessageHolder holder = (GlueMessageHolder)message; 46 this.message = holder.getMessage(); 47 Iterator iter = IteratorUtils.asIterator(holder.getService().getContext().getPropertyNames()); 48 String key; 49 while (iter.hasNext()) 50 { 51 key = iter.next().toString(); 52 setProperty(key, holder.getService().getContext().getProperty(key)); 53 } 54 } 55 else 56 { 57 this.message = message; 58 } 59 String value = (String )ThreadContext.removeProperty(MuleProperties.MULE_REPLY_TO_PROPERTY); 60 if (value != null) 61 { 62 setReplyTo(value); 63 } 64 value = (String )ThreadContext.removeProperty(MuleProperties.MULE_CORRELATION_ID_PROPERTY); 65 if (value != null) 66 { 67 setCorrelationId(value); 68 } 69 70 value = (String )ThreadContext.removeProperty(MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY); 71 if (value != null && !"-1".equals(value)) 72 { 73 setCorrelationSequence(Integer.parseInt(value)); 74 } 75 value = (String )ThreadContext.removeProperty(MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY); 76 if (value != null && !"-1".equals(value)) 77 { 78 setCorrelationGroupSize(Integer.parseInt(value)); 79 } 80 } 81 82 90 public String getPayloadAsString(String encoding) throws Exception 91 { 92 return new String (getPayloadAsBytes(), encoding); 93 } 94 95 101 public byte[] getPayloadAsBytes() throws Exception 102 { 103 return (byte[])transformer.transform(message); 104 } 105 106 109 public Object getPayload() 110 { 111 return message; 112 } 113 114 public static class GlueMessageHolder 115 { 116 private Object message; 117 private IService service; 118 119 public GlueMessageHolder(Object message, IService service) 120 { 121 this.message = message; 122 this.service = service; 123 } 124 125 public Object getMessage() 126 { 127 return message; 128 } 129 130 public IService getService() 131 { 132 return service; 133 } 134 } 135 } 136 | Popular Tags |