sudhakar_koundinya
asked on
HTTPS : Download Attachments from MS Exchange Server
Hi All,
I just started a small project where i need to communicate with MS Exchange Server . For this I choose Apache Slide Project and working fine .
But when i try to download the attachments from the Exchange server which is configured to HTTPS protocol, I am unable to do it so because webDavResourceFile.getMeth odData() is returning any empty input stream i.e. webDavResourceFile.getMeth odData().a vailable() is returning always a zero for me. So obviously i am not able to download
them
The Same thing is working if the server is configured to HTTP Protocol.
So please help me to get the attachments when it is configured to HTTPS protocol
thanks
sudhakar
I just started a small project where i need to communicate with MS Exchange Server . For this I choose Apache Slide Project and working fine .
But when i try to download the attachments from the Exchange server which is configured to HTTPS protocol, I am unable to do it so because webDavResourceFile.getMeth
them
The Same thing is working if the server is configured to HTTP Protocol.
So please help me to get the attachments when it is configured to HTTPS protocol
thanks
sudhakar
Can't you point us to the online javadoc for the API you're using?
ASKER
Apache Slide Documentation
http://jakarta.apache.org/slide/clientjavadoc/index.html
http://jakarta.apache.org/slide/clientjavadoc/index.html
ASKER
and this is main class for entire process
http://jakarta.apache.org/slide/clientjavadoc/org/apache/webdav/lib/WebdavResource.html
http://jakarta.apache.org/slide/clientjavadoc/org/apache/webdav/lib/WebdavResource.html
Actually, although this is not intended to represent a solution to the problem, you should not use available() as it is unreliable. You should simply read the stream until it is exhausted.
What kind of resource is it that you're trying to get, as a matter of interest?
What kind of resource is it that you're trying to get, as a matter of interest?
ASKER
here is code snippet how i am working with it
FileOutputStream attachmentOutStream = new FileOutputStream(
strAttachmentFile);
int offset = 0;
//read the buffer from http stream
while (true) {
int availByteCount = attachmentInStream.availab le();
if (availByteCount <= 0) {
//end of attachment buffer
break;
}
byte buffer[] = new byte[availByteCount];
offset = attachmentInStream.read(bu ffer);
//write the downloaded attachment buffer in the Local System Object
attachmentOutStream.write( buffer, 0, offset);
buffer = null;
}
//clear the buffer;
attachmentOutStream.close( );
attachmentInStream.close() ;
FileOutputStream attachmentOutStream = new FileOutputStream(
strAttachmentFile);
int offset = 0;
//read the buffer from http stream
while (true) {
int availByteCount = attachmentInStream.availab
if (availByteCount <= 0) {
//end of attachment buffer
break;
}
byte buffer[] = new byte[availByteCount];
offset = attachmentInStream.read(bu
//write the downloaded attachment buffer in the Local System Object
attachmentOutStream.write(
buffer = null;
}
//clear the buffer;
attachmentOutStream.close(
attachmentInStream.close()
ASKER
as i said earlier
it is working with HTTP protocol, i am facing problem only with https protocol
it is working with HTTP protocol, i am facing problem only with https protocol
ASKER
and for getting the url stream
org.apache.webdav.lib.Webd avResource webDavResourceFile = getWebResource(
urlEML);
//get the attachment
InputStream attachmentInStream = webDavResourceFile.getMeth odData();
org.apache.webdav.lib.Webd
urlEML);
//get the attachment
InputStream attachmentInStream = webDavResourceFile.getMeth
Are you sure this API supports https?
ASKER
yes
because i am able to download all the emails and user acoount information using https protocol. only i am facing with attachments of emails :(
because i am able to download all the emails and user acoount information using https protocol. only i am facing with attachments of emails :(
ASKER
and for creating the HTTPS URL Object
here is the snippet
url = new org.apache.commons.httpcli ent.HttpsU RL(usernam e, password, hostname, port, strPath)
here is the snippet
url = new org.apache.commons.httpcli
Can you show me the value of urlEML? (disguise as little as possible)
ASKER
org.apache.commons.httpcli ent.HttpUR L urlEML = getURL(path + "/" +
mailbox + "/" + folder + "/" + filename);
private org.apache.commons.httpcli ent.HttpUR L getURL(String strPath) {
org.apache.commons.httpcli ent.HttpUR L url = null;
try {
if (bHttps == false) {
//instantiate the email object for http protocol
url = new org.apache.commons.httpcli ent.HttpUR L(username , password,
hostname, port, strPath);
}
else {
//instantiate the email object for https protocol
url = new org.apache.commons.httpcli ent.HttpsU RL(usernam e, password,
hostname, port, strPath);
}
}
catch (Exception ex) {
url = null;
}
return url;
}
mailbox + "/" + folder + "/" + filename);
private org.apache.commons.httpcli
org.apache.commons.httpcli
try {
if (bHttps == false) {
//instantiate the email object for http protocol
url = new org.apache.commons.httpcli
hostname, port, strPath);
}
else {
//instantiate the email object for https protocol
url = new org.apache.commons.httpcli
hostname, port, strPath);
}
}
catch (Exception ex) {
url = null;
}
return url;
}
ASKER
where username is administrative user account of ms exchange server
ASKER
say suppose if i want to access the particular email from inbox folder
i have to create object some thing like this
org.apache.commons.httpcli ent.HttpUR L urlEML = getURL("comp37:80/Exchange /Sudhakar_ Koundinya/ Inbox/Your Info.EML") ;
i have to create object some thing like this
org.apache.commons.httpcli
No i meant the *value* of that path
OK - cross-posted. Shall think about this
ASKER
ok
a. are you sure that the port is correct for your https?
b. make sure all exceptions are being reported by printing their stack traces
b. make sure all exceptions are being reported by printing their stack traces
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@CEHJ
I tried all the possible ways that are applicable. And also I said that emails are downloading, the only problem is with attachments. SO there is no problem with port
@objects
I am using the same method for downloading either emails or attachments.
And again I am saying that the code is working for HTTP protocol. And even in HTTPS i am able to download emails only problem is with attachments download
thanks
sudhakar
I tried all the possible ways that are applicable. And also I said that emails are downloading, the only problem is with attachments. SO there is no problem with port
@objects
I am using the same method for downloading either emails or attachments.
And again I am saying that the code is working for HTTP protocol. And even in HTTPS i am able to download emails only problem is with attachments download
thanks
sudhakar
>>And also I said that emails are downloading, the only problem is with attachments.
Emails and attachments are one and the same thing. When you see attachment icons in your mail client that is only a 'view' thing, not a model thing. The attachments are embedded in the email.
An eml file is not an attachment really - it's a mail that's been saved as a file.
Emails and attachments are one and the same thing. When you see attachment icons in your mail client that is only a 'view' thing, not a model thing. The attachments are embedded in the email.
An eml file is not an attachment really - it's a mail that's been saved as a file.
ASKER
Yes I do agree
but the way WebDAV resources behaviour is quite different here, MS-Exchange WebDAV server gives the responses in XML format. As attachment of email downloading is different response, MS-Exchange server WebDAV server sends the responses as different XML strings.
1st XML string contains the text part and email attributes such as receiver name, sender name, date ,subject,body and so on
2nd xml string contains name of email attachment, content-type of attachment and so on.
We need to parse the 1st xml string for getting entire email content and I am able to do both it for both http and https servers
And We need to parse this 2nd xml string for getting the attachments. And I was able to do with HTTP attachment downloads without any problem.
In Https request also i am getting the right xml information. I am able to identify correct paths of attachments. But the problem I was facing was I am not able to get the content of that attachments.
Hope you understand this
Thanks,
Sudhakar
but the way WebDAV resources behaviour is quite different here, MS-Exchange WebDAV server gives the responses in XML format. As attachment of email downloading is different response, MS-Exchange server WebDAV server sends the responses as different XML strings.
1st XML string contains the text part and email attributes such as receiver name, sender name, date ,subject,body and so on
2nd xml string contains name of email attachment, content-type of attachment and so on.
We need to parse the 1st xml string for getting entire email content and I am able to do both it for both http and https servers
And We need to parse this 2nd xml string for getting the attachments. And I was able to do with HTTP attachment downloads without any problem.
In Https request also i am getting the right xml information. I am able to identify correct paths of attachments. But the problem I was facing was I am not able to get the content of that attachments.
Hope you understand this
Thanks,
Sudhakar
Yes I figured all that.
An aside, did you try the method I posted above? Saves you handling the file download yourself.
An aside, did you try the method I posted above? Saves you handling the file download yourself.
ASKER
As an example
email- http://www.geocities.com/sudhakar_koundinya/http/mail.xml
attachment- http://www.geocities.com/sudhakar_koundinya/http/mail_att.xml
email- http://www.geocities.com/sudhakar_koundinya/http/mail.xml
attachment- http://www.geocities.com/sudhakar_koundinya/http/mail_att.xml
ASKER
Yes objects
I am doing in the same way
I am doing in the same way
when u access the xml using https does the href have http or https?
ASKER
this is some code snippet
org.apache.commons.httpcli ent.HttpUR L urlEML = getURL(path + "/" +
mailbox + "/" + folder + "/" + filename + "/" + strAttachmentName +
"/");
org.apache.webdav.lib.Webd avResource webDavResourceFile = getWebResource(
urlEML);
/************ ATTACHMENT DOWN LOAD******************/
//get the attachment
InputStream attachmentInStream = webDavResourceFile.getMeth odData();
/************ END OF ATTACHMENT DOWNLOAD ******************/
String strAttachmentFile = targetPath + "/" + mailbox + "/" + folder +
"/" + filename.replaceAll(":", "%3A") + "_Dir/" + strAttachmentName;
FileOutputStream attachmentOutStream = new FileOutputStream(
strAttachmentFile);
int offset = 0;
//read the buffer from http stream
while (true) {
int availByteCount = attachmentInStream.availab le();
if (availByteCount <= 0) {
//end of attachment buffer
break;
}
byte buffer[] = new byte[availByteCount];
offset = attachmentInStream.read(bu ffer);
//write the downloaded attachment buffer in the Local System Object
attachmentOutStream.write( buffer, 0, offset);
buffer = null;
}
//clear the buffer;
attachmentOutStream.close( );
attachmentInStream.close() ;
org.apache.commons.httpcli
mailbox + "/" + folder + "/" + filename + "/" + strAttachmentName +
"/");
org.apache.webdav.lib.Webd
urlEML);
/************ ATTACHMENT DOWN LOAD******************/
//get the attachment
InputStream attachmentInStream = webDavResourceFile.getMeth
/************ END OF ATTACHMENT DOWNLOAD ******************/
String strAttachmentFile = targetPath + "/" + mailbox + "/" + folder +
"/" + filename.replaceAll(":", "%3A") + "_Dir/" + strAttachmentName;
FileOutputStream attachmentOutStream = new FileOutputStream(
strAttachmentFile);
int offset = 0;
//read the buffer from http stream
while (true) {
int availByteCount = attachmentInStream.availab
if (availByteCount <= 0) {
//end of attachment buffer
break;
}
byte buffer[] = new byte[availByteCount];
offset = attachmentInStream.read(bu
//write the downloaded attachment buffer in the Local System Object
attachmentOutStream.write(
buffer = null;
}
//clear the buffer;
attachmentOutStream.close(
attachmentInStream.close()
ASKER
https
ASKER
I just got a mail from Apache Slide -Mail Archive
Hi Sudhakar,
I reply you in private because i think it is not a general slide
problem.
I use slide 2.0 rc1 to connect to exchange server both in http and https
and it works perfectly.
To read mail attachment, i use X-MS-ENUMATTACH method and then i simply
use a HttpClient (indeed this is a clone of session of WebdavResource)
and a GetMethod on it and it works fine, i use this because i've extends
WebdavResource class and when i get attachments i don't want that the
status of the resource change.
Do you have any exception when you instantiate the WebdavResource ?
Are you sure that your certificate of your server is valid (and sure
that java will find it valid)?
Try this piece of code to check your certificate :
HttpClient client = new HttpClient();
GetMethod get = new GetMethod("https://yourserver.com");
try
{
client.executeMethod(get);
}
catch ( IOException e )
{
e.printStackTrace();
}
System.out.println( get.getResponseBodyAsStrin g() );
Hi Sudhakar,
I reply you in private because i think it is not a general slide
problem.
I use slide 2.0 rc1 to connect to exchange server both in http and https
and it works perfectly.
To read mail attachment, i use X-MS-ENUMATTACH method and then i simply
use a HttpClient (indeed this is a clone of session of WebdavResource)
and a GetMethod on it and it works fine, i use this because i've extends
WebdavResource class and when i get attachments i don't want that the
status of the resource change.
Do you have any exception when you instantiate the WebdavResource ?
Are you sure that your certificate of your server is valid (and sure
that java will find it valid)?
Try this piece of code to check your certificate :
HttpClient client = new HttpClient();
GetMethod get = new GetMethod("https://yourserver.com");
try
{
client.executeMethod(get);
}
catch ( IOException e )
{
e.printStackTrace();
}
System.out.println( get.getResponseBodyAsStrin
ASKER
do you have any idea about X-MS-ENUMATTACH
> webDavResourceFile.getMeth odData();
thought you said you were using getMethod.
thought you said you were using getMethod.
ASKER
What is the difference ?
ASKER
I mean what is the difference in usage of these methods?
saves you having to worry about reading the stream yourself
ASKER
http://jakarta.apache.org/slide/clientjavadoc/org/apache/webdav/lib/WebdavResource.html#method_summary
According to the API
boolean getMethod(java.io.File file)
Execute the GET method for this WebdavResource path.
java.io.InputStream getMethodData()
Get InputStream for the GET method.
I think getMethod is not the correct one for testing.
Any How let me test again with another one
getMethod(java.lang.String path, java.io.File file)
According to the API
boolean getMethod(java.io.File file)
Execute the GET method for this WebdavResource path.
java.io.InputStream getMethodData()
Get InputStream for the GET method.
I think getMethod is not the correct one for testing.
Any How let me test again with another one
getMethod(java.lang.String
ASKER
No Objects,
getMethod is not the right one, it takes WebDAVResourceFile as an argument
getMethod is not the right one, it takes WebDAVResourceFile as an argument
no it takes a java.io.File.