public static void main(String[] args) throws Exception{
if (args.length != 2){
System.out.println("Please enter feed file");
return;
}
String feedFileName = args[0];
String logFileName = args[1];
ObjectInputStream in = new ObjectInputStream(new FileInputStream(feedFileName));
File file = new File(logFileName);
if (file.exists()){
file.delete();
}
FileOutputStream out = new FileOutputStream(logFileName);
PrintWriter log = new PrintWriter(out);
try{
ArrayList arrayList = (ArrayList)in.readObject();
for (int i = 0 ; i < arrayList.size() ; i++){
PAReportUploadInfoVO paReportUploadInfoVO = (PAReportUploadInfoVO)arrayList.get(i);
try{
HttpClient client = new HttpClient();
PostMethod m = new PostMethod(url);
prepare(m, paReportUploadInfoVO);
int rc = client.executeMethod(m);
BufferedReader r = new BufferedReader(new InputStreamReader(m.getResponseBodyAsStream()));
String reply;
boolean hasError = true;
while ((reply = r.readLine()) != null){
if (reply.equals("OK")){
hasError = false;
break;
}
}
if (hasError){
log.write((new Date()).toString() + " ERROR in sending PA report branch(" + paReportUploadInfoVO.getFileName() + " , AgentCod : " + paReportUploadInfoVO.getAgentCode()+")\n");
}
} catch (Exception e){
log.write((new Date()).toString() + " ERROR in sending PA report branch(" + paReportUploadInfoVO.getFileName() + ")");
e.printStackTrace(log);
}
}
} catch (Exception e){
e.printStackTrace(log);
}
log.close();
}
protected static void prepare(PostMethod method, PAReportUploadInfoVO paReportUploadInfoVO) throws Exception{
List parts = new ArrayList();
parts.add(new StringPart("agent_code", paReportUploadInfoVO.getAgentCode()));
parts.add(new StringPart("report_code", paReportUploadInfoVO.getReportCode()));
parts.add(new StringPart("report_name", paReportUploadInfoVO.getReportName()));
parts.add(new StringPart("user", paReportUploadInfoVO.getAgentName()));
parts.add(new StringPart("upload_dir", paReportUploadInfoVO.getUploadDir()));
parts.add(new FilePart("report", new File(paReportUploadInfoVO.getFileName())));
//commons-httpclient-3.0-rc2.jar
//public class org.apache.commons.httpclient.methods.multipart.FilePart extends org.apache.commons.httpclient.methods.multipart.PartBase
//public class org.apache.commons.httpclient.methods.multipart.StringPart extends org.apache.commons.httpclient.methods.multipart.PartBase
MultipartRequestEntity mre = new MultipartRequestEntity((Part[])parts.toArray(new Part[parts.size()]), method.getParams());
method.setRequestEntity(mre);
}
相关推荐
在具体使用中,"commons-httpclient-3.0-rc2.jar"是该库的核心组件,包含了所有必要的类和方法。开发者可以通过导入这个jar文件,轻松地将HttpClient的功能集成到他们的项目中。例如,创建一个HTTP GET请求可以如下...
commons-httpclient-3.0-rc2.jar
commons-httpclient-2.0.jar
commons-httpclient.jar commons-io.jar commons-logging-1.0.4.jar commons-logging-1.1.jar commons-logging.jar commons-pool.jar concurrent-1.3.2.jar connector.jar cos.jar dom4j-1.6.1.jar dwr.jar ehcache-...
webmvc.jar spring-portlet.jar struts.jar commons-fileupload.jar commons-httpclient.jar freemarker.jar jasperreports-1.3.3.jar commons-io.jar portlet-api.jar jxl.jar itext...
struts.jar spring-web.jar spring-webmvc.jar spring-portlet.jar struts.jar commons-fileupload.jar commons-httpclient.jar freemarker.jar jasperreports-1.3.3.jar commons-io.jar...
在处理文件上传的问题上,HttpClient也提供了便捷的方法,使得开发者可以轻松地发送POST请求并附带文件数据。 以下是一个使用HttpClient简单读取网页内容的例子: ```java import java.io.IOException; import org...
5. commons-httpclient-3.0-rc2.jar:Apache HttpClient是处理HTTP请求的库,对于通过HTTP协议进行Web服务通信至关重要。 6. saaj-impl-1.3.jar:SOAP with Attachments API for Java (SAAJ) 实现,用于处理SOAP...
如果我们自己使用java.net.HttpURLConnection来搞定这些问题是很恐怖的事情,因此在开始之前我们先要介绍一下一个开放源码的项目,这个项目就是Apache开源组织中的httpclient,它隶属于Jakarta的commons项目,目前的...
6. `commons-httpclient-3.0-rc2.jar`:Apache HttpClient库提供了一种方式来执行HTTP请求,这在处理SOAP请求时是必要的。 7. `ibmjsse.jar`:IBM的Java Secure Socket Extension,用于提供SSL/TLS安全通信,确保...