Merge branch 'master' into 'uat'
# Conflicts: # src/main/java/com/chinaunicom/mall/ebtp/extend/signature/service/impl/ExpertSignatureServiceImpl.java
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
package com.chinaunicom.mall.ebtp.extend.feign.client;
|
||||
|
||||
import com.chinaunicom.mall.ebtp.extend.feign.client.factory.DocumentCenterServiceFallbackFactory;
|
||||
import com.chinaunicom.mall.ebtp.extend.feign.config.FeignConfiguration;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
@ -1,95 +0,0 @@
|
||||
package com.chinaunicom.mall.ebtp.extend.feign.config;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import feign.RequestInterceptor;
|
||||
import feign.RequestTemplate;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class FeignConfiguration implements RequestInterceptor {
|
||||
|
||||
@Value("${document.clientHttpUrl}")
|
||||
private String clientHttpUrl;
|
||||
|
||||
@Override
|
||||
public void apply(RequestTemplate requestTemplate) {
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
if (attributes != null) {
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
log.info("token=======requestTemplate.headers" + requestTemplate.headers());
|
||||
String access_token = request.getHeader("Authorization");
|
||||
log.info("token=======" + access_token);
|
||||
if (access_token == null || StringUtils.isBlank(access_token)) {
|
||||
access_token = getAccessToken();
|
||||
log.info("token=======access_token===" + access_token);
|
||||
requestTemplate.header(HttpHeaders.AUTHORIZATION, "Bearer " + access_token);
|
||||
}
|
||||
} else {
|
||||
String access_token = getAccessToken();
|
||||
log.info("token=======attributes==null===" + access_token);
|
||||
requestTemplate.header(HttpHeaders.AUTHORIZATION, "Bearer " + access_token);
|
||||
}
|
||||
}
|
||||
|
||||
private String getAccessToken() {
|
||||
StringBuffer strBf = new StringBuffer();
|
||||
try {
|
||||
URL realUrl = new URL(clientHttpUrl);
|
||||
//将realUrl以 open方法返回的urlConnection 连接强转为HttpURLConnection连接 (标识一个url所引用的远程对象连接)
|
||||
HttpURLConnection connection = (HttpURLConnection) realUrl.openConnection();// 此时cnnection只是为一个连接对象,待连接中
|
||||
//设置连接输出流为true,默认false (post请求是以流的方式隐式的传递参数)
|
||||
connection.setDoOutput(true);
|
||||
//设置连接输入流为true
|
||||
connection.setDoInput(true);
|
||||
//设置请求方式为post
|
||||
connection.setRequestMethod("POST");
|
||||
//post请求缓存设为false
|
||||
connection.setUseCaches(false);
|
||||
//设置该HttpURLConnection实例是否自动执行重定向
|
||||
connection.setInstanceFollowRedirects(true);
|
||||
//设置请求头里面的各个属性 (以下为设置内容的类型,设置为经过urlEncoded编码过的from参数)
|
||||
connection.setRequestProperty("Content-Type", "application/json;charset=utf-8");
|
||||
//建立连接 (请求未开始,直到connection.getInputStream()方法调用时才发起,以上各个参数设置需在此方法之前进行)
|
||||
connection.connect();
|
||||
//创建输入输出流,用于往连接里面输出携带的参数,(输出内容为?后面的内容)
|
||||
DataOutputStream dataout = new DataOutputStream(connection.getOutputStream());
|
||||
// String query = data.toString();
|
||||
// //将参数输出到连接
|
||||
// dataout.write(query.getBytes("UTF-8"));
|
||||
// 输出完成后刷新并关闭流
|
||||
dataout.flush();
|
||||
dataout.close(); // 重要且易忽略步骤 (关闭流,切记!)
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
|
||||
String lines;
|
||||
while ((lines = reader.readLine()) != null) {
|
||||
lines = new String(lines.getBytes(), "utf-8");
|
||||
strBf.append(lines);
|
||||
}
|
||||
reader.close();
|
||||
connection.disconnect();
|
||||
log.info("toke返回数据:---------------------- " + strBf.toString());
|
||||
} catch (Exception e) {
|
||||
log.info("toke返回数据:---------------------- " + e.getMessage());
|
||||
}
|
||||
JSONObject json = JSONObject.parseObject(strBf.toString());
|
||||
if ((boolean) json.get("success")) {
|
||||
return ((JSONObject) json.get("data")).get("value").toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -124,16 +124,20 @@ public class ExpertSignatureServiceImpl implements ExpertSignatureService {
|
||||
}
|
||||
|
||||
File f = new File(path + "merged.pdf");
|
||||
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
FontSettings.getDefaultInstance().setFontsFolder(fontAddress, true);
|
||||
try (FileOutputStream fos = new FileOutputStream(f);) {
|
||||
fos = new FileOutputStream(f);
|
||||
com.aspose.words.Document doc = new com.aspose.words.Document(path + "merged.docx");
|
||||
doc.save(fos, SaveFormat.PDF);
|
||||
fos.flush();
|
||||
} catch (Exception e) {
|
||||
log.info(ExceptionUtil.stacktraceToString(e));
|
||||
} finally {
|
||||
source.close();
|
||||
addObj.close();
|
||||
IOUtils.closeQuietly(source);
|
||||
IOUtils.closeQuietly(addObj);
|
||||
IOUtils.closeQuietly(fos);
|
||||
|
||||
}
|
||||
|
||||
long l1 = System.currentTimeMillis();
|
||||
|
Reference in New Issue
Block a user