Skip to content

Commit

Permalink
modfiy http
Browse files Browse the repository at this point in the history
  • Loading branch information
KenelLiu committed Jul 25, 2017
1 parent d96c15a commit e2b4f82
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 30 deletions.
5 changes: 2 additions & 3 deletions CDOUtil/src/main/java/com/cdo/util/constants/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ public static class CDO{
public final static String HTTP_CDO_UPLOADFILE_KEY="$CDOSerialFile$";

public final static String HTTP_CDO_RESPONSE="$$CDOResponse$$";
public final static String HTTP_UPLOAD_FILE_PATH="uploadPath";
public final static String TEMP_FILE_PATH="tmpPath";
public final static String UPLOAD_FILE_MAX_SIZE="uploadFileMaxSize";
public final static String HTTP_UPLOAD_FILE_PATH="cdo.uploadPath";
public final static String UPLOAD_FILE_MAX_SIZE="cdo.uploadFile.MaxSize";

}
}
6 changes: 2 additions & 4 deletions CDOUtil/src/main/java/com/cdo/util/http/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
//import com.cdo.util.common.Zipper;
import com.cdo.util.constants.Constants;
import com.cdo.util.exception.HttpException;
import com.cdo.util.resource.GlobalResource;
//import com.cdo.util.resource.GlobalResource;
//import com.cdo.util.serial.Serializable;
import com.cdoframework.cdolib.data.cdo.CDO;
/**
Expand Down Expand Up @@ -387,9 +387,7 @@ private byte[] outCDO(InputStream instream,int xmlLen) throws IOException{
}
//--------------下载到文件,临时存储的位置-------------------//
private String getTmpPath(){
String tmpDirPath =GlobalResource.cdoConfig==null?null:GlobalResource.cdoConfig.getString(Constants.CDO.TEMP_FILE_PATH);
if(tmpDirPath==null || tmpDirPath.trim().equals(""))
tmpDirPath=System.getProperty("java.io.tmpdir");
String tmpDirPath=System.getProperty("java.io.tmpdir");
File tmpDir= new File(tmpDirPath);
if(!tmpDir.exists() || !tmpDir.isDirectory())
tmpDir.mkdirs();
Expand Down
37 changes: 14 additions & 23 deletions CDOWeb/src/main/java/com/cdoframework/cdolib/web/CDOServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void doPost(HttpServletRequest request,HttpServletResponse response) thro
{
// 构造请求对象
CDO cdoRequest=null;
String strCDORequest=null;

Map<String, File> mapFileMap=null;
String strTransName=null;
try
Expand All @@ -99,9 +99,7 @@ public void doPost(HttpServletRequest request,HttpServletResponse response) thro
if(serialFile!=null && serialFile.trim().equals("1")){
//表示有文件对象需要上传
mapFileMap=new HashMap<String,File>();
strCDORequest=processUploadFile(request, mapFileMap);

cdoRequest=CDO.fromXML(strCDORequest);
cdoRequest=processUploadFile(request, mapFileMap);
if(mapFileMap!=null){
for(Iterator<Map.Entry<String, File>> iterator=mapFileMap.entrySet().iterator();iterator.hasNext();){
Entry<String, File> entry=iterator.next();
Expand Down Expand Up @@ -224,9 +222,7 @@ private void outputReponse(HttpServletResponse response, String strOutput,CDO cd
log.error("wirte response errr"+e.getMessage(), e);
}finally{
if(inStream!=null){try{inStream.close();}catch(Exception ex){};}
if(out != null){
out.close();
}
if(out != null){try{out.close();}catch(Exception ex){};}
}
}

Expand Down Expand Up @@ -302,20 +298,15 @@ private CDO parseInputStream2CDO(InputStream inputStream)

}

protected String processUploadFile(HttpServletRequest request,Map<String,File> mapFile) throws ServletException, IOException {
String strCDORequest=null;
protected CDO processUploadFile(HttpServletRequest request,Map<String,File> mapFile) throws ServletException, IOException {
try {
String saveDirPath =GlobalResource.cdoConfig==null?null:GlobalResource.cdoConfig.getString(Constants.CDO.HTTP_UPLOAD_FILE_PATH);
String tmpDirPath =GlobalResource.cdoConfig==null?null:GlobalResource.cdoConfig.getString(Constants.CDO.TEMP_FILE_PATH);
long maxSize=maxFileSize;
if(GlobalResource.cdoConfig!=null && GlobalResource.cdoConfig.getString(Constants.CDO.UPLOAD_FILE_MAX_SIZE)!=null){
maxSize=Long.parseLong(GlobalResource.cdoConfig.getString(Constants.CDO.UPLOAD_FILE_MAX_SIZE));
}
String saveDirPath =System.getProperty(Constants.CDO.HTTP_UPLOAD_FILE_PATH,
this.getServletContext().getRealPath("/cdoUploadPath"));

String tmpDirPath =System.getProperty("java.io.tmpdir");

if(saveDirPath==null || saveDirPath.trim().equals(""))
saveDirPath = this.getServletContext().getRealPath("/cdoUploadPath");
if(tmpDirPath==null || tmpDirPath.trim().equals(""))
tmpDirPath=System.getProperty("java.io.tmpdir");

long maxSize=Long.parseLong(System.getProperty(Constants.CDO.UPLOAD_FILE_MAX_SIZE, maxFileSize+""));

if(log.isDebugEnabled()){
log.debug(" tmpDir= [" + tmpDirPath + "]"+" saveDir= [" + saveDirPath + "]");
Expand Down Expand Up @@ -373,16 +364,16 @@ protected String processUploadFile(HttpServletRequest request,Map<String,File> m
if(log.isDebugEnabled())
log.debug("fieldName[" + fieldName + "] value[" + fileItem.getString() + "]");
if(fieldName.equals(Constants.CDO.HTTP_CDO_REQUEST)){
strCDORequest=fileItem.getString();
return CDO.fromXML(fileItem.getString());
}
}
}
if(strCDORequest==null)
throw new IOException("param["+Constants.CDO.HTTP_CDO_REQUEST+"] is not exists.... ");

throw new IOException("param["+Constants.CDO.HTTP_CDO_REQUEST+"] is not exists.... ");
} catch(Exception e) {
log.error("解释上传文件数据失败....."+e.getMessage(), e);
throw new IOException(e.getMessage(),e);
}
return strCDORequest;

}
}

0 comments on commit e2b4f82

Please sign in to comment.