Commit 24300f36626c87c64f834b002bf58d8478909397

Authored by jiangjiazhi
1 parent 8b81554f71

增加配置

Showing 8 changed files with 341 additions and 109 deletions

platform-report-api/pom.xml View file @ 24300f3
... ... @@ -11,24 +11,87 @@
11 11 <artifactId>platform-report-api</artifactId>
12 12  
13 13 <dependencies>
14   -
  14 +
15 15 <dependency>
16 16 <groupId>com.lyms.core</groupId>
17 17 <artifactId>platform-common</artifactId>
18 18 <version>${project.version}</version>
19 19 </dependency>
20   - <!-- <dependency>
  20 + <dependency>
21 21 <groupId>com.lyms.core</groupId>
22   - <artifactId>permission-service</artifactId>
  22 + <artifactId>platform-dal</artifactId>
23 23 <version>${project.version}</version>
24 24 </dependency>
25 25 <dependency>
26 26 <groupId>com.lyms.core</groupId>
27   - <artifactId>permission-dal</artifactId>
  27 + <artifactId>platform-biz-service</artifactId>
28 28 <version>${project.version}</version>
29   - </dependency>-->
  29 + </dependency>
  30 + <dependency>
  31 + <groupId>com.lyms.core</groupId>
  32 + <artifactId>platform-biz-patient-service</artifactId>
  33 + <version>${project.version}</version>
  34 + </dependency>
30 35 </dependencies>
  36 + <profiles>
  37 + <profile>
  38 + <id>dev</id>
  39 +
  40 + <!-- 默认激活开发配制,使用config-dev.properties来替换设置过虑的资源文件中的${key} -->
  41 + <activation>
  42 + <activeByDefault>true</activeByDefault>
  43 + </activation>
  44 + <build>
  45 + <filters>
  46 + <filter>../platform-resource/resources/config-dev.properties</filter>
  47 + </filters>
  48 + </build>
  49 + </profile>
  50 + <profile>
  51 + <id>test</id>
  52 + <build>
  53 + <filters>
  54 + <filter>../platform-resource/resources/config-test.properties</filter>
  55 + </filters>
  56 + </build>
  57 + </profile>
  58 + <profile>
  59 + <id>prod</id>
  60 + <build>
  61 + <filters>
  62 + <filter>../platform-resource/resources/config-product.properties</filter>
  63 + </filters>
  64 + </build>
  65 + </profile>
  66 + </profiles>
31 67 <build>
  68 + <resources>
  69 + <resource>
  70 + <directory>../platform-resource/resources</directory>
  71 + <excludes>
  72 + <exclude>
  73 + **/*
  74 + </exclude>
  75 + </excludes>
  76 + <filtering>true</filtering>
  77 + </resource>
  78 + <resource>
  79 + <directory>src/main/resources</directory>
  80 + <includes>
  81 + <include>**/*</include>
  82 + </includes>
  83 +
  84 + </resource>
  85 + <!-- 设置对auto-config.properties,jdbc.properties进行过虑,即这些文件中的${key}会被替换掉为真正的值 -->
  86 + <!-- -->
  87 + <resource>
  88 + <directory>src/main/resources</directory>
  89 + <includes>
  90 + <include>database.properties</include>
  91 + </includes>
  92 + <filtering>true</filtering>
  93 + </resource>
  94 + </resources>
