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.
Related
I have an app where we serve resources protected by a custom authentication and authorization framework. This results in us having to respect range headers (in particular for video).
We had to change this code to support iOS and safari. In the process we started getting a broken pipe exception from Chrome but I can't figure out why. The video plays in chrome, safari and iOS as expected but we'd like to clean up the exception.
Chrome requests the whole package in the first request and we send it. Then it comes back and starts asking for chunks (see VID requests in image below.
What would cause chrome to kill this connection? Is it because there is something wrong with the first response returning the whole asset?
I've also tried returning a 200 when the first package sends everything but the outcome is the same.
No exceptions when using Safari.
Finally, we have other unprotected content served by EAP and no exceptions are reported.
The code that manages the response is:
protected void createResponse(HttpServletResponse resp, ResourceInterface resource,
ResourceInstance instance, String range) throws IOException, ServletException {
_logger.info("Range parameter {}", range);
int rangeStart = 0;
int rangeEnd = -1;
InputStream is = resource.getResourceStream(instance);
int lengthHeader = is.available();
if (range != null) {
String[] rangeSplit = range.split("=");
//String type = rangeSplit[0];
String[] rangeVals = rangeSplit[1].split("-");
rangeStart = Integer.parseInt(rangeVals[0]);
resp.setHeader(HttpHeaders.ACCEPT_RANGES, "bytes");
resp.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
if (rangeVals.length > 1 && !StringUtils.isBlank(rangeVals[1])) {
rangeEnd = Integer.parseInt(rangeVals[1]);
//bufferSize = rangeEnd - rangeStart + 1;
} else {
rangeEnd = lengthHeader-1;
}
_logger.info("Start Range {} - End Range {}", rangeStart, rangeEnd);
if (null != is) {
resp.setHeader(HttpHeaders.CONTENT_RANGE, "bytes " + rangeStart+"-"+rangeEnd + "/" + lengthHeader);
String lastModifiedPattern = "EEE, dd MMM yyyy HH:mm:ss zzz";
String dateString = DateConverter.getFormattedDate(new Date(), lastModifiedPattern);
resp.setHeader(HttpHeaders.LAST_MODIFIED, dateString);
_logger.info("serving resource {} with length {} bytes", instance.getFileName(), lengthHeader);
}
} else {
_logger.info("NULL RANGE");
}
resp.setHeader("Content-Disposition", "inline; filename=" + instance.getFileName());
resp.setContentType(instance.getMimeType());
//CDP_DW_PUB-279: modifica nome file originale risorse protected
String fileName = resource.getMasterFileName();
if ("Image".equals(resource.getType())) {
int lastIndexOf = instance.getFileName().lastIndexOf("_");
String suffix = instance.getFileName().substring(lastIndexOf + 1, lastIndexOf + 3);
StringBuilder sb = new StringBuilder(suffix);
sb.append("_");
sb.append(fileName);
fileName = sb.toString();
}
//CDP_DW_PUB-279
ServletOutputStream out = resp.getOutputStream();
try {
is.skip(rangeStart);
byte[] slice = new byte[rangeEnd-rangeStart+1];
is.read(slice, 0, rangeEnd-rangeStart+1);
resp.setHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(slice.length));
_logger.info("Slice size "+slice.length);
out.write(slice);
} catch (Throwable t) {
_logger.error("Error extracting protected resource", t);
throw new ServletException("Error extracting protected resource", t);
} finally {
out.close();
}
}
The exception is pretty generic:
Caused by: javax.servlet.ServletException: Error extracting protected resource
at org.entando.entando.plugins.jacms.aps.servlet.ProtectedResourceProvider.createResponse(ProtectedResourceProvider.java:192)
at org.entando.entando.plugins.jacms.aps.servlet.ProtectedResourceProvider.provideProtectedResource(ProtectedResourceProvider.java:112)
... 69 more
Caused by: org.eclipse.jetty.io.EofException
at org.eclipse.jetty.io.ChannelEndPoint.flush(ChannelEndPoint.java:292)
at org.eclipse.jetty.io.WriteFlusher.flush(WriteFlusher.java:429)
at org.eclipse.jetty.io.WriteFlusher.completeWrite(WriteFlusher.java:384)
at org.eclipse.jetty.io.ChannelEndPoint$3.run(ChannelEndPoint.java:139)
... 7 more
Caused by: java.io.IOException: Broken pipe
at sun.nio.ch.FileDispatcherImpl.write0(Native Method)
at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47)
at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)
at sun.nio.ch.IOUtil.write(IOUtil.java:65)
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:471)
at org.eclipse.jetty.io.ChannelEndPoint.flush(ChannelEndPoint.java:270)
... 10 more
This is the network traffic. The VID calls are the calls for the MP4
The response headers are:
HTTP/1.1 206 Partial Content
Date: Thu, 08 Aug 2019 07:47:10 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Headers: Content-Type, Authorization
Access-Control-Max-Age: 3600
Accept-Ranges: bytes
Last-Modified: Thu, 08 Aug 2019 09:47:10 CEST
Content-Disposition: inline; filename=38012166d7833c09c4b8632ea186634e.mp4
HTTP/1.1 206 Partial Content
Date: Thu, 08 Aug 2019 07:47:10 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Headers: Content-Type, Authorization
Access-Control-Max-Age: 3600
Accept-Ranges: bytes
Last-Modified: Thu, 08 Aug 2019 09:47:10 CEST
Content-Disposition: inline; filename=38012166d7833c09c4b8632ea186634e.mp4
Content-Type: video/mp4;charset=utf-8
Server: Jetty(9.4.8.v20180619)
Content-Range: bytes 2097152-2107841/2107842
Content-Length: 10690
Content-Type: video/mp4;charset=utf-8
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
Server: Jetty(9.4.8.v20180619)
Content-Range: bytes 0-2107841/2107842
Content-Length: 2107842
HTTP/1.1 206 Partial Content
Date: Thu, 08 Aug 2019 07:47:10 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Headers: Content-Type, Authorization
Access-Control-Max-Age: 3600
Accept-Ranges: bytes
Last-Modified: Thu, 08 Aug 2019 09:47:10 CEST
Content-Disposition: inline; filename=38012166d7833c09c4b8632ea186634e.mp4
Content-Type: video/mp4;charset=utf-8
Server: Jetty(9.4.8.v20180619)
Content-Range: bytes 2097152-2107841/2107842
Content-Length: 10690
HTTP/1.1 206 Partial Content
Date: Thu, 08 Aug 2019 07:47:10 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Headers: Content-Type, Authorization
Access-Control-Max-Age: 3600
Accept-Ranges: bytes
Last-Modified: Thu, 08 Aug 2019 09:47:10 CEST
Content-Disposition: inline; filename=38012166d7833c09c4b8632ea186634e.mp4
Content-Type: video/mp4;charset=utf-8
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
Server: Jetty(9.4.8.v20180619)
Content-Range: bytes 65536-2107841/2107842
Content-Length: 2042306
This ultimately resolved the issue.
protected void createResponse(HttpServletResponse resp, ResourceInterface resource,
ResourceInstance instance) throws IOException, ServletException {
resp.setContentType(instance.getMimeType());
resp.setHeader("Content-Disposition", "inline; filename=" + instance.getFileName());
ServletOutputStream out = resp.getOutputStream();
try {
InputStream is = resource.getResourceStream(instance);
if (null != is) {
byte[] buffer = new byte[2048];
int length = -1;
// Transfer the data
while ((length = is.read(buffer)) != -1) {
out.write(buffer, 0, length);
out.flush();
}
is.close();
}
} catch (Throwable t) {
logger.error("Error extracting protected resource", t);
throw new ServletException("Error extracting protected resource", t);
} finally {
out.close();
}
}
I am trying to get MAC address of the device in a local network by using its IP address. To implement this in java I found a library name Pcap4j. I am using its class SendArpRequest to generate ARP request and receive a reply, but it always says "IP-Address was resolved to null".
Here is the java code:
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.pcap4j.core.BpfProgram.BpfCompileMode;
import org.pcap4j.core.NotOpenException;
import org.pcap4j.core.PacketListener;
import org.pcap4j.core.PcapHandle;
import org.pcap4j.core.PcapNativeException;
import org.pcap4j.core.PcapNetworkInterface;
import org.pcap4j.core.PcapNetworkInterface.PromiscuousMode;
import org.pcap4j.core.Pcaps;
import org.pcap4j.packet.ArpPacket;
import org.pcap4j.packet.EthernetPacket;
import org.pcap4j.packet.Packet;
import org.pcap4j.packet.namednumber.ArpHardwareType;
import org.pcap4j.packet.namednumber.ArpOperation;
import org.pcap4j.packet.namednumber.EtherType;
import org.pcap4j.util.ByteArrays;
import org.pcap4j.util.MacAddress;
import org.pcap4j.util.NifSelector;
#SuppressWarnings("javadoc")
public class SendArpRequest {
private static final String COUNT_KEY = SendArpRequest.class.getName() + ".count";
private static final int COUNT = Integer.getInteger(COUNT_KEY, 1);
private static final String READ_TIMEOUT_KEY = SendArpRequest.class.getName() + ".readTimeout";
private static final int READ_TIMEOUT = Integer.getInteger(READ_TIMEOUT_KEY, 10); // [ms]
private static final String SNAPLEN_KEY = SendArpRequest.class.getName() + ".snaplen";
private static final int SNAPLEN =Integer.getInteger(SNAPLEN_KEY, 65536); // [bytes]
private static final MacAddress SRC_MAC_ADDR =MacAddress.getByName("00:db:df:8b:b1:a9");
private static MacAddress resolvedAddr;
private SendArpRequest() {}
public static void main(String[] args) throws PcapNativeException, NotOpenException {
String strSrcIpAddress = "192.168.0.11"; // for InetAddress.getByName()
//String strDstIpAddress = args[0]; // for InetAddress.getByName()
String strDstIpAddress = "192.168.0.3"; // for InetAddress.getByName()
System.out.println(COUNT_KEY + ": " + COUNT);
System.out.println(READ_TIMEOUT_KEY + ": " + READ_TIMEOUT);
System.out.println(SNAPLEN_KEY + ": " + SNAPLEN);
System.out.println("\n");
PcapNetworkInterface nif;
try {
nif = new NifSelector().selectNetworkInterface();
} catch (IOException e){
e.printStackTrace();
return;
}
if (nif == null) {
return;
}
System.out.println(nif.getName() + "(" + nif.getDescription() + ")");
PcapHandle handle = nif.openLive(SNAPLEN, PromiscuousMode.PROMISCUOUS, READ_TIMEOUT);
PcapHandle sendHandle = nif.openLive(SNAPLEN, PromiscuousMode.PROMISCUOUS, READ_TIMEOUT);
ExecutorService pool = Executors.newSingleThreadExecutor();
try {
handle.setFilter(
"arp and src host "
+ strDstIpAddress
+ " and dst host "
+ strSrcIpAddress
+ " and ether dst "
+ Pcaps.toBpfString(SRC_MAC_ADDR),
BpfCompileMode.OPTIMIZE);
PacketListener listener =
new PacketListener() {
public void gotPacket(Packet packet) {
if (packet.contains(ArpPacket.class)) {
ArpPacket arp = packet.get(ArpPacket.class);
if (arp.getHeader().getOperation().equals(ArpOperation.REPLY)) {
SendArpRequest.resolvedAddr = arp.getHeader().getSrcHardwareAddr();
}
}
System.out.println(packet);
}
};
Task t = new Task(handle, listener);
pool.execute(t);
ArpPacket.Builder arpBuilder = new ArpPacket.Builder();
try {
arpBuilder
.hardwareType(ArpHardwareType.ETHERNET)
.protocolType(EtherType.IPV4)
.hardwareAddrLength((byte) MacAddress.SIZE_IN_BYTES)
.protocolAddrLength((byte) ByteArrays.INET4_ADDRESS_SIZE_IN_BYTES)
.operation(ArpOperation.REQUEST)
.srcHardwareAddr(SRC_MAC_ADDR)
.srcProtocolAddr(InetAddress.getByName(strSrcIpAddress))
.dstHardwareAddr(MacAddress.ETHER_BROADCAST_ADDRESS)
.dstProtocolAddr(InetAddress.getByName(strDstIpAddress));
} catch (UnknownHostException e) {
throw new IllegalArgumentException(e);
}
EthernetPacket.Builder etherBuilder = new EthernetPacket.Builder();
etherBuilder
.dstAddr(MacAddress.ETHER_BROADCAST_ADDRESS)
.srcAddr(SRC_MAC_ADDR)
.type(EtherType.ARP)
.payloadBuilder(arpBuilder)
.paddingAtBuild(true);
for (int i = 0; i < COUNT; i++) {
Packet p = etherBuilder.build();
System.out.println(p);
sendHandle.sendPacket(p);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
break;
}
}
} finally {
if (handle != null && handle.isOpen()) {
handle.close();
}
if (sendHandle != null && sendHandle.isOpen()) {
sendHandle.close();
}
if (pool != null && !pool.isShutdown()) {
pool.shutdown();
}
System.out.println(strDstIpAddress + " was resolved to " + resolvedAddr);
}
}
private static class Task implements Runnable {
private PcapHandle handle;
private PacketListener listener;
public Task(PcapHandle handle, PacketListener listener) {
this.handle = handle;
this.listener = listener;
}
public void run() {
try {
handle.loop(COUNT, listener);
} catch (PcapNativeException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (NotOpenException e) {
e.printStackTrace();
}
}
}
}
And I got this output by using sourceIP = "192.168.0.11", sourceMAC = "00:db:df:8b:b1:a9" and destinationIP = "192.168.0.3".
com.arpscan.SendArpRequest.count: 1
com.arpscan.SendArpRequest.readTimeout: 10
com.arpscan.SendArpRequest.snaplen: 65536
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
6
6
7
2
2
0
0
0
0
0
NIF[0]: wlp1s0
: link layer address: 00:db:df:8b:b1:a9
: address: /192.168.0.11
: address: /fe80:0:0:0:c090:df9:7448:e0be
NIF[1]: any
: description: Pseudo-device that captures on all interfaces
NIF[2]: lo
: link layer address: 00:00:00:00:00:00
: address: /127.0.0.1
: address: /0:0:0:0:0:0:0:1
NIF[3]: virbr0
: link layer address: 52:54:00:72:e9:70
: address: /192.168.122.1
NIF[4]: enp0s31f6
: link layer address: 50:7b:9d:cc:71:d2
NIF[5]: bluetooth0
: description: Bluetooth adapter number 0
NIF[6]: nflog
: description: Linux netfilter log (NFLOG) interface
NIF[7]: nfqueue
: description: Linux netfilter queue (NFQUEUE) interface
NIF[8]: usbmon1
: description: USB bus number 1
NIF[9]: usbmon2
: description: USB bus number 2
Select a device number to capture packets, or enter 'q' to quit > 0
wlp1s0(null)
[Ethernet Header (14 bytes)]
Destination address: ff:ff:ff:ff:ff:ff
Source address: 00:db:df:8b:b1:a9
Type: 0x0806 (ARP)
[ARP Header (28 bytes)]
Hardware type: 1 (Ethernet (10Mb))
Protocol type: 0x0800 (IPv4)
Hardware address length: 6 [bytes]
Protocol address length: 4 [bytes]
Operation: 1 (REQUEST)
Source hardware address: 00:db:df:8b:b1:a9
Source protocol address: /192.168.0.11
Destination hardware address: ff:ff:ff:ff:ff:ff
Destination protocol address: /192.168.0.3
[Ethernet Pad (18 bytes)]
Hex stream: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[data (42 bytes)]
Hex stream: 00 db df 8b b1 a9 d0 04 01 62 61 38 08 06 00 01 08 00 06 04 00 02 d0 04 01 62 61 38 c0 a8 00 03 00 db df 8b b1 a9 c0 a8 00 0b
192.168.0.3 was resolved to null
Here I got null for destination MAC Address as you can see.
But when I run arp-scan command I got correct MAC address for the given IP Address. Here is screenshot of arp-scan result.
Please suggest me how I can implement it properly.
You need to add a packet factory moudle (e.g. pcap4j-packetfactory-static.jar) to your class path so that Pcap4J can dessect the ARP response.
And, probably you'd better add volatile to private static MacAddress resolvedAddr;.
I have the following
javax.swing.Timer timer = new javax.swing.Timer(3000, new java.awt.event.ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
jLabelMsgL.setText("");
NitgenSwingWorker sWorker = new NitgenSwingWorker();
sWorker.execute();
}
});
timer.start();
private final class NitgenSwingWorker extends SwingWorker<Boolean, Void> {
#Override
protected Boolean doInBackground() throws Exception {
return nitgen.checkFinger();
}
#Override
protected void done() {
try {
Boolean isCheckFinger = get();
if(isCheckFinger){
delegate.getListaByIdEmpleado(123);
}else{
delegate.getListaByIdEmpleado(123);
}
} catch (InterruptedException | ExecutionException e) {
System.err.println("NitgenSwingWorker Error: " + e.getMessage());
}
}
}
but when 'isCheckFinger' is true, throws
Mon Jun 29 10:44:14 CDT 2015 INFO: ** Performance Metrics Report **
Longest reported query: 0 ms
Shortest reported query: 9223372036854775807 ms
Average query execution time: NaN ms
Number of statements executed: 0
Number of result sets created: 0
Number of statements prepared: 0
Number of prepared statement executions: 0
Mon Jun 29 10:44:14 CDT 2015 TRACE: send() packet payload:
0a 00 00 00 03 73 65 6c . . . . . s e l
65 63 74 20 31 3b e c t . 1 ;
org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
...
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)
...
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
...
only send me the error when nitgen.checkFinger returns true,
nitgen is a library of a fingerprint reader. I guess when this return
true, it changes something in swing and can not access hibernate.
The exception is sent until it try to do this:
getSession().beginTransaction()
Otherwise no problems, anyone can help me?
I solved
The problem was that I was using a JNI library, and when a value is changed, this happened. To fix and change the default value and ready solved.
public boolean checkFinger() throws Exception {
//Boolean thereIsFinger = Boolean.FALSE; //original line
Boolean thereIsFinger = Boolean.TRUE; //solution
//bsp is a JNI Library
bsp.CheckFinger(thereIsFinger);
return thereIsFinger;
}
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)
I am trying to access to an URL using WS on Play Framework 2.1 using JAVA api.
Here is what I want:
Some where in the code, start a WS request using WS.get() (I set timeout 1000ms)
If WS.get times out or another exception happens, I don't want my Promise throw an exception (since my flow reqiures it that way) So I use Promise.recover() to wrap that promise with another. Which returns a null Reponse object in case of failures.
Some where else in code I want to "get" my Response. I wait for 5000ms but what I get is java.util.concurrent.TimeoutException: Futures timed out after [5000 milliseconds]
How? WS.get() timesout after 1000ms and since it throws an java.util.concurrent.TimeoutException: No response received after 1000 it is catched by my recover function. It returns a null response instead of an exception.
So promise is "completed" after 1000ms at most. Why it times out and throws an exception after 5000 ms?
Code:
Logger.info("Fetch started: " + new Date().toString());
Promise<WS.Response> p1 = WS.url("http://athena.ics.forth.gr:9090/RDF/VRP/Examples/tap.rdf").setTimeout(1000).get();
Promise<WS.Response> p2 = p1.recover(new Function<Throwable, WS.Response>() {
#Override
public Response apply(Throwable a) throws Throwable {
Logger.error("Promise thrown an exception so I will return null. " + new Date().toString() + " " + System.currentTimeMillis(), a);
return null;
}
});
try {
/* This should return null or valid response but shouldn't throw an exception */
Response r = p2.get(5000L);
Logger.info(r.toString());
} catch (Exception e) {
/* Sholdn't happen! */
Logger.error("Outer exception: " + " " + System.currentTimeMillis(), e);
}
Logger.error("Fetch finished: " + new Date().toString() + " " + System.currentTimeMillis());
Output I get:
[info] application - Fetch started: Tue Mar 19 10:04:42 EET 2013
[error] application - Outer exception: 1363680287626
java.util.concurrent.TimeoutException: Futures timed out after [5000 milliseconds]
at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:96) ~[scala-library.jar:na]
at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:58) ~[scala-library.jar:na]
at scala.concurrent.Await$$anonfun$ready$1.apply(package.scala:86) ~[scala-library.jar:na]
at scala.concurrent.Await$$anonfun$ready$1.apply(package.scala:86) ~[scala-library.jar:na]
at akka.dispatch.MonitorableThreadFactory$AkkaForkJoinWorkerThread$$anon$3.block(ThreadPoolBuilder.scala:173) ~[akka-actor_2.10.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool.managedBlock(ForkJoinPool.java:2803) [scala-library.jar:na]
[error] application - Fetch finished: Tue Mar 19 10:04:47 EET 2013 1363680287627
[error] application - Promise thrown an exception so I will return null. Tue Mar 19 10:04:47 EET 2013 1363680287627
java.util.concurrent.TimeoutException: No response received after 1000
at com.ning.http.client.providers.netty.NettyAsyncHttpProvider$ReaperFuture.run(NettyAsyncHttpProvider.java:1809) ~[async-http-client.jar:na]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) ~[na:1.7.0_11]
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351) ~[na:1.7.0_11]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178) ~[na:1.7.0_11]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) ~[na:1.7.0_11]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) ~[na:1.7.0_11]
Even I wait for promise2 and promise2 is "recover wrapped promise1" recover function runs AFTER exception is thrown.