mirror of
https://gitee.com/wangkang/udf.git
synced 2026-11-01 17:23:41 +00:00
更新
This commit is contained in:
@@ -4,14 +4,14 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<!-- mavne坐标 -->
|
||||
<groupId>com.egridcloud.udf</groupId>
|
||||
<artifactId>udf-parent</artifactId>
|
||||
<artifactId>udf-starter</artifactId>
|
||||
<version>1.0</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>udf-parent</name>
|
||||
<name>udf-starter</name>
|
||||
<url>http://www.egridcloud.com</url>
|
||||
<!-- 公共参数 -->
|
||||
<properties>
|
||||
<udf-parent.version>1.0</udf-parent.version>
|
||||
<udf-starter.version>1.0</udf-starter.version>
|
||||
<springboot.version>1.5.2.RELEASE</springboot.version>
|
||||
<springcloud.version>Dalston.RELEASE</springcloud.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
@@ -21,8 +21,29 @@
|
||||
</properties>
|
||||
<!--子模块 -->
|
||||
<modules>
|
||||
<module>udf-core-starter</module>
|
||||
<module>udf-starter-core</module>
|
||||
<module>udf-demo</module>
|
||||
</modules>
|
||||
<!-- 环境 -->
|
||||
<profiles>
|
||||
<!-- 开发 -->
|
||||
<profile>
|
||||
<id>dev</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<properties>
|
||||
<profiles.activation>dev</profiles.activation>
|
||||
</properties>
|
||||
</profile>
|
||||
<!-- qa -->
|
||||
<profile>
|
||||
<id>qa</id>
|
||||
<properties>
|
||||
<profiles.activation>qa</profiles.activation>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
<!-- 依赖管理 -->
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
@@ -42,6 +63,12 @@
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<!-- udf-core-starter -->
|
||||
<dependency>
|
||||
<groupId>com.egridcloud.udf</groupId>
|
||||
<artifactId>udf-starter-core</artifactId>
|
||||
<version>${udf-starter.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<!-- 构建 -->
|
||||
@@ -75,15 +102,15 @@
|
||||
<!-- 分发管理 -->
|
||||
<distributionManagement>
|
||||
<!-- 公司内网仓库-snapshot -->
|
||||
<snapshotRepository>
|
||||
<!-- <snapshotRepository>
|
||||
<id>snapshot</id>
|
||||
<url>http://192.168.1.11:8081/nexus/content/repositories/snapshots/</url>
|
||||
</snapshotRepository>
|
||||
</snapshotRepository> -->
|
||||
<!-- 公司内网仓库-release -->
|
||||
<repository>
|
||||
<!-- <repository>
|
||||
<id>release</id>
|
||||
<url>http://192.168.1.11:8081/nexus/content/repositories/releases/</url>
|
||||
</repository>
|
||||
</repository> -->
|
||||
</distributionManagement>
|
||||
<!-- 依赖仓库 -->
|
||||
<repositories>
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<!-- maven坐标 -->
|
||||
<artifactId>udf-core-starter</artifactId>
|
||||
<name>udf-core-starter</name>
|
||||
<packaging>jar</packaging>
|
||||
<url>http://www.egridcloud.com</url>
|
||||
<!-- 父依赖 -->
|
||||
<parent>
|
||||
<groupId>com.egridcloud.udf</groupId>
|
||||
<artifactId>udf-parent</artifactId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<!-- 依赖 -->
|
||||
<dependencies>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<!-- maven坐标 -->
|
||||
<artifactId>udf-demo</artifactId>
|
||||
<name>udf-demo</name>
|
||||
<packaging>jar</packaging>
|
||||
<url>http://www.egridcloud.com</url>
|
||||
<!-- 父依赖 -->
|
||||
<parent>
|
||||
<groupId>com.egridcloud.udf</groupId>
|
||||
<artifactId>udf-starter</artifactId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<!-- 参数 -->
|
||||
<properties>
|
||||
<server.port>8080</server.port>
|
||||
</properties>
|
||||
<!-- 依赖 -->
|
||||
<dependencies>
|
||||
<!-- udf-starter-core udf核心包-->
|
||||
<dependency>
|
||||
<groupId>com.egridcloud.udf</groupId>
|
||||
<artifactId>udf-starter-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<!-- 构建 -->
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${project.basedir}/src/main/resources/</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${springboot.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* BaseApplication.java
|
||||
* Created at 2016-10-02
|
||||
* Created by wangkang
|
||||
* Copyright (C) 2016 egridcloud.com, All rights reserved.
|
||||
*/
|
||||
package com.egridcloud.udf.demo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.cloud.client.SpringCloudApplication;
|
||||
|
||||
import com.egridcloud.udf.core.BaseApplication;
|
||||
|
||||
/**
|
||||
* 描述 : 系统入口
|
||||
*
|
||||
* @author wangkang
|
||||
*
|
||||
*/
|
||||
@SpringCloudApplication
|
||||
public class UdfDemoApplication extends BaseApplication {
|
||||
|
||||
/**
|
||||
* 描述 : spring boot的入口,在整个项目中,包括其子项目在内, 只能有一个main方法,否则spring boot启动不起来
|
||||
*
|
||||
* @param args 参数
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(UdfDemoApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
########################################################
|
||||
###com.egridcloud.application.config (ApplicationConfig)
|
||||
########################################################
|
||||
com.egridcloud.application.config.outputExceptionStackTrace=true
|
||||
@@ -0,0 +1,4 @@
|
||||
########################################################
|
||||
###com.egridcloud.application.config (ApplicationConfig)
|
||||
########################################################
|
||||
com.egridcloud.application.config.outputExceptionStackTrace=false
|
||||
@@ -0,0 +1,50 @@
|
||||
########################################################
|
||||
###com.egridcloud.application.config (ApplicationConfig)
|
||||
########################################################
|
||||
com.egridcloud.application.config.encoding=UTF-8
|
||||
com.egridcloud.application.config.timeZone=Asia/Shanghai
|
||||
com.egridcloud.application.config.dateFormat=yyyy-MM-dd'T'HH:mm:ss:SSSZ
|
||||
|
||||
########################################################
|
||||
###INFO
|
||||
########################################################
|
||||
info.build.group=${project.groupId}
|
||||
info.build.artifact=${project.artifactId}
|
||||
info.build.version=${project.version}
|
||||
info.build.name=${project.name}
|
||||
|
||||
########################################################
|
||||
###IDENTITY
|
||||
########################################################
|
||||
spring.application.name=${project.name}
|
||||
spring.application.systemTag=${project.name}
|
||||
|
||||
########################################################
|
||||
###WEB PROPERTIES
|
||||
########################################################
|
||||
server.port=${server.port}
|
||||
|
||||
########################################################
|
||||
###PROFILES
|
||||
########################################################
|
||||
spring.profiles.active=${profiles.activation}
|
||||
|
||||
########################################################
|
||||
###SPRING MVC (WebMvcProperties)
|
||||
########################################################
|
||||
spring.mandatory-file-encoding=${com.egridcloud.application.config.encoding}
|
||||
spring.mvc.dateFormat=${com.egridcloud.application.config.dateFormat}
|
||||
spring.mvc.throw-exception-if-no-handler-found=true
|
||||
spring.resources.add-mappings=false
|
||||
|
||||
########################################################
|
||||
###JACKSON ( JacksonProperties )
|
||||
########################################################
|
||||
spring.jackson.dateFormat=${com.egridcloud.application.config.dateFormat}
|
||||
spring.jackson.jodaDateTimeFormat=${com.egridcloud.application.config.dateFormat}
|
||||
spring.jackson.timeZone=${com.egridcloud.application.config.timeZone}
|
||||
spring.jackson.serialization.INDENT_OUTPUT=true
|
||||
spring.jackson.serialization.FAIL_ON_EMPTY_BEANS=true
|
||||
spring.jackson.deserialization.FAIL_ON_UNKNOWN_PROPERTIES=true
|
||||
spring.jackson.parser.ALLOW_SINGLE_QUOTES=true
|
||||
spring.jackson.parser.ALLOW_UNQUOTED_CONTROL_CHARS=true
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="true">
|
||||
<fileset name="all" enabled="true" check-config-name="checkstyle.egridcloud.com" local="false">
|
||||
<file-match-pattern match-pattern="." include-pattern="true"/>
|
||||
</fileset>
|
||||
</fileset-config>
|
||||
@@ -0,0 +1,4 @@
|
||||
/target/
|
||||
/bin/
|
||||
/.classpath
|
||||
/.project
|
||||
@@ -0,0 +1,2 @@
|
||||
/org.eclipse.core.resources.prefs
|
||||
/org.eclipse.jdt.core.prefs
|
||||
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<!-- maven坐标 -->
|
||||
<artifactId>udf-starter-core</artifactId>
|
||||
<name>udf-starter-core</name>
|
||||
<packaging>jar</packaging>
|
||||
<url>http://www.egridcloud.com</url>
|
||||
<!-- 父依赖 -->
|
||||
<parent>
|
||||
<groupId>com.egridcloud.udf</groupId>
|
||||
<artifactId>udf-starter</artifactId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<!-- 依赖 -->
|
||||
<dependencies>
|
||||
<!-- springboot web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
<!-- springboot actuator -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<!-- springboot configuration-processor -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<!-- spring-cloud-starter-config 分布式配置-客户端 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-config</artifactId>
|
||||
</dependency>
|
||||
<!-- spring-cloud-starter-eureka 服务发现-客户端 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-eureka</artifactId>
|
||||
</dependency>
|
||||
<!-- spring-cloud-starter-ribbon 服务发现-负载均衡 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-ribbon</artifactId>
|
||||
</dependency>
|
||||
<!-- spring-cloud-starter-feign 服务发现-声明式web service客户端(包括负载均衡) -->
|
||||
<!-- <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-feign</artifactId> </dependency> -->
|
||||
<!-- spring-cloud-starter-hystrix 断路器 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-hystrix</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* ApplicationConfig.java
|
||||
* Created at 2016-10-03
|
||||
* Created by wangkang
|
||||
* Copyright (C) 2016 egridcloud.com, All rights reserved.
|
||||
*/
|
||||
package com.egridcloud.udf.core;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 描述 : 系统配置
|
||||
*
|
||||
* @author wangkang
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "com.egridcloud.application.config")
|
||||
public class ApplicationConfig {
|
||||
|
||||
/**
|
||||
* 描述 : 是否输出异常堆栈
|
||||
*/
|
||||
private boolean outputExceptionStackTrace = false;
|
||||
|
||||
/**
|
||||
* 描述 : 编码
|
||||
*/
|
||||
private String encoding = "UTF-8";
|
||||
|
||||
/**
|
||||
* 描述 : 时区
|
||||
*/
|
||||
private String timeZone = "Asia/Shanghai";
|
||||
|
||||
/**
|
||||
* 描述 : 日期格式
|
||||
*/
|
||||
private String dateFormat = "yyyy-MM-dd'T'HH:mm:ss:SSSZ";
|
||||
|
||||
/**
|
||||
* 描述 : 获取timeZone
|
||||
*
|
||||
* @return the timeZone
|
||||
*/
|
||||
public String getTimeZone() {
|
||||
return timeZone;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 设置timeZone
|
||||
*
|
||||
* @param timeZone the timeZone to set
|
||||
*/
|
||||
public void setTimeZone(String timeZone) {
|
||||
this.timeZone = timeZone;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 获取encoding
|
||||
*
|
||||
* @return the encoding
|
||||
*/
|
||||
public String getEncoding() {
|
||||
return encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 设置encoding
|
||||
*
|
||||
* @param encoding the encoding to set
|
||||
*/
|
||||
public void setEncoding(String encoding) {
|
||||
this.encoding = encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 获取dateFormat
|
||||
*
|
||||
* @return the dateFormat
|
||||
*/
|
||||
public String getDateFormat() {
|
||||
return dateFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 设置dateFormat
|
||||
*
|
||||
* @param dateFormat the dateFormat to set
|
||||
*/
|
||||
public void setDateFormat(String dateFormat) {
|
||||
this.dateFormat = dateFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 获取outputExceptionStackTrace
|
||||
*
|
||||
* @return the outputExceptionStackTrace
|
||||
*/
|
||||
public boolean isOutputExceptionStackTrace() {
|
||||
return outputExceptionStackTrace;
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述 : 设置outputExceptionStackTrace
|
||||
*
|
||||
* @param outputExceptionStackTrace the outputExceptionStackTrace to set
|
||||
*/
|
||||
public void setOutputExceptionStackTrace(boolean outputExceptionStackTrace) {
|
||||
this.outputExceptionStackTrace = outputExceptionStackTrace;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* BaseApplication.java
|
||||
* Created at 2016-10-02
|
||||
* Created by wangkang
|
||||
* Copyright (C) 2016 egridcloud.com, All rights reserved.
|
||||
*/
|
||||
package com.egridcloud.udf.core;
|
||||
|
||||
import org.springframework.boot.web.servlet.ServletComponentScan;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
import com.egridcloud.udf.core.xss.XssStringJsonSerializer;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
|
||||
/**
|
||||
* 描述 : 系统入口
|
||||
*
|
||||
* @author wangkang
|
||||
*
|
||||
*/
|
||||
@ServletComponentScan
|
||||
@ComponentScan(basePackages = { "com.egridcloud" })
|
||||
@EnableAsync
|
||||
@RefreshScope
|
||||
public class BaseApplication {
|
||||
|
||||
/**
|
||||
* 描述 : xssObjectMapper
|
||||
*
|
||||
* @param builder builder
|
||||
* @return xssObjectMapper
|
||||
*/
|
||||
@Bean
|
||||
public ObjectMapper xssObjectMapper(Jackson2ObjectMapperBuilder builder) {
|
||||
//解析器
|
||||
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
|
||||
//注册xss解析器
|
||||
SimpleModule xssModule = new SimpleModule("XssStringJsonSerializer");
|
||||
xssModule.addSerializer(new XssStringJsonSerializer());
|
||||
objectMapper.registerModule(xssModule);
|
||||
//返回
|
||||
return objectMapper;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* XssFilter.java
|
||||
* Created at 2016-09-19
|
||||
* Created by wangkang
|
||||
* Copyright (C) 2016 egridcloud.com, All rights reserved.
|
||||
*/
|
||||
package com.egridcloud.udf.core.xss;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.annotation.WebFilter;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 描述 : 跨站请求防范
|
||||
*
|
||||
* @author wangkang
|
||||
*
|
||||
*/
|
||||
@WebFilter(filterName = "xssFilter", urlPatterns = "/*", asyncSupported = true)
|
||||
public class XssFilter implements Filter {
|
||||
|
||||
/**
|
||||
* 描述 : 日志
|
||||
*/
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(XssFilter.class);
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
LOGGER.debug("(XssFilter) initialize");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
XssHttpServletRequestWrapper xssRequest =
|
||||
new XssHttpServletRequestWrapper((HttpServletRequest) request);
|
||||
chain.doFilter(xssRequest, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
LOGGER.debug("(XssFilter) destroy");
|
||||
}
|
||||
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* XssHttpServletRequestWrapper.java
|
||||
* Created at 2016-09-19
|
||||
* Created by wangkang
|
||||
* Copyright (C) 2016 egridcloud.com, All rights reserved.
|
||||
*/
|
||||
package com.egridcloud.udf.core.xss;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletRequestWrapper;
|
||||
|
||||
import org.springframework.web.util.HtmlUtils;
|
||||
|
||||
/**
|
||||
* 描述 : 跨站请求防范
|
||||
*
|
||||
* @author wangkang
|
||||
*
|
||||
*/
|
||||
public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper {
|
||||
|
||||
/**
|
||||
* 描述 : 构造函数
|
||||
*
|
||||
* @param request 请求对象
|
||||
*/
|
||||
public XssHttpServletRequestWrapper(HttpServletRequest request) {
|
||||
super(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHeader(String name) {
|
||||
String value = super.getHeader(name);
|
||||
return HtmlUtils.htmlEscape(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParameter(String name) {
|
||||
String value = super.getParameter(name);
|
||||
return HtmlUtils.htmlEscape(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getParameterValues(String name) {
|
||||
String[] values = super.getParameterValues(name);
|
||||
if (values != null) {
|
||||
int length = values.length;
|
||||
String[] escapseValues = new String[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
escapseValues[i] = HtmlUtils.htmlEscape(values[i]);
|
||||
}
|
||||
return escapseValues;
|
||||
}
|
||||
return super.getParameterValues(name);
|
||||
}
|
||||
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* XssStringJsonSerializer.java
|
||||
* Created at 2016-09-19
|
||||
* Created by wangkang
|
||||
* Copyright (C) 2016 egridcloud.com, All rights reserved.
|
||||
*/
|
||||
package com.egridcloud.udf.core.xss;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.web.util.HtmlUtils;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
|
||||
/**
|
||||
* 描述 : 基于xss的JsonSerializer
|
||||
*
|
||||
* @author wangkang
|
||||
*
|
||||
*/
|
||||
public class XssStringJsonSerializer extends JsonSerializer<String> {
|
||||
|
||||
@Override
|
||||
public Class<String> handledType() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(String value, JsonGenerator jsonGenerator,
|
||||
SerializerProvider serializerProvider) throws IOException {
|
||||
if (value != null) {
|
||||
String encodedValue = HtmlUtils.htmlEscape(value);
|
||||
jsonGenerator.writeString(encodedValue);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user