32 95 <plugins>
33 96 <plugin>
34 97 <groupId>org.apache.maven.plugins</groupId>
... ... @@ -41,37 +104,5 @@
41 104 </plugins>
42 105 <finalName>platform-report-api</finalName>
43 106 </build>
44   - <!--
45   - <profiles>
46   - <profile>
47   - <id>mysql</id>
48   - <properties>
49   - <deploy.type>mysql</deploy.type>
50   - </properties>
51   - <activation>
52   - <activeByDefault>true</activeByDefault>
53   - </activation>
54   - <dependencies>
55   - <dependency>
56   - <groupId>com.lyms.core</groupId>
57   - <artifactId>permission-dal-mysql</artifactId>
58   - <version>${project.version}</version>
59   - </dependency>
60   - </dependencies>
61   - </profile>
62   - <profile>
63   - <id>mongo</id>
64   - <properties>
65   - <deploy.type>mongo</deploy.type>
66   - </properties>
67   - <dependencies>
68   - <dependency>
69   - <groupId>com.lyms.core</groupId>
70   - <artifactId>permission-dal-mongo</artifactId>
71   - <version>${project.version}</version>
72   - </dependency>
73   - </dependencies>
74   - </profile>
75   - </profiles>-->
76 107 </project>
platform-report-api/src/main/java/com/lyms/platform/report/web/controller/TestController.java View file @ 24300f3
  1 +package com.lyms.platform.report.web.controller;
  2 +
  3 +import org.springframework.stereotype.Controller;
  4 +
  5 +/**
  6 + *
  7 + *
  8 + *
  9 + * Created by Administrator on 2016/4/20 0020.
  10 + */
  11 +@Controller
  12 +public class TestController {
  13 +}
platform-report-api/src/main/java/com/lyms/platform/report/web/inteceptor/TokenValidateInteceptor.java View file @ 24300f3
  1 +
  2 +package com.lyms.platform.report.web.inteceptor;
  3 +
  4 +
  5 +import com.lyms.platform.common.annotation.TokenRequired;
  6 +import com.lyms.platform.common.base.BaseController;
  7 +import com.lyms.platform.common.base.ContextHolder;
  8 +import com.lyms.platform.common.base.LoginContext;
  9 +import com.lyms.platform.common.exception.ParameterException;
  10 +import com.lyms.platform.common.exception.TokenException;
  11 +import com.lyms.platform.common.utils.LogUtil;
  12 +import com.lyms.platform.common.utils.LoginUtil;
  13 +import com.lyms.platform.permission.model.Users;
  14 +import com.lyms.platform.permission.service.UsersService;
  15 +import org.apache.commons.lang.StringUtils;
  16 +import org.springframework.beans.factory.annotation.Autowired;
  17 +import org.springframework.web.method.HandlerMethod;
  18 +import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
  19 +
  20 +import javax.servlet.http.HttpServletRequest;
  21 +import javax.servlet.http.HttpServletResponse;
  22 +import java.lang.annotation.Annotation;
  23 +
  24 +/**
  25 + * 验证token拦截器
  26 + *
  27 + * <ul>
  28 + * <li>
  29 + * 1、springmvc中配置TokenValidateInteceptor的拦截
  30 + * 2、在需要拦截的方法上面配置TokenRequired注解
  31 + * </li>
  32 + * </ul>
  33 + *
  34 + */
  35 +
  36 +public class TokenValidateInteceptor extends HandlerInterceptorAdapter {
  37 +
  38 + @Autowired
  39 + private UsersService usersService;
  40 +
  41 + public static boolean isSiteController(Object handler) {
  42 + return handler instanceof HandlerMethod && (((HandlerMethod) handler).getBean() instanceof BaseController);
  43 + }
  44 +
  45 + @Override
  46 + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
  47 +
  48 + if (!isSiteController(handler))
  49 + return true;
  50 + TokenRequired clientRequired = findAnnotation((HandlerMethod) handler, TokenRequired.class);
  51 + if (null == clientRequired)
  52 + return true;
  53 +
  54 + validateToken(request, response);
  55 +
  56 + return true;
  57 + }
  58 +
  59 + private <T extends Annotation> T findAnnotation(HandlerMethod handler, Class<T> annotationType) {
  60 + T annotation = handler.getBeanType().getAnnotation(annotationType);
  61 + if (annotation != null)
  62 + return annotation;
  63 + return handler.getMethodAnnotation(annotationType);
  64 + }
  65 +
  66 + public boolean validateToken(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
  67 + String token = httpServletRequest.getHeader("Authorization");
  68 + if (StringUtils.isEmpty(token)) {
  69 + throw new ParameterException();
  70 + }
  71 + LoginContext loginContext = LoginUtil.checkLoginState(token);
  72 + if(!loginContext.isLogin()) {
  73 + throw new TokenException();
  74 + }
  75 + Users users = usersService.getUsersByLoginCenterId(loginContext.getId());
  76 + if(null == users) {
  77 + throw new TokenException();
  78 + }
  79 + loginContext.setId(users.getId());
  80 + loginContext.setToken(token);
  81 + httpServletRequest.setAttribute("loginContext", loginContext);
  82 +
  83 + LogUtil.tokenInfo(" userId:" + users.getId() + ", ,url:" + httpServletRequest.getRequestURI() + ",method:" + httpServletRequest.getMethod());
  84 +
  85 + return loginContext.isLogin();
  86 + }
  87 +
  88 + @Override
  89 + public void afterCompletion(
  90 + HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
  91 + throws Exception {
  92 + ContextHolder.clean();
  93 + }
  94 +}
