What causes a BAD Command Argument Error coming from exchange server? - java

I am writing a java program to iterate through all emails on an exchange server and move those to a folder. I am properly iterating through the emails and have found the attachment from the Multipart message, but when it comes to the point where I need to save the file. I am getting the error: "BAD Command Argument Error. 11". I have searched for the past few days and have not found what is causing this. What is causing this issue?
Here is my code:
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.Properties;
import javax.mail.Address;
import javax.mail.Flags;
import javax.mail.Folder;
import javax.mail.Header;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Part;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.internet.MimeBodyPart;
import javax.mail.search.FlagTerm;
import com.sun.mail.util.BASE64DecoderStream;
public class EmailAttachmentMoverIMAP {
private static Store store = null;
public static void main(String args[]) {
store = buildStore();
Message[] messages = getMessages();
iterateAttachments(messages);
try{store.close();}catch (MessagingException e){e.printStackTrace();}
}
public static Store buildStore(){
Properties properties = System.getProperties();
properties = new Properties();
properties.setProperty("mail.host", "MYHOST");
properties.setProperty("mail.port", "143");
properties.setProperty("mail.transport.protocol", "imap");
Session session = Session.getInstance(properties,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("USER", "PASS");
}
});
try {
store = session.getStore("imap");
}
catch (Exception e){
e.printStackTrace();
}
return store;
}
public static Message[] getMessages(){
Message[] messages = null;
try
{
store.connect();
Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_WRITE);
Flags seen = new Flags(Flags.Flag.SEEN);
FlagTerm unseenFlagTerm = new FlagTerm(seen, false);
messages = inbox.search(unseenFlagTerm);
if (messages.length == 0) System.out.println("No messages found.");
}
catch (MessagingException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return messages;
}
public static void iterateAttachments(Message[] messages){
System.out.println("Moving "+messages.length + " attachments");
for (int i=0; i<messages.length; i++){
System.out.println("moving attachment "+i+" of "+messages.length);
moveAttachments(messages[i], i);
}
}
public static void moveAttachments(Message message, int num){
try{
Address[] fromAddress = message.getFrom();
String from = fromAddress[0].toString();
String subject = message.getSubject();
String sentDate = message.getSentDate().toString();
String contentType = message.getContentType();
String messageContent = "";
// store attachment file name, separated by comma
String attachFiles = "";
if (contentType.contains("multipart")) {
// content may contain attachments
Multipart multiPart = (Multipart) message.getContent();
int numberOfParts = multiPart.getCount();
for (int partCount = 0; partCount < numberOfParts; partCount++) {
MimeBodyPart part = (MimeBodyPart) multiPart.getBodyPart(partCount);
if (Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition())) {
// this part is attachment
String fileName = part.getFileName();
attachFiles += fileName + ", ";
part.saveFile("C:\\skyspark-2.1.8\\db\\demo\\io\\" + File.separator + fileName);
} else {
// this part may be the excel file
if(part.getContentType().equalsIgnoreCase("application/vnd.ms-excel")){
getPartDetails(part);
part.saveFile("C:\\skyspark-2.1.8\\db\\demo\\io\\" + File.separator + part.getFileName());
}
}
}
if (attachFiles.length() > 1) {
attachFiles = attachFiles.substring(0, attachFiles.length() - 2);
}
} else if (contentType.contains("text/plain")
|| contentType.contains("text/html")) {
Object content = message.getContent();
if (content != null) {
messageContent = content.toString();
}
}
System.out.println("\t From: " + from);
System.out.println("\t Subject: " + subject);
System.out.println("\t Sent Date: " + sentDate);
System.out.println("\t Message: " + messageContent);
System.out.println("\t Attachments: " + attachFiles);
}
catch(Exception e){
e.printStackTrace();
}
}
public static void getPartDetails(MimeBodyPart part){
try{
System.out.println("part content class: "+part.getContent().getClass().toString());
System.out.println("part content Type: "+part.getContentType());
System.out.println("part description: "+part.getDescription());
System.out.println("part disposition: "+part.getDisposition());
System.out.println("part encoding: "+part.getEncoding());
System.out.println("part file name: "+part.getFileName());
System.out.println("part line count: "+part.getLineCount());
System.out.println("part size: "+part.getSize());
Enumeration headers = part.getAllHeaders();
int i = 0;
while (headers.hasMoreElements()){
Header hdr = (Header) headers.nextElement();
System.out.println("header "+i+" name: "+hdr.getName());
System.out.println("header "+i+" value: "+hdr.getValue());
i++;
}
}
catch (Exception e){
e.printStackTrace();
}
}
}
Here is a sample of the output:
Moving 3975 attachments
moving attachment 0 of 3975
part content class: class com.sun.mail.util.BASE64DecoderStream
part content Type: application/vnd.ms-excel
part description: null
part disposition: inline
part encoding: base64
part file name: Temp 2015 Mar 23 0601.csv
part line count: -1
part size: 5342
header 0 name: Content-Type
header 0 value: application/vnd.ms-excel
header 1 name: Content-Transfer-Encoding
header 1 value: base64
header 2 name: Content-Disposition
header 2 value: inline; filename="Temp 2015 Mar 23 0601.csv"
java.io.IOException: A8 BAD Command Argument Error. 11
at com.sun.mail.imap.IMAPInputStream.fill(IMAPInputStream.java:154)
at com.sun.mail.imap.IMAPInputStream.read(IMAPInputStream.java:213)
at com.sun.mail.imap.IMAPInputStream.read(IMAPInputStream.java:239)
at com.sun.mail.util.BASE64DecoderStream.getByte(BASE64DecoderStream.java:358)
at com.sun.mail.util.BASE64DecoderStream.decode(BASE64DecoderStream.java:249)
at com.sun.mail.util.BASE64DecoderStream.read(BASE64DecoderStream.java:144)
at java.io.FilterInputStream.read(Unknown Source)
at javax.mail.internet.MimeBodyPart.saveFile(MimeBodyPart.java:825)
at javax.mail.internet.MimeBodyPart.saveFile(MimeBodyPart.java:851)
at EmailAttachmentMoverIMAP.moveAttachments(EmailAttachmentMoverIMAP.java:111)
moving attachment 1 of 3975
at EmailAttachmentMoverIMAP.iterateAttachments(EmailAttachmentMoverIMAP.java:79)
at EmailAttachmentMoverIMAP.main(EmailAttachmentMoverIMAP.java:29)
part content class: class com.sun.mail.util.BASE64DecoderStream
part content Type: application/vnd.ms-excel
part description: null
part disposition: inline
part encoding: base64
part file name: Temperature 2015 Mar 23 0601.csv
part line count: -1
part size: 5342
header 0 name: Content-Type
header 0 value: application/vnd.ms-excel
header 1 name: Content-Transfer-Encoding
header 1 value: base64
header 2 name: Content-Disposition
header 2 value: inline; filename="Temperature 2015 Mar 23 0601.csv"
java.io.IOException: A13 BAD Command Argument Error. 11
at com.sun.mail.imap.IMAPInputStream.fill(IMAPInputStream.java:154)
at com.sun.mail.imap.IMAPInputStream.read(IMAPInputStream.java:213)
at com.sun.mail.imap.IMAPInputStream.read(IMAPInputStream.java:239)
at com.sun.mail.util.BASE64DecoderStream.getByte(BASE64DecoderStream.java:358)
at com.sun.mail.util.BASE64DecoderStream.decode(BASE64DecoderStream.java:249)
at com.sun.mail.util.BASE64DecoderStream.read(BASE64DecoderStream.java:144)
at java.io.FilterInputStream.read(Unknown Source)
at javax.mail.internet.MimeBodyPart.saveFile(MimeBodyPart.java:825)
at javax.mail.internet.MimeBodyPart.saveFile(MimeBodyPart.java:851)
at EmailAttachmentMoverIMAP.moveAttachments(EmailAttachmentMoverIMAP.java:111)
at EmailAttachmentMoverIMAP.iterateAttachments(EmailAttachmentMoverIMAP.java:79)
at EmailAttachmentMoverIMAP.main(EmailAttachmentMoverIMAP.java:29)moving attachment 2 of 3975
As you can see I am finding the attachment (it has a filename and a filesize), but I cannot write to an output stream (I've tried to get the input stream and write to an output stream in every way possible and receive the same issue).
Edit: protocol debugging enabled:
DEBUG: JavaMail version 1.4.7
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle]
DEBUG IMAP: mail.imap.fetchsize: 16384
DEBUG IMAP: mail.imap.ignorebodystructuresize: false
DEBUG IMAP: mail.imap.statuscachetimeout: 1000
DEBUG IMAP: mail.imap.appendbuffersize: -1
DEBUG IMAP: mail.imap.minidletime: 10
DEBUG IMAP: protocolConnect returning false, host=ACTUALHOSTADDRESS, user=ACTUALUSER, password=<null>
DEBUG IMAP: trying to connect to host "ACTUALHOSTADDRESS", port 143, isSSL false
* OK The Microsoft Exchange IMAP4 service is ready.
A0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN STARTTLS CHILDREN IDLE NAMESPACE LITERAL+
A0 OK CAPABILITY completed.
DEBUG IMAP: AUTH: NTLM
DEBUG IMAP: AUTH: GSSAPI
DEBUG IMAP: AUTH: PLAIN
DEBUG IMAP: protocolConnect login, host=ACTUALHOSTADDRESS, user=ACTUALUSERNAME, password=<non-null>
DEBUG IMAP: AUTHENTICATE PLAIN command trace suppressed
DEBUG IMAP: AUTHENTICATE PLAIN command result: A1 OK AUTHENTICATE completed.
A2 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN STARTTLS CHILDREN IDLE NAMESPACE LITERAL+
A2 OK CAPABILITY completed.
DEBUG IMAP: AUTH: NTLM
DEBUG IMAP: AUTH: GSSAPI
DEBUG IMAP: AUTH: PLAIN
DEBUG IMAP: connection available -- size: 1
A3 SELECT INBOX
* 6184 EXISTS
* 254 RECENT
* FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)
* OK [PERMANENTFLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)] Permanent flags
* OK [UNSEEN 5323] Is the first unseen message
* OK [UIDVALIDITY 141703] UIDVALIDITY value
* OK [UIDNEXT 6298] The next unique identifier value
A3 OK [READ-WRITE] SELECT completed.
A4 SEARCH UNSEEN ALL
* SEARCH 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184
A4 OK SEARCH completed.
Moving 860 attachments
moving attachment 0 of 860
A5 FETCH 5323 (ENVELOPE INTERNALDATE RFC822.SIZE)
* 5323 FETCH (UID 5430 ENVELOPE ("Thu, 30 Apr 2015 10:44:59 -0500" "=?utf-8?B?TWljcm9zb2Z0IE91dGxvb2sgVGVzdCBNZXNzYWdl?=" (("Microsoft Outlook" NIL "USER" "HOST")) NIL NIL (("=?utf-8?B?TktDc2QgU3Bhcms=?=" NIL "nkcsdspark" "HOST")) NIL NIL NIL "<2ac2507b-1f41-4a49-8835-cf396ffefced#HOST.com>") INTERNALDATE "30-Apr-2015 10:44:59 -0500" RFC822.SIZE 839)
A5 OK FETCH completed.
A6 FETCH 5323 (BODYSTRUCTURE)
* 5323 FETCH (UID 5430 BODYSTRUCTURE ("text" "html" ("charset" "utf-8") NIL NIL "8bit" 181 2 NIL NIL NIL NIL))
A6 OK FETCH completed.
A7 FETCH 5323 (BODY[TEXT]<0.181>)
A7 BAD Command Argument Error. 11
DEBUG IMAP: IMAPProtocol noop
A8 NOOP
A8 OK NOOP completed.
moving attachment 1 of 860
A9 FETCH 5324 (ENVELOPE INTERNALDATE RFC822.SIZE)
java.io.IOException: A7 BAD Command Argument Error. 11
at com.sun.mail.imap.IMAPInputStream.fill(IMAPInputStream.java:154)
at com.sun.mail.imap.IMAPInputStream.read(IMAPInputStream.java:213)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at com.sun.mail.handlers.text_plain.getContent(text_plain.java:125)
at javax.activation.DataSourceDataContentHandler.getContent(Unknown Source)
at javax.activation.DataHandler.getContent(Unknown Source)
at javax.mail.internet.MimeMessage.getContent(MimeMessage.java:1420)
at EmailAttachmentMoverCSCIMAP.moveAttachments(EmailAttachmentMoverCSCIMAP.java:118)
at EmailAttachmentMoverCSCIMAP.iterateAttachments(EmailAttachmentMoverCSCIMAP.java:75)
at EmailAttachmentMoverCSCIMAP.main(EmailAttachmentMoverCSCIMAP.java:23)

