1 17 package org.apache.activemq.command; 18 19 import org.apache.activemq.BlobMessage; 20 import org.apache.activemq.blob.BlobUploader; 21 import org.apache.activemq.util.JMSExceptionSupport; 22 23 import javax.jms.JMSException ; 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.net.MalformedURLException ; 27 import java.net.URL ; 28 29 35 public class ActiveMQBlobMessage extends ActiveMQMessage implements BlobMessage { 36 public static final byte DATA_STRUCTURE_TYPE = CommandTypes.ACTIVEMQ_BLOB_MESSAGE; 37 38 public static final String BINARY_MIME_TYPE = "application/octet-stream"; 39 40 private String remoteBlobUrl; 41 private String mimeType; 42 private String name; 43 private boolean deletedByBroker; 44 45 private transient BlobUploader blobUploader; 46 private transient URL url; 47 48 49 public Message copy() { 50 ActiveMQBlobMessage copy = new ActiveMQBlobMessage(); 51 copy(copy); 52 return copy; 53 } 54 55 private void copy(ActiveMQBlobMessage copy) { 56 super.copy(copy); 57 copy.setRemoteBlobUrl(getRemoteBlobUrl()); 58 copy.setMimeType(getMimeType()); 59 copy.setDeletedByBroker(isDeletedByBroker()); 60 } 61 62 public byte getDataStructureType() { 63 return DATA_STRUCTURE_TYPE; 64 } 65 66 69 public String getRemoteBlobUrl() { 70 return remoteBlobUrl; 71 } 72 73 public void setRemoteBlobUrl(String remoteBlobUrl) { 74 this.remoteBlobUrl = remoteBlobUrl; 75 url = null; 76 } 77 78 83 public String getMimeType() { 84 if (mimeType == null) { 85 return BINARY_MIME_TYPE; 86 } 87 return mimeType; 88 } 89 90 public void setMimeType(String mimeType) { 91 this.mimeType = mimeType; 92 } 93 94 public String getName() { 95 return name; 96 } 97 98 103 public void setName(String name) { 104 this.name = name; 105 } 106 107 110 public boolean isDeletedByBroker() { 111 return deletedByBroker; 112 } 113 114 public void setDeletedByBroker(boolean deletedByBroker) { 115 this.deletedByBroker = deletedByBroker; 116 } 117 118 public String getJMSXMimeType() { 119 return getMimeType(); 120 } 121 122 public InputStream getInputStream() throws IOException , JMSException { 123 URL value = getURL(); 124 if (value == null) { 125 return null; 126 } 127 return value.openStream(); 128 } 129 130 public URL getURL() throws JMSException { 131 if (url == null && remoteBlobUrl != null) { 132 try { 133 url = new URL (remoteBlobUrl); 134 } 135 catch (MalformedURLException e) { 136 throw JMSExceptionSupport.create(e); 137 } 138 } 139 return url; 140 } 141 142 public void setURL(URL url) { 143 this.url = url; 144 remoteBlobUrl = url != null ? url.toExternalForm() : null; 145 } 146 147 148 public BlobUploader getBlobUploader() { 149 return blobUploader; 150 } 151 152 public void setBlobUploader(BlobUploader blobUploader) { 153 this.blobUploader = blobUploader; 154 } 155 156 public void onSend() throws JMSException { 157 super.onSend(); 158 159 if (blobUploader != null) { 161 try { 162 URL value = blobUploader.upload(this); 163 setURL(value); 164 } 165 catch (IOException e) { 166 throw JMSExceptionSupport.create(e); 167 } 168 } 169 } 170 } 171 | Popular Tags |