platform-report-api/src/main/resources/spring/applicationContext-mvc.xml View file @ 24300f3
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<beans xmlns="http://www.springframework.org/schema/beans"
  3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
  4 + xmlns:mvc="http://www.springframework.org/schema/mvc"
  5 + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
  6 + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
  7 + http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"
  8 + default-lazy-init="true">
  9 +
  10 +
  11 + <context:component-scan base-package="com.lyms.platform.report.web.controller"
  12 + use-default-filters="false">
  13 + <context:include-filter type="annotation"
  14 + expression="org.springframework.stereotype.Controller" />
  15 + </context:component-scan>
  16 +
  17 + <mvc:annotation-driven validator="localValidator">
  18 + <mvc:argument-resolvers >
  19 + <bean id="annotationFormArgumentResolver" class="com.lyms.platform.common.core.resolve.AnnotationFormArgumentResolver"/>
  20 + </mvc:argument-resolvers>
  21 + <mvc:message-converters>
  22 + <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
  23 + <bean class="com.lyms.platform.common.core.converter.StringMessageConverter"/>
  24 + <bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter"/>
  25 + <bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"/>
  26 + <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
  27 + </mvc:message-converters>
  28 + </mvc:annotation-driven>
  29 + <bean id="localValidator"
  30 + class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
  31 + <property name="traversableResolver">
  32 + <bean
  33 + class="org.hibernate.validator.internal.engine.resolver.DefaultTraversableResolver" />
  34 + </property>
  35 + </bean>
  36 +
  37 +
  38 + <mvc:interceptors>
  39 + <bean id="tokenValidateInteceptor" class="com.lyms.platform.report.web.inteceptor.TokenValidateInteceptor"/>
  40 + </mvc:interceptors>
  41 +
  42 +</beans>
platform-report-api/src/main/resources/spring/applicationContext.xml View file @ 24300f3
... ... @@ -13,6 +13,6 @@
13 13 <context:annotation-config />
14 14  
15 15 <!-- 配置要扫描的包 -->
16   - <context:component-scan base-package="com.lyms.core.data.sync" />
  16 + <context:component-scan base-package="com.lyms.platform.*" />