Related

Agent configuration for 'a1' has no configfilters

I got an error(Agent configuration for 'a1' has no configfilters) when I use flume 1.9 to transfer the data from kafka to HDFS, but no other error or info were reported.
The source I used is KafkaSource, sink is file sink.
Interceptor I used is self-define which I will show bolow.
Agent configuration for 'a1' has no configfilters.
the logger info is below. differ from other question, the
16 Aug 2022 11:45:27,600 WARN [conf-file-poller-0] (org.apache.flume.conf.FlumeConfiguration$AgentConfiguration.validateConfigFilterSet:623) - Agent configuration for 'a1' has no configfilters.
16 Aug 2022 11:45:27,623 INFO [conf-file-poller-0] (org.apache.flume.conf.FlumeConfiguration.validateConfiguration:163) - Post-validation flume configuration contains configuration for agents: [a1]
16 Aug 2022 11:45:27,624 INFO [conf-file-poller-0] (org.apache.flume.node.AbstractConfigurationProvider.loadChannels:151) - Creating channels
16 Aug 2022 11:45:27,628 INFO [conf-file-poller-0] (org.apache.flume.channel.DefaultChannelFactory.create:42) - Creating instance of channel c1 type file
16 Aug 2022 11:45:27,642 INFO [conf-file-poller-0] (org.apache.flume.node.AbstractConfigurationProvider.loadChannels:205) - Created channel c1
16 Aug 2022 11:45:27,643 INFO [conf-file-poller-0] (org.apache.flume.source.DefaultSourceFactory.create:41) - Creating instance of source r1, type org.apache.flume.source.kafka.KafkaSource
16 Aug 2022 11:45:27,655 INFO [conf-file-poller-0] (org.apache.flume.sink.DefaultSinkFactory.create:42) - Creating instance of sink: k1, type: hdfs
16 Aug 2022 11:45:27,786 INFO [conf-file-poller-0] (org.apache.flume.node.AbstractConfigurationProvider.getConfiguration:120) - Channel c1 connected to [r1, k1]
16 Aug 2022 11:45:27,787 INFO [conf-file-poller-0] (org.apache.flume.node.Application.startAllComponents:162) - Starting new configuration:{ sourceRunners:{r1=PollableSourceRunner: { source:org.apache.flume.source.kafka.KafkaSource{name:r1,state:IDLE} counterGroup:{ name:null counters:{} } }} sinkRunners:{k1=SinkRunner: { policy:org.apache.flume.sink.DefaultSinkProcessor#2aa62fb9 counterGroup:{ name:null counters:{} } }} channels:{c1=FileChannel c1 { dataDirs: [/opt/module/flume/data/ranqi/behavior2] }} }
16 Aug 2022 11:45:27,788 INFO [conf-file-poller-0] (org.apache.flume.node.Application.startAllComponents:169) - Starting Channel c1
16 Aug 2022 11:45:27,790 INFO [conf-file-poller-0] (org.apache.flume.node.Application.startAllComponents:184) - Waiting for channel: c1 to start. Sleeping for 500 ms
16 Aug 2022 11:45:27,790 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.FileChannel.start:278) - Starting FileChannel c1 { dataDirs: [/opt/module/flume/data/ranqi/behavior2] }...
16 Aug 2022 11:45:27,833 INFO [lifecycleSupervisor-1-0] (org.apache.flume.instrumentation.MonitoredCounterGroup.register:119) - Monitored counter group for type: CHANNEL, name: c1: Successfully registered new MBean.
16 Aug 2022 11:45:27,833 INFO [lifecycleSupervisor-1-0] (org.apache.flume.instrumentation.MonitoredCounterGroup.start:95) - Component type: CHANNEL, name: c1 started
16 Aug 2022 11:45:27,839 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.Log.<init>:356) - Encryption is not enabled
16 Aug 2022 11:45:27,840 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.Log.replay:406) - Replay started
16 Aug 2022 11:45:27,845 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.Log.replay:418) - Found NextFileID 3, from [/opt/module/flume/data/ranqi/behavior2/log-3, /opt/module/flume/data/ranqi/behavior2/log-2]
16 Aug 2022 11:45:27,851 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.EventQueueBackingStoreFileV3.<init>:55) - Starting up with /opt/module/flume/checkpoint/ranqi/behavior2/checkpoint and /opt/module/flume/checkpoint/ranqi/behavior2/checkpoint.meta
16 Aug 2022 11:45:27,851 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.EventQueueBackingStoreFileV3.<init>:59) - Reading checkpoint metadata from /opt/module/flume/checkpoint/ranqi/behavior2/checkpoint.meta
16 Aug 2022 11:45:27,906 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.FlumeEventQueue.<init>:115) - QueueSet population inserting 0 took 0
16 Aug 2022 11:45:27,908 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.Log.replay:457) - Last Checkpoint Mon Aug 15 17:11:08 CST 2022, queue depth = 0
16 Aug 2022 11:45:27,918 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.Log.doReplay:542) - Replaying logs with v2 replay logic
16 Aug 2022 11:45:27,919 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.ReplayHandler.replayLog:249) - Starting replay of [/opt/module/flume/data/ranqi/behavior2/log-2, /opt/module/flume/data/ranqi/behavior2/log-3]
16 Aug 2022 11:45:27,920 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.ReplayHandler.replayLog:262) - Replaying /opt/module/flume/data/ranqi/behavior2/log-2
16 Aug 2022 11:45:27,925 INFO [lifecycleSupervisor-1-0] (org.apache.flume.tools.DirectMemoryUtils.getDefaultDirectMemorySize:112) - Unable to get maxDirectMemory from VM: NoSuchMethodException: sun.misc.VM.maxDirectMemory(null)
16 Aug 2022 11:45:27,926 INFO [lifecycleSupervisor-1-0] (org.apache.flume.tools.DirectMemoryUtils.allocate:48) - Direct Memory Allocation: Allocation = 1048576, Allocated = 0, MaxDirectMemorySize = 1908932608, Remaining = 1908932608
16 Aug 2022 11:45:27,982 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.LogFile$SequentialReader.skipToLastCheckpointPosition:660) - Checkpoint for file(/opt/module/flume/data/ranqi/behavior2/log-2) is: 1660554206424, which is beyond the requested checkpoint time: 1660555388025 and position 0
16 Aug 2022 11:45:27,982 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.ReplayHandler.replayLog:262) - Replaying /opt/module/flume/data/ranqi/behavior2/log-3
16 Aug 2022 11:45:27,983 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.LogFile$SequentialReader.skipToLastCheckpointPosition:658) - fast-forward to checkpoint position: 273662090
16 Aug 2022 11:45:27,983 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.LogFile$SequentialReader.next:683) - Encountered EOF at 273662090 in /opt/module/flume/data/ranqi/behavior2/log-3
16 Aug 2022 11:45:27,983 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.ReplayHandler.replayLog:345) - read: 0, put: 0, take: 0, rollback: 0, commit: 0, skip: 0, eventCount:0
16 Aug 2022 11:45:27,984 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.FlumeEventQueue.replayComplete:417) - Search Count = 0, Search Time = 0, Copy Count = 0, Copy Time = 0
16 Aug 2022 11:45:27,988 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.Log.replay:505) - Rolling /opt/module/flume/data/ranqi/behavior2
16 Aug 2022 11:45:27,988 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.Log.roll:990) - Roll start /opt/module/flume/data/ranqi/behavior2
16 Aug 2022 11:45:27,989 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.LogFile$Writer.<init>:220) - Opened /opt/module/flume/data/ranqi/behavior2/log-4
16 Aug 2022 11:45:27,996 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.Log.roll:1006) - Roll end
16 Aug 2022 11:45:27,996 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.EventQueueBackingStoreFile.beginCheckpoint:230) - Start checkpoint for /opt/module/flume/checkpoint/ranqi/behavior2/checkpoint, elements to sync = 0
16 Aug 2022 11:45:28,000 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.EventQueueBackingStoreFile.checkpoint:255) - Updating checkpoint metadata: logWriteOrderID: 1660621527859, queueSize: 0, queueHead: 557327
16 Aug 2022 11:45:28,008 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.Log.writeCheckpoint:1065) - Updated checkpoint for file: /opt/module/flume/data/ranqi/behavior2/log-4 position: 0 logWriteOrderID: 1660621527859
16 Aug 2022 11:45:28,008 INFO [lifecycleSupervisor-1-0] (org.apache.flume.channel.file.FileChannel.start:289) - Queue Size after replay: 0 [channel=c1]
16 Aug 2022 11:45:28,290 INFO [conf-file-poller-0] (org.apache.flume.node.Application.startAllComponents:196) - Starting Sink k1
16 Aug 2022 11:45:28,291 INFO [conf-file-poller-0] (org.apache.flume.node.Application.startAllComponents:207) - Starting Source r1
16 Aug 2022 11:45:28,292 INFO [lifecycleSupervisor-1-1] (org.apache.flume.instrumentation.MonitoredCounterGroup.register:119) - Monitored counter group for type: SINK, name: k1: Successfully registered new MBean.
16 Aug 2022 11:45:28,292 INFO [lifecycleSupervisor-1-1] (org.apache.flume.instrumentation.MonitoredCounterGroup.start:95) - Component type: SINK, name: k1 started
16 Aug 2022 11:45:28,292 INFO [lifecycleSupervisor-1-4] (org.apache.flume.source.kafka.KafkaSource.doStart:524) - Starting org.apache.flume.source.kafka.KafkaSource{name:r1,state:IDLE}...
flume agent start use shell command below.
#!/bin/bash
case $1 in
"start")
echo " --------start flume-------"
ssh hadoop104 "nohup /opt/module/flume/bin/flume-ng agent -n a1 -c /opt/module/flume/conf -f /opt/module/flume/job/ranqi/ranqi_kafka_to_hdfs_db.conf >/dev/null 2>&1 &"
;;
"stop")
echo " --------stop flume-------"
ssh hadoop104 "ps -ef | grep ranqi_kafka_to_hdfs_db.conf | grep -v grep |awk '{print \$2}' | xargs -n1 kill"
;;
esac
flume config is below.
a1.sources = r1
a1.channels = c1
a1.sinks = k1
a1.sources.r1.type = org.apache.flume.source.kafka.KafkaSource
a1.sources.r1.batchSize = 5000
a1.sources.r1.batchDurationMillis = 2000
a1.sources.r1.kafka.bootstrap.servers = hadoop102:9092,hadoop103:9092
a1.sources.r1.kafka.topics = copy_1015
a1.sources.r1.kafka.consumer.group.id = flume
a1.sources.r1.setTopicHeader = true
a1.sources.r1.topicHeader = topic
a1.sources.r1.interceptors = i1
a1.sources.r1.interceptors.i1.type = com.atguigu.flume.interceptor.ranqi.ranqiTimestampInterceptor$Builder
a1.channels.c1.type = file
a1.channels.c1.checkpointDir = /opt/module/flume/checkpoint/ranqi/behavior2
a1.channels.c1.dataDirs = /opt/module/flume/data/ranqi/behavior2/
a1.channels.c1.maxFileSize = 2146435071
a1.channels.c1.capacity = 1123456
a1.channels.c1.keep-alive = 6
## sink1
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path = /origin_data/ranqi/db/%{topic}_inc/%Y-%m-%d
a1.sinks.k1.hdfs.filePrefix = db
a1.sinks.k1.hdfs.round = false
a1.sinks.k1.hdfs.rollInterval = 10
a1.sinks.k1.hdfs.rollSize = 134217728
a1.sinks.k1.hdfs.rollCount = 0
a1.sinks.k1.hdfs.fileType = CompressedStream
a1.sinks.k1.hdfs.codeC = gzip
## 拼装
a1.sources.r1.channels = c1
a1.sinks.k1.channel= c1
ranqiTimestampInterceptor class I defined is below, which in flume/lib.
package com.atguigu.flume.interceptor.ranqi;
import com.alibaba.fastjson.JSONObject;
import com.atguigu.flume.interceptor.db.TimestampInterceptor;
import org.apache.flume.Context;
import org.apache.flume.Event;
import org.apache.flume.interceptor.Interceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
public class ranqiTimestampInterceptor implements Interceptor {
public static String dateToStamp(String s) throws ParseException {
String res;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = simpleDateFormat.parse(s);
long ts = date.getTime();
res = String.valueOf(ts);
return res;
}
#Override
public void initialize() {
}
private final static Logger logger = LoggerFactory.getLogger(ranqiTimestampInterceptor.class);
#Override
public Event intercept(Event event) {
byte[] body = event.getBody();
Long createDate ;
String time = new String();
String log = new String(body, StandardCharsets.UTF_8);
JSONObject jsonObject = JSONObject.parseObject(log);
// logger.info(log);
logger.info(String.valueOf(jsonObject));
JSONObject data = jsonObject.getObject("data", JSONObject.class);
if(data.containsKey("createDate") && data.getLong("createDate") != null){
createDate = data.getLong("createDate");
try {
createDate = Long.valueOf(dateToStamp(String.valueOf(createDate)));
time = String.valueOf(createDate);
} catch (ParseException e) {
e.printStackTrace();
}
finally {
Long ts = jsonObject.getLong("ts");
time = String.valueOf(ts);
}
}else{
Long ts = jsonObject.getLong("ts");
time = String.valueOf(ts);
}
System.out.println(time);
logger.info(time);
Map<String, String> headers = event.getHeaders();
headers.put("timestamp",time);
return event;
}
#Override
public List<Event> intercept(List<Event> list) {
for (Event event : list) {
intercept(event);
}
return list;
}
#Override
public void close() {
}
public static class Builder implements Interceptor.Builder{
#Override
public Interceptor build() {
return new TimestampInterceptor();
}
#Override
public void configure(Context context) {
}
}
}
.

