- 浏览: 346208 次
- 性别:
- 来自: 厦门
-
文章分类
最新评论
-
弦月001:
我目前也是碰到这样的情况,在jsp里面没有问题,但在free ...
Spring+Freemarker(国际化) -
laj12347:
zhangsw_00 写道我参照你的方法,配置环境,在jsp文 ...
Spring+Freemarker(国际化) -
yctan:
hi,能不能把发送邮件的代码也贴一下啊。
用webdav协议访问exchange邮件服务器,下载附件的问题 -
maketc:
楼上正解,这个问题也被郁闷了半天,试过重启tomcat、ecl ...
Tomcat 部署 Could not copy all resources to 或者Undeployment Failure could not be re -
masuweng:
楼上正解,这个问题曾被郁闷了半天
Tomcat 部署 Could not copy all resources to 或者Undeployment Failure could not be re
前几天用webdav 访问exchange邮件服务器,一般的操作都完成,可是要下载邮件的附件就没有相关的方法或类来完成操作,在网上找了很久也没找到,后来自己看了看源码,自己从新继承写了下,就可以完成从exchange上下载附件的功能。发上来有能用上提供的帮助,大家也可以有机会讨论。
webdav.java
/**
* Created by IntelliJ IDEA.
* User: zkx
* Date: 2006-8-14
* Time: 9:34:29
* To change this template use File | Settings | File Templates.
*/
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpURL;
import org.apache.commons.httpclient.NTCredentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.webdav.lib.Property;
import org.apache.webdav.lib.ResponseEntity;
import org.apache.webdav.lib.WebdavResource;
import org.apache.webdav.lib.methods.DepthSupport;
import org.apache.webdav.lib.methods.PropFindMethod;
import org.apache.webdav.lib.methods.attFindMethod;
import org.w3c.dom.NodeList;
import java.util.Vector;
import java.io.IOException;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.net.MalformedURLException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class webdav {
public static String userName="5";
public static String password="5";
public static String hostAdd="192.168.1.45";
public static String domain ="local";
public static String inbox = "http://192.168.1.45/exchange/5/Inbox/";
public static Vector properties;
static {
properties = new Vector();
properties.addElement("DAV:autoversion");
properties.addElement("DAV:contentclass");
properties.addElement("DAV:creationdate");
properties.addElement("DAV:displayname");
properties.addElement("DAV:getcontentlength");
properties.addElement("DAV:getcontenttype");
properties.addElement("DAV:getetag");
properties.addElement("DAV:getlastmodified");
properties.addElement("DAV:href");
properties.addElement("DAV:id");
properties.addElement("DAV:iscollection");
properties.addElement("DAV:isfolder");
properties.addElement("DAV:ishidden");
properties.addElement("DAV:isreadonly");
properties.addElement("DAV:isstructureddocument");
properties.addElement("DAV:isversioned");
properties.addElement("DAV:lockdiscovery");
properties.addElement("DAV:parentname");
properties.addElement("DAV:resourcetype");
properties.addElement("DAV:revisionid");
properties.addElement("DAV:revisionlabel");
properties.addElement("DAV:revisionuri");
properties.addElement("DAV:supportedlock");
properties.addElement("DAV:uid");
properties.addElement("DAV:resourcetype");
properties.addElement("DAV:vresourceid");
properties.addElement("urn:schemas:httpmail:date");
properties.addElement("urn:schemas:httpmail:datereceived");
properties.addElement("urn:schemas:httpmail:displaycc");
properties.addElement("urn:schemas:httpmail:displayto");
properties.addElement("urn:schemas:httpmail:from");
properties.addElement("urn:schemas:httpmail:fromemail");
properties.addElement("urn:schemas:httpmail:fromname");
properties.addElement("urn:schemas:httpmail:hasattachment");
properties.addElement("urn:schemas:httpmail:htmldescription");
properties.addElement("urn:schemas:httpmail:importance");
properties.addElement("urn:schemas:httpmail:normalizedsubject");
properties.addElement("urn:schemas:httpmail:read");
properties.addElement("urn:schemas:httpmail:sendername");
properties.addElement("urn:schemas:httpmail:subject");
properties.addElement("urn:schemas:httpmail:submitted");
properties.addElement("urn:schemas:httpmail:textdescription");
properties.addElement("urn:schemas:httpmail:thread-topic");
properties.addElement("urn:schemas:httpmail:to");
properties.addElement("urn:schemas:mailheader:content-class");
properties.addElement("urn:schemas:mailheader:date");
properties.addElement("urn:schemas:mailheader:from");
properties.addElement("urn:schemas:mailheader:message-id");
properties.addElement("urn:schemas:mailheader:received");
properties.addElement("urn:schemas:mailheader:subject");
properties.addElement("urn:schemas:mailheader:thread-index");
properties.addElement("urn:schemas:mailheader:thread-topic");
properties.addElement("urn:schemas:mailheader:to");
properties.addElement("urn:schemas:mailheader:xref");
properties.addElement("urn:schemas:mailheader:x-unsent");
properties.addElement("urn:schemas:mailheader:x-mailer");
properties.addElement("x-mimeole");
properties.addElement("urn:schemas:mailheader:x-catchall");
properties.addElement("urn:schemas:mailheader:x-ms-has-attach");
properties.addElement("urn:schemas:mailheader:content-disposition");
}
public static void main(String args[])
{
try{
NTCredentials creds = new NTCredentials(userName, password, hostAdd,domain);
HttpURL host = new HttpURL(inbox);
SimpleDateFormat bartDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss:SSS");
Date beginDate = new Date();
System.out.println("beginDate="+bartDateFormat.format(beginDate));
WebdavResource wdr = new WebdavResource(host,creds, WebdavResource.ALL, DepthSupport.DEPTH_INFINITY);
Date endDate = new Date();
System.out.println("endDate="+bartDateFormat.format(endDate));
HttpClient client=wdr.retrieveSessionInstance();
PropFindMethod method = new PropFindMethod(inbox,Integer.MAX_VALUE,properties.elements());
int status = client.executeMethod(method);
java.util.Enumeration responses = method.getResponses();
Date processDate = new Date();
System.out.println("processDate="+bartDateFormat.format(processDate));
while (responses.hasMoreElements()){
ResponseEntity response = (ResponseEntity)responses.nextElement();
java.util.Enumeration properties1 = response.getProperties();
String mailName="";
while (properties1.hasMoreElements()) {
Property property = (Property)properties1.nextElement();
System.out.println("name="+property.getName() + " type ="+ property.getLocalName() + " = content value= " + property.getPropertyAsString() +"=status code="+ property.getStatusCode());
if(property.getLocalName().equals("displayname") )
{
mailName=property.getPropertyAsString();
System.out.println("mailName="+mailName);
}
if(property.getLocalName().equals("hasattachment")&&property.getPropertyAsString().equals("1") )
{
System.out.println("attachment="+inbox+mailName);
fetchAttachment(inbox+mailName);
}
}
System.out.println("--------------------------------------------------------");
}
}catch(MalformedURLException mue)
{
mue.printStackTrace();
}
catch(HttpException he)
{
he.printStackTrace();
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
}
protected static void fetchAttachment(String attPath) throws Exception
{
System.out.println("attPath="+attPath);
try
{
NTCredentials creds = new NTCredentials(userName, password, hostAdd,domain);
HttpURL host = new HttpURL(attPath);
WebdavResource wdr = new WebdavResource(host,creds, WebdavResource.ALL, DepthSupport.DEPTH_0);
org.apache.commons.httpclient.HttpClient client=wdr.retrieveSessionInstance();
java.util.Vector vproperties= new java.util.Vector();
vproperties.addElement("urn:schemas:httpmail:attachmentfilename");
vproperties.addElement("http://schemas.microsoft.com/mapi/proptag/x0E210003");
vproperties.addElement("http://schemas.microsoft.com/mapi/proptag/x3716001F");
vproperties.addElement("http://schemas.microsoft.com/mapi/proptag/x37140003");
vproperties.addElement("http://schemas.microsoft.com/mapi/proptag/x3713001F");
vproperties.addElement("http://schemas.microsoft.com/mapi/proptag/x370E001F");
vproperties.addElement("http://schemas.microsoft.com/mapi/proptag/x370B0003");
vproperties.addElement("http://schemas.microsoft.com/mapi/proptag/x37050003");
vproperties.addElement("http://schemas.microsoft.com/mapi/proptag/x3704001F");
attFindMethod method = new attFindMethod(attPath,Integer.MAX_VALUE,vproperties.elements());
int status = client.executeMethod(method);
java.util.Enumeration responses = method.getResponses();
System.out.println("============================================");
while (responses.hasMoreElements()){
ResponseEntity response = (ResponseEntity)responses.nextElement();
java.util.Enumeration properties1 = response.getProperties();
while (properties1.hasMoreElements()) {
Property property = (Property)properties1.nextElement();
System.out.println("name="+property.getName() + " type ="+ property.getLocalName() + " = content value= " + property.getPropertyAsString() +"=status code="+ property.getStatusCode());
String attName="";
if(property.getLocalName().equals("attachmentfilename"))
{
attName = property.getPropertyAsString();
NTCredentials creds1 = new NTCredentials(userName, password, hostAdd,domain);
HttpURL host1 = new HttpURL(attPath+"/"+attName);
WebdavResource wdr1 = new WebdavResource(host1,creds1, WebdavResource.ALL, DepthSupport.DEPTH_0);
File f= new File(attName);
boolean bool=wdr1.getMethod(f) ;
System.out.println("bool="+bool);
}
}
}
System.out.println("============================================");
}
catch(MalformedURLException mue)
{
mue.printStackTrace();
}
catch(HttpException he)
{
he.printStackTrace();
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
}
attFindMethod.java
/*
* $Header: /home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/PropFindMethod.java,v 1.7 2004/08/02 15:45:48 unico Exp $
* $Revision: 1.7 $
* $Date: 2004/08/02 15:45:48 $
*
* ====================================================================
*
* Copyright 1999-2002 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.webdav.lib.methods;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;
import org.apache.commons.httpclient.HttpConnection;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpState;
import org.apache.webdav.lib.PropertyName;
import org.apache.webdav.lib.util.XMLPrinter;
/**
* This class implements the WebDAV PROPFIND Method.
*
* <P> The PROPFIND method retrieves properties defined on the resource
* identified by the Request-URI, if the resource does not have any internal
* members, or on the resource identified by the Request-URI and potentially
* its member resources, if the resource is a collection that has internal
* member URIs.
*
* <P> A typical request looks like this:
*
* <PRE>
*
* PROPFIND /file HTTP/1.1
* Host: www.foo.bar
* Content-type: text/xml; charset="utf-8"
* Content-Length: xxxx
*
* <?xml version="1.0" encoding="utf-8" ?>
* <D:propfind xmlns:D="DAV:">
* <D:prop xmlns:R="http://www.foo.bar/boxschema/">
* <R:bigbox/>
* <R:author/>
* <R:DingALing/>
* <R:Random/>
* </D:prop>
* </D:propfind>
* </PRE>
*
*/
public class attFindMethod extends XMLResponseMethodBase
implements DepthSupport {
// -------------------------------------------------------------- Constants
/**
* Request of named properties.
*/
public static final int BY_NAME = 0;
/**
* Request of all properties name and value.
*/
public static final int ALL = 1;
/**
* Request of all properties name.
*/
public static final int NAMES = 2;
// ----------------------------------------------------------- Constructors
/**
* Method constructor.
*/
public attFindMethod() {
}
/**
* Method constructor.
*/
public attFindMethod(String path) {
super(path);
}
/**
* Method constructor.
*/
public attFindMethod(String path, int depth) {
this(path);
setDepth(depth);
}
/**
* Method constructor.
*/
public attFindMethod(String path, int depth, int type) {
this(path);
setDepth(depth);
setType(type);
}
/**
* Method constructor.
*/
public attFindMethod(String path, Enumeration propertyNames) {
this(path);
setDepth(1);
setPropertyNames(propertyNames);
setType(BY_NAME);
}
/**
* Method constructor.
*/
public attFindMethod(String path, int depth, Enumeration propertyNames) {
this(path);
setDepth(depth);
setPropertyNames(propertyNames);
setType(BY_NAME);
}
// ----------------------------------------------------- Instance Variables
/**
* Type of the Propfind.
*/
protected int type = ALL;
/**
* Property name list.
*/
protected PropertyName[] propertyNames;
/**
* Depth.
*/
protected int depth = DEPTH_INFINITY;
/**
* The namespace abbreviation that prefixes DAV tags
*/
protected String prefix = null;
// ------------------------------------------------------------- Properties
/**
* Set a request header value, redirecting the special case of the "Depth" header
* to invoke {@link #setDepth} instead.
*
* @param headerName Header name
* @param headerValue Header value
*/
public void setRequestHeader(String headerName, String headerValue) {
if (headerName.equalsIgnoreCase("Depth")){
int depth = -1;
if (headerValue.equals("0")){
depth = DEPTH_0;
}
else if (headerValue.equals("1")){
depth = DEPTH_1;
}
else if (headerValue.equalsIgnoreCase("infinity")){
depth = DEPTH_INFINITY;
}
setDepth(depth);
}
else{
super.setRequestHeader(headerName, headerValue);
}
}
/**
* Type setter.
*
* @param type New type value
*/
public void setType(int type) {
checkNotUsed();
this.type = type;
}
/**
* Type getter.
*
* @return int type value
*/
public int getType() {
return type;
}
/**
* Depth setter.
*
* @param depth New depth value
*/
public void setDepth(int depth) {
checkNotUsed();
this.depth = depth;
}
/**
* Depth getter.
*
* @return int depth value
*/
public int getDepth() {
return depth;
}
/**
* Property names setter.
* The enumeration may contain strings with or without a namespace prefix
* but the preferred way is to provide PropertyName objects.
*
* @param propertyNames List of the property names
*/
public void setPropertyNames(Enumeration propertyNames) {
checkNotUsed();
Vector list = new Vector();
while (propertyNames.hasMoreElements()) {
Object item = propertyNames.nextElement();
if (item instanceof PropertyName)
{
list.add(item);
}
else if (item instanceof String)
{
String propertyName = (String) item;
int length = propertyName.length();
boolean found = false;
int i = 1;
while (!found && (i <= length)) {
char chr = propertyName.charAt(length - i);
if (!Character.isUnicodeIdentifierPart(chr)
&& chr!='-' && chr!='_' && chr!='.') {
found = true;
} else {
i++;
}
}
if ((i == 1) || (i >= length)) {
list.add(new PropertyName("DAV:",propertyName));
} else {
String namespace = propertyName.substring(0, length + 1 - i);
String localName = propertyName.substring(length + 1 - i);
list.add(new PropertyName(namespace,localName));
}
}
else
{
// unknown type
// ignore
}
}
this.propertyNames = (PropertyName[])list.toArray(new PropertyName[list.size()]);
}
// --------------------------------------------------- WebdavMethod Methods
public void recycle() {
super.recycle();
prefix = null;
}
public String getName() {
return "X-MS-ENUMATTS";
}
/**
* Generate additional headers needed by the request.
*
* @param state State token
* @param conn The connection being used to make the request.
*/
public void addRequestHeaders(HttpState state, HttpConnection conn)
throws IOException, HttpException {
// set the default utf-8 encoding, if not already present
if (getRequestHeader("Content-Type") == null ) super.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
super.addRequestHeaders(state, conn);
switch (depth) {
case DEPTH_0:
super.setRequestHeader("Depth", "0");
break;
case DEPTH_1:
super.setRequestHeader("Depth", "1");
break;
case DEPTH_INFINITY:
super.setRequestHeader("Depth", "infinity");
break;
}
}
/**
* DAV requests that contain a body must override this function to
* generate that body.
*
* <p>The default behavior simply returns an empty body.</p>
*/
public String generateRequestBody() {
XMLPrinter printer = new XMLPrinter();
printer.writeXMLHeader();
printer.writeElement("D", "DAV:", "PROPFIND",
XMLPrinter.OPENING);
switch (type) {
case ALL:
printer.writeElement("D", "allprop", XMLPrinter.NO_CONTENT);
break;
case NAMES:
printer.writeElement("D", "propname", XMLPrinter.NO_CONTENT);
break;
case BY_NAME:
printer.writeElement("D", "prop", XMLPrinter.OPENING);
for (int i=0 ; i<propertyNames.length ; i++)
{
String namespace = propertyNames[i].getNamespaceURI();
String localname = propertyNames[i].getLocalName();
if ("DAV:".equals(namespace)) {
printer.writeElement("D", localname, XMLPrinter.NO_CONTENT);
} else {
if (namespace.length() > 0) {
printer.writeElement("ZZ", namespace, localname,
XMLPrinter.NO_CONTENT);
} else {
printer.writeElement(null, null, localname,
XMLPrinter.NO_CONTENT);
}
}
}
printer.writeElement("D", "prop", XMLPrinter.CLOSING);
break;
}
printer.writeElement("D", "PROPFIND", XMLPrinter.CLOSING);
return printer.toString();
}
/**
* This method returns an enumeration of URL paths. If the attFindMethod
* was sent to the URL of a collection, then there will be multiple URLs.
* The URLs are picked out of the <code><D:href></code> elements
* of the response.
*
* @return an enumeration of URL paths as Strings
*/
public Enumeration getAllResponseURLs() {
checkUsed();
return getResponseURLs().elements();
}
/**
* Returns an enumeration of <code>Property</code> objects.
*/
public Enumeration getResponseProperties(String urlPath) {
checkUsed();
Response response = (Response) getResponseHashtable().get(urlPath);
if (response != null) {
return response.getProperties();
} else {
return (new Vector()).elements();
}
}
}
webdav.java
/**
* Created by IntelliJ IDEA.
* User: zkx
* Date: 2006-8-14
* Time: 9:34:29
* To change this template use File | Settings | File Templates.
*/
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpURL;
import org.apache.commons.httpclient.NTCredentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.webdav.lib.Property;
import org.apache.webdav.lib.ResponseEntity;
import org.apache.webdav.lib.WebdavResource;
import org.apache.webdav.lib.methods.DepthSupport;
import org.apache.webdav.lib.methods.PropFindMethod;
import org.apache.webdav.lib.methods.attFindMethod;
import org.w3c.dom.NodeList;
import java.util.Vector;
import java.io.IOException;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.net.MalformedURLException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class webdav {
public static String userName="5";
public static String password="5";
public static String hostAdd="192.168.1.45";
public static String domain ="local";
public static String inbox = "http://192.168.1.45/exchange/5/Inbox/";
public static Vector properties;
static {
properties = new Vector();
properties.addElement("DAV:autoversion");
properties.addElement("DAV:contentclass");
properties.addElement("DAV:creationdate");
properties.addElement("DAV:displayname");
properties.addElement("DAV:getcontentlength");
properties.addElement("DAV:getcontenttype");
properties.addElement("DAV:getetag");
properties.addElement("DAV:getlastmodified");
properties.addElement("DAV:href");
properties.addElement("DAV:id");
properties.addElement("DAV:iscollection");
properties.addElement("DAV:isfolder");
properties.addElement("DAV:ishidden");
properties.addElement("DAV:isreadonly");
properties.addElement("DAV:isstructureddocument");
properties.addElement("DAV:isversioned");
properties.addElement("DAV:lockdiscovery");
properties.addElement("DAV:parentname");
properties.addElement("DAV:resourcetype");
properties.addElement("DAV:revisionid");
properties.addElement("DAV:revisionlabel");
properties.addElement("DAV:revisionuri");
properties.addElement("DAV:supportedlock");
properties.addElement("DAV:uid");
properties.addElement("DAV:resourcetype");
properties.addElement("DAV:vresourceid");
properties.addElement("urn:schemas:httpmail:date");
properties.addElement("urn:schemas:httpmail:datereceived");
properties.addElement("urn:schemas:httpmail:displaycc");
properties.addElement("urn:schemas:httpmail:displayto");
properties.addElement("urn:schemas:httpmail:from");
properties.addElement("urn:schemas:httpmail:fromemail");
properties.addElement("urn:schemas:httpmail:fromname");
properties.addElement("urn:schemas:httpmail:hasattachment");
properties.addElement("urn:schemas:httpmail:htmldescription");
properties.addElement("urn:schemas:httpmail:importance");
properties.addElement("urn:schemas:httpmail:normalizedsubject");
properties.addElement("urn:schemas:httpmail:read");
properties.addElement("urn:schemas:httpmail:sendername");
properties.addElement("urn:schemas:httpmail:subject");
properties.addElement("urn:schemas:httpmail:submitted");
properties.addElement("urn:schemas:httpmail:textdescription");
properties.addElement("urn:schemas:httpmail:thread-topic");
properties.addElement("urn:schemas:httpmail:to");
properties.addElement("urn:schemas:mailheader:content-class");
properties.addElement("urn:schemas:mailheader:date");
properties.addElement("urn:schemas:mailheader:from");
properties.addElement("urn:schemas:mailheader:message-id");
properties.addElement("urn:schemas:mailheader:received");
properties.addElement("urn:schemas:mailheader:subject");
properties.addElement("urn:schemas:mailheader:thread-index");
properties.addElement("urn:schemas:mailheader:thread-topic");
properties.addElement("urn:schemas:mailheader:to");
properties.addElement("urn:schemas:mailheader:xref");
properties.addElement("urn:schemas:mailheader:x-unsent");
properties.addElement("urn:schemas:mailheader:x-mailer");
properties.addElement("x-mimeole");
properties.addElement("urn:schemas:mailheader:x-catchall");
properties.addElement("urn:schemas:mailheader:x-ms-has-attach");
properties.addElement("urn:schemas:mailheader:content-disposition");
}
public static void main(String args[])
{
try{
NTCredentials creds = new NTCredentials(userName, password, hostAdd,domain);
HttpURL host = new HttpURL(inbox);
SimpleDateFormat bartDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss:SSS");
Date beginDate = new Date();
System.out.println("beginDate="+bartDateFormat.format(beginDate));
WebdavResource wdr = new WebdavResource(host,creds, WebdavResource.ALL, DepthSupport.DEPTH_INFINITY);
Date endDate = new Date();
System.out.println("endDate="+bartDateFormat.format(endDate));
HttpClient client=wdr.retrieveSessionInstance();
PropFindMethod method = new PropFindMethod(inbox,Integer.MAX_VALUE,properties.elements());
int status = client.executeMethod(method);
java.util.Enumeration responses = method.getResponses();
Date processDate = new Date();
System.out.println("processDate="+bartDateFormat.format(processDate));
while (responses.hasMoreElements()){
ResponseEntity response = (ResponseEntity)responses.nextElement();
java.util.Enumeration properties1 = response.getProperties();
String mailName="";
while (properties1.hasMoreElements()) {
Property property = (Property)properties1.nextElement();
System.out.println("name="+property.getName() + " type ="+ property.getLocalName() + " = content value= " + property.getPropertyAsString() +"=status code="+ property.getStatusCode());
if(property.getLocalName().equals("displayname") )
{
mailName=property.getPropertyAsString();
System.out.println("mailName="+mailName);
}
if(property.getLocalName().equals("hasattachment")&&property.getPropertyAsString().equals("1") )
{
System.out.println("attachment="+inbox+mailName);
fetchAttachment(inbox+mailName);
}
}
System.out.println("--------------------------------------------------------");
}
}catch(MalformedURLException mue)
{
mue.printStackTrace();
}
catch(HttpException he)
{
he.printStackTrace();
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
}
protected static void fetchAttachment(String attPath) throws Exception
{
System.out.println("attPath="+attPath);
try
{
NTCredentials creds = new NTCredentials(userName, password, hostAdd,domain);
HttpURL host = new HttpURL(attPath);
WebdavResource wdr = new WebdavResource(host,creds, WebdavResource.ALL, DepthSupport.DEPTH_0);
org.apache.commons.httpclient.HttpClient client=wdr.retrieveSessionInstance();
java.util.Vector vproperties= new java.util.Vector();
vproperties.addElement("urn:schemas:httpmail:attachmentfilename");
vproperties.addElement("http://schemas.microsoft.com/mapi/proptag/x0E210003");
vproperties.addElement("http://schemas.microsoft.com/mapi/proptag/x3716001F");
vproperties.addElement("http://schemas.microsoft.com/mapi/proptag/x37140003");
vproperties.addElement("http://schemas.microsoft.com/mapi/proptag/x3713001F");
vproperties.addElement("http://schemas.microsoft.com/mapi/proptag/x370E001F");
vproperties.addElement("http://schemas.microsoft.com/mapi/proptag/x370B0003");
vproperties.addElement("http://schemas.microsoft.com/mapi/proptag/x37050003");
vproperties.addElement("http://schemas.microsoft.com/mapi/proptag/x3704001F");
attFindMethod method = new attFindMethod(attPath,Integer.MAX_VALUE,vproperties.elements());
int status = client.executeMethod(method);
java.util.Enumeration responses = method.getResponses();
System.out.println("============================================");
while (responses.hasMoreElements()){
ResponseEntity response = (ResponseEntity)responses.nextElement();
java.util.Enumeration properties1 = response.getProperties();
while (properties1.hasMoreElements()) {
Property property = (Property)properties1.nextElement();
System.out.println("name="+property.getName() + " type ="+ property.getLocalName() + " = content value= " + property.getPropertyAsString() +"=status code="+ property.getStatusCode());
String attName="";
if(property.getLocalName().equals("attachmentfilename"))
{
attName = property.getPropertyAsString();
NTCredentials creds1 = new NTCredentials(userName, password, hostAdd,domain);
HttpURL host1 = new HttpURL(attPath+"/"+attName);
WebdavResource wdr1 = new WebdavResource(host1,creds1, WebdavResource.ALL, DepthSupport.DEPTH_0);
File f= new File(attName);
boolean bool=wdr1.getMethod(f) ;
System.out.println("bool="+bool);
}
}
}
System.out.println("============================================");
}
catch(MalformedURLException mue)
{
mue.printStackTrace();
}
catch(HttpException he)
{
he.printStackTrace();
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
}
attFindMethod.java
/*
* $Header: /home/cvs/jakarta-slide/webdavclient/clientlib/src/java/org/apache/webdav/lib/methods/PropFindMethod.java,v 1.7 2004/08/02 15:45:48 unico Exp $
* $Revision: 1.7 $
* $Date: 2004/08/02 15:45:48 $
*
* ====================================================================
*
* Copyright 1999-2002 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.webdav.lib.methods;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;
import org.apache.commons.httpclient.HttpConnection;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpState;
import org.apache.webdav.lib.PropertyName;
import org.apache.webdav.lib.util.XMLPrinter;
/**
* This class implements the WebDAV PROPFIND Method.
*
* <P> The PROPFIND method retrieves properties defined on the resource
* identified by the Request-URI, if the resource does not have any internal
* members, or on the resource identified by the Request-URI and potentially
* its member resources, if the resource is a collection that has internal
* member URIs.
*
* <P> A typical request looks like this:
*
* <PRE>
*
* PROPFIND /file HTTP/1.1
* Host: www.foo.bar
* Content-type: text/xml; charset="utf-8"
* Content-Length: xxxx
*
* <?xml version="1.0" encoding="utf-8" ?>
* <D:propfind xmlns:D="DAV:">
* <D:prop xmlns:R="http://www.foo.bar/boxschema/">
* <R:bigbox/>
* <R:author/>
* <R:DingALing/>
* <R:Random/>
* </D:prop>
* </D:propfind>
* </PRE>
*
*/
public class attFindMethod extends XMLResponseMethodBase
implements DepthSupport {
// -------------------------------------------------------------- Constants
/**
* Request of named properties.
*/
public static final int BY_NAME = 0;
/**
* Request of all properties name and value.
*/
public static final int ALL = 1;
/**
* Request of all properties name.
*/
public static final int NAMES = 2;
// ----------------------------------------------------------- Constructors
/**
* Method constructor.
*/
public attFindMethod() {
}
/**
* Method constructor.
*/
public attFindMethod(String path) {
super(path);
}
/**
* Method constructor.
*/
public attFindMethod(String path, int depth) {
this(path);
setDepth(depth);
}
/**
* Method constructor.
*/
public attFindMethod(String path, int depth, int type) {
this(path);
setDepth(depth);
setType(type);
}
/**
* Method constructor.
*/
public attFindMethod(String path, Enumeration propertyNames) {
this(path);
setDepth(1);
setPropertyNames(propertyNames);
setType(BY_NAME);
}
/**
* Method constructor.
*/
public attFindMethod(String path, int depth, Enumeration propertyNames) {
this(path);
setDepth(depth);
setPropertyNames(propertyNames);
setType(BY_NAME);
}
// ----------------------------------------------------- Instance Variables
/**
* Type of the Propfind.
*/
protected int type = ALL;
/**
* Property name list.
*/
protected PropertyName[] propertyNames;
/**
* Depth.
*/
protected int depth = DEPTH_INFINITY;
/**
* The namespace abbreviation that prefixes DAV tags
*/
protected String prefix = null;
// ------------------------------------------------------------- Properties
/**
* Set a request header value, redirecting the special case of the "Depth" header
* to invoke {@link #setDepth} instead.
*
* @param headerName Header name
* @param headerValue Header value
*/
public void setRequestHeader(String headerName, String headerValue) {
if (headerName.equalsIgnoreCase("Depth")){
int depth = -1;
if (headerValue.equals("0")){
depth = DEPTH_0;
}
else if (headerValue.equals("1")){
depth = DEPTH_1;
}
else if (headerValue.equalsIgnoreCase("infinity")){
depth = DEPTH_INFINITY;
}
setDepth(depth);
}
else{
super.setRequestHeader(headerName, headerValue);
}
}
/**
* Type setter.
*
* @param type New type value
*/
public void setType(int type) {
checkNotUsed();
this.type = type;
}
/**
* Type getter.
*
* @return int type value
*/
public int getType() {
return type;
}
/**
* Depth setter.
*
* @param depth New depth value
*/
public void setDepth(int depth) {
checkNotUsed();
this.depth = depth;
}
/**
* Depth getter.
*
* @return int depth value
*/
public int getDepth() {
return depth;
}
/**
* Property names setter.
* The enumeration may contain strings with or without a namespace prefix
* but the preferred way is to provide PropertyName objects.
*
* @param propertyNames List of the property names
*/
public void setPropertyNames(Enumeration propertyNames) {
checkNotUsed();
Vector list = new Vector();
while (propertyNames.hasMoreElements()) {
Object item = propertyNames.nextElement();
if (item instanceof PropertyName)
{
list.add(item);
}
else if (item instanceof String)
{
String propertyName = (String) item;
int length = propertyName.length();
boolean found = false;
int i = 1;
while (!found && (i <= length)) {
char chr = propertyName.charAt(length - i);
if (!Character.isUnicodeIdentifierPart(chr)
&& chr!='-' && chr!='_' && chr!='.') {
found = true;
} else {
i++;
}
}
if ((i == 1) || (i >= length)) {
list.add(new PropertyName("DAV:",propertyName));
} else {
String namespace = propertyName.substring(0, length + 1 - i);
String localName = propertyName.substring(length + 1 - i);
list.add(new PropertyName(namespace,localName));
}
}
else
{
// unknown type
// ignore
}
}
this.propertyNames = (PropertyName[])list.toArray(new PropertyName[list.size()]);
}
// --------------------------------------------------- WebdavMethod Methods
public void recycle() {
super.recycle();
prefix = null;
}
public String getName() {
return "X-MS-ENUMATTS";
}
/**
* Generate additional headers needed by the request.
*
* @param state State token
* @param conn The connection being used to make the request.
*/
public void addRequestHeaders(HttpState state, HttpConnection conn)
throws IOException, HttpException {
// set the default utf-8 encoding, if not already present
if (getRequestHeader("Content-Type") == null ) super.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
super.addRequestHeaders(state, conn);
switch (depth) {
case DEPTH_0:
super.setRequestHeader("Depth", "0");
break;
case DEPTH_1:
super.setRequestHeader("Depth", "1");
break;
case DEPTH_INFINITY:
super.setRequestHeader("Depth", "infinity");
break;
}
}
/**
* DAV requests that contain a body must override this function to
* generate that body.
*
* <p>The default behavior simply returns an empty body.</p>
*/
public String generateRequestBody() {
XMLPrinter printer = new XMLPrinter();
printer.writeXMLHeader();
printer.writeElement("D", "DAV:", "PROPFIND",
XMLPrinter.OPENING);
switch (type) {
case ALL:
printer.writeElement("D", "allprop", XMLPrinter.NO_CONTENT);
break;
case NAMES:
printer.writeElement("D", "propname", XMLPrinter.NO_CONTENT);
break;
case BY_NAME:
printer.writeElement("D", "prop", XMLPrinter.OPENING);
for (int i=0 ; i<propertyNames.length ; i++)
{
String namespace = propertyNames[i].getNamespaceURI();
String localname = propertyNames[i].getLocalName();
if ("DAV:".equals(namespace)) {
printer.writeElement("D", localname, XMLPrinter.NO_CONTENT);
} else {
if (namespace.length() > 0) {
printer.writeElement("ZZ", namespace, localname,
XMLPrinter.NO_CONTENT);
} else {
printer.writeElement(null, null, localname,
XMLPrinter.NO_CONTENT);
}
}
}
printer.writeElement("D", "prop", XMLPrinter.CLOSING);
break;
}
printer.writeElement("D", "PROPFIND", XMLPrinter.CLOSING);
return printer.toString();
}
/**
* This method returns an enumeration of URL paths. If the attFindMethod
* was sent to the URL of a collection, then there will be multiple URLs.
* The URLs are picked out of the <code><D:href></code> elements
* of the response.
*
* @return an enumeration of URL paths as Strings
*/
public Enumeration getAllResponseURLs() {
checkUsed();
return getResponseURLs().elements();
}
/**
* Returns an enumeration of <code>Property</code> objects.
*/
public Enumeration getResponseProperties(String urlPath) {
checkUsed();
Response response = (Response) getResponseHashtable().get(urlPath);
if (response != null) {
return response.getProperties();
} else {
return (new Vector()).elements();
}
}
}
发表评论
-
手动将class打包成jar包方法
2010-09-10 00:41 2832<!-- ------------------ --&g ... -
教你用Java生成RSS 简单实用
2010-09-10 00:40 3309<!-- ------------------ --&g ... -
代码的坏味道
2010-06-29 13:10 16431. Duplicated Code(重 ... -
java 获取客户端ip mac地址
2010-02-23 15:47 2958转自:http://hi.baidu.com/coolcode ... -
java中输出流OutputStream类应用实例
2010-02-04 15:30 5248OutputStream类 该类是字节输出流的抽象类,定义了输 ... -
大幅优化myeclipse的速度&关闭自动更新
2010-02-01 21:24 1444去除不需要加载的模块 一个系统20%的功能往往能够满足80% ... -
Servlet 上传文件(转)
2010-01-18 14:45 1609编程思路:下面的UploadServlet.java ,其主 ... -
JAVA线程实例-----卖票
2010-01-08 15:44 2007package test; import java. ... -
如何学习Hibernate
2009-12-21 09:28 947Hibernate入门容易,掌握精通我也不敢自夸。我第 ... -
Tomcat 部署 Could not copy all resources to 或者Undeployment Failure could not be re
2009-12-16 22:13 3229Tomcat 部署,在部署可能会出现以下问题: Deploy ... -
Java 的JDBC 数据库连接池实现方法
2009-12-16 01:10 1364关键字: Java, JDBC, Connection Poo ... -
jdbc PreparedStatement的用法
2009-12-15 21:51 40431jdbc(java database connectivity ... -
用java获取文件夹的大小
2009-12-14 09:15 2498/** * <p> * Created on ... -
JavaBean实现多文件上传的两种方法
2009-12-10 10:32 1089摘要:本文介绍了J ... -
通过 http 协议上传文件
2009-12-10 10:07 21301、概述 在最初的 http ... -
自学Javabean迅速成为Java高手
2009-12-10 09:17 834很多网友咨询学习Java有 ... -
response.setContentType()的String参数及对应类型
2009-12-09 13:43 2511response.setContentType()的Strin ... -
Apache Commons fileUpload实现文件上传
2009-10-19 00:15 1287Apache的commons-fileupload.jar可方 ... -
Postfix邮件服务器架设笔记
2009-08-26 06:57 1683# 安装步骤1、安装操作系统 2、安装postfixadmin ... -
3分钟安装配置Postfix邮件服务器
2009-08-26 06:51 3056Linux邮件服务器通常使用sendmail,在网上googl ...
相关推荐
使用WebDAV,可以通过创建一个新的XML文档来构造邮件,然后使用WebClient的UploadData方法将数据发送到Exchange服务器的WebDAV端点。记得设置适当的HTTP头,如Content-Type和Authorization,以确保请求能正确被...
2. 邮件推送:K9支持IMAP IDLE协议,可以实现实时的邮件推送,一旦服务器上有新邮件到达,用户就能立即收到通知,无需频繁检查。 3. 多账户管理:K9支持添加多个邮件账户,包括POP3、IMAP4以及Exchange 2003/2007的...
JavaMail API 是一个Java编程语言中的库,用于处理电子邮件的创建、发送和接收。这个API提供了与邮件协议无关的...在使用JavaMail API时,需要考虑服务器配置、协议支持以及性能优化等问题,以确保邮件功能的正常运行。
此外,JavaMail还提供了对EWS(Exchange Web Services)和WebDAV的支持,以与Microsoft Exchange和其他支持这些协议的服务器交互。 总的来说,`javamail1.4.5` 和 `javax.mail-1.5.5.jar` 提供了强大的邮件处理功能...
内容概要:本文档详细介绍了基于 MATLAB 实现的 LSTM-AdaBoost 时间序列预测模型,涵盖项目背景、目标、挑战、特点、应用领域以及模型架构和代码示例。随着大数据和AI的发展,时间序列预测变得至关重要。传统方法如 ARIMA 在复杂非线性序列中表现欠佳,因此引入了 LSTM 来捕捉长期依赖性。但 LSTM 存在易陷局部最优、对噪声鲁棒性差的问题,故加入 AdaBoost 提高模型准确性和鲁棒性。两者结合能更好应对非线性和长期依赖的数据,提供更稳定的预测。项目还展示了如何在 MATLAB 中具体实现模型的各个环节。 适用人群:对时间序列预测感兴趣的开发者、研究人员及学生,特别是有一定 MATLAB 编程经验和熟悉深度学习或机器学习基础知识的人群。 使用场景及目标:①适用于金融市场价格预测、气象预报、工业生产故障检测等多种需要时间序列分析的场合;②帮助使用者理解并掌握将LSTM与AdaBoost结合的实现细节及其在提高预测精度和抗噪方面的优势。 其他说明:尽管该模型有诸多优点,但仍存在训练时间长、计算成本高等挑战。文中提及通过优化数据预处理、调整超参数等方式改进性能。同时给出了完整的MATLAB代码实现,便于学习与复现。
palkert_3ck_01_0918
pepeljugoski_01_1106
tatah_01_1107
AB PLC例程代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!
题目:基于单片机的步进电机控制系统 模块: 主控:AT89C52RC 步进电机(ULN2003驱动) 按键(3个) 蓝牙(虚拟终端模拟) 功能: 1、可以通过蓝牙远程控制步进电机转动 2、可以通过按键实现手动与自动控制模式切换。 3、自动模式下,步进电机正转一圈,反转一圈,循环 4、手动模式下可以通过按键控制步进电机转动(顺时针和逆时针)
AB PLC例程代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!
AB PLC例程代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!
内容概要:本文详细介绍了建设智慧校园平台所需的六个关键步骤。首先通过需求分析深入了解并确定校方和使用者的具体需求;其次是规划设计阶段,依据所得需求制定全面的建设方案。再者是对现有系统的整合——系统集成,确保新旧平台之间的互操作性和数据一致性。培训支持帮助全校教职工和学生快速熟悉新平台,提高效率。实施试点确保系统逐步稳定部署。最后,强调持续改进的重要性,以适应技术和环境变化。通过这一系列有序的工作,可以使智慧校园建设更为科学高效,减少失败风险。 适用人群:教育领域的决策者和技术人员,包括负责信息化建设和运维的团队成员。 使用场景及目标:用于指导高校和其他各级各类学校规划和发展自身的数字校园生态链;目的是建立更加便捷高效的现代化管理模式和服务机制。 其他说明:智慧校园不仅仅是简单的IT设施升级或软件安装,它涉及到全校范围内的流程再造和创新改革。
该文档系统梳理了人工智能技术在商业场景中的落地路径,聚焦内容生产、电商运营、智能客服、数据分析等12个高潜力领域,提炼出100个可操作性变现模型。内容涵盖AI工具开发、API服务收费、垂直场景解决方案、数据增值服务等多元商业模式,每个思路均配备应用场景拆解、技术实现路径及收益测算框架。重点呈现低代码工具应用、现有平台流量复用、细分领域自动化改造三类轻量化启动方案,为创业者提供从技术选型到盈利闭环的全流程参考。
palkert_3ck_02_0719
克鲁格曼专业化指数,最初是由Krugman于1991年提出,用于反映地区间产业结构的差异,也被用来衡量两个地区间的专业化水平,因而又称地区间专业化指数。该指数的计算公式及其含义可以因应用背景和具体需求的不同而有所调整,但核心都是衡量地区间的产业结构差异或专业化程度。 指标 年份、城市、第一产业人数(first_industry1)、第二产业人数(second_industry1)、第三产业人数(third_industry1)、专业化指数(ksi)。
AB PLC例程代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!
精品推荐,通信技术LTE干货资料合集,19份。 LTE PCI网络规划工具.xlsx LTE-S1切换占比专题优化分析报告.docx LTE_TDD问题定位指导书-吞吐量篇.docx LTE三大常见指标优化指导书.xlsx LTE互操作邻区配置核查原则.docx LTE信令流程详解指导书.docx LTE切换问题定位指导一(定位思路和问题现象).docx LTE劣化小区优化指导手册.docx LTE容量优化高负荷小区优化指导书.docx LTE小区搜索过程学习.docx LTE小区级与邻区级切换参数说明.docx LTE差小区处理思路和步骤.docx LTE干扰日常分析介绍.docx LTE异频同频切换.docx LTE弱覆盖问题分析与优化.docx LTE网优电话面试问题-应答技巧.docx LTE网络切换优化.docx LTE高负荷小区容量优化指导书.docx LTE高铁优化之多频组网优化提升“用户感知,网络价值”.docx
matlab程序代码项目案例 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!
pepeljugoski_01_0508