You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Eugeny N Dzhurinsky <bo...@redwerk.com> on 2008/08/07 11:00:46 UTC

Broker upload url is null?

Hello, everybody!

I had configured the internal broker with this descriptor

<beans>
    <bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
    <broker brokerName="broker0" xmlns="http://activemq.org/config/1.0">
        <managementContext>
            <managementContext connectorPort="1599"
                jmxDomainName="org.apache.activemq"/>
        </managementContext>
        <!-- The transport connectors ActiveMQ will listen to -->
        <transportConnectors>
            <transportConnector name="openwire" uri="tcp://localhost:1235" />
        </transportConnectors>
    </broker>
    <jetty xmlns="http://mortbay.com/schemas/jetty/1.0">
        <connectors>
            <nioConnector port="8161" />
        </connectors>
        <handlers>
            <webAppContext contextPath="/admin"
                resourceBase="webapps/admin" logUrlOnStart="true" />
            <webAppContext contextPath="/demo"
                resourceBase="webapps/demo" logUrlOnStart="true" />
            <webAppContext contextPath="/fileserver"
                resourceBase="webapps/fileserver" logUrlOnStart="true" />
        </handlers>
    </jetty>
</beans>

Pretty simple, the broker is started with this piece of code:

==================================================================================
final BrokerService broker = BrokerFactory.createBroker(new URI(
        "xbean:activemq.xml"));
broker.start();
==================================================================================

and the JMS client is started with this piece of code:

==================================================================================
final ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(
        "tcp://localhost:1235?jms.blobTransferPolicy.uploadUrl=http://localhost:8161/fileserver");
final ActiveMQConnection connection = (ActiveMQConnection) factory
        .createConnection();
System.out.println("Using upload url = "
        + connection.getBlobTransferPolicy().getBrokerUploadUrl());
connection.start();
==================================================================================

for some weird reason the upload URL is not propagated by the broker to the client, 
and in the output of the client I can see 

Using upload url = null

and then on each try to send and receive BlobMessage the stream is null.

I tried to set the upload url explicitly with

connection.getBlobTransferPolicy().setBrokerUploadUrl(
        "http://localhost:8161/fileserver");

but this doesn't work either.

Could somebody please help?

-- 
Eugene N Dzhurinsky

Re: Broker upload url is null?

Posted by Eugeny N Dzhurinsky <bo...@redwerk.com>.
On Thu, Aug 07, 2008 at 03:23:26PM +0200, Marco Buss wrote:
> remove the setting of the blobUploadStrategy from your code an use this 
> brokerURL to initialise your ActiveMQConnectionFactory
> 
> tcp://localhost:1235?jms.*blobTransferPolicy*.defaultUploadUrl=http://localhost:8161/fileserver/

I was able to make things working by unpacking the
activemq-fileserver-5.1.0.war into webapps directory, and altering the Jetty
config like listed below:

    <jetty xmlns="http://mortbay.com/schemas/jetty/1.0">
        <connectors>
            <nioConnector port="8161" />
        </connectors>
        <handlers>
            <webAppContext contextPath="/fileserver"
                resourceBase="webapps/" logUrlOnStart="true" />
        </handlers>
    </jetty>

I removed my custom blob upload manager and everything works fine now - I can
send and receive blobs.

Thank you for your help!

-- 
Eugene N Dzhurinsky

Re: Broker upload url is null?