Python Tika error: URLError: <urlopen error unknown url type: c>

I've been using a lot python tika to exctract text from some pdfs. Suddenly Tika doesn't work any more with the following code and similar:
from tika import parser
document = parser.from_file("prova.pdf")['content']
or
from tika import parser
parser.from_file("C:/Users/Daniele/Desktop/progetto_tesi_magistrale/prova.pdf")['content']
and every time I get this error:
2021-02-23 10:57:36,244 [MainThread ] [INFO ] Retrieving C:\Program Files\tika-server-1.24.1.jar to C:\Users\Daniele\AppData\Local\Temp\tika-server.jar.
---------------------------------------------------------------------------
URLError Traceback (most recent call last)
~\anaconda3\lib\site-packages\tika\tika.py in getRemoteJar(urlOrPath, destPath)
797 try:
--> 798 urlretrieve(urlOrPath, destPath)
799 except IOError:
~\anaconda3\lib\urllib\request.py in urlretrieve(url, filename, reporthook, data)
246
--> 247 with contextlib.closing(urlopen(url, data)) as fp:
248 headers = fp.info()
~\anaconda3\lib\urllib\request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
221 opener = _opener
--> 222 return opener.open(url, data, timeout)
223
~\anaconda3\lib\urllib\request.py in open(self, fullurl, data, timeout)
524 sys.audit('urllib.Request', req.full_url, req.data, req.headers, req.get_method())
--> 525 response = self._open(req, data)
526
~\anaconda3\lib\urllib\request.py in _open(self, req, data)
546
--> 547 return self._call_chain(self.handle_open, 'unknown',
548 'unknown_open', req)
~\anaconda3\lib\urllib\request.py in _call_chain(self, chain, kind, meth_name, *args)
501 func = getattr(handler, meth_name)
--> 502 result = func(*args)
503 if result is not None:
~\anaconda3\lib\urllib\request.py in unknown_open(self, req)
1420 type = req.type
-> 1421 raise URLError('unknown url type: %s' % type)
1422
URLError: <urlopen error unknown url type: c>
During handling of the above exception, another exception occurred:
URLError Traceback (most recent call last)
<ipython-input-4-5aa5aa48deec> in <module>
1 from tika import parser
2
----> 3 document = parser.from_file("prova.pdf")['content']
4 #import tika
5 #from tika import parser
~\anaconda3\lib\site-packages\tika\parser.py in from_file(filename, serverEndpoint, service, xmlContent, headers, config_path, requestOptions)
38 '''
39 if not xmlContent:
---> 40 output = parse1(service, filename, serverEndpoint, headers=headers, config_path=config_path, requestOptions=requestOptions)
41 else:
42 output = parse1(service, filename, serverEndpoint, services={'meta': '/meta', 'text': '/tika', 'all': '/rmeta/xml'},
~\anaconda3\lib\site-packages\tika\tika.py in parse1(option, urlOrPath, serverEndpoint, verbose, tikaServerJar, responseMimeType, services, rawResponse, headers, config_path, requestOptions)
334 headers.update({'Accept': responseMimeType, 'Content-Disposition': make_content_disposition_header(path.encode('utf-8') if type(path) is unicode_string else path)})
335 with urlOrPath if _is_file_object(urlOrPath) else open(path, 'rb') as f:
--> 336 status, response = callServer('put', serverEndpoint, service, f,
337 headers, verbose, tikaServerJar, config_path=config_path,
338 rawResponse=rawResponse, requestOptions=requestOptions)
~\anaconda3\lib\site-packages\tika\tika.py in callServer(verb, serverEndpoint, service, data, headers, verbose, tikaServerJar, httpVerbs, classpath, rawResponse, config_path, requestOptions)
529 global TikaClientOnly
530 if not TikaClientOnly:
--> 531 serverEndpoint = checkTikaServer(scheme, serverHost, port, tikaServerJar, classpath, config_path)
532
533 serviceUrl = serverEndpoint + service
~\anaconda3\lib\site-packages\tika\tika.py in checkTikaServer(scheme, serverHost, port, tikaServerJar, classpath, config_path)
590 if not alreadyRunning:
591 if not os.path.isfile(jarPath) and urlp.scheme != '':
--> 592 getRemoteJar(tikaServerJar, jarPath)
593
594 if not checkJarSig(tikaServerJar, jarPath):
~\anaconda3\lib\site-packages\tika\tika.py in getRemoteJar(urlOrPath, destPath)
806 if os.path.exists(destPath) and os.path.isfile(destPath):
807 os.remove(destPath)
--> 808 urlretrieve(urlOrPath, destPath)
809
810 return (destPath, 'remote')
~\anaconda3\lib\urllib\request.py in urlretrieve(url, filename, reporthook, data)
245 url_type, path = _splittype(url)
246
--> 247 with contextlib.closing(urlopen(url, data)) as fp:
248 headers = fp.info()
249
~\anaconda3\lib\urllib\request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
220 else:
221 opener = _opener
--> 222 return opener.open(url, data, timeout)
223
224 def install_opener(opener):
~\anaconda3\lib\urllib\request.py in open(self, fullurl, data, timeout)
523
524 sys.audit('urllib.Request', req.full_url, req.data, req.headers, req.get_method())
--> 525 response = self._open(req, data)
526
527 # post-process response
~\anaconda3\lib\urllib\request.py in _open(self, req, data)
545 return result
546
--> 547 return self._call_chain(self.handle_open, 'unknown',
548 'unknown_open', req)
549
~\anaconda3\lib\urllib\request.py in _call_chain(self, chain, kind, meth_name, *args)
500 for handler in handlers:
501 func = getattr(handler, meth_name)
--> 502 result = func(*args)
503 if result is not None:
504 return result
~\anaconda3\lib\urllib\request.py in unknown_open(self, req)
1419 def unknown_open(self, req):
1420 type = req.type
-> 1421 raise URLError('unknown url type: %s' % type)
1422
1423 def parse_keqv_list(l):
URLError: <urlopen error unknown url type: c>
I tried to unistall tika python, tika server, java, python... basically everything. And the strange thing is that suddenly I have the same issue in my second pc.
Any suggestions ? Thanks a lot.

Unable to receive a message from Azure Service Bus in Qpid JMS (qpid-jms-client-0.11.1.jar) sent from a .Net app

I have created 2 Java Demo applications which connects to an already configured Azure Service Bus using the following guides:
How to use the Java Message Service (JMS) API with Service Bus and AMQP 1.0 - azure.microsoft.com/nl-nl/documentation/articles/service-bus-java-how-to-use-jms-api-amqp
Qpid JMS 0.11.1 documentation - qpid.apache.org/releases/qpid-jms-0.11.1/docs/index.html
The Sender.java app can successfully place a message in a queue on the preconfigured Azure Service Bus.
The SimpleReceiver.java app is setup to receive a message from a queue on Azure ServiceBus.
Currently the SimpleReceiver.java can successfully receive a message that was originally sent from the Sender.java app to the Service Bus. But fails to receive messasges that where sent by a .Net(C#) Sender.cs app.
How Can I implement/setup the SimpleReceiver.java to receive all messages from the Azure Service Bus Queue? (using Qpid JMS 0.11.1)
Side note: I am able to achieve this using the older library Qpid JMS 0.32. But version 0.11.1 is a necessity.
To sum up what i have so far:
[works] Sender.java -> Azure Service Bus -> SimpleReceiver.java
[works] Sender.java -> Azure Service Bus -> (.Net) Receiver.cs
[works] (.Net) Sender.cs -> Azure Service Bus -> (.Net) Receiver.cs
[fails] (.Net) Sender.cs -> Azure Service Bus -> SimpleReceiver.java
When I try to receive messages sent by .Net with the SimpleReceiver.java i get the following traces/log:
2016-11-07 09:44:18,778 [ntLoopGroup-2-1] - TRACE NettyTcpTransport - SSL Handshake has completed: [id: 0xe1a2112b, L:/10.70.1.160:57828 - R:demo-sandbox-open-bus.servicebus.windows.net/13.69.253.135:5671]
2016-11-07 09:44:18,778 [ntLoopGroup-2-1] - TRACE NettyTcpTransport - Channel has become active! Channel is [id: 0xe1a2112b, L:/10.70.1.160:57828 - R:demo-sandbox-open-bus.servicebus.windows.net/13.69.253.135:5671]
2016-11-07 09:44:18,778 [ntLoopGroup-2-1] - DEBUG SslHandler - [id: 0xe1a2112b, L:/10.70.1.160:57828 - R:demo-sandbox-open-bus.servicebus.windows.net/13.69.253.135:5671] HANDSHAKEN: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
connection :org.apache.qpid.jms.JmsConnection#c1c084f
2016-11-07 09:44:18,813 [us.windows.net]] - TRACE MetaDataSupport - Problem generating primary version details
java.lang.NullPointerException
at java.util.regex.Matcher.getTextLength(Matcher.java:1234)
at java.util.regex.Matcher.reset(Matcher.java:308)
at java.util.regex.Matcher.<init>(Matcher.java:228)
at java.util.regex.Pattern.matcher(Pattern.java:1088)
at org.apache.qpid.jms.util.MetaDataSupport.<clinit>(MetaDataSupport.java:47)
at org.apache.qpid.jms.provider.amqp.builders.AmqpConnectionBuilder.createEndpoint(AmqpConnectionBuilder.java:108)
at org.apache.qpid.jms.provider.amqp.builders.AmqpConnectionBuilder.createEndpoint(AmqpConnectionBuilder.java:41)
at org.apache.qpid.jms.provider.amqp.builders.AmqpResourceBuilder.buildResource(AmqpResourceBuilder.java:72)
at org.apache.qpid.jms.provider.amqp.builders.AmqpConnectionBuilder.buildResource(AmqpConnectionBuilder.java:94)
at org.apache.qpid.jms.provider.amqp.AmqpProvider$4$1.processConnectionInfo(AmqpProvider.java:323)
at org.apache.qpid.jms.meta.JmsConnectionInfo.visit(JmsConnectionInfo.java:373)
at org.apache.qpid.jms.provider.amqp.AmqpProvider$4.run(AmqpProvider.java:252)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
2016-11-07 09:44:18,819 [us.windows.net]] - TRACE NettyTcpTransport - Attempted write of: 8 bytes
2016-11-07 09:44:18,845 [ntLoopGroup-2-1] - TRACE NettyTcpTransport - New data read: 8 bytes incoming: UnpooledUnsafeHeapByteBuf(ridx: 0, widx: 8, cap: 37)
2016-11-07 09:44:18,846 [us.windows.net]] - TRACE AmqpProvider - New Proton Event: CONNECTION_INIT
2016-11-07 09:44:18,847 [us.windows.net]] - TRACE AmqpProvider - New Proton Event: CONNECTION_LOCAL_OPEN
2016-11-07 09:44:18,926 [ntLoopGroup-2-1] - TRACE NettyTcpTransport - New data read: 63 bytes incoming: UnpooledUnsafeHeapByteBuf(ridx: 0, widx: 63, cap: 101)
2016-11-07 09:44:18,928 [us.windows.net]] - DEBUG SaslMechanismFinder - Unknown SASL mechanism: [MSSBCBS]
2016-11-07 09:44:18,931 [us.windows.net]] - DEBUG SaslMechanismFinder - Skipping SASL-EXTERNAL mechanism because the available credentials are not sufficient
2016-11-07 09:44:18,931 [us.windows.net]] - INFO SaslMechanismFinder - Best match for SASL auth was: SASL-PLAIN
2016-11-07 09:44:18,933 [us.windows.net]] - TRACE NettyTcpTransport - Attempted write of: 125 bytes
2016-11-07 09:44:18,958 [ntLoopGroup-2-1] - TRACE NettyTcpTransport - New data read: 26 bytes incoming: UnpooledUnsafeHeapByteBuf(ridx: 0, widx: 26, cap: 53)
[395414939:0] -> Open{ containerId='ID:9669bcc7-59c0-43eb-9908-00605f8153dd:1', hostname='demo-sandbox-open-bus.servicebus.windows.net', maxFrameSize=1048576, channelMax=32767, idleTimeOut=75000, outgoingLocales=null, incomingLocales=null, offeredCapabilities=null, desiredCapabilities=[sole-connection-for-container], properties={product=QpidJMS, version=0.11.1, platform=JVM: 1.7.0_75, 24.75-b04, Oracle Corporation, OS: Windows 8.1, 6.3, amd64}}
2016-11-07 09:44:18,961 [us.windows.net]] - TRACE FRAMES - SENT: Open{ containerId='ID:9669bcc7-59c0-43eb-9908-00605f8153dd:1', hostname='demo-sandbox-open-bus.servicebus.windows.net', maxFrameSize=1048576, channelMax=32767, idleTimeOut=75000, outgoingLocales=null, incomingLocales=null, offeredCapabilities=null, desiredCapabilities=[sole-connection-for-container], properties={product=QpidJMS, version=0.11.1, platform=JVM: 1.7.0_75, 24.75-b04, Oracle Corporation, OS: Windows 8.1, 6.3, amd64}}
2016-11-07 09:44:18,961 [us.windows.net]] - TRACE NettyTcpTransport - Attempted write of: 290 bytes
2016-11-07 09:44:18,985 [ntLoopGroup-2-1] - TRACE NettyTcpTransport - New data read: 8 bytes incoming: UnpooledUnsafeHeapByteBuf(ridx: 0, widx: 8, cap: 37)
2016-11-07 09:44:19,061 [ntLoopGroup-2-1] - TRACE NettyTcpTransport - New data read: 70 bytes incoming: UnpooledUnsafeHeapByteBuf(ridx: 0, widx: 70, cap: 101)
[395414939:0] <- Open{ containerId='d3a14a268d4c45b1a5f6acabc01c1bdd_G43', hostname='null', maxFrameSize=65536, channelMax=4999, idleTimeOut=240000, outgoingLocales=null, incomingLocales=null, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,061 [us.windows.net]] - TRACE FRAMES - RECV: Open{ containerId='d3a14a268d4c45b1a5f6acabc01c1bdd_G43', hostname='null', maxFrameSize=65536, channelMax=4999, idleTimeOut=240000, outgoingLocales=null, incomingLocales=null, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,061 [us.windows.net]] - TRACE AmqpProvider - New Proton Event: CONNECTION_REMOTE_OPEN
2016-11-07 09:44:19,064 [us.windows.net]] - TRACE AmqpProvider - New Proton Event: SESSION_INIT
2016-11-07 09:44:19,064 [us.windows.net]] - TRACE AmqpProvider - New Proton Event: SESSION_LOCAL_OPEN
[395414939:0] -> Begin{remoteChannel=null, nextOutgoingId=1, incomingWindow=2047, outgoingWindow=2147483647, handleMax=65535, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,066 [us.windows.net]] - TRACE FRAMES - SENT: Begin{remoteChannel=null, nextOutgoingId=1, incomingWindow=2047, outgoingWindow=2147483647, handleMax=65535, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,066 [us.windows.net]] - TRACE NettyTcpTransport - Attempted write of: 32 bytes
2016-11-07 09:44:19,091 [ntLoopGroup-2-1] - TRACE NettyTcpTransport - New data read: 34 bytes incoming: UnpooledUnsafeHeapByteBuf(ridx: 0, widx: 34, cap: 69)
[395414939:0] <- Begin{remoteChannel=0, nextOutgoingId=1, incomingWindow=5000, outgoingWindow=2047, handleMax=255, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,091 [us.windows.net]] - TRACE FRAMES - RECV: Begin{remoteChannel=0, nextOutgoingId=1, incomingWindow=5000, outgoingWindow=2047, handleMax=255, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,091 [us.windows.net]] - TRACE AmqpProvider - New Proton Event: SESSION_REMOTE_OPEN
2016-11-07 09:44:19,091 [us.windows.net]] - DEBUG AmqpConnectionBuilder - AmqpConnection { ID:13845de8-37ce-42de-8d5d-2e4d9de7352f:1 } is now open:
2016-11-07 09:44:19,091 [us.windows.net]] - TRACE AmqpProvider - IdleTimeoutCheck being initiated, initial delay: 120000
2016-11-07 09:44:19,092 [us.windows.net]] - INFO JmsConnection - Connection ID:13845de8-37ce-42de-8d5d-2e4d9de7352f:1 connected to remote Broker: amqps://demo-sandbox-open-bus.servicebus.windows.net
[395414939:1] -> Begin{remoteChannel=null, nextOutgoingId=1, incomingWindow=2047, outgoingWindow=2147483647, handleMax=65535, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,102 [us.windows.net]] - TRACE FRAMES - SENT: Begin{remoteChannel=null, nextOutgoingId=1, incomingWindow=2047, outgoingWindow=2147483647, handleMax=65535, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,102 [us.windows.net]] - TRACE NettyTcpTransport - Attempted write of: 32 bytes
2016-11-07 09:44:19,126 [ntLoopGroup-2-1] - TRACE NettyTcpTransport - New data read: 34 bytes incoming: UnpooledUnsafeHeapByteBuf(ridx: 0, widx: 34, cap: 69)
[395414939:1] <- Begin{remoteChannel=1, nextOutgoingId=1, incomingWindow=5000, outgoingWindow=2047, handleMax=255, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,126 [us.windows.net]] - TRACE FRAMES - RECV: Begin{remoteChannel=1, nextOutgoingId=1, incomingWindow=5000, outgoingWindow=2047, handleMax=255, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,126 [us.windows.net]] - TRACE AmqpProvider - New Proton Event: SESSION_INIT
2016-11-07 09:44:19,126 [us.windows.net]] - TRACE AmqpProvider - New Proton Event: SESSION_LOCAL_OPEN
2016-11-07 09:44:19,126 [us.windows.net]] - TRACE AmqpProvider - New Proton Event: SESSION_REMOTE_OPEN
[395414939:1] -> Attach{name='qpid-jms:receiver:ID:13845de8-37ce-42de-8d5d-2e4d9de7352f:1:1:1:a_receiver/verwerker/klant', handle=0, role=RECEIVER, sndSettleMode=UNSETTLED, rcvSettleMode=FIRST, source=Source{address='a_receiver/verwerker/klant', durable=NONE, expiryPolicy=LINK_DETACH, timeout=0, dynamic=false, dynamicNodeProperties=null, distributionMode=null, filter=null, defaultOutcome=Modified{deliveryFailed=true, undeliverableHere=null, messageAnnotations=null}, outcomes=[amqp:accepted:list, amqp:rejected:list, amqp:released:list, amqp:modified:list], capabilities=[queue]}, target=Target{address='null', durable=NONE, expiryPolicy=SESSION_END, timeout=0, dynamic=false, dynamicNodeProperties=null, capabilities=null}, unsettled=null, incompleteUnsettled=false, initialDeliveryCount=null, maxMessageSize=null, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,138 [us.windows.net]] - TRACE FRAMES - SENT: Attach{name='qpid-jms:receiver:ID:13845de8-37ce-42de-8d5d-2e4d9de7352f:1:1:1:a_receiver/verwerker/klant', handle=0, role=RECEIVER, sndSettleMode=UNSETTLED, rcvSettleMode=FIRST, source=Source{address='a_receiver/verwerker/klant', durable=NONE, expiryPolicy=LINK_DETACH, timeout=0, dynamic=false, dynamicNodeProperties=null, distributionMode=null, filter=null, defaultOutcome=Modified{deliveryFailed=true, undeliverableHere=null, messageAnnotations=null}, outcomes=[amqp:accepted:list, amqp:rejected:list, amqp:released:list, amqp:modified:list], capabilities=[queue]}, target=Target{address='null', durable=NONE, expiryPolicy=SESSION_END, timeout=0, dynamic=false, dynamicNodeProperties=null, capabilities=null}, unsettled=null, incompleteUnsettled=false, initialDeliveryCount=null, maxMessageSize=null, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,138 [us.windows.net]] - TRACE NettyTcpTransport - Attempted write of: 276 bytes
2016-11-07 09:44:19,164 [ntLoopGroup-2-1] - TRACE NettyTcpTransport - New data read: 310 bytes incoming: UnpooledUnsafeHeapByteBuf(ridx: 0, widx: 310, cap: 341)
[395414939:1] <- Attach{name='qpid-jms:receiver:ID:13845de8-37ce-42de-8d5d-2e4d9de7352f:1:1:1:a_receiver/verwerker/klant', handle=0, role=SENDER, sndSettleMode=MIXED, rcvSettleMode=SECOND, source=Source{address='a_receiver/verwerker/klant', durable=NONE, expiryPolicy=LINK_DETACH, timeout=0, dynamic=false, dynamicNodeProperties=null, distributionMode=null, filter=null, defaultOutcome=Modified{deliveryFailed=true, undeliverableHere=null, messageAnnotations=null}, outcomes=[amqp:accepted:list, amqp:rejected:list, amqp:released:list, amqp:modified:list], capabilities=[queue]}, target=Target{address='null', durable=NONE, expiryPolicy=SESSION_END, timeout=0, dynamic=false, dynamicNodeProperties=null, capabilities=null}, unsettled=null, incompleteUnsettled=false, initialDeliveryCount=0, maxMessageSize=266240, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,164 [us.windows.net]] - TRACE FRAMES - RECV: Attach{name='qpid-jms:receiver:ID:13845de8-37ce-42de-8d5d-2e4d9de7352f:1:1:1:a_receiver/verwerker/klant', handle=0, role=SENDER, sndSettleMode=MIXED, rcvSettleMode=SECOND, source=Source{address='a_receiver/verwerker/klant', durable=NONE, expiryPolicy=LINK_DETACH, timeout=0, dynamic=false, dynamicNodeProperties=null, distributionMode=null, filter=null, defaultOutcome=Modified{deliveryFailed=true, undeliverableHere=null, messageAnnotations=null}, outcomes=[amqp:accepted:list, amqp:rejected:list, amqp:released:list, amqp:modified:list], capabilities=[queue]}, target=Target{address='null', durable=NONE, expiryPolicy=SESSION_END, timeout=0, dynamic=false, dynamicNodeProperties=null, capabilities=null}, unsettled=null, incompleteUnsettled=false, initialDeliveryCount=0, maxMessageSize=266240, offeredCapabilities=null, desiredCapabilities=null, properties=null}
2016-11-07 09:44:19,165 [us.windows.net]] - TRACE AmqpProvider - New Proton Event: LINK_INIT
2016-11-07 09:44:19,165 [us.windows.net]] - TRACE AmqpProvider - New Proton Event: LINK_LOCAL_OPEN
2016-11-07 09:44:19,165 [us.windows.net]] - TRACE AmqpProvider - New Proton Event: LINK_REMOTE_OPEN
2016-11-07 09:44:19,166 [us.windows.net]] - TRACE AmqpConsumer - Consumer ID:13845de8-37ce-42de-8d5d-2e4d9de7352f:1:1:1 granting additional credit: 1000
receiver.getMessageSelector(): is null
[395414939:1] -> Flow{nextIncomingId=1, incomingWindow=2047, nextOutgoingId=1, outgoingWindow=2147483647, handle=0, deliveryCount=0, linkCredit=1000, available=null, drain=false, echo=false, properties=null}
2016-11-07 09:44:19,167 [us.windows.net]] - TRACE FRAMES - SENT: Flow{nextIncomingId=1, incomingWindow=2047, nextOutgoingId=1, outgoingWindow=2147483647, handle=0, deliveryCount=0, linkCredit=1000, available=null, drain=false, echo=false, properties=null}
2016-11-07 09:44:19,167 [us.windows.net]] - TRACE NettyTcpTransport - Attempted write of: 35 bytes
Type 'exit' + [enter] to quit.
2016-11-07 09:44:19,194 [ntLoopGroup-2-1] - TRACE NettyTcpTransport - New data read: 548 bytes incoming: UnpooledUnsafeHeapByteBuf(ridx: 0, widx: 548, cap: 581)
[395414939:1] <- Transfer{handle=0, deliveryId=0, deliveryTag=~\x00\x5c#\xa0j\xd6A\x92N\x82\x91\x1a\x09\xd3\x12, messageFormat=0, settled=null, more=false, rcvSettleMode=null, state=null, resume=false, aborted=false, batchable=true} (506) "\x00Sp\xc0\x0a\x05##p\x0er\xbb\x00#C\x00Sr\xc1\x5c\x06\xa3\x13x-opt-enqueued-time\x83\x00\x00\x01X=\xf5\x108\xa3\x15x-opt-sequence-number\x81\x00\x00\x00\x00\x00\x00\x01\xca\xa3\x12x-opt-locked-until\x83\x00\x00\x01X=\xf6\x96\xcf\x00Ss\xc0=\x0d\xa1\x1dtestsender2016-11-07T09:43:38#####\xa3\x10application/json######\x00St\xc1\xb5\x0e\xa1\x0bMessageType\xa1\x0fDocumentMessage\xa1\x0cSourceSystem\xa1\x0asis_sender\xa1\x0dEnterpriseKey\xa1\x18sis_sender-klant-bericht\xa1\x08TenantId\xa1\x05klant\xa1\x09EventType\xa1\x07bericht\xa1\x10EventTypeVersion\xa1\x031.0\xa1\x0dOperationType\xa1\x06Create\x00Su\xa0\x89#\x06string\x083http://schemas.microsoft.com/2003/10/Serialization/\x99J{"id": 1,"name": "A .net door","price": 12.50,"tags": ["home", "C# .Net"]}"
2016-11-07 09:44:19,201 [us.windows.net]] - TRACE FRAMES - RECV: Transfer{handle=0, deliveryId=0, deliveryTag=~\x00\x5c#\xa0j\xd6A\x92N\x82\x91\x1a\x09\xd3\x12, messageFormat=0, settled=null, more=false, rcvSettleMode=null, state=null, resume=false, aborted=false, batchable=true}
2016-11-07 09:44:19,203 [us.windows.net]] - TRACE AmqpProvider - New Proton Event: DELIVERY
2016-11-07 09:44:19,203 [us.windows.net]] - TRACE AmqpConsumer - AmqpConsumer { ID:13845de8-37ce-42de-8d5d-2e4d9de7352f:1:1:1 } has incoming Message(s).
2016-11-07 09:44:19,210 [us.windows.net]] - DEBUG AmqpConsumer - Dispatching received message: JmsInboundMessageDispatch {sequence = 1, messageId = testsender2016-11-07T09:43:38, consumerId = ID:13845de8-37ce-42de-8d5d-2e4d9de7352f:1:1:1}
2016-11-07 09:44:19,211 [1:1] dispatcher] - TRACE JmsMessageConsumer - checking envelope with 0 redeliveries
2016-11-07 09:44:19,212 [us.windows.net]] - DEBUG AmqpConsumer - Delivered Ack of message: JmsInboundMessageDispatch {sequence = 1, messageId = testsender2016-11-07T09:43:38, consumerId = ID:13845de8-37ce-42de-8d5d-2e4d9de7352f:1:1:1}
I also have a comparison of a message sent by Java vs one sent by .net(C#) (messages exported from Service Bus Explorer). I have a feeling it has something to do with the contentType/ type of message sent.
Below are traces/logs of a successfull message sent by Java and a Unsucceful message sent by .Net:
[2138532527:1] <- Transfer{handle=0, deliveryId=0, deliveryTag=Z\x80\x91\x15\xa3v{D\x96`\x04\x1ad\xb8;V, messageFormat=0, settled=null, more=false, rcvSettleMode=null, state=null, resume=false, aborted=false, batchable=true} (529) "\x00Sp\xc0\x0a\x05B#p\x0er\xbb\x00#C\x00Sr\xc1\x84\x0a\xa3\x12x-opt-jms-msg-typeQ\x05\xa3\x0ex-opt-jms-destQ\x00\xa3\x13x-opt-enqueued-time\x83\x00\x00\x01X*i\x17!\xa3\x15x-opt-sequence-number\x81\x00\x00\x00\x00\x00\x00\x01\xa9\xa3\x12x-opt-locked-until\x83\x00\x00\x01X*j\x01\x91\x00Ss\xc0t\x0d\xa1/ID:e076122e-f27d-4cdd-9b13-33e75716d70a:1:1:1-1#\xa1\x1csis_receiver/verwerker/klant\xa1\x10application/json#####\x83\x00\x00\x01X*i\x12h###\x00St\xc1\xb5\x0e\xa1\x08TenantId\xa1\x05klant\xa1\x0dEnterpriseKey\xa1\x18sis_sender-klant-bericht\xa1\x09EventType\xa1\x07bericht\xa1\x10EventTypeVersion\xa1\x031.0\xa1\x0bMessageType\xa1\x0fDocumentMessage\xa1\x0dOperationType\xa1\x06Create\xa1\x0cSourceSystem\xa1\x0asis_sender\x00Sw\xa1A{"logged":false,"userID":"0","bericht Marvin Java":"test body2"} "
Received message with JMSMessageID = ID:e076122e-f27d-4cdd-9b13-33e75716d70a:1:1:1-1
[2138532527:1] -> Disposition{role=RECEIVER, first=0, last=0, settled=true, state=Accepted{}, batchable=false}
[2138532527:1] <- Transfer{handle=0, deliveryId=1, deliveryTag=\xd7\xbb\x1b\xcb>\x91\x14O\xa2\x83q\x9e\xc9|N\x09, messageFormat=0, settled=null, more=false, rcvSettleMode=null, state=null, resume=false, aborted=false, batchable=true} (504) "\x00Sp\xc0\x0a\x05##p\x0er\xbb\x00#C\x00Sr\xc1\x5c\x06\xa3\x13x-opt-enqueued-time\x83\x00\x00\x01X*i\x5c\x10\xa3\x15x-opt-sequence-number\x81\x00\x00\x00\x00\x00\x00\x01\xaa\xa3\x12x-opt-locked-until\x83\x00\x00\x01X*jFp\x00Ss\xc0=\x0d\xa1\x1dtestsender2016-11-03T14:38:15#####\xa3\x10application/json######\x00St\xc1\xb5\x0e\xa1\x0bMessageType\xa1\x0fDocumentMessage\xa1\x0cSourceSystem\xa1\x0asis_sender\xa1\x0dEnterpriseKey\xa1\x18sis_sender-klant-bericht\xa1\x08TenantId\xa1\x05klant\xa1\x09EventType\xa1\x07bericht\xa1\x10EventTypeVersion\xa1\x031.0\xa1\x0dOperationType\xa1\x06Create\x00Su\xa0\x87#\x06string\x083http://schemas.microsoft.com/2003/10/Serialization/\x99H{"id": 1,"name": "A .net door","price": 12.50,"tags": ["home", "green"]}"
I have the follwing properties file servicebus.properties:
# Set the InitialContextFactory class to use
java.naming.factory.initial = org.apache.qpid.jms.jndi.JmsInitialContextFactory
# Define the required ConnectionFactory instances
# connectionfactory.<JNDI-lookup-name> = <URI>
connectionfactory.myFactoryLookup = amqps://demo-sandbox-open-bus.servicebus.windows.net?amqp.idleTimeout=150000&amqp.traceFrames=true&jms.username=somePolicy&jms.password=aM1k3PaXY5jdIkmGKm7G%2FcH%2BUFQaFAgHIYc3dSsuiLI%3D
# Register some queues in JNDI using the form
# queue.[jndi_name] = [physical_name]
# topic.[jndi_name] = [physical_name]
queue.myQueueLookup = queue1
I have the following class SimpleReceiver.java:
package com.demo.AzureTest;
import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Hashtable;
import java.util.Random;
public class SimpleReceiver implements MessageListener {
private Connection connection;
private Session receiveSession;
private MessageConsumer receiver;
private static Random randomGenerator = new Random();
public SimpleReceiver() throws Exception {
Context context = new InitialContext();
ConnectionFactory cf = (ConnectionFactory) context.lookup("myFactoryLookup");
Destination queue = (Destination) context.lookup("myQueueLookup");
// Create Connection
connection = cf.createConnection();
System.out.println("connection :"+connection);
// Create receiver-side Session, MessageConsumer,and MessageListener
receiveSession = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
receiver = receiveSession.createConsumer(queue);
if (receiver.getMessageSelector() != null){
System.out.println("receiver.getMessageSelector(): " + receiver.getMessageSelector());
}
else {
System.out.println("receiver.getMessageSelector(): is null" );
}
receiver.setMessageListener(this);
connection.start();
}
public static void main(String[] args) {
try {
SimpleReceiver simpleSenderReceiver = new SimpleReceiver();
System.out.println("Type 'exit' + [enter] to quit.");
BufferedReader commandLine = new java.io.BufferedReader(new InputStreamReader(System.in));
while (true) {
String s = commandLine.readLine();
if (s.equalsIgnoreCase("exit")) {
simpleSenderReceiver.close();
System.exit(0);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void close() throws JMSException {
connection.close();
}
public void onMessage(Message message) {
try {
System.out.println("Received message with JMSMessageID = " + message.getJMSMessageID());
TextMessage txtmessage = (TextMessage) message;
System.out.println("Received message with Text = " + txtmessage.getText());
message.acknowledge();
} catch (Exception e) {
e.printStackTrace();
}
}
}
I have the following class Sender.java:
package com.demo.QpidTest;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.ExceptionListener;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
public class Sender {
private static final int DEFAULT_COUNT = 1;
private static final int DELIVERY_MODE = DeliveryMode.NON_PERSISTENT;
private static Random randomGenerator = new Random();
public static void main(String[] args) throws Exception {
int count = DEFAULT_COUNT;
if (args.length == 0) {
System.out.println("Sending up to " + count + " messages.");
} else {
count = Integer.parseInt(args[0]);
System.out.println("Sending up to " + count + " messages.");
}
try {
// The configuration for the Qpid InitialContextFactory has been supplied in
// a jndi.properties file in the classpath, which results in it being picked
// up automatically by the InitialContext constructor.
Context context = new InitialContext();
ConnectionFactory factory = (ConnectionFactory) context.lookup("myFactoryLookup");
Destination queue = (Destination) context.lookup("myQueueLookup");
Connection connection = factory.createConnection();
connection.setExceptionListener(new MyExceptionListener());
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer messageProducer = session.createProducer(queue);
long start = System.currentTimeMillis();
for (int i = 1; i <= count; i++) {
// TextMessage message = session.createTextMessage("Text!");
TextMessage message = session.createTextMessage("{\"id\": 1,\"name\": \"A .net door\",\"price\": 12.50,\"tags\": [\"home\", \"green\"]}");
long randomMessageID = randomGenerator.nextLong() >>>1;
message.setStringProperty("TenantId", "klant");
message.setStringProperty("EventType", "bericht");
message.setStringProperty("EventTypeVersion", "1.0");
message.setStringProperty("MessageType", "DocumentMessage");
message.setStringProperty("OperationType", "Create");
message.setStringProperty("SourceSystem", "sis_sender");
message.setStringProperty("EnterpriseKey", "sender-lant-bericht");
message.setJMSMessageID("ID:" + randomMessageID);
messageProducer.send(message, DELIVERY_MODE, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
if (i % 100 == 0) {
System.out.println("Sent message " + i);
}
}
long finish = System.currentTimeMillis();
long taken = finish - start;
System.out.println("Sent " + count + " messages in " + taken + "ms");
connection.close();
} catch (Exception exp) {
System.out.println("Caught exception, exiting.");
exp.printStackTrace(System.out);
System.exit(1);
}
}
private static class MyExceptionListener implements ExceptionListener {
#Override
public void onException(JMSException exception) {
System.out.println("Connection ExceptionListener fired, exiting.");
exception.printStackTrace(System.out);
System.exit(1);
}
}
}

RabbitMQ Messaging with QPID 0.32 client

Using QPID Java Client i can only get messages delivered through the exchange to the bound queue using the following expanded syntax of AMQAnyDestination
Destination queue = new AMQAnyDestination( new AMQShortString("onms2"),
new AMQShortString("direct"),
new AMQShortString("Simon"),
true,
true,
new AMQShortString(""),
false,
bindvars);
If i attempt to use the different form which just specifies the address as follows it doesnt work:-
Destination queue = new AMQAnyDestination("onms2/Simon");
The message hits RabbitMQ ok but is not delivered.
Qpid 0.32 Client
Rabbit MQ 3.5.7
Exchange onms
Routing Key Simon
I have been using the qpid examples and modifying the ListSender example as below
package org.apache.qpid.example;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Session;
import org.apache.qpid.client.AMQAnyDestination;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.jms.ListMessage;
public class ListSender {
public static void main(String[] args) throws Exception
{
Connection connection =
new AMQConnection("amqp://simon:simon#localhost/test?brokerlist='tcp://localhost:5672'");
AMQShortString a1 = new AMQShortString("");
AMQShortString a2 = new AMQShortString("");
AMQShortString[] bindvars = new AMQShortString[]{a1,a2};
boolean is_durable = true;
/*
Destination queue = new AMQAnyDestination( new AMQShortString("onms2"),
new AMQShortString("direct"),
new AMQShortString("Simon"),
true,
true,
new AMQShortString(""),
false,
bindvars);
*/
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination queue = new AMQAnyDestination("onms2/Simon");
//Destination queue = new AMQAnyDestination("amqp:OpenNMSExchange/Taylor; {create: always}");
//Destination queue = new AMQAnyDestination("OpenNMSExchange; {create: always}");
MessageProducer producer = session.createProducer(queue);
ListMessage m = ((org.apache.qpid.jms.Session)session).createListMessage();
m.setIntProperty("Id", 987654321);
m.setStringProperty("name", "WidgetSimon");
m.setDoubleProperty("price", 0.99);
List<String> colors = new ArrayList<String>();
colors.add("red");
colors.add("green");
colors.add("white");
m.add(colors);
Map<String,Double> dimensions = new HashMap<String,Double>();
dimensions.put("length",10.2);
dimensions.put("width",5.1);
dimensions.put("depth",2.0);
m.add(dimensions);
List<List<Integer>> parts = new ArrayList<List<Integer>>();
parts.add(Arrays.asList(new Integer[] {1,2,5}));
parts.add(Arrays.asList(new Integer[] {8,2,5}));
m.add(parts);
Map<String,Object> specs = new HashMap<String,Object>();
specs.put("colours", colors);
specs.put("dimensions", dimensions);
specs.put("parts", parts);
m.add(specs);
producer.send((Message)m);
System.out.println("Sent: " + m);
connection.close();
}
}
When it works using the expanded format of AMQAnyDestination the debug logs looks like this:-
163 [main] INFO org.apache.qpid.client.AMQConnection - Connection 1 now connected from /127.0.0.1:43298 to localhost/127.0.0.1:5672
163 [main] DEBUG org.apache.qpid.client.AMQConnection - Are we connected:true
163 [main] DEBUG org.apache.qpid.client.AMQConnection - Connected with ProtocolHandler Version:0-91
166 [main] DEBUG org.apache.qpid.client.AMQDestination - Based on direct://onms2/Simon/?routingkey='Simon'&exclusive='true'&autodelete='true' the selected destination syntax is BURL
169 [main] DEBUG org.apache.qpid.client.AMQConnectionDelegate_8_0 - Write channel open frame for channel id 1
184 [main] DEBUG org.apache.qpid.client.AMQSession - Created session:org.apache.qpid.client.AMQSession_0_8#1d251891
186 [IoReceiver - localhost/127.0.0.1:5672] DEBUG org.apache.qpid.client.protocol.AMQProtocolHandler - (1028176102)Method frame received: [ChannelOpenOkBody]
189 [IoReceiver - localhost/127.0.0.1:5672] DEBUG org.apache.qpid.client.protocol.AMQProtocolHandler - (1028176102)Method frame received: [BasicQosOkBodyImpl: ]
195 [main] DEBUG org.apache.qpid.client.BasicMessageProducer_0_8 - MessageProducer org.apache.qpid.client.BasicMessageProducer_0_8#668bc3d5 using publish mode : ASYNC_PUBLISH_ALL
206 [main] DEBUG org.apache.qpid.client.BasicMessageProducer_0_8 - Sending content body frames to direct://onms2/Simon/?routingkey='Simon'&exclusive='true'&autodelete='true'
206 [main] DEBUG org.apache.qpid.client.BasicMessageProducer_0_8 - Sending content header frame to direct://onms2/Simon/?routingkey='Simon'&exclusive='true'&autodelete='true'
207 [main] DEBUG org.apache.qpid.framing.FieldTable - FieldTable::writeToBuffer: Writing encoded length of 67...
When it fails using the shorter syntax the debug log looks like this:-
149 [main] INFO org.apache.qpid.client.AMQConnection - Connection 1 now connected from /127.0.0.1:36940 to localhost/127.0.0.1:5672
149 [main] DEBUG org.apache.qpid.client.AMQConnection - Are we connected:true
149 [main] DEBUG org.apache.qpid.client.AMQConnection - Connected with ProtocolHandler Version:0-91
153 [main] DEBUG org.apache.qpid.client.AMQConnectionDelegate_8_0 - Write channel open frame for channel id 1
169 [main] DEBUG org.apache.qpid.client.AMQSession - Created session:org.apache.qpid.client.AMQSession_0_8#6bdf28bb
170 [IoReceiver - localhost/127.0.0.1:5672] DEBUG org.apache.qpid.client.protocol.AMQProtocolHandler - (472294496)Method frame received: [ChannelOpenOkBody]
171 [IoReceiver - localhost/127.0.0.1:5672] DEBUG org.apache.qpid.client.protocol.AMQProtocolHandler - (472294496)Method frame received: [BasicQosOkBodyImpl: ]
179 [main] DEBUG org.apache.qpid.client.AMQDestination - Based on onms2/Simon the selected destination syntax is ADDR
182 [main] DEBUG org.apache.qpid.client.AMQConnectionDelegate_8_0 - supportsIsBound: false
182 [main] DEBUG org.apache.qpid.client.AMQConnectionDelegate_8_0 - supportsIsBound: false
182 [main] DEBUG org.apache.qpid.client.AMQConnectionDelegate_8_0 - supportsIsBound: false
184 [IoReceiver - localhost/127.0.0.1:5672] DEBUG org.apache.qpid.client.protocol.AMQProtocolHandler - (472294496)Method frame received: [ExchangeDeclareOkBodyImpl: ]
184 [main] DEBUG org.apache.qpid.client.BasicMessageProducer_0_8 - MessageProducer org.apache.qpid.client.BasicMessageProducer_0_8#15975490 using publish mode : ASYNC_PUBLISH_ALL
195 [main] DEBUG org.apache.qpid.client.BasicMessageProducer_0_8 - Sending content body frames to 'onms2'/'Simon'; None
195 [main] DEBUG org.apache.qpid.client.BasicMessageProducer_0_8 - Sending content header frame to 'onms2'/'Simon'; None
196 [main] DEBUG org.apache.qpid.framing.FieldTable - FieldTable::writeToBuffer: Writing encoded length of 90...
196 [main] DEBUG org.apache.qpid.framing.FieldTable - {Id=[INT: 987654321], name=[LONG_STRING: WidgetSimon], price=[DOUBLE: 0.99], qpid.subject=[LONG_STRING: Simon], JMS_QPID_DESTTYPE=[INT: 2]}
198 [main] DEBUG org.apache.qpid.client.AMQSession - Closing session: org.apache.qpid.client.AMQSession_0_8#6bdf28bb
198 [main] DEBUG org.apache.qpid.client.protocol.AMQProtocolSession - closeSession called on protocol session for session 1
Ideally i need the shorter syntax to work as this is what is used by another application I am using which is posting messages using AMQP.
I suspect there is something incorrect with the syntax i am using to define the address but i cant see what it is.
I have tried:-
amqp:onms2/Simon
ADDR:onms2/Simon
I have confirmed the rabbit config is correct by testing using both a standalone java client using qpid and also using both perl (using net_amqp) and python (using pika). So i dont think its that.
Any gudiance appreciated.
EDIT:-
Found some extra configuration parameters on the QPID website i had missed
When i configure the address as follows it works!
onms3/Simon; {'create':'always','node':{'type':'topic'} }
Detail
<name> [ / <subject> ] ; {
create: always | sender | receiver | never,
delete: always | sender | receiver | never,
assert: always | sender | receiver | never,
mode: browse | consume,
node: {
type: queue | topic,
durable: True | False,
x-declare: { ... <declare-overrides> ... },
x-bindings: [<binding_1>, ... <binding_n>]
},
link: {
name: <link-name>,
durable: True | False,
reliability: unreliable | at-most-once | at-least-once | exactly-once,
x-declare: { ... <declare-overrides> ... },
x-bindings: [<binding_1>, ... <binding_n>],
x-subscribe: { ... <subscribe-overrides> ... }
}
}
Simon
EDIT:-
Found some extra configuration parameters on the QPID website i had missed
When i configure the address as follows it works!
onms3/Simon; {'create':'always','node':{'type':'topic'} }
Detail
<name> [ / <subject> ] ; {
create: always | sender | receiver | never,
delete: always | sender | receiver | never,
assert: always | sender | receiver | never,
mode: browse | consume,
node: {
type: queue | topic,
durable: True | False,
x-declare: { ... <declare-overrides> ... },
x-bindings: [<binding_1>, ... <binding_n>]
},
link: {
name: <link-name>,
durable: True | False,
reliability: unreliable | at-most-once | at-least-once | exactly-once,
x-declare: { ... <declare-overrides> ... },
x-bindings: [<binding_1>, ... <binding_n>],
x-subscribe: { ... <subscribe-overrides> ... }
}
}

How to resolve IOException while renaming file using SFTP?

I am using SFTPClient to download and upload files. Here requirement is while downloading from remote server, needed to move the file in archive folder in the same server.
I know that, we have option to rename using below one-: **
SFTPClient.rename(filename,destinationPath)
.
I have tried the same but i am getting following exception:
**code:
try {
sftp.lcd(details.get("LOCAL_DIR"));
sftp.cd(details.get("REMOTE_DIR"));
List<SftpFile> remoteFiles = sftp.ls();
for(int i = 0 ; i < remoteFiles.size(); ++i) {
String patternFile = remoteFiles.get(i).getFilename().toUpperCase();
// System.out.println(patternFile);
// System.out.println("Files Format"+patternFile+"***************"+patternFile.matches(details.get("DOWNLOAD_PATTERN")));
if(remoteFiles.get(i).isFile() && patternFile.matches(details.get("DOWNLOAD_PATTERN"))) {
String remoteFile = remoteFiles.get(i).getFilename();
sftp.get(remoteFile);
System.out.println("[SFTPOperations][downLoad] Downloaded: " + remoteFile);
System.out.println("Remote File: " + remoteFile);
System.out.println("Remote Archive Dir: " + details.get("REMOTE_ARCHIVE_DIR"));
sftp.rename(remoteFiles.get(i).getFilename(), details.get("REMOTE_ARCHIVE_DIR"));
System.out.println("[SFTPOperations][downLoad] Archived: " + remoteFile);
}
}
} catch(IOException e) {
System.out.println("[SFTPOperations][downLoad] IOException occurred: " + e.getMessage());
System.out.println("[SFTPOperations][downLoad] Failed to download from " + details.get("REMOTE_DIR"));
e.printStackTrace(System.out);
throw new SFTPException(e.getMessage());
}
Exception:
[Jun 04 10:57:58] [SFTPOperations][downLoad] IOException occurred:
Failure [Jun 04 10:57:58] [SFTPOperations][downLoad] Failed to
download from /home/cordys/CryptoTest/INGInput java.io.IOException:
Failure [Jun 04 10:57:58] at
com.sshtools.j2ssh.sftp.SftpSubsystemClient.getOKRequestStatus(Unknown
Source) [Jun 04 10:57:58] at
com.sshtools.j2ssh.sftp.SftpSubsystemClient.renameFile(Unknown Source)
[Jun 04 10:57:58] at com.sshtools.j2ssh.SftpClient.rename(Unknown
Source) [Jun 04 10:57:58] at
com.ing.sftp.SFTPOperations.downLoad(SFTPOperations.java:82) [Jun 04
10:57:58] at
com.ing.schedular.INGCryptoSchedular.downloadEncFiles(INGCryptoSchedular.java:207)
[Jun 04 10:57:58] at
com.ing.schedular.INGCryptoSchedular.download(INGCryptoSchedular.java:187)
[Jun 04 10:57:58] at
com.ing.schedular.INGCryptoSchedular.schedule(INGCryptoSchedular.java:83)
[Jun 04 10:57:58] at
com.ing.schedular.INGCryptoSchedular.main(INGCryptoSchedular.java:294)
Please suggest how to resolve the mentioned above.

Categories

Resources