Skip to content

Commit

Permalink
整合Restful api, 5.17+方式
Browse files Browse the repository at this point in the history
  • Loading branch information
henryyan committed Nov 26, 2015
1 parent 1181423 commit 127a566
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 109 deletions.
20 changes: 0 additions & 20 deletions src/main/java/org/activiti/conf/JacksonConfiguration.java

This file was deleted.

26 changes: 26 additions & 0 deletions src/main/java/org/activiti/conf/RestConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.activiti.conf;

import org.activiti.rest.common.application.ContentTypeResolver;
import org.activiti.rest.common.application.DefaultContentTypeResolver;
import org.activiti.rest.service.api.RestResponseFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* @author Joram Barrez
*/
@Configuration
public class RestConfiguration {

@Bean()
public RestResponseFactory restResponseFactory() {
RestResponseFactory restResponseFactory = new RestResponseFactory();
return restResponseFactory;
}

@Bean()
public ContentTypeResolver contentTypeResolver() {
ContentTypeResolver resolver = new DefaultContentTypeResolver();
return resolver;
}
}
34 changes: 34 additions & 0 deletions src/main/java/org/activiti/conf/SecurityConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.activiti.conf;

import org.activiti.rest.security.BasicAuthenticationProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;

@Configuration
@EnableWebSecurity
@EnableWebMvcSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

@Bean
public AuthenticationProvider authenticationProvider() {
return new BasicAuthenticationProvider();
}

@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authenticationProvider(authenticationProvider())
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.csrf().disable()
.authorizeRequests()
.anyRequest().authenticated()
.and()
.httpBasic();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.activiti.explorer.servlet;
package org.activiti.explorer;

import java.util.List;

Expand All @@ -20,7 +20,7 @@
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

@Configuration
@ComponentScan({"org.activiti.rest.editor", "org.activiti.rest.diagram"})
@ComponentScan({"org.activiti.rest,org.activiti.conf"})
@EnableAsync
public class DispatcherServletConfiguration extends WebMvcConfigurationSupport {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.activiti.explorer.servlet;
package org.activiti.explorer;

import java.io.DataOutputStream;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.activiti.explorer.servlet;
package org.activiti.explorer;

import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.activiti.explorer.servlet;
package org.activiti.explorer;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down
77 changes: 0 additions & 77 deletions src/main/java/org/activiti/explorer/servlet/WebConfigurer.java

This file was deleted.

5 changes: 4 additions & 1 deletion src/main/resources/applicationContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</bean>

<!-- 使用annotation 自动注册bean, 并保证@Required、@Autowired的属性被注入 -->
<context:component-scan base-package="me.kafeitu.demo.activiti,org.activiti.conf,org.activiti.rest.editor">
<context:component-scan base-package="me.kafeitu.demo.activiti,org.activiti.conf,org.activiti.rest.editor,org.activiti.rest.service">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

Expand Down Expand Up @@ -67,6 +67,9 @@
<!-- 使用annotation定义事务 -->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>

<!-- 单例json对象 -->
<bean id="objectMapper" class="com.fasterxml.jackson.databind.ObjectMapper"/>

<!-- 引擎内部提供的UUID生成器,依赖fastxml的java-uuid-generator模块 -->
<bean id="uuidGenerator" class="org.activiti.engine.impl.persistence.StrongUuidGenerator" />

Expand Down
2 changes: 0 additions & 2 deletions src/main/webapp/WEB-INF/spring-mvc-modeler.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@
</context:component-scan>

<mvc:annotation-driven />

<mvc:default-servlet-handler />
</beans>
15 changes: 15 additions & 0 deletions src/main/webapp/WEB-INF/spring-mvc-rest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">

<!-- 自动扫描且只扫描@Controller -->
<context:component-scan base-package="org.activiti.rest">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>

<mvc:annotation-driven />
</beans>
11 changes: 11 additions & 0 deletions src/main/webapp/WEB-INF/views/main/menu.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,15 @@
<li><a href="#" rel='management/identity/user/list'>用户与组</a></li>
</ul>
</li>
<li>
<a rel="#">Rest示例</a>
<ul>
<li><a href="${ctx}/rest/management/properties" target="_blank">引擎属性</a></li>
<li><a href="${ctx}/rest/runtime/tasks" target="_blank">我的任务</a></li>
<li><a href="${ctx}/rest/runtime/executions" target="_blank">我参与的流程</a></li>
<li><a href="${ctx}/rest/management/tables" target="_blank">数据库表</a></li>
<li><a href="${ctx}/rest/identity/users" target="_blank">用户</a></li>
<li><a href="${ctx}/rest/identity/groups" target="_blank">组</a></li>
</ul>
</li>
</ul>
5 changes: 2 additions & 3 deletions src/main/webapp/WEB-INF/views/main/welcome.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,15 @@
<div class="rest template">
<p>在web.xml中映射了两个两个Servlet</p>
<dl>
<dt>ExplorerRestletServlet</dt>
<dt>ModelRestServlet</dt>
<dd>
<p>针对Activiti Modeler的Rest接口,映射路径:/service/*</p>
</dd>
<dt>RestletServlet</dt>
<dt>RestServlet</dt>
<dd>
<p>官方提供的完整Rest接口</p>
<p>访问路径:http://localhost/yourappname/<用户手册提供的Rest地址></p>
<p>映射路径:/rest/*</p>
<p><a href="http://www.kafeitu.me/activiti/2013/01/12/kft-activiti-demo-rest.html">如何使用Activiti Rest模块</a></p>
</dd>
</dl>
</div>
Expand Down
32 changes: 31 additions & 1 deletion src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,27 @@
<!-- JSONP -->
<filter>
<filter-name>JSONPFilter</filter-name>
<filter-class>org.activiti.explorer.servlet.JsonpCallbackFilter</filter-class>
<filter-class>org.activiti.explorer.JsonpCallbackFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>JSONPFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>

<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/rest/*</url-pattern>
<dispatcher>ERROR</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>

<!-- 注册WebService -->
<servlet>
<servlet-name>CXFServlet</servlet-name>
Expand Down Expand Up @@ -96,6 +110,7 @@
<url-pattern>/</url-pattern>
</servlet-mapping>

<!-- Modeler的Rest服务 -->
<servlet>
<servlet-name>ModelRestServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
Expand All @@ -110,6 +125,21 @@
<url-pattern>/service/*</url-pattern>
</servlet-mapping>

<!-- Rest接口 -->
<servlet>
<servlet-name>RestServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mvc-rest.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>RestServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>

<!-- session超时定义,单位为分钟 -->
<session-config>
<session-timeout>20</session-timeout>
Expand Down
18 changes: 18 additions & 0 deletions src/main/webapp/example/rest.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<%@ include file="/common/global.jsp"%>
<%@ include file="/common/meta.jsp" %>
<%@ include file="/common/include-base-styles.jsp" %>
<%@ include file="/common/include-jquery-ui-theme.jsp" %>
<%@ include file="/common/include-custom-styles.jsp" %>
<title>Rest示例</title>

</head>
<body>



</body>
</html>
2 changes: 2 additions & 0 deletions src/main/webapp/js/module/main/main-frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ function dealRoles() {
$('#css3menu a').click(function() {
if ($(this).attr('rel') == '#') {
return false;
} else if (!$(this).attr('rel')) {
return true;
}
$('.active').removeClass('active');
$(this).addClass('active');
Expand Down

0 comments on commit 127a566

Please sign in to comment.