Return-Path: Delivered-To: apmail-activemq-users-archive@www.apache.org Received: (qmail 49009 invoked from network); 14 Apr 2010 08:33:47 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 14 Apr 2010 08:33:47 -0000 Received: (qmail 73130 invoked by uid 500); 14 Apr 2010 08:33:47 -0000 Delivered-To: apmail-activemq-users-archive@activemq.apache.org Received: (qmail 73001 invoked by uid 500); 14 Apr 2010 08:33:47 -0000 Mailing-List: contact users-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@activemq.apache.org Delivered-To: mailing list users@activemq.apache.org Received: (qmail 72987 invoked by uid 99); 14 Apr 2010 08:33:46 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Apr 2010 08:33:46 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=FREEMAIL_FROM,HTML_MESSAGE,SPF_HELO_PASS,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of lists@nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Apr 2010 08:33:39 +0000 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1O1y2A-0008OP-M1 for users@activemq.apache.org; Wed, 14 Apr 2010 01:33:18 -0700 Message-ID: <28239844.post@talk.nabble.com> Date: Wed, 14 Apr 2010 01:33:18 -0700 (PDT) From: ireneshy To: users@activemq.apache.org Subject: Re: Getting IllegalAgrEception while Sending BlobMessage In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_4025_5518736.1271233998680" X-Nabble-From: irenesonghy@gmail.com References: <28237935.post@talk.nabble.com> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_4025_5518736.1271233998680 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi, I'm using the version 'apache-activemq-5.3.1',and the code here. Maybe something wrong with the configuration? The activemq.xml is like this: =20 =20 =20 file:${activemq.base}/conf/credentials.properties =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 " producerFlowControl=3D"false" memoryLimit=3D"1 gb"> =20 =20 =20 =20 " producerFlowControl=3D"false" memoryLimit=3D"1 gb"> =20 =20 =09=09=09=09=09 =09=09=09=09 =20 =09=09=09=09 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =09=09 =09=09 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 1. The producer import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import javax.jms.DeliveryMode; import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.MessageProducer; import javax.jms.Session; import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQSession; import org.apache.activemq.BlobMessage; =20 public class ProducerTool { =20 =20 private String user =3D ActiveMQConnection.DEFAULT_USER; =20 =20 private String password =3D ActiveMQConnection.DEFAULT_PASSWORD; =20 =20 private String url =3D "tcp://localhost:61616?jms.blobTransferPolicy.defaultUploadUrl=3Dhttp://loc= alhost:8161/fileserver/"; =20 =20 private String subject =3D "blob.queue"; =20 =20 private Destination destination =3D null; =20 =20 private ActiveMQConnection connection =3D null; =20 =20 private ActiveMQSession session =3D null; =20 =20 private MessageProducer producer =3D null; =20 =20 // =E5=88=9D=E5=A7=8B=E5=8C=96 =20 private void initialize() throws JMSException, Exception { =20 ActiveMQConnectionFactory connectionFactory =3D new ActiveMQConnectionFactory( =20 user, password, url); =20 connection =3D (ActiveMQConnection)connectionFactory.createConnection(); =20 session =3D (ActiveMQSession)connection.createSession(false, Session.AUTO_ACKNOWLEDGE); =20 destination =3D session.createQueue(subject); =20 producer =3D session.createProducer(destination); =20 producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);=20 connection.setCopyMessageOnSend(false); } =20 =20 // =E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF =20 public void produceMessage(String filename) throws JMSException, Exception { =20 initialize(); =20 File file =3D new File(filename); BlobMessage msg =3D session.createBlobMessage(file); =20 //=E8=AE=BE=E7=BD=AE=E4=B8=80=E4=BA=9B=E6=89=80=E5=8F=91=E9=80=81= =E9=99=84=E4=BB=B6=E7=9A=84=E5=B1=9E=E6=80=A7 msg.setStringProperty("fileName", file.getName()); msg.setLongProperty("fileSize", file.length()); =20 connection.start(); =20 System.out.println("Producer:->Sending message: " + file.getName()+",=E6=96=87=E4=BB=B6=E5=A4=A7=E5=B0=8F=E4=B8=BA=EF=BC=9A" + = file.length()+"B"); =20 //=E5=8F=91=E9=80=81=E6=96=87=E4=BB=B6 producer.send(msg); =20 System.out.println("Producer:->Message sent complete!"); =20 } =20 // =E5=85=B3=E9=97=AD=E8=BF=9E=E6=8E=A5 =20 public void close() throws JMSException { =20 System.out.println("Producer:->Closing connection"); =20 if (producer !=3D null) =20 producer.close(); =20 if (session !=3D null) =20 session.close(); =20 if (connection !=3D null) =20 connection.close(); =20 } =20 } =20 2. The consumer package blobMsg; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageConsumer; import javax.jms.MessageListener; import javax.jms.Session; import org.apache.activemq.ActiveMQConnection; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQSession; import org.apache.activemq.BlobMessage; import org.apache.activemq.blob.BlobDownloadStrategy; import org.apache.activemq.blob.FTPBlobDownloadStrategy; import org.apache.activemq.command.ActiveMQBlobMessage; =20 public class ConsumerTool implements MessageListener { =20 =20 private String user =3D ActiveMQConnection.DEFAULT_USER; =20 =20 private String password =3D ActiveMQConnection.DEFAULT_PASSWORD; =20 =20 private String url =3D "tcp://localhost:61616?jms.blobTransferPolicy.defaultUploadUrl=3Dhttp://loc= alhost:8161/fileserver/"; =20 =20 private String subject =3D "blob.queue"; =20 =20 private Destination destination =3D null; =20 =20 private ActiveMQConnection connection =3D null; =20 =20 private ActiveMQSession session =3D null; =20 =20 private MessageConsumer consumer =3D null;=20 =20 // =E5=88=9D=E5=A7=8B=E5=8C=96 =20 private void initialize() throws JMSException, Exception { =20 ActiveMQConnectionFactory connectionFactory =3D new ActiveMQConnectionFactory( =20 user, password, url); =20 connection =3D (ActiveMQConnection)connectionFactory.createConnection(); =20 session =3D (ActiveMQSession)connection.createSession(false, Session.AUTO_ACKNOWLEDGE); =20 destination =3D session.createQueue(subject); =20 consumer =3D session.createConsumer(destination); } =20 =20 // =E6=B6=88=E8=B4=B9=E6=B6=88=E6=81=AF =20 public void consumeMessage() throws JMSException, Exception { =20 initialize(); =20 connection.start(); =20 // =E5=BC=80=E5=A7=8B=E7=9B=91=E5=90=AC =20 System.out.println("Consumer:->Begin listening..."); =20 // =E8=AE=BE=E7=BD=AE=E7=9B=91=E5=90=AC=E5=99=A8 =20 consumer.setMessageListener(this); =20 // Message message =3D consumer.receive(); =20 } =20 =20 // =E5=85=B3=E9=97=AD=E8=BF=9E=E6=8E=A5 =20 public void close() throws JMSException { =20 System.out.println("Consumer:->Closing connection"); =20 if (consumer !=3D null) =20 consumer.close(); =20 if (session !=3D null) =20 session.close(); =20 if (connection !=3D null) =20 connection.close(); =20 } =20 =20 // =E6=B6=88=E6=81=AF=E5=A4=84=E7=90=86=E5=87=BD=E6=95=B0 =20 public void onMessage(Message message) { =20 try { =20 if (message instanceof BlobMessage) { =20 BlobMessage blobMsg =3D (BlobMessage) message; =09 System.out.println("Consumer:->Received: " + blobMsg); =09 String fileName =3D blobMsg.getStringProperty("fileName"); =09 System.out.println("fileName:"+fileName); =09 long fileSize =3D blobMsg.getLongProperty("fileSize"); =09 System.out.println("fileSize:"+fileSize+"B"); =09 =09 =09 InputStream inStr =3D blobMsg.getInputStream(); BufferedInputStream bin =3D new BufferedInputStream(inStr); =09 File file =3D new File("d:/test"+fileName); =09 BufferedOutputStream bout =3D new BufferedOutputStream(new FileOutputStream(file));=20 =09=20 =09 byte[] block =3D new byte[1024]; =09 while (bin.read(block)!=3D-1) { =09=09=20 =09=09 bout.write(block);=20 =09 } =09=20 =09 bout.close(); =20 =09 bin.close(); =09 inStr.close(); } else { =09 =20 System.out.println("Consumer:->Received: " + message); = =20 } =20 } catch (JMSException e) { =20 // TODO Auto-generated catch block =20 e.printStackTrace(); =20 } catch (IOException e) { =09=09=09// TODO Auto-generated catch block =09=09=09e.printStackTrace(); =09=09}=20 } =20 } =20 3. The test code import javax.jms.JMSException; =20 =20 public class Test { =20 =20 public static void main(String[] args) throws JMSException, Exception { =20 // TODO Auto-generated method stub =20 ConsumerTool consumer =3D new ConsumerTool(); =20 ProducerTool producer =3D new ProducerTool(); =20 // =E5=BC=80=E5=A7=8B=E7=9B=91=E5=90=AC =20 consumer.consumeMessage(); =20 =20 // =E5=BB=B6=E6=97=B6500=E6=AF=AB=E7=A7=92=E4=B9=8B=E5=90=8E=E5=8F= =91=E9=80=81=E6=B6=88=E6=81=AF =20 Thread.sleep(500); =20 producer.produceMessage("d:/1.doc"); =20 producer.close(); =20 =20 // =E5=BB=B6=E6=97=B6500=E6=AF=AB=E7=A7=92=E4=B9=8B=E5=90=8E=E5=81= =9C=E6=AD=A2=E6=8E=A5=E5=8F=97=E6=B6=88=E6=81=AF =20 Thread.sleep(500); =20 consumer.close(); =20 } =20 } =20 Dejan Bosanac wrote: >=20 > Hi, >=20 > what version are you using and can you post your code? >=20 > Cheers > -- > Dejan Bosanac - http://twitter.com/dejanb >=20 > Open Source Integration - http://fusesource.com/ > ActiveMQ in Action - http://www.manning.com/snyder/ > Blog - http://www.nighttale.net >=20 >=20 > On Wed, Apr 14, 2010 at 5:11 AM, ireneshy wrote: >=20 >> >> Hi , >> I am trying a simple producer and consumer application for BlobMessage, >> it >> works fine for files of size 8 kb.But if I send file of size more than >> 64KB >> , it throws an exception in the activemq console : >> >> ERROR log - EXCEPTION >> java.lang.IllegalArgumentException >> at java.nio.Buffer.position(Buffer.java:218) >> at org.mortbay.io.nio.NIOBuffer.poke(NIOBuffer.java:142) >> at org.mortbay.io.AbstractBuffer.put(AbstractBuffer.java:391) >> at org.mortbay.jetty.HttpParser.reset(HttpParser.java:844) >> at >> org.mortbay.jetty.HttpConnection.destroy(HttpConnection.java:131) >> at >> >> org.mortbay.jetty.AbstractConnector.connectionClosed(AbstractConnector.j= ava:785) >> at >> >> org.mortbay.jetty.nio.SelectChannelConnector.access$100(SelectChannelCon= nector.java:64) >> at >> >> org.mortbay.jetty.nio.SelectChannelConnector$1.endPointClosed(SelectChan= nelConnector.java:92) >> at >> >> org.mortbay.io.nio.SelectChannelEndPoint.doUpdateKey(SelectChannelEndPoi= nt.java:382) >> at >> >> org.mortbay.io.nio.SelectorManager$SelectSet.doSelect(SelectorManager.ja= va:337) >> at >> org.mortbay.io.nio.SelectorManager.doSelect(SelectorManager.java:166) >> at >> >> org.mortbay.jetty.nio.SelectChannelConnector.accept(SelectChannelConnect= or.java:124) >> at >> >> org.mortbay.jetty.AbstractConnector$Acceptor.run(AbstractConnector.java:= 537) >> >> I've tried the code listed in the url: >> >> http://old.nabble.com/Getting-IllegalAgrEception-while-Sending-BlobMessa= ge-td17731668.html#a17731668 >> >> But got the same error. Who knows how to fix the problem? >> >> >> -- >> View this message in context: >> http://old.nabble.com/Getting-IllegalAgrEception-while-Sending-BlobMessa= ge-tp28237935p28237935.html >> Sent from the ActiveMQ - User mailing list archive at Nabble.com. >> >> >=20 >=20 > ----- > Dejan Bosanac >=20 > Open Source Integration - http://fusesource.com/ > ActiveMQ in Action - http://www.manning.com/snyder/ > Blog - http://www.nighttale.net >=20 --=20 View this message in context: http://old.nabble.com/Getting-IllegalAgrEcept= ion-while-Sending-BlobMessage-tp28237935p28239844.html Sent from the ActiveMQ - User mailing list archive at Nabble.com. ------=_Part_4025_5518736.1271233998680--