17 17 </beans>
platform-report-api/src/main/resources/spring/spring-mongodb.xml View file @ 24300f3
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<beans xmlns="http://www.springframework.org/schema/beans"
  3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mongo="http://www.springframework.org/schema/data/mongo"
  4 + xsi:schemaLocation="http://www.springframework.org/schema/data/mongo
  5 + http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd
  6 + http://www.springframework.org/schema/beans
  7 + http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
  8 +
  9 + <mongo:db-factory id="mongoDbFactory" host="${mongo.db.host}"
  10 + port="${mongo.db.port}" dbname="${mongo.db.dbname}" />
  11 +
  12 + <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
  13 + <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
  14 + <!-- <constructor-arg name="userCredentials" ref="userCredentials"/> -->
  15 + <constructor-arg name="mongoConverter" ref="mappingMongoConverter" />
  16 + </bean>
  17 +
  18 + <mongo:mapping-converter base-package="com.lyms.platform.pojo" />
  19 + <bean id="mappingContext" class="org.springframework.data.mongodb.core.mapping.MongoMappingContext" />
  20 + <!-- 配置mongodb映射类型 -->
  21 + <bean id="mappingMongoConverter" class="org.springframework.data.mongodb.core.convert.MappingMongoConverter">
  22 + <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
  23 + <constructor-arg name="mappingContext" ref="mappingContext" />
  24 + <property name="typeMapper" ref="defaultMongoTypeMapper" />
  25 + </bean>
  26 +
  27 + <!-- 默认Mongodb类型映射 -->
  28 + <bean id="defaultMongoTypeMapper" class="org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper">
  29 + <constructor-arg name="typeKey">
  30 + <null /><!-- 这里设置为空,可以把 spring data mongodb 多余保存的_class字段去掉 -->
  31 + </constructor-arg>
  32 + </bean>
  33 + <!--
  34 + <bean id="userCredentials" class="org.springframework.data.authentication.UserCredentials">
  35 + <description>认证口令</description>
  36 + <constructor-arg name="username" value="${${mongo.username}}" />
  37 + <constructor-arg name="password" value="${${mongo.password}}" />
  38 + </bean>
  39 +
  40 + <mongo:mongo id="mongo" host="${${mongo.host}}" port="${${mongo.port}}">
  41 +
  42 + <mongo:options connections-per-host="${${mongo.connectionsPerHost}}"
  43 +
  44 + threads-allowed-to-block-for-connection-multiplier="${${mongo.threadsAllowedToBlockForConnectionMultiplier}}"
  45 +
  46 + connect-timeout="${${mongo.connectTimeout}}" max-wait-time="${${mongo.maxWaitTime}}"
  47 +
  48 + auto-connect-retry="${${mongo.autoConnectRetry}}" socket-keep-alive="${${mongo.socketKeepAlive}}"
  49 +
  50 + socket-timeout="${${mongo.socketTimeout}}" slave-ok="${${mongo.slaveOk}}"
  51 +
  52 + write-number="1" write-timeout="0" write-fsync="true" />
  53 + </mongo:mongo>-->
  54 +</beans>
platform-report-api/src/main/webapp/WEB-INF/cxf-servlet.xml View file @ 24300f3
1   -<?xml version="1.0" encoding="UTF-8"?>
2   -<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
3   - license agreements. See the NOTICE file distributed with this work for additional
4   - information regarding copyright ownership. The ASF licenses this file to
5   - you under the Apache License, Version 2.0 (the "License"); you may not use
6   - this file except in compliance with the License. You may obtain a copy of
7   - the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
8   - by applicable law or agreed to in writing, software distributed under the
9   - License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
10   - OF ANY KIND, either express or implied. See the License for the specific
11   - language governing permissions and limitations under the License. -->
12   -<!-- START SNIPPET: beans -->
13   -<beans xmlns="http://www.springframework.org/schema/beans"
14   - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
15   - xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
16   - <import resource="classpath:META-INF/cxf/cxf.xml" />
17   - <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
18   -
19   - <jaxws:endpoint id="emergenceWs"
20   - implementor="com.lyms.core.data.sync.web.ws.EmergenceController"
21   - address="/emergenceWs" />
22   -</beans>
23   -<!-- END SNIPPET: beans -->
platform-report-api/src/main/webapp/WEB-INF/web.xml View file @ 24300f3
1 1 <?xml version="1.0" encoding="UTF-8"?>
2   -<!--
3   - Licensed to the Apache Software Foundation (ASF) under one
4   - or more contributor license agreements. See the NOTICE file
5   - distributed with this work for additional information
6   - regarding copyright ownership. The ASF licenses this file
7   - to you under the Apache License, Version 2.0 (the
8   - "License"); you may not use this file except in compliance
9   - with the License. You may obtain a copy of the License at
  2 +<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
  3 + license agreements. See the NOTICE file distributed with this work for additional
  4 + information regarding copyright ownership. The ASF licenses this file to
  5 + you under the Apache License, Version 2.0 (the "License"); you may not use
  6 + this file except in compliance with the License. You may obtain a copy of
  7 + the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
  8 + by applicable law or agreed to in writing, software distributed under the
  9 + License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
  10 + OF ANY KIND, either express or implied. See the License for the specific
  11 + language governing permissions and limitations under the License. -->
  12 +<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  13 + version="2.5"
  14 + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  15 + <context-param>
  16 + <param-name>contextConfigLocation</param-name>
  17 + <param-value>
  18 + classpath*:/spring/applicationContext.xml
  19 + </param-value>
  20 + </context-param>