Posted by Marco Buss <ma...@gmx.de>.
Eugeny N Dzhurinsky schrieb:
> On Thu, Aug 07, 2008 at 02:43:33PM +0200, Marco Buss wrote:
>   
>> Eugeny N Dzhurinsky schrieb:
>>     
>>> On Thu, Aug 07, 2008 at 02:18:40PM +0200, Marco Buss wrote:
>>>   
>>>       
>>>> First try this.  Set CopyMessageOnSend to false on your connection. See 
>>>> http://www.nabble.com/A-problem-with-blobmessage-on-activemq-5.0-td15523989.html#a17364301
>>>> If this is true (default) the Upload does not work.
>>>>     
>>>>         
>>> Really, this setting solved the issue when the blob wasn't even tried to be
>>> uploaded, however I'm getting weird issue with jetty now - it complains 
>>>
>>> "PUT was not successful: 405 HTTP method PUT is not supported by this URL"
>>>
>>> on the URL I specified as one to be used for file upload. Looks like XBean
>>> configuration for Jetty needs to be updated somehow?
>>>
>>>   
>>>       
>> The so called fileserver webapp must run on the upload URL.
>>     
>
> The configuration for jetty in axtivemq.xml
>     <jetty xmlns="http://mortbay.com/schemas/jetty/1.0">
>         <connectors>
>             <nioConnector port="8161" />
>         </connectors>
>         <handlers>
>             <webAppContext contextPath="/admin"
>                 resourceBase="webapps/admin" logUrlOnStart="true" />
>             <webAppContext contextPath="/demo"
>                 resourceBase="webapps/demo" logUrlOnStart="true" />
>             <webAppContext contextPath="/fileserver"
>                 resourceBase="webapps/fileserver" logUrlOnStart="true" />
>         </handlers>
>     </jetty>
>
> Currently I can browse http://localhost:8161/fileserver/, so looks like the
> web application is up. What else do I need to do in this configuration file in
> order to allow the blob to be uploaded on the server?
>
> Another question is - I learned it is possible to write the stream directly to
> the queue (http://activemq.apache.org/jms-streams.html)
>
> The only thing which is not clear for me - how can I assign the stream to
> certain message? Do I need to generate an unique name for the stream, upload
> the content to the queue, then produce the message and provide the name for
> the saved stream in one of the message properties? Or there is some another
> way? And how efficient the streams are in comparison to blob messages?
>
> The task I need to solve is exchange the data between hosts, the data is
> mostly large images of several tens or hundreds of megabytes in size.
>
>   
remove the setting of the blobUploadStrategy from your code an use this 
brokerURL to initialise your ActiveMQConnectionFactory

tcp://localhost:1235?jms.*blobTransferPolicy*.defaultUploadUrl=http://localhost:8161/fileserver/

Re: Broker upload url is null?

Posted by Eugeny N Dzhurinsky <bo...@redwerk.com>.
On Thu, Aug 07, 2008 at 02:43:33PM +0200, Marco Buss wrote:
> Eugeny N Dzhurinsky schrieb:
> > On Thu, Aug 07, 2008 at 02:18:40PM +0200, Marco Buss wrote:
> >   
> >> First try this.  Set CopyMessageOnSend to false on your connection. See 
> >> http://www.nabble.com/A-problem-with-blobmessage-on-activemq-5.0-td15523989.html#a17364301
> >> If this is true (default) the Upload does not work.
> >>     
> >
> > Really, this setting solved the issue when the blob wasn't even tried to be
> > uploaded, however I'm getting weird issue with jetty now - it complains 
> >
> > "PUT was not successful: 405 HTTP method PUT is not supported by this URL"
> >
> > on the URL I specified as one to be used for file upload. Looks like XBean
> > configuration for Jetty needs to be updated somehow?
> >
> >   
> The so called fileserver webapp must run on the upload URL.

The configuration for jetty in axtivemq.xml
    <jetty xmlns="http://mortbay.com/schemas/jetty/1.0">
        <connectors>
            <nioConnector port="8161" />
        </connectors>
        <handlers>
            <webAppContext contextPath="/admin"
                resourceBase="webapps/admin" logUrlOnStart="true" />
            <webAppContext contextPath="/demo"
                resourceBase="webapps/demo" logUrlOnStart="true" />
            <webAppContext contextPath="/fileserver"
                resourceBase="webapps/fileserver" logUrlOnStart="true" />
        </handlers>
    </jetty>

Currently I can browse http://localhost:8161/fileserver/, so looks like the
web application is up. What else do I need to do in this configuration file in
order to allow the blob to be uploaded on the server?

Another question is - I learned it is possible to write the stream directly to
the queue (http://activemq.apache.org/jms-streams.html)

The only thing which is not clear for me - how can I assign the stream to
certain message? Do I need to generate an unique name for the stream, upload
the content to the queue, then produce the message and provide the name for
the saved stream in one of the message properties? Or there is some another
way? And how efficient the streams are in comparison to blob messages?

The task I need to solve is exchange the data between hosts, the data is
mostly large images of several tens or hundreds of megabytes in size.

-- 
Eugene N Dzhurinsky

Re: Broker upload url is null?

Posted by Marco Buss <ma...@gmx.de>.
Eugeny N Dzhurinsky schrieb:
> On Thu, Aug 07, 2008 at 02:18:40PM +0200, Marco Buss wrote:
>   
>> First try this.  Set CopyMessageOnSend to false on your connection. See 
>> http://www.nabble.com/A-problem-with-blobmessage-on-activemq-5.0-td15523989.html#a17364301
>> If this is true (default) the Upload does not work.
>>     
>
> Really, this setting solved the issue when the blob wasn't even tried to be
> uploaded, however I'm getting weird issue with jetty now - it complains 
>
> "PUT was not successful: 405 HTTP method PUT is not supported by this URL"
>
> on the URL I specified as one to be used for file upload. Looks like XBean
> configuration for Jetty needs to be updated somehow?
>
>   
The so called fileserver webapp must run on the upload URL.

Re: Broker upload url is null?

Posted by Eugeny N Dzhurinsky <bo...@redwerk.com>.
On Thu, Aug 07, 2008 at 02:18:40PM +0200, Marco Buss wrote:
> First try this.  Set CopyMessageOnSend to false on your connection. See 
> http://www.nabble.com/A-problem-with-blobmessage-on-activemq-5.0-td15523989.html#a17364301
> If this is true (default) the Upload does not work.

Really, this setting solved the issue when the blob wasn't even tried to be
uploaded, however I'm getting weird issue with jetty now - it complains 

"PUT was not successful: 405 HTTP method PUT is not supported by this URL"

on the URL I specified as one to be used for file upload. Looks like XBean
configuration for Jetty needs to be updated somehow?

-- 
Eugene N Dzhurinsky

Re: Broker upload url is null?

Posted by Marco Buss <ma...@gmx.de>.
Eugeny N Dzhurinsky schrieb:
> On Thu, Aug 07, 2008 at 01:15:51PM +0200, Marco Buss wrote:
>   
>> Is the Blob successfuly uploaded? Can you see it in the jetty file system?
>>     
>
> No, the blob isn't uploaded at all. Moreover, I added the code listed below:
>
> ===============================================================================
>    private BlobTransferPolicy getTransferPolicy() {
>         BlobTransferPolicy policy = new BlobTransferPolicy();
>         policy.setUploadStrategy(new DefaultBlobUploadStrategy(policy) {
>
>             @Override
>             public void deleteFile(ActiveMQBlobMessage message)
>                     throws IOException, JMSException {
>                 System.err.println("Removing file");
>                 super.deleteFile(message);
>             }
>
>             @Override
>             public URL uploadFile(ActiveMQBlobMessage message, File file)
>                     throws JMSException, IOException {
>                 System.err.println("Uploading file");
>                 return super.uploadFile(message, file);
>             }
>
>             @Override
>             public URL uploadStream(ActiveMQBlobMessage arg0, InputStream arg1)
>                     throws JMSException, IOException {
>                 System.err.println("Uploading stream");
>                 return super.uploadStream(arg0, arg1);
>             }
>
>         });
>         return policy;
>     }
>
> ....
>
>     public void run() {
>         final ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(
>                 "tcp://localhost:1235");
>         final BlobTransferPolicy policy = getTransferPolicy();
>         factory.setBlobTransferPolicy(policy);
>         try {
>             final ActiveMQConnection connection = (ActiveMQConnection) factory
>                     .createConnection();
>             System.out.println("Using upload url = "
>                     + policy.getDefaultUploadUrl());
>             connection.setBlobTransferPolicy(policy);
>             connection.start();
>             final ActiveMQSession session = (ActiveMQSession) connection
>                     .createSession(false, Session.CLIENT_ACKNOWLEDGE);
>             session.setBlobTransferPolicy(policy);
>             final Destination destination = session
>                     .createQueue(ImageProcessorInterface.srcImgQueueName);
>             final Destination tempDestination = session.createTemporaryQueue();
>             final MessageProducer producer = session
>                     .createProducer(destination);
>             final MessageConsumer responseConsumer = session
>                     .createConsumer(tempDestination);
>             responseConsumer.setMessageListener(new MessageListener() {
>             producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
>             for (int i = 0; i < MESSAGES_NUMBER; i++) {
>                 InputStream data = ImageProducer.class
>                         .getResourceAsStream("/sample_image.jpg");
>                 System.out.println("Data stream is " + data);
>                 final BlobMessage message = session.createBlobMessage(data);
>                 message.setJMSReplyTo(tempDestination);
>                 message.setJMSCorrelationID(generateMsgId());
>                 producer.send(message);
>                 Thread.sleep(SLEEP_TIME);
>             }
>         } catch (final Exception e) {
>             throw new RuntimeException(e);
>         }
>         System.out.println("Done");
>     }
> ===============================================================================
>
> to inject a custom BlobTransferPolicy into ActiveMQConnectionFactory,
> ActiveMQConnection and ActiveMQSession instances - but as far as I can see,
> there's noting about an attempt to upload the file in logs. At this point I'm
> stuck :)
>
>   
Hello,

First try this.  Set CopyMessageOnSend to false on your connection. See 
http://www.nabble.com/A-problem-with-blobmessage-on-activemq-5.0-td15523989.html#a17364301
If this is true (default) the Upload does not work.

If that will not help please provied the whole code including the broker 
an jetty start. I think you will start the broker and jetty programmaticaly.

regards
Marco

Re: Broker upload url is null?

Posted by Eugeny N Dzhurinsky <bo...@redwerk.com>.
On Thu, Aug 07, 2008 at 01:15:51PM +0200, Marco Buss wrote:
> Is the Blob successfuly uploaded? Can you see it in the jetty file system?

No, the blob isn't uploaded at all. Moreover, I added the code listed below:

===============================================================================
   private BlobTransferPolicy getTransferPolicy() {
        BlobTransferPolicy policy = new BlobTransferPolicy();
        policy.setUploadStrategy(new DefaultBlobUploadStrategy(policy) {

            @Override
            public void deleteFile(ActiveMQBlobMessage message)
                    throws IOException, JMSException {
                System.err.println("Removing file");
                super.deleteFile(message);
            }

            @Override
            public URL uploadFile(ActiveMQBlobMessage message, File file)
                    throws JMSException, IOException {
                System.err.println("Uploading file");
                return super.uploadFile(message, file);
            }

            @Override
            public URL uploadStream(ActiveMQBlobMessage arg0, InputStream arg1)
                    throws JMSException, IOException {
                System.err.println("Uploading stream");
                return super.uploadStream(arg0, arg1);
            }

        });
        return policy;
    }

....

    public void run() {
        final ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(
                "tcp://localhost:1235");
        final BlobTransferPolicy policy = getTransferPolicy();
        factory.setBlobTransferPolicy(policy);
        try {
            final ActiveMQConnection connection = (ActiveMQConnection) factory
                    .createConnection();
            System.out.println("Using upload url = "
                    + policy.getDefaultUploadUrl());
            connection.setBlobTransferPolicy(policy);
            connection.start();
            final ActiveMQSession session = (ActiveMQSession) connection
                    .createSession(false, Session.CLIENT_ACKNOWLEDGE);
            session.setBlobTransferPolicy(policy);
            final Destination destination = session
                    .createQueue(ImageProcessorInterface.srcImgQueueName);
            final Destination tempDestination = session.createTemporaryQueue();
            final MessageProducer producer = session
                    .createProducer(destination);
            final MessageConsumer responseConsumer = session
                    .createConsumer(tempDestination);
            responseConsumer.setMessageListener(new MessageListener() {
            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
            for (int i = 0; i < MESSAGES_NUMBER; i++) {
                InputStream data = ImageProducer.class
                        .getResourceAsStream("/sample_image.jpg");
                System.out.println("Data stream is " + data);
                final BlobMessage message = session.createBlobMessage(data);
                message.setJMSReplyTo(tempDestination);
                message.setJMSCorrelationID(generateMsgId());
                producer.send(message);
                Thread.sleep(SLEEP_TIME);
            }
        } catch (final Exception e) {
            throw new RuntimeException(e);
        }
        System.out.println("Done");
    }
===============================================================================

to inject a custom BlobTransferPolicy into ActiveMQConnectionFactory,
ActiveMQConnection and ActiveMQSession instances - but as far as I can see,
there's noting about an attempt to upload the file in logs. At this point I'm
stuck :)

-- 
Eugene N Dzhurinsky

Re: Broker upload url is null?

Posted by Marco Buss <ma...@gmx.de>.
Is the Blob successfuly uploaded? Can you see it in the jetty file system?

Eugeny N Dzhurinsky schrieb:
> Hello, everybody!
>
> I had configured the internal broker with this descriptor
>
> <beans>
>     <bean
>         class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
>     <broker brokerName="broker0" xmlns="http://activemq.org/config/1.0">
>         <managementContext>
>             <managementContext connectorPort="1599"
>                 jmxDomainName="org.apache.activemq"/>
>         </managementContext>
>         <!-- The transport connectors ActiveMQ will listen to -->
>         <transportConnectors>
>             <transportConnector name="openwire" uri="tcp://localhost:1235" />
>         </transportConnectors>
>     </broker>
>     <jetty xmlns="http://mortbay.com/schemas/jetty/1.0">
>         <connectors>
>             <nioConnector port="8161" />
>         </connectors>
>         <handlers>
>             <webAppContext contextPath="/admin"
>                 resourceBase="webapps/admin" logUrlOnStart="true" />
>             <webAppContext contextPath="/demo"
>                 resourceBase="webapps/demo" logUrlOnStart="true" />
>             <webAppContext contextPath="/fileserver"
>                 resourceBase="webapps/fileserver" logUrlOnStart="true" />
>         </handlers>
>     </jetty>
> </beans>
>
> Pretty simple, the broker is started with this piece of code:
>
> ==================================================================================
> final BrokerService broker = BrokerFactory.createBroker(new URI(
>         "xbean:activemq.xml"));
> broker.start();
> ==================================================================================
>
> and the JMS client is started with this piece of code:
>
> ==================================================================================
> final ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(
>         "tcp://localhost:1235?jms.blobTransferPolicy.uploadUrl=http://localhost:8161/fileserver");
> final ActiveMQConnection connection = (ActiveMQConnection) factory
>         .createConnection();
> System.out.println("Using upload url = "
>         + connection.getBlobTransferPolicy().getBrokerUploadUrl());
> connection.start();
> ==================================================================================
>
> for some weird reason the upload URL is not propagated by the broker to the client, 
> and in the output of the client I can see 
>
> Using upload url = null
>
> and then on each try to send and receive BlobMessage the stream is null.
>
> I tried to set the upload url explicitly with
>
> connection.getBlobTransferPolicy().setBrokerUploadUrl(
>         "http://localhost:8161/fileserver");
>
> but this doesn't work either.
>
> Could somebody please help?
>
>