8 Commits

Author SHA1 Message Date
8918bb7e2a Merge pull request 'feature-mass-identify' (#2) from feature-mass-identify into develop
Reviewed-on: #2
2025-05-09 03:25:37 +00:00
bbe1ee44c1 清理代码。 2025-05-08 18:56:46 +08:00
78c7a0d9a9 改变架构! 2025-05-08 00:56:14 +08:00
74e038dd56 保存进度! 2025-05-07 19:07:24 +08:00
56fb6b6b10 保存进度! 2025-05-07 19:01:51 +08:00
ede811fa02 修改包名从NewCitizen变为newcitizen。 2025-05-07 15:18:07 +08:00
97adb0ff47 Merge pull request 'feature-mass-identify' (#1) from feature-mass-identify into develop
Reviewed-on: #1
2025-05-07 06:30:15 +00:00
7160a58245 将springmvc升级到6.2.4。 2025-05-07 14:29:01 +08:00
12 changed files with 337 additions and 178 deletions

View File

@@ -0,0 +1,87 @@
/*
* @Author: Kane
* @Date: 2025-03-16 00:35:09
* @LastEditors: Kane
* @FilePath: /cpicxim-huixiabao/.vscode/fileheader.template.js
* @Description:
*
* Copyright (c) ${2023} by Kane, All Rights Reserved.
*/
/**
* This file is generated by VSCode extension: Fileheader Pro
*/
/**
* These comments can help you write your own template with type hint
* @typedef {Object} FileheaderVariable Fileheader variables
* @property {string} birthtime file birth time. will get it from VCS or fallback to filesystem when it is not available
* @property {string} mtime file modification time. will get it from VCS or fallback to filesystem when it is not available
* @property {string} authorName if the file is tracked by VCS, it will get the author name from VCS. else it will get it from current user name
* @property {string} authorEmail if the file is tracked by VCS, it will get the author email from VCS. else it will get it from current user email
* @property {string} userName else it will get it from current user name
* @property {string} userEmail user email is from VSCode config, and fallback to VCS config
* @property {string} companyName
* @property {string} projectName name of current project
* @property {string} filePath the file path, relative to project root with POSIX path separator
* @property {string} dirPath the directory path, relative to project root with POSIX path separator
* @property {string} fileName filename with extension
*/
/**
* @typedef {string | number | null | undefined | Template | boolean} TemplateInterpolation NOTE: boolean or falsy value will render empty string
*
* @typedef {{ strings: TemplateStringsArray; interpolations: TemplateInterpolation[]; }} Template
* @typedef {(strings: TemplateStringsArray, ...values: any[]) => string} ITemplateFunction
*
*/
/**
* Please confirm your provider extends from globalThis.FileheaderLanguageProvider
*/
class CustomLanguageProvider extends globalThis.FileheaderLanguageProvider {
/**
* @type {string[]}
*/
languages = [
"java",
"javascript",
"typescript",
"javascriptreact",
"typescriptreact",
];
/**
* @type {string=} the language block comment start string.
* this is for future feature: support detect old custom template when custom template changes
*/
blockCommentStart = "/**";
/**
* @type {string=}
*/
blockCommentEnd = "*/";
/**
* get your template when document language matched
* @param {ITemplateFunction} tpl template function, it is a tagged function, support nested interpolation
* @param {FileheaderVariable} variables template variables
* @returns {Template}
*/
getTemplate(tpl, variables) {
// prettier-ignore
return tpl
`/**
* @Author: ${variables.authorName} <${variables.authorEmail}>
* @Date: ${variables.birthtime}
* @LastEditors: ${variables.userName}
* @LastModified: ${variables.mtime}
* @FilePath: ${variables.filePath}
* @Description:
*
* Copyright (c) ${2025} by Kane All rights reserved
*/`;
}
}
// export your provider classes
module.exports = [CustomLanguageProvider];

View File

@@ -13,12 +13,20 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source> <maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target> <maven.compiler.target>8</maven.compiler.target>
<spring.version>5.3.24</spring.version> <spring.version>6.2.4</spring.version>
<log4j.version>2.24.3</log4j.version>
<jackson.version>2.18.3</jackson.version>
<!-- <spring.version>6.0.8</spring.version> --> <!-- <spring.version>6.0.8</spring.version> -->
</properties> </properties>
<dependencies> <dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit --> <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.17</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
@@ -48,49 +56,64 @@
<version>${spring.version}</version> <version>${spring.version}</version>
</dependency> </dependency>
<dependency> <!-- <dependency>
<groupId>javax.servlet</groupId> <groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId> <artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version> <version>4.0.1</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> -->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.1.0</version>
<scope>provided</scope>
</dependency> </dependency>
<!--文件上传依赖的两个jar包--> <!-- log4j -->
<dependency> <dependency>
<groupId>commons-fileupload</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>commons-fileupload</artifactId> <artifactId>log4j-core</artifactId>
<version>1.5</version> <version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-io</groupId> <groupId>org.apache.directory.studio</groupId>
<artifactId>commons-io</artifactId> <artifactId>org.apache.commons.codec</artifactId>
<version>2.11.0</version> <version>1.8</version>
</dependency> </dependency>
<!--jackson--> <!-- jackson -->
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
<version>2.14.2</version> <version>${jackson.version}</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId> <artifactId>jackson-core</artifactId>
<version>2.13.4</version> <version>${jackson.version}</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId> <artifactId>jackson-annotations</artifactId>
<version>2.13.4</version> <version>${jackson.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.oracle</groupId> <groupId>com.mysql</groupId>
<artifactId>ojdbc8</artifactId> <artifactId>mysql-connector-j</artifactId>
<version>19.3.0.0.0</version> <version>9.2.0</version>
</dependency> </dependency>
<dependency> <dependency>
@@ -113,9 +136,9 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
<version>3.7</version> <version>3.7</version>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -1,4 +1,13 @@
/**
* @Author: Kane Wang <wangkane@qq.com>
* @Date: 2023-05-26 18:40:36
* @LastEditors: Kane Wang
* @LastModified: 2025-05-07 22:02:07
* @FilePath: src/main/java/com/cpic/xim/utils/config/EncryptionParameters.java
* @Description:
*
* Copyright (c) 2025 by Kane All rights reserved
*/
package com.cpic.xim.utils.config; package com.cpic.xim.utils.config;
public class EncryptionParameters public class EncryptionParameters

View File

@@ -0,0 +1,65 @@
/**
* @Author: Kane Wang <wangkane@qq.com>
* @Date: 2024-04-29 11:09:50
* @LastEditors: Kane Wang
* @LastModified: 2025-05-07 22:04:08
* @FilePath: src/main/java/com/cpic/xim/utils/http/HttpUtils.java
* @Description: 用于http的相关工具方法
*
* Copyright (c) 2025 by Kane All rights reserved
*/
package com.cpic.xim.utils.http;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.http.HttpEntity;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
public class HttpUtils
{
/**
*
* @param url
* @param bodyMap
* @return
*/
public static String sendPost( String url, Map<String, String> bodyMap )
{
HttpPost post = new HttpPost( url );
try
{
// 创建参数集合
List<BasicNameValuePair> list = new ArrayList<>();
// 添加参数
if ( bodyMap != null )
{
for ( String str : bodyMap.keySet() )
{
list.add( new BasicNameValuePair( str, bodyMap.get( str ) ) );
}
}
// 把参数放入请求对象post发送的参数list指定格式
post.setEntity( new UrlEncodedFormEntity( list, "UTF-8" ) );
CloseableHttpClient client = HttpClients.createDefault();
// 启动执行请求,并获得返回值
CloseableHttpResponse response = client.execute( post );
// 得到返回的entity对象
HttpEntity entity = response.getEntity();
// 把实体对象转换为string
return EntityUtils.toString( entity, "UTF-8" );
}
catch ( Exception e1 )
{
e1.printStackTrace();
return "";
}
}
}

View File

@@ -1,54 +1,45 @@
/* /**
* @Author: Kane * @Author: Kane Wang <wangkane@qq.com>
* @Date: 2023-05-25 15:26:09 * @Date: 2023-05-26 18:40:36
* @LastEditors: Kane * @LastEditors: Kane Wang
* @FilePath: /NewCitizenQueryResult/src/main/java/com/cpic/xim/utils/newcitizen/NewCitizenUitls.java * @LastModified: 2025-05-08 18:55:36
* @Description: 新市民认证相关的工具方法 * @FilePath: src/main/java/com/cpic/xim/utils/newcitizen/NewCitizenUitls.java
* @Description:
* *
* Copyright (c) ${2022} by Kane, All Rights Reserved. * Copyright (c) 2025 by Kane All rights reserved
*/ */
package com.cpic.xim.utils.newcitizen; package com.cpic.xim.utils.newcitizen;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.http.HttpEntity;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
// import com.cdp.product.security.decode.CdpDecryptUtil;
// import com.cdp.product.security.encode.EncryptionUtils;
// import com.cdp.product.security.sign.CdpSignUtil;
import com.cpic.xim.utils.security.encode.EncryptionUtils;
import com.cpic.xim.utils.security.decode.DecryptionUtils;
import com.cpic.xim.utils.security.sign.SignUtils;
import com.cpic.xim.utils.config.EncryptionParameters; import com.cpic.xim.utils.config.EncryptionParameters;
import com.cpic.xim.utils.http.HttpUtils;
import com.cpic.xim.utils.security.decode.DecryptionUtils;
import com.cpic.xim.utils.security.encode.EncryptionUtils;
import com.cpic.xim.utils.security.sign.SignUtils;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
public class NewCitizenUitls public class NewCitizenUitls
{ {
// 请求地址 // 请求地址
private static String identifyURL = "https://api.xmcic.cn:51888/government/economic/352"; private static String identifyURL = "https://api.xmcic.cn:8443/government/economic/352";
/** /**
* 新市民验证 * 新市民验证
*
* @param idCardNo 身份证号码 * @param idCardNo 身份证号码
* @param name 姓名 * @param name 姓名
* @return * @return
* @throws Exception * @throws Exception
*/ */
public static IdentifyResult identifyNewCitizen( String idCardNo, String name ) throws Exception public static IdentifyResult identifyNewCitizen( String idCardNo, String name )
throws Exception
{ {
String secretKey = EncryptionParameters.getSecretKey(); String secretKey = EncryptionParameters.getSecretKey();
String key = EncryptionParameters.getKey(); String key = EncryptionParameters.getKey();
String pushURL = "http://222.76.244.118:11101/NewCitizen/save_score.do"; String pushURL = "http://222.76.244.118:11101/NewCitizen/save_score.do";
Map<String, String> param = new HashMap<String, String>(); Map<String, String> param = new HashMap<String, String>();
@@ -57,19 +48,19 @@ public class NewCitizenUitls
param.put( "name", EncryptionUtils.aesEncrypt( name, secretKey ) ); param.put( "name", EncryptionUtils.aesEncrypt( name, secretKey ) );
param.put( "pushurl", EncryptionUtils.aesEncrypt( pushURL, secretKey ) ); param.put( "pushurl", EncryptionUtils.aesEncrypt( pushURL, secretKey ) );
param.put( "timestamp", param.put( "timestamp",
EncryptionUtils.aesEncrypt( System.currentTimeMillis() + "", secretKey ) ); EncryptionUtils.aesEncrypt( System.currentTimeMillis() + "", secretKey ) );
String sign = SignUtils.sign( param ); String sign = SignUtils.sign( param );
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
params.putAll( param ); params.putAll( param );
params.put( "key", key ); params.put( "key", key );
params.put( "sign", sign ); params.put( "sign", sign );
String resultJSON = sendPost( identifyURL, params ); String resultJSON = HttpUtils.sendPost( identifyURL, params );
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
IdentifyResult identifyResult = null; IdentifyResult identifyResult = null;
ResponseResult response = null; ResponseResult response = null;
response = mapper.readValue( resultJSON, ResponseResult.class ); response = mapper.readValue( resultJSON, ResponseResult.class );
@@ -84,46 +75,14 @@ public class NewCitizenUitls
return identifyResult; return identifyResult;
} }
public static String sendPost( String url, Map<String, String> bodyMap )
{
HttpPost post = new HttpPost( url );
try
{
// 创建参数集合
List<BasicNameValuePair> list = new ArrayList<>();
// 添加参数
if ( bodyMap != null )
{
for ( String str : bodyMap.keySet() )
{
list.add( new BasicNameValuePair( str, bodyMap.get( str ) ) );
}
}
// 把参数放入请求对象post发送的参数list指定格式
post.setEntity( new UrlEncodedFormEntity( list, "UTF-8" ) );
CloseableHttpClient client = HttpClients.createDefault();
// 启动执行请求,并获得返回值
CloseableHttpResponse response = client.execute( post );
// 得到返回的entity对象
HttpEntity entity = response.getEntity();
// 把实体对象转换为string
return EntityUtils.toString( entity, "UTF-8" );
}
catch ( Exception e1 )
{
e1.printStackTrace();
return "";
}
}
} }
class ResponseResult class ResponseResult
{ {
public ResponseResult() public ResponseResult()
{} {
}
public String getCode() public String getCode()
{ {
@@ -178,4 +137,3 @@ class ResponseResult
private String seqNo; private String seqNo;
} }

View File

@@ -1,19 +1,22 @@
/* /**
* @Author: Kane * @Author: Kane Wang <wangkane@qq.com>
* @Date: 2023-05-25 15:17:49 * @Date: 2023-05-26 18:40:36
* @LastEditors: Kane * @LastEditors: Kane Wang
* @FilePath: /NewCitizenQueryResult/src/main/java/com/cpic/xim/web/controllers/NewCitizen/IdentifyNewCitizenRequest.java * @LastModified: 2025-05-07 14:59:15
* @FilePath: src/main/java/com/cpic/xim/web/controllers/NewCitizen/IdentifyNewCitizenRequest.java
* @Description: * @Description:
* *
* Copyright (c) ${2022} by Kane, All Rights Reserved. * Copyright (c) 2025 by Kane All rights reserved
*/ */
package com.cpic.xim.web.controllers.NewCitizen; package com.cpic.xim.web.controllers.newcitizen;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
public class IdentifyNewCitizenRequest public class IdentifyNewCitizenRequest
{ {
public IdentifyNewCitizenRequest() {} public IdentifyNewCitizenRequest()
{
}
public String getIdCardNo() public String getIdCardNo()
{ {
@@ -35,9 +38,9 @@ public class IdentifyNewCitizenRequest
this.name = name; this.name = name;
} }
@JsonProperty("idcard_no") @JsonProperty( "idcard_no" )
private String idCardNo; private String idCardNo;
@JsonProperty("name") @JsonProperty( "name" )
private String name; private String name;
} }

View File

@@ -1,13 +1,14 @@
/* /**
* @Author: Kane * @Author: Kane Wang <wangkane@qq.com>
* @Date: 2023-05-25 20:26:06 * @Date: 2024-04-29 11:09:50
* @LastEditors: Kane * @LastEditors: Kane Wang
* @FilePath: /NewCitizenQueryResult/src/main/java/com/cpic/xim/web/controllers/NewCitizen/IdentifyNewCitizenResult.java * @LastModified: 2025-05-07 22:01:21
* @FilePath: src/main/java/com/cpic/xim/web/controllers/newcitizen/IdentifyNewCitizenResponse.java
* @Description: * @Description:
* *
* Copyright (c) ${2022} by Kane, All Rights Reserved. * Copyright (c) 2025 by Kane All rights reserved
*/ */
package com.cpic.xim.web.controllers.NewCitizen; package com.cpic.xim.web.controllers.newcitizen;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;

View File

@@ -1,16 +1,16 @@
/* /**
* @Author: Kane * @Author: Kane Wang <wangkane@qq.com>
* @Date: 2023-05-25 12:09:27 * @Date: 2024-04-29 11:09:50
* @LastEditors: Kane * @LastEditors: Kane Wang
* @FilePath: /NewCitizenQueryResult/src/main/java/com/cpic/xim/web/controllers/NewCitizen/QueryResultController.java * @LastModified: 2025-05-07 22:00:48
* @FilePath: src/main/java/com/cpic/xim/web/controllers/newcitizen/QueryResultController.java
* @Description: * @Description:
* *
* Copyright (c) ${2022} by Kane, All Rights Reserved. * Copyright (c) 2025 by Kane All rights reserved
*/ */
package com.cpic.xim.web.controllers.newcitizen;
package com.cpic.xim.web.controllers.NewCitizen; import jakarta.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
@@ -23,37 +23,37 @@ import com.cpic.xim.utils.newcitizen.*;
@Controller @Controller
public class QueryResultController public class QueryResultController
{ {
@RequestMapping("/save_score.do") @RequestMapping( "/save_score.do" )
public void saveQueryResult(HttpServletResponse response, @RequestBody QueryResultRequest result ) public void saveQueryResult( HttpServletResponse response, @RequestBody QueryResultRequest result )
{ {
response.setStatus(HttpServletResponse.SC_OK); response.setStatus( HttpServletResponse.SC_OK );
} }
@RequestMapping("/identify.do") @RequestMapping( "/identify.do" )
@ResponseBody @ResponseBody
public IdentifyNewCitizenResponse identifyNewCitizen(@RequestBody IdentifyNewCitizenRequest request ) public IdentifyNewCitizenResponse identifyNewCitizen( @RequestBody IdentifyNewCitizenRequest request )
{ {
String idCardNo = request.getIdCardNo(); String idCardNo = request.getIdCardNo();
String name = request.getName(); String name = request.getName();
IdentifyResult result = null; IdentifyResult result = null;
IdentifyNewCitizenResponse response = new IdentifyNewCitizenResponse(); IdentifyNewCitizenResponse response = new IdentifyNewCitizenResponse();
try try
{ {
result = NewCitizenUitls.identifyNewCitizen(idCardNo, name); result = NewCitizenUitls.identifyNewCitizen( idCardNo, name );
response.setSuccess(true); response.setSuccess( true );
response.setMessage("调用成功"); response.setMessage( "调用成功" );
response.setCitizenType(result.getCitizenType()); response.setCitizenType( result.getCitizenType() );
response.setScore(result.getScore()); response.setScore( result.getScore() );
response.setExpireDate(result.getExpireDate()); response.setExpireDate( result.getExpireDate() );
} }
catch ( Exception error ) catch ( Exception error )
{ {
System.out.println( error.getMessage() ); System.out.println( error.getMessage() );
response.setSuccess(false); response.setSuccess( false );
response.setMessage(error.getMessage()); response.setMessage( error.getMessage() );
} }
return response; return response;

View File

@@ -1,5 +1,14 @@
/**
package com.cpic.xim.web.controllers.NewCitizen; * @Author: Kane Wang <wangkane@qq.com>
* @Date: 2024-04-29 11:09:50
* @LastEditors: Kane Wang
* @LastModified: 2025-05-07 22:00:35
* @FilePath: src/main/java/com/cpic/xim/web/controllers/newcitizen/QueryResultRequest.java
* @Description:
*
* Copyright (c) 2025 by Kane All rights reserved
*/
package com.cpic.xim.web.controllers.newcitizen;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;

View File

@@ -1,40 +1,41 @@
/* /**
* @Author: Kane * @Author: Kane Wang <wangkane@qq.com>
* @Date: 2023-05-25 11:02:53 * @Date: 2023-05-26 18:40:36
* @LastEditors: Kane * @LastEditors: Kane Wang
* @FilePath: /NewCitizenQueryResult/src/main/java/com/cpic/xim/web/filters/CrosFilter.java * @LastModified: 2025-05-07 22:00:26
* @FilePath: src/main/java/com/cpic/xim/web/filters/CrosFilter.java
* @Description: * @Description:
* *
* Copyright (c) ${2022} by Kane, All Rights Reserved. * Copyright (c) 2025 by Kane All rights reserved
*/ */
package com.cpic.xim.web.filters; package com.cpic.xim.web.filters;
import java.io.IOException; import java.io.IOException;
import javax.servlet.Filter; import jakarta.servlet.Filter;
import javax.servlet.FilterChain; import jakarta.servlet.FilterChain;
import javax.servlet.ServletException; import jakarta.servlet.ServletException;
import javax.servlet.ServletRequest; import jakarta.servlet.ServletRequest;
import javax.servlet.ServletResponse; import jakarta.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
public class CrosFilter implements Filter public class CrosFilter implements Filter
{ {
@Override @Override
public void doFilter( ServletRequest req, ServletResponse resp, FilterChain chain ) public void doFilter( ServletRequest req, ServletResponse resp, FilterChain chain )
throws ServletException, IOException throws ServletException,
IOException
{ {
HttpServletRequest request = (HttpServletRequest) req; HttpServletRequest request = ( HttpServletRequest ) req;
HttpServletResponse response = (HttpServletResponse) resp; HttpServletResponse response = ( HttpServletResponse ) resp;
String method = request.getMethod(); String method = request.getMethod();
String originHeader = request.getHeader( "Origin" ); String originHeader = request.getHeader( "Origin" );
System.out.println( "收到" + method + "请求,来自" + originHeader); System.out.println( "收到" + method + "请求,来自" + originHeader );
// 如果是Options请求 // 如果是Options请求
if ( method.equals(HttpMethod.OPTIONS.toString()) ) if ( method.equals( HttpMethod.OPTIONS.toString() ) )
{ {
originHeader = "*"; originHeader = "*";
} }
@@ -43,7 +44,7 @@ public class CrosFilter implements Filter
response.setHeader( "Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT" ); response.setHeader( "Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT" );
response.setHeader( "Access-Control-Max-Age", "0" ); response.setHeader( "Access-Control-Max-Age", "0" );
response.setHeader( "Access-Control-Allow-Headers", response.setHeader( "Access-Control-Allow-Headers",
"Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With,userId,token" ); "Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With,userId,token" );
response.setHeader( "Access-Control-Allow-Credentials", "true" ); response.setHeader( "Access-Control-Allow-Credentials", "true" );
response.setHeader( "XDomainRequestAllowed", "1" ); response.setHeader( "XDomainRequestAllowed", "1" );
response.setHeader( "XDomainRequestAllowed", "1" ); response.setHeader( "XDomainRequestAllowed", "1" );

View File

@@ -17,21 +17,20 @@
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd"> http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">
<context:component-scan base-package="com.cpic.xim" />
<mvc:annotation-driven /> <mvc:annotation-driven />
<context:component-scan base-package="com.cpic.xim" />
<mvc:default-servlet-handler /> <mvc:default-servlet-handler />
<!-- <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property <property
name="prefix" value="/WEB-INF/jsp/" /> name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" /> <property name="suffix" value=".jsp" />
</bean> --> </bean>
<bean id="multipartResolver" <!-- <bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8" /> <property name="defaultEncoding" value="UTF-8" />
<property name="maxUploadSize" value="-1" /> <property name="maxUploadSize" value="-1" />
</bean> </bean> -->
</beans> </beans>

View File

@@ -1,7 +1,11 @@
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" <?xml version="1.0" encoding="UTF-8"?>
<web-app
version="4.0"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:javaee="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd">
version="3.1">
<display-name>Archetype Created Web Application</display-name> <display-name>Archetype Created Web Application</display-name>