10 21  
11   - http://www.apache.org/licenses/LICENSE-2.0
12   -
13   - Unless required by applicable law or agreed to in writing,
14   - software distributed under the License is distributed on an
15   - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   - KIND, either express or implied. See the License for the
17   - specific language governing permissions and limitations
18   - under the License.
19   --->
20   -<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
21   - <display-name>cxf</display-name>
  22 + <session-config>
  23 + <session-timeout>60</session-timeout>
  24 + </session-config>
22 25 <context-param>
23   - <param-name>contextConfigLocation</param-name>
24   - <param-value>
25   - classpath*:/applicationContext.xml
26   - </param-value>
27   - </context-param>
  26 + <param-name>log4jConfigLocation</param-name>
  27 + <param-value>classpath:log4j_config.xml</param-value>
  28 + </context-param>
  29 + <context-param>
  30 + <param-name>webAppRootKey</param-name>
  31 + <param-value>webapp.report-api</param-value>
  32 + </context-param>
  33 + <context-param>
  34 + <param-name>log4jRefreshInterval</param-name>
  35 + <param-value>60000</param-value>
  36 + </context-param>
28 37 <servlet>
29   - <description>Apache CXF Endpoint</description>
30   - <display-name>cxf</display-name>
31   - <servlet-name>cxf</servlet-name>
32   - <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
  38 + <servlet-name>dispatcher</servlet-name>
  39 + <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  40 + <init-param>
  41 + <param-name>contextConfigLocation</param-name>
  42 + <param-value>classpath*:/spring/applicationContext-mvc.xml</param-value>
  43 + </init-param>
33 44 <load-on-startup>1</load-on-startup>
34 45 </servlet>
35 46 <servlet-mapping>
36   - <servlet-name>cxf</servlet-name>
37   - <url-pattern>/services/*</url-pattern>
  47 + <servlet-name>dispatcher</servlet-name>
  48 + <url-pattern>/</url-pattern>
38 49 </servlet-mapping>
39   - <session-config>
40   - <session-timeout>60</session-timeout>
41   - </session-config>
42   - <context-param>
43   - <param-name>log4jConfigLocation</param-name>
44   - <param-value>classpath:log4j_config.xml</param-value>
45   - </context-param>
46   - <context-param>
47   - <param-name>log4jRefreshInterval</param-name>
48   - <param-value>60000</param-value>
49   - </context-param>
50   - <listener>
51   - <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
52   - </listener>
53   - <listener>
54   - <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
55   - </listener>
  50 + <filter>
  51 + <filter-name>HttpMethodFilter</filter-name>
  52 + <filter-class>org.springframework.web.filter.HttpPutFormContentFilter</filter-class>
  53 + </filter>
  54 + <filter-mapping>
  55 + <filter-name>HttpMethodFilter</filter-name>
  56 + <url-pattern>/*</url-pattern>
  57 + </filter-mapping>
  58 + <filter>
  59 + <filter-name>encodingFilter</filter-name>
  60 + <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  61 + <init-param>
  62 + <param-name>encoding</param-name>
  63 + <param-value>UTF-8</param-value>
  64 + </init-param>
  65 + </filter>
  66 +
  67 + <filter-mapping>
  68 + <filter-name>encodingFilter</filter-name>
  69 + <url-pattern>/*</url-pattern>
  70 + </filter-mapping>
  71 + <listener>
  72 + <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  73 + </listener>
  74 + <listener>
  75 + <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  76 + </listener>
56 77 </web-app>