activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r511798 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/ main/java/org/apache/activemq/blob/ test/java/org/apache/activemq/blob/
Date Mon, 26 Feb 2007 13:13:55 GMT
Author: jstrachan
Date: Mon Feb 26 05:13:54 2007
New Revision: 511798

URL: http://svn.apache.org/viewvc?view=rev&rev=511798
Log:
added a simple default cut of the DefaultBlobUploadStrategy implementation along with a test
case for the URI based configuration

Added:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/BlobTransferPolicyUriTest.java
  (with props)
Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/BlobTransferPolicy.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/DefaultBlobUploadStrategy.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java?view=diff&rev=511798&r1=511797&r2=511798
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java
Mon Feb 26 05:13:54 2007
@@ -504,9 +504,15 @@
             setRedeliveryPolicy(rp);
             rc = true;
         }
-        
+
+        BlobTransferPolicy blobTransferPolicy = new BlobTransferPolicy();
+        if ( IntrospectionSupport.setProperties(blobTransferPolicy, properties, "blobTransferPolicy.")
) {
+            setBlobTransferPolicy(blobTransferPolicy);
+            rc = true;
+        }
+
         rc |= IntrospectionSupport.setProperties(this, properties);
-        
+
         return rc;
     }
 

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/BlobTransferPolicy.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/BlobTransferPolicy.java?view=diff&rev=511798&r1=511797&r2=511798
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/BlobTransferPolicy.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/BlobTransferPolicy.java
Mon Feb 26 05:13:54 2007
@@ -26,6 +26,7 @@
     private String defaultUploadUrl = "http://localhost:8080";
     private String brokerUploadUrl;
     private String uploadUrl;
+    private int bufferSize = 128 * 1024;
     private BlobUploadStrategy uploadStrategy;
 
     /**
@@ -94,6 +95,17 @@
      */
     public void setUploadStrategy(BlobUploadStrategy uploadStrategy) {
         this.uploadStrategy = uploadStrategy;
+    }
+
+    public int getBufferSize() {
+        return bufferSize;
+    }
+
+    /**
+     * Sets the default buffer size used when uploading or downloading files
+     */
+    public void setBufferSize(int bufferSize) {
+        this.bufferSize = bufferSize;
     }
 
     protected BlobUploadStrategy createUploadStrategy() {

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/DefaultBlobUploadStrategy.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/DefaultBlobUploadStrategy.java?view=diff&rev=511798&r1=511797&r2=511798
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/DefaultBlobUploadStrategy.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/blob/DefaultBlobUploadStrategy.java
Mon Feb 26 05:13:54 2007
@@ -20,10 +20,13 @@
 
 import javax.jms.JMSException;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.net.URLConnection;
 
 /**
  * A default implementation of {@link BlobUploadStrategy} which uses the URL class to upload
@@ -37,17 +40,36 @@
     }
 
     public URL uploadFile(ActiveMQBlobMessage message, File file) throws JMSException, IOException
{
-        URL url = createUploadURL(message);
-        // TODO upload to URL
-        // return url;
-        throw new JMSException("Not implemented yet!");
+        return uploadStream(message, new FileInputStream(file));
     }
 
-    public URL uploadStream(ActiveMQBlobMessage message, InputStream in) throws JMSException,
IOException {
+    public URL uploadStream(ActiveMQBlobMessage message, InputStream fis) throws JMSException,
IOException {
         URL url = createUploadURL(message);
-        // TODO upload to URL
-        // return url;
-        throw new JMSException("Not implemented yet!");
+
+        URLConnection connection = url.openConnection();
+        connection.setDoOutput(true);
+        OutputStream os = connection.getOutputStream();
+
+        byte[] buf = new byte[transferPolicy.getBufferSize()];
+        for (int c = fis.read(buf); c != -1; c = fis.read(buf)) {
+            os.write(buf, 0, c);
+        }
+        os.close();
+        fis.close();
+
+        /*
+        // Read the response.
+        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+        String inputLine;
+        while ((inputLine = in.readLine()) != null) {
+            System.out.println(inputLine);
+        }
+        in.close();
+        */
+
+        // TODO we now need to ensure that the return code is OK?
+
+        return url;
     }
 
     protected URL createUploadURL(ActiveMQBlobMessage message) throws JMSException, MalformedURLException
{

Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/BlobTransferPolicyUriTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/BlobTransferPolicyUriTest.java?view=auto&rev=511798
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/BlobTransferPolicyUriTest.java
(added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/BlobTransferPolicyUriTest.java
Mon Feb 26 05:13:54 2007
@@ -0,0 +1,33 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.blob;
+
+import junit.framework.TestCase;
+import org.apache.activemq.ActiveMQConnectionFactory;
+
+/**
+ * @version $Revision$
+ */
+public class BlobTransferPolicyUriTest extends TestCase {
+    public void testBlobTransferPolicyIsConfiguredViaUri() throws Exception {
+        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost?jms.blobTransferPolicy.defaultUploadUrl=http://foo.com");
+        BlobTransferPolicy policy = factory.getBlobTransferPolicy();
+        assertEquals("http://foo.com", policy.getDefaultUploadUrl());
+        assertEquals("http://foo.com", policy.getUploadUrl());
+    }
+}

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/BlobTransferPolicyUriTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/BlobTransferPolicyUriTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/blob/BlobTransferPolicyUriTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message