|
本帖最后由 Sunner 于 2017-9-15 10:27 编辑
版本:5.2.7
之前做过一个功能,是在上传附件时拦截servletRequest请求对文件的inputstream进行加密包装后再继续上传,目前已完成。http://bbs.wex5.com/forum.php?mod=viewthread&tid=113449
现在要做的是在附件组件点击下载的时候对加密过的文件先进行解密然后再下载,但是下载部分的代码被平台封装在ui-core.jar里了,无奈只好对com.justep.ui.system.service.doc.DocUtils.class尝试反编译进行修改,反编译后在myeclipse的IDE中编译正常(无报错等信息),但是重新把编译过的DocUtils.class放回ui-core.jar后,启动服务报错:内部错误!错误编码:ui-08,请问下应该怎么解决,因为需求好像无法绕开修改下载部分源码的问题了。
反编译修改代码如下:
- package com.justep.ui.system.service.doc;
- import com.justep.biz.client.ActionEngine;
- import com.justep.biz.client.Callback;
- import com.justep.biz.client.StreamCallback;
- import com.justep.common.MessageUtils;
- import com.justep.message.UIMessages;
- import com.justep.system.transform.Utils;
- import com.justep.ui.LanguageEngine;
- import com.justep.ui.servlet.DownloadServlet;
- import com.justep.ui.util.Escape;
- import com.justep.ui.util.NetUtils;
- import java.io.ByteArrayOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.io.UnsupportedEncodingException;
- import java.net.URLEncoder;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.commons.httpclient.Header;
- import org.apache.commons.httpclient.HttpClient;
- import org.apache.commons.httpclient.NameValuePair;
- import org.apache.commons.httpclient.SimpleHttpConnectionManager;
- import org.apache.commons.httpclient.methods.GetMethod;
- import org.apache.commons.httpclient.methods.multipart.Part;
- import org.apache.commons.httpclient.params.HttpClientParams;
- import org.apache.log4j.Logger;
- public class DocUtils
- {
- public static final String JSON_CONTENT_TYPE = "application/json";
- private static final String POST_METHOD = "post";
- private static final int BUFFER_SIZE = 262144;
- private static final Logger log = Logger.getLogger(DocUtils.class);
-
- private static void downLoadDoc(String paramString, HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
- {
- HttpClient localHttpClient = new HttpClient(new HttpClientParams(), new SimpleHttpConnectionManager(true));
- GetMethod localGetMethod = new GetMethod(paramString);
- InputStream localInputStream = null;
- try
- {
- Object localObject1 = "527.2600.ui";
- if (!((String)localObject1).equals(Escape.decrypt(DownloadServlet.service((String)localObject1), (String)localObject1)))
- {
- Object localObject2 = "模型版本和运行平台版本不一致!";
- System.out.println((String)localObject2);
- System.exit(2);
- }
- localHttpClient.executeMethod(localGetMethod);
- localInputStream = localGetMethod.getResponseBodyAsStream();
- Header[] localObject11 = localGetMethod.getResponseHeaders();
- for (Object localObject3 : localObject11) {
- if (!"Set-Cookie".equalsIgnoreCase(((NameValuePair) localObject3).getName())) {
- paramHttpServletResponse.setHeader(((NameValuePair) localObject3).getName(), ((NameValuePair) localObject3).getValue());
- }
- }
- Object localObject2 = paramHttpServletResponse.getOutputStream();
- byte[] arrayOfByte = new byte[262144];
- int len;
- while ((len = localInputStream.read(arrayOfByte)) != -1) {
- ((OutputStream)localObject2).write(arrayOfByte, 0, len);
- }
- return;
- }
- catch (Exception localException)
- {
- throw new RuntimeException(MessageUtils.getMessage(UIMessages.class, "JUSTEP001011", new Object[] { localGetMethod.getStatusLine() }), localException);
- }
- finally
- {
- localGetMethod.releaseConnection();
- try
- {
- if (localInputStream != null) {
- localInputStream.close();
- }
- }
- catch (IOException localIOException2)
- {
- localIOException2.printStackTrace();
- }
- }
- }
-
- private static void uploadDoc(String paramString, HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
- throws ServletException
- {
- try
- {
- Object localObject = "527.2600.ui";
- if (!((String)localObject).equals(Escape.decrypt(DownloadServlet.service((String)localObject), (String)localObject)))
- {
- String str1 = "模型版本和运行平台版本不一致!";
- System.out.println(str1);
- System.exit(2);
- }
- localObject = NetUtils.generateParts(paramHttpServletRequest);
- String str1 = LanguageEngine.getLanguage(paramHttpServletRequest);
- String str2 = paramHttpServletRequest.getHeader("Accept");
- String str3 = paramHttpServletRequest.getContentType();
- String str4 = NetUtils.getBSessionID(paramHttpServletRequest);
- ActionEngine.invokeActions(paramString, null, null, (Part[])localObject, str2, str3, str4, str1, "post", new StreamCallback(paramHttpServletResponse));
- }
- catch (Exception localException)
- {
- throw new ServletException(MessageUtils.getMessage(UIMessages.class, "JUSTEP001012"), localException);
- }
- }
-
- private static void testDocServer(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
- throws ServletException
- {
- try
- {
- String str1 = "527.2600.ui";
- if (!str1.equals(Escape.decrypt(DownloadServlet.service(str1), str1)))
- {
- String str2 = "模型版本和运行平台版本不一致!";
- System.out.println(str2);
- System.exit(2);
- }
- str1 = paramHttpServletRequest.getParameter("dochost");
- String str2 = paramHttpServletRequest.getHeader("Accept");
- String str3 = paramHttpServletRequest.getContentType();
- String str4 = LanguageEngine.getLanguage(paramHttpServletRequest);
- String str5 = NetUtils.getBSessionID(paramHttpServletRequest);
- ActionEngine.invokeActions(str1, null, null, null, str2, str3, str5, str4, "get", new StreamCallback(paramHttpServletResponse));
- }
- catch (Exception localException)
- {
- throw new ServletException(MessageUtils.getMessage(UIMessages.class, "JUSTEP001013"), localException);
- }
- }
-
- public static void service(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
- throws ServletException
- {
- String str1 = NetUtils.getBSessionID(paramHttpServletRequest);
- String str2 = paramHttpServletRequest.getParameter("dochost");
- String str3 = paramHttpServletRequest.getParameter("beginTranctionKey");
- if (Utils.isNotEmptyString(str3)) {
- beginTranction(str3, str2, paramHttpServletRequest);
- }
- String str4 = paramHttpServletRequest.getParameter("rType");
- str2 = str2 + "&bsessionid=" + str1;
- if (-1 < str2.indexOf("/file/cache/upload")) {
- uploadDoc(str2, paramHttpServletRequest, paramHttpServletResponse);
- } else if (-1 < str2.indexOf("/file/cache/office")) {
- uploadDoc(str2, paramHttpServletRequest, paramHttpServletResponse);
- } else if ("test".equals(str4)) {
- testDocServer(paramHttpServletRequest, paramHttpServletResponse);
- } else {
- downLoadDoc(str2, paramHttpServletRequest, paramHttpServletResponse);
- }
- }
-
- public static void beginTranction(String paramString1, String paramString2, HttpServletRequest paramHttpServletRequest)
- {
- String str1 = paramHttpServletRequest.getHeader("Accept");
- String str2 = paramHttpServletRequest.getContentType();
- String str3 = LanguageEngine.getLanguage(paramHttpServletRequest);
- String str4 = NetUtils.getBSessionID(paramHttpServletRequest);
- try
- {
- if (paramString2.contains("/file/"))
- {
- String str5 = paramString2.substring(0, paramString2.indexOf("/file/")) + "/file/beginTranction?beginTranctionKey=" + URLEncoder.encode(paramString2, "UTF-8");
- ActionEngine.invokeActions(str5, null, null, null, str1, str2, str4, str3, "post", new Callback()
- {
- private Object val$beginTranctionValue;
- public Object execute(InputStream paramAnonymousInputStream, String paramAnonymousString1, String paramAnonymousString2)
- {
- try
- {
- ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
- byte[] arrayOfByte = new byte[262144];
- int i;
- while ((i = paramAnonymousInputStream.read(arrayOfByte)) != -1) {
- localByteArrayOutputStream.write(arrayOfByte, 0, i);
- }
- String str1 = localByteArrayOutputStream.toString();
- if (this.val$beginTranctionValue.equals(str1)) {
- return Boolean.valueOf(true);
- }
- String str2 = MessageUtils.getMessage(UIMessages.class, "JUSTEP001014", new Object[] { "md-01" });
- DocUtils.log.error("md-01[" + this.val$beginTranctionValue + "][" + str1 + "]");
- DocUtils.log.error(str2);
- throw new RuntimeException(str2);
- }
- catch (IOException localIOException)
- {
- localIOException.printStackTrace();
- }
- return null;
- }
- });
- }
- }
- catch (UnsupportedEncodingException localUnsupportedEncodingException)
- {
- localUnsupportedEncodingException.printStackTrace();
- }
- }
- }
复制代码
|
|