Skip to content

Commit

Permalink
1.chage rop-sample acorrding the change of rop project.
Browse files Browse the repository at this point in the history
  • Loading branch information
stamen committed Jul 29, 2012
1 parent c921c25 commit db55e37
Show file tree
Hide file tree
Showing 13 changed files with 304 additions and 55 deletions.
28 changes: 28 additions & 0 deletions rop-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<org.codehaus.jackson.version>1.9.5</org.codehaus.jackson.version>
<testng.version>6.3</testng.version>
<mockito.version>1.8.5</mockito.version>
<unitils.version>3.3</unitils.version>
</properties>

<dependencies>
Expand All @@ -57,6 +58,27 @@
<version>1.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.unitils</groupId>
<artifactId>unitils-core</artifactId>
<version>${unitils.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.unitils</groupId>
<artifactId>unitils-testng</artifactId>
<version>${unitils.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.unitils</groupId>
<artifactId>unitils-spring</artifactId>
<version>${unitils.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
Expand All @@ -70,6 +92,12 @@
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
</dependencies>

<build>
Expand Down
28 changes: 28 additions & 0 deletions rop-sample/src/main/java/com/rop/sample/LogoutService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* 版权声明:中图一购网络科技有限公司 版权所有 违者必究 2012
* 日 期:12-7-27
*/
package com.rop.sample;

import com.rop.RopRequest;
import com.rop.RopResponse;
import com.rop.annotation.ServiceMethod;
import com.rop.annotation.ServiceMethodBean;

/**
* <pre>
* 功能说明:
* </pre>
*
* @author 陈雄华
* @version 1.0
*/
@ServiceMethodBean(version = "1.0")
public class LogoutService {

@ServiceMethod(value = "user.logout")
public RopResponse logout(RopRequest request){
return new RopResponse() {};
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
package com.rop.sample;

import com.rop.AbstractInterceptor;
import com.rop.RequestContext;
import com.rop.RopRequestContext;
import com.rop.sample.response.InterceptorResponse;
import org.springframework.stereotype.Component;

/**
* <pre>
* 该拦截器仅对method为“user.add”进行拦截,你可以在{@link #isMatch(com.rop.RequestContext)}方法中定义拦截器的匹配规则。
* 你可以通过{@link com.rop.RequestContext#getServiceMethodDefinition()}获取服务方法的注解信息,通过这些信息进行拦截匹配规则
* 该拦截器仅对method为“user.add”进行拦截,你可以在{@link #isMatch(com.rop.RopRequestContext)}方法中定义拦截器的匹配规则。
* 你可以通过{@link com.rop.RopRequestContext#getServiceMethodDefinition()}获取服务方法的注解信息,通过这些信息进行拦截匹配规则
* 定义。
* </pre>
*
Expand All @@ -26,42 +26,42 @@ public class ReservedUserNameInterceptor extends AbstractInterceptor {
/**
* 在数据绑定后,服务方法调用前执行该拦截方法
*
* @param methodContext
* @param ropRequestContext
*/
@Override
public void beforeService(RequestContext methodContext) {
public void beforeService(RopRequestContext ropRequestContext) {
System.out.println("beforeService ...");

if ("jhonson".equals(methodContext.getParamValue("userName"))) {
if ("jhonson".equals(ropRequestContext.getParamValue("userName"))) {
InterceptorResponse response = new InterceptorResponse();
response.setTestField("the userName can't be jhonson!");
//设置了RopResponse后,后续的服务将不执行,直接返回这个RopResponse响应
methodContext.setRopResponse(response);
ropRequestContext.setRopResponse(response);
}
}

/**
* 在服务执行完成后,响应返回前执行该拦截方法
*
* @param methodContext
* @param ropRequestContext
*/
@Override
public void beforeResponse(RequestContext methodContext) {
public void beforeResponse(RopRequestContext ropRequestContext) {
System.out.println("beforeResponse ...");
}

/**
* 对method为user.add的方法进行拦截,你可以通过methodContext中的信息制定拦截方案
*
* @param methodContext
* @param ropRequestContext
* @return
*/
@Override
public boolean isMatch(RequestContext methodContext) {
public boolean isMatch(RopRequestContext ropRequestContext) {
// if("group1".equals(methodContext.getServiceMethodDefinition().getMethodGroup())){
// //do sth
// }
return "user.add".equals(methodContext.getMethod());
return "user.add".equals(ropRequestContext.getMethod());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
*/
package com.rop.sample;

import com.rop.RopRequestContext;
import com.rop.RopRequest;
import com.rop.event.AfterDoServiceEvent;
import com.rop.event.RopEventListener;
import com.rop.marshaller.MessageMarshallerUtils;

/**
* <pre>
Expand All @@ -19,7 +22,12 @@ public class SampleAfterDoServiceEventListener implements RopEventListener<After

@Override
public void onRopEvent(AfterDoServiceEvent ropEvent) {
System.out.println("SampleAfterDoServiceEventListener!!!");
RopRequestContext ropRequestContext = ropEvent.getRopRequestContext();
if(ropRequestContext != null && ropRequestContext.getRopRequest() != null){
RopRequest ropRequest = ropRequestContext.getRopRequest();
String message = MessageMarshallerUtils.asUrlString(ropRequest);
System.out.println("message("+ropEvent.getServiceEndTime()+")"+message);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void onRopEvent(AfterStartedRopEvent ropRopEvent) {

@Override
public int getOrder() {
return 0; //To change body of implemented methods use File | Settings | File Templates.
return 0;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* 版权声明:中图一购网络科技有限公司 版权所有 违者必究 2012
* 日 期:12-7-17
*/
package com.rop.sample;

import com.rop.RopRequestContext;
import com.rop.RopRequest;
import com.rop.event.PreDoServiceEvent;
import com.rop.event.RopEventListener;
import com.rop.marshaller.MessageMarshallerUtils;

/**
* <pre>
* 功能说明:
* </pre>
*
* @author 陈雄华
* @version 1.0
*/
public class SamplePreDoServiceEventListener implements RopEventListener<PreDoServiceEvent> {

@Override
public void onRopEvent(PreDoServiceEvent ropEvent) {
RopRequestContext ropRequestContext = ropEvent.getRopRequestContext();
if(ropRequestContext != null && ropRequestContext.getRopRequest() != null){
RopRequest ropRequest = ropRequestContext.getRopRequest();
String message = MessageMarshallerUtils.getMessage(ropRequest, ropRequestContext.getMessageFormat());
System.out.println("message("+ropEvent.getServiceBeginTime()+")"+message);
}
}

@Override
public int getOrder() {
return 1;
}
}

26 changes: 15 additions & 11 deletions rop-sample/src/main/java/com/rop/sample/SampleSecurityManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
*/
package com.rop.sample;

import com.rop.RequestContext;
import com.rop.SecurityManager;
import com.rop.AbstractSecurityManager;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
Expand All @@ -18,23 +19,26 @@
* @author 陈雄华
* @version 1.0
*/
public class SampleSecurityManager implements SecurityManager {
public class SampleSecurityManager extends AbstractSecurityManager {

private static final Map<String, Boolean> aclMap = new HashMap<String, Boolean>();
private static final Map<String, List<String>> aclMap = new HashMap<String, List<String>>();

static {
aclMap.put("mockSessionId1", true);
aclMap.put("mockSessionId2", false);
ArrayList<String> serviceMethods = new ArrayList<String>();
serviceMethods.add("user.logon");
serviceMethods.add("user.logout");
serviceMethods.add("user.getSession");
aclMap.put("00002", serviceMethods);
}

@Override
public boolean isGranted(RequestContext methodContext) {
if (methodContext.getSessionId() != null) {
return aclMap.get(methodContext.getSessionId());
} else {
public boolean isIsvGranted(String appKey,String method,String version) {
if(aclMap.containsKey(appKey)){
List<String> serviceMethods = aclMap.get(appKey);
return serviceMethods.contains(method);
}else{
return true;
}

}
}

29 changes: 29 additions & 0 deletions rop-sample/src/main/java/com/rop/sample/SampleThreadFerry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* 版权声明:中图一购网络科技有限公司 版权所有 违者必究 2012
* 日 期:12-7-20
*/
package com.rop.sample;

import com.rop.ThreadFerry;

/**
* <pre>
* 功能说明:
* </pre>
*
* @author 陈雄华
* @version 1.0
*/
public class SampleThreadFerry implements ThreadFerry{

@Override
public void doInSrcThread() {
System.out.println("doInSrcThread:"+Thread.currentThread().getId());
}

@Override
public void doInDestThread() {
System.out.println("doInSrcThread:"+Thread.currentThread().getId());
}
}

Loading

0 comments on commit db55e37

Please sign in to comment.