Skip to content

Commit

Permalink
modify the JacksonJsonRopMarshaller make null property not serialize …
Browse files Browse the repository at this point in the history
…to message
  • Loading branch information
itstamen committed Mar 26, 2014
1 parent 8eab2d4 commit 5a3c03a
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.rop.event.RopEventListener;
import com.rop.marshaller.MessageMarshallerUtils;

import java.util.Map;

/**
* <pre>
* 功能说明:
Expand All @@ -23,9 +25,9 @@ public class SampleAfterDoServiceEventListener implements RopEventListener<After
@Override
public void onRopEvent(AfterDoServiceEvent ropEvent) {
RopRequestContext ropRequestContext = ropEvent.getRopRequestContext();
if(ropRequestContext != null && ropRequestContext.getRopRequest() != null){
RopRequest ropRequest = ropRequestContext.getRopRequest();
String message = MessageMarshallerUtils.asUrlString(ropRequest);
if(ropRequestContext != null){
Map<String,String> allParams = ropRequestContext.getAllParams();
String message = MessageMarshallerUtils.asUrlString(allParams);
System.out.println("message("+ropEvent.getServiceEndTime()+")"+message);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.rop.event.RopEventListener;
import com.rop.marshaller.MessageMarshallerUtils;

import java.util.Map;

/**
* <pre>
* 功能说明:
Expand All @@ -23,9 +25,9 @@ public class SamplePreDoServiceEventListener implements RopEventListener<PreDoSe
@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());
if(ropRequestContext != null){
Map<String,String> allParams = ropRequestContext.getAllParams();
String message = MessageMarshallerUtils.getMessage(allParams, ropRequestContext.getMessageFormat());
System.out.println("message("+ropEvent.getServiceBeginTime()+")"+message);
}
}
Expand Down
4 changes: 2 additions & 2 deletions rop-sample/src/main/java/com/rop/sample/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ public Object userList(RopRequest ropRequest) throws Throwable {

@ServiceMethod(method = "img.get", version = "1.0",
httpAction = HttpAction.GET,
ignoreSign = IgnoreSignType.YES,
needInSession = NeedInSessionType.NO)
ignoreSign = IgnoreSignType.YES,
needInSession = NeedInSessionType.NO)
public void getImg(RopRequest ropRequest) throws Throwable {
HttpServletResponse response = (HttpServletResponse)
ropRequest.getRopRequestContext().getRawResponseObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ public class CreateUserResponse{
@XmlElement
private String feedback;

@XmlAttribute
private Boolean status = true;

@XmlAttribute
private Integer age = 10;

@XmlAttribute
private Float height = 170.01f;

@XmlElement
private List<Foo> fooList;

Expand All @@ -53,6 +62,30 @@ public void setFooList(List<Foo> fooList) {
this.fooList = fooList;
}

public Boolean getStatus() {
return status;
}

public void setStatus(Boolean status) {
this.status = status;
}

public Integer getAge() {
return age;
}

public void setAge(Integer age) {
this.age = age;
}

public Float getHeight() {
return height;
}

public void setHeight(Float height) {
this.height = height;
}

public String getUserId() {
return userId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@
public class UserServiceRawClient {

public static final String SERVER_URL = "http://localhost:8088/router";

private String sessionId;

/**
* 创建一个服务端的会话
*/
@BeforeMethod
// @BeforeMethod
public void createSession() {
RestTemplate restTemplate = new RestTemplate();
MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
Expand Down
7 changes: 7 additions & 0 deletions rop/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ http://yourhost?method=rop.user.add&v=1.0&callback=myfun,则响应报文的
图片获取等;
2.重构了pom.xml的结构.

1.0.2-SNAPSHOT (2014-03-24)
1.ServiceMethodAdapter的方法 :Object invokeServiceMethod(RopRequestContext ropRequestContext)变更为:
Object invokeServiceMethod(RopRequest ropRequest);
2.ReopRequestContext删除getRopRequest及setRopRequest的方法;
3.SimpleRopRequestContext添加session属性,在创建RopRequestContext时获取设置session;
4.解决会话更新后不能自动同步到会话管理器的BUG.




Expand Down
37 changes: 18 additions & 19 deletions rop/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,25 +183,24 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
<configuration>
<charset>${file.encoding}</charset>
<encoding>${file.encoding}</encoding>
<docencoding>${file.encoding}</docencoding>
<source></source>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!--<plugin>-->
<!--<groupId>org.apache.maven.plugins</groupId>-->
<!--<artifactId>maven-javadoc-plugin</artifactId>-->
<!--<version>2.7</version>-->
<!--<configuration>-->
<!--<charset>${file.encoding}</charset>-->
<!--<encoding>${file.encoding}</encoding>-->
<!--<docencoding>${file.encoding}</docencoding>-->
<!--</configuration>-->
<!--<executions>-->
<!--<execution>-->
<!--<id>attach-javadocs</id>-->
<!--<goals>-->
<!--<goal>jar</goal>-->
<!--</goals>-->
<!--</execution>-->
<!--</executions>-->
<!--</plugin>-->

<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
2 changes: 1 addition & 1 deletion rop/src/main/java/com/rop/RequestContextBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public interface RequestContextBuilder {
*
* @param ropRequestContext
*/
void bindBusinessParams(RopRequestContext ropRequestContext);
RopRequest buildRopRequest(RopRequestContext ropRequestContext);
}

15 changes: 1 addition & 14 deletions rop/src/main/java/com/rop/RopRequestContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public interface RopRequestContext {
/**
* 设置服务开始时间
*
* @param serviceBeginTime
* @param serviceEndTime
*/
void setServiceEndTime(long serviceEndTime);

Expand Down Expand Up @@ -182,19 +182,6 @@ public interface RopRequestContext {
*/
Object getRopResponse();

/**
* 设置{@link RopRequest}
*
* @param ropRequest
*/
void setRopRequest(RopRequest ropRequest);

/**
* 请求对象
*
* @return
*/
RopRequest getRopRequest();

/**
* 获取特定属性
Expand Down
4 changes: 2 additions & 2 deletions rop/src/main/java/com/rop/ServiceMethodAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public interface ServiceMethodAdapter {
/**
* 调用服务方法
*
* @param ropRequestContext
* @param ropRequest
* @return
*/
Object invokeServiceMethod(RopRequestContext ropRequestContext);
Object invokeServiceMethod(RopRequest ropRequest);

}

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
package com.rop.impl;

import com.rop.RopRequest;
import com.rop.RopRequestContext;
import com.rop.ServiceMethodAdapter;
import com.rop.ServiceMethodHandler;
Expand Down Expand Up @@ -31,11 +32,12 @@ public class AnnotationServiceMethodAdapter implements ServiceMethodAdapter {
/**
* 调用ROP服务方法
*
* @param ropRequestContext
* @param ropRequest
* @return
*/
public Object invokeServiceMethod(RopRequestContext ropRequestContext) {
public Object invokeServiceMethod(RopRequest ropRequest) {
try {
RopRequestContext ropRequestContext = ropRequest.getRopRequestContext();
//分析上下文中的错误
ServiceMethodHandler serviceMethodHandler = ropRequestContext.getServiceMethodHandler();
if (logger.isDebugEnabled()) {
Expand All @@ -44,7 +46,7 @@ public Object invokeServiceMethod(RopRequestContext ropRequestContext) {
}
if (serviceMethodHandler.isHandlerMethodWithParameter()) {
return serviceMethodHandler.getHandlerMethod().invoke(
serviceMethodHandler.getHandler(), ropRequestContext.getRopRequest());
serviceMethodHandler.getHandler(),ropRequest);
} else {
return serviceMethodHandler.getHandlerMethod().invoke(serviceMethodHandler.getHandler());
}
Expand Down
20 changes: 11 additions & 9 deletions rop/src/main/java/com/rop/impl/AnnotationServletServiceRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ public void run() {
}

RopRequestContext ropRequestContext = null;

RopRequest ropRequest = null;
try {
//用系统级参数构造一个RequestContext实例(第一阶段绑定)
ropRequestContext = requestContextBuilder.buildBySysParams(
Expand All @@ -388,7 +388,7 @@ public void run() {
} else {

//绑定业务数据(第二阶段绑定)
requestContextBuilder.bindBusinessParams(ropRequestContext);
ropRequest = requestContextBuilder.buildRopRequest(ropRequestContext);

//进行其它检查业务数据合法性,业务安全等
mainError = securityManager.validateOther(ropRequestContext);
Expand All @@ -402,10 +402,10 @@ public void run() {

if (ropRequestContext.getRopResponse() == null) { //拦截器未生成response
//如果拦截器没有产生ropResponse时才调用服务方法
ropRequestContext.setRopResponse(doService(ropRequestContext));
ropRequestContext.setRopResponse(doService(ropRequest));

//输出响应前拦截
invokeBeforceResponseOfInterceptors(ropRequestContext);
invokeBeforceResponseOfInterceptors(ropRequest);
}
}
}
Expand All @@ -418,7 +418,7 @@ public void run() {
ServiceUnavailableErrorResponse ropResponse = new ServiceUnavailableErrorResponse(method, locale, e);

//输出响应前拦截
invokeBeforceResponseOfInterceptors(ropRequestContext);
invokeBeforceResponseOfInterceptors(ropRequest);
writeResponse(ropResponse, servletResponse, ropRequestContext.getMessageFormat(),jsonpCallback);
}else{
throw new RopException("RopRequestContext is null.", e);
Expand Down Expand Up @@ -534,9 +534,10 @@ private void invokeBeforceServiceOfInterceptors(RopRequestContext ropRequestCont
/**
* 在服务调用之后,返回响应之前拦截
*
* @param ropRequestContext
* @param ropRequest
*/
private void invokeBeforceResponseOfInterceptors(RopRequestContext ropRequestContext) {
private void invokeBeforceResponseOfInterceptors(RopRequest ropRequest) {
RopRequestContext ropRequestContext = ropRequest.getRopRequestContext();
Interceptor tempInterceptor = null;
try {
if (interceptors != null && interceptors.size() > 0) {
Expand Down Expand Up @@ -593,15 +594,16 @@ private void writeResponse(Object ropResponse, HttpServletResponse httpServletRe
}
}

private Object doService(RopRequestContext ropRequestContext) {
private Object doService(RopRequest ropRequest) {
Object ropResponse = null;
RopRequestContext ropRequestContext = ropRequest.getRopRequestContext();
if (ropRequestContext.getMethod() == null) {
ropResponse = new ErrorResponse(MainErrors.getError(MainErrorType.MISSING_METHOD, ropRequestContext.getLocale()));
} else if (!ropContext.isValidMethod(ropRequestContext.getMethod())) {
ropResponse = new ErrorResponse(MainErrors.getError(MainErrorType.INVALID_METHOD, ropRequestContext.getLocale()));
} else {
try {
ropResponse = serviceMethodAdapter.invokeServiceMethod(ropRequestContext);
ropResponse = serviceMethodAdapter.invokeServiceMethod(ropRequest);
} catch (Exception e) { //出错则招聘服务不可用的异常
if (logger.isInfoEnabled()) {
logger.info("调用" + ropRequestContext.getMethod() + "时发生异常,异常信息为:" + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private String getRemoteAddr(HttpServletRequest request) {
* @param ropRequestContext
*/
@Override
public void bindBusinessParams(RopRequestContext ropRequestContext) {
public RopRequest buildRopRequest(RopRequestContext ropRequestContext) {
AbstractRopRequest ropRequest = null;
if (ropRequestContext.getServiceMethodHandler().isRopRequestImplType()) {
HttpServletRequest request =
Expand All @@ -134,7 +134,7 @@ public void bindBusinessParams(RopRequestContext ropRequestContext) {
ropRequest = new DefaultRopRequest();
}
ropRequest.setRopRequestContext(ropRequestContext);
ropRequestContext.setRopRequest(ropRequest);
return ropRequest;
}


Expand Down
22 changes: 8 additions & 14 deletions rop/src/main/java/com/rop/impl/SimpleRopRequestContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public class SimpleRopRequestContext implements RopRequestContext {

private String requestId = RopUtils.getUUID();

private Session session;

@Override
public long getServiceBeginTime() {
return this.serviceBeginTime;
Expand Down Expand Up @@ -149,15 +151,17 @@ public String getSessionId() {

@Override
public Session getSession() {
if (ropContext != null && ropContext.getSessionManager() != null && getSessionId() != null) {
return ropContext.getSessionManager().getSession(getSessionId());
} else {
return null;
if (session == null && ropContext != null &&
ropContext.getSessionManager() != null && getSessionId() != null) {
session = ropContext.getSessionManager().getSession(getSessionId());
}
return session;
}

@Override
public void addSession(String sessionId, Session session) {
this.sessionId = sessionId;
this.session = session;
if (ropContext != null && ropContext.getSessionManager() != null) {
ropContext.getSessionManager().addSession(sessionId, session);
}
Expand Down Expand Up @@ -189,16 +193,6 @@ public Object getRopResponse() {
return this.ropResponse;
}

@Override
public RopRequest getRopRequest() {
return this.ropRequest;
}

@Override
public void setRopRequest(RopRequest ropRequest) {
this.ropRequest = ropRequest;
}

public String getAppKey() {
return this.appKey;
}
Expand Down
Loading

0 comments on commit 5a3c03a

Please sign in to comment.