itstamen / rop Goto Github PK
View Code? Open in Web Editor NEWrapid open platform
Home Page: https://[email protected]/itstamen/rop.git
rapid open platform
Home Page: https://[email protected]/itstamen/rop.git
Introduction ROP is the Rapid Open Platform ,thus like the TOP(Taobao Open Platform:http://api.taobao.com). The rest url of ROP is thus like the following : 1)http://yourhost?method=rop.user.add&v=1.0¶m1=value1¶m=value2... 2)http://yourhost?method=rop.user.update&v=1.0¶m1=value1¶m=value2... ROP can router the request to the dest handler's api.You can use the @ServiceMethod("rop.user.add") annotation to mark the api method in the handler. Handler must be a add a @ServiceMethodBean annotation ,ServiceMethodBean has already annotated a @Service(Spring),So the Service Class would be a Spring Service Bean automaticly. This is a right handler rest service api method: import com.rop.annotation.ServiceMethod; import com.rop.annotation.ServiceMethodBean; @ServiceMethodBean//<--1. must mark the annotation,let it be a Service Bean public class SampleRestService { @ServiceMethod("rop.sample.method1")//<--2.Let it be a Service Method. public Object method1(SampleRopRequest1 request1) { SampleRopResponse1 response = new SampleRopResponse1(); response.setCreateTime("20120101010101"); response.setUserId("1"); return response; } } The parameter's list of the api method must extends the RopRequest,and the Return parameter can be any Object. The Rop can marshaller the response to the xml or json format output,you can control the output format by "format" parameter. Author and participants 1)Stamen XiaMen http://stamen.iteye.com/ 2)Wangxiancai GuangZhou http://wangxiancai.iteye.com/ Good Luck! 2014! stame by 2014-07-16 Xiamen China
弄错了~sorry
请求类里如果定义一个List的熟悉,就会报异常?是我用错了还是本身Rop就不支持泛型?
parent呢?
在做压力测试的时候,并发量为100的时候,后台收到了下面的异常,不知道如何处理。感觉是我的连接池参数配置的问题,请指教。谢谢
这个是我在Rop里的配置:
core-pool-size="200"
max-pool-size="500"
queue-capacity="10"
keep-alive-seconds="30"
sign-enable="true"
我的数据库最大连接数是50。
2014.07.24 17:19:33 [org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean#0-461] ERROR [com.rop.event.SimpleRopEventMulticaster] - 处理com.rop.event.AfterDoServiceEvent事件发生异常
java.util.concurrent.RejectedExecutionException: Task com.rop.event.SimpleRopEventMulticaster$1@71e818ae rejected from java.util.concurrent.ThreadPoolExecutor@40999a27[Running, pool size = 499, active threads = 47, queued tasks = 10, completed tasks = 10760]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2048)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:821)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1372)
at com.rop.event.SimpleRopEventMulticaster.multicastEvent(SimpleRopEventMulticaster.java:32)
at com.rop.impl.AnnotationServletServiceRouter.fireAfterDoServiceEvent(AnnotationServletServiceRouter.java:437)
at com.rop.impl.AnnotationServletServiceRouter.access$1000(AnnotationServletServiceRouter.java:40)
at com.rop.impl.AnnotationServletServiceRouter$ServiceRunnable.run(AnnotationServletServiceRouter.java:374)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
2
rop工程里面的pom.xml文件里的<jackson.xml.version>2.3.2-jdk1.5</jackson.xml.version> 有误,应该为<jackson.xml.version>2.3.2</jackson.xml.version> ,否则不能下载对应的jar包
报错:org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.bookegou.com/schema/rop]
Offending resource: file [D:\developer\workspace\mss\src\main\webapp\WEB-INF\classes\spring\ropApplicationContext.xml]
配置文件是这样的:
使用spring security oauth2 认证,OAuth2AuthenticationProcessingFilter 通过access_token获取到Authentication对象,设置到SecurityContextHolder.getContext().setAuthentication(authResult);中。
但AnnotationServletServiceRouter是异步方式执行service method,不在同一个线程中。System.out.println("auth = " + SecurityContextHolder.getContext().getAuthentication());
获取为空。
可否抽空看看。多谢。
下面两个方法很明显,一旦异常,在catch中会有个空指针异常
/**
* 在服务调用之前拦截
*
* @param ropRequestContext
*/
private void invokeBeforceServiceOfInterceptors(RopRequestContext ropRequestContext) {
Interceptor tempInterceptor = null;
try {
if (interceptors != null && interceptors.size() > 0) {
for (Interceptor interceptor : interceptors) {
interceptor.beforeService(ropRequestContext);
//如果有一个产生了响应,则阻止后续的调用
if (ropRequestContext.getRopResponse() != null) {
if (logger.isDebugEnabled()) {
logger.debug("拦截器[" + interceptor.getClass().getName() + "]产生了一个RopResponse," +
" 阻止本次服务请求继续,服务将直接返回。");
}
return;
}
}
}
} catch (Throwable e) {
ropRequestContext.setRopResponse(new ServiceUnavailableErrorResponse(ropRequestContext.getMethod(), ropRequestContext.getLocale(), e));
logger.error("在执行拦截器[" + tempInterceptor.getClass().getName() + "]时发生异常.", e);
}
}
/**
* 在服务调用之后,返回响应之前拦截
*
* @param ropRequestContext
*/
private void invokeBeforceResponseOfInterceptors(RopRequestContext ropRequestContext) {
Interceptor tempInterceptor = null;
try {
if (interceptors != null && interceptors.size() > 0) {
for (Interceptor interceptor : interceptors) {
interceptor.beforeResponse(ropRequestContext);
}
}
} catch (Throwable e) {
ropRequestContext.setRopResponse(new ServiceUnavailableErrorResponse(ropRequestContext.getMethod(), ropRequestContext.getLocale(), e));
logger.error("在执行拦截器[" + tempInterceptor.getClass().getName() + "]时发生异常.", e);
}
}
com.rop.session.SessionBindInterceptor
com.rop.CommonConstant
RopServlet入口 HttpServletRequest就没有取到所有的参数 method,appkey等等,小图可以接收到
在使用DefaultRopClient post数据时,如果参数是中文,在服务器接收方参数会变成乱码。经过查看源代码,发现DefaultRopClient是使用Spring的RestTemplate进行post数据,RestTemplate构造函数里默认的字符串编码是ISO-8859-1,所以会造成中文编码?请问这个问题Rop里面怎么解决?
由于2013年真太忙了,整天加班,所以ROP的维护工作就放下了,想不到使用ROP的人还挺多的,经常抱怨我怎么没有维护了,实在是对不住大家了。
由于ROP一直在我工作中都有用,所以这一年其实也改了挺多东西的,可以说在实际使用中还真是挺好用的,发现的BUG不多,新增的功能只是增量的东西,不影响原来的使用的。
2014年我会持续维护ROP,把这个平台打造得更强更好。谢谢大家,并祝大家马年马到成功,事事顺心!
stamen 2014-01-25
程序中用了这个 LinkedBlockingDeque队列
// 设置异步执行器
if (this.threadPoolExecutor == null) {
this.threadPoolExecutor = new ThreadPoolExecutor(200,Integer.MAX_VALUE, 5 * 60, TimeUnit.SECONDS,new LinkedBlockingDeque());
}
然而在Future<?> future = this.threadPoolExecutor.submit(runnable);用了这个,很明显,在多线程环境下,排队多了的情况,会有概率性,出现执行的并不是当前 request的线程。也有可能是 a客户端的request,的结果返回给了b客户端,虽然概率很低很低,但是会有可能发生,建议主机把 LinkedBlockingDeque提出来。
以前返回数据是这样
[{
id:123,
name:'zz',
uname:null
}]
现在是这样
[{
id:123,
name:'zz'
}]
如果参数是Number类型就没法强制转换为String,那么错误信息就没法准确定位了
public static String getSubErrorCode(SubErrorType subErrorType, Object... params) {
String subErrorCode = subErrorType.value();
if (params.length > 0) {
if (params.length == 1) {
subErrorCode = subErrorCode.replace(PARAM_1, (String) params[0]);
} else {
subErrorCode = subErrorCode.replace(PARAM_1, (String) params[0]);
if (params[1] != null) {
subErrorCode = subErrorCode.replace(PARAM_2, (String) params[1]);
}
}
}
return subErrorCode;
}
目前是修改为
public static String getSubErrorCode(SubErrorType subErrorType, Object... params) {
String subErrorCode = subErrorType.value();
if (params.length > 0) {
String replaceStr=params[0] instanceof Number?String.valueOf(params[0]):(String) params[0];
if (params.length == 1) {
subErrorCode = subErrorCode.replace(PARAM_1, replaceStr);
} else {
subErrorCode = subErrorCode.replace(PARAM_1, replaceStr);
if (params[1] != null) {
subErrorCode = subErrorCode.replace(PARAM_2, params[0] instanceof Number?String.valueOf(params[1]):(String) params[1]);
}
}
}
return subErrorCode;
}
Rop user SessionManager to manage the session, You can use standalone server just like redis or memcached and so on to manage the session status.Not recommend us servlet HttpSession to manage the session, cause it can't make you architecture be horizontal scale.
the following is example which using redis to manage the session data:
import com.google.common.collect.Maps;
import com.rop.session.Session;
import com.rop.session.SessionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.RedisTemplate;
import redis.clients.jedis.Jedis;
import java.util.Date;
import java.util.Map;
/**
@author : chenxh([email protected])
@Date: 13-10-16
*/
public class AppSessionManager implements SessionManager {
private RedisTemplate redisTemplate;
private static Map<String,Long> lastTimeMap = Maps.newHashMap();
@OverRide
public void addSession(String key, Session session) {
redisTemplate.opsForValue().set(key,session);
redisTemplate.expireAt(key, getSessionExpireDate());
lastTimeMap.put(key,System.currentTimeMillis());
}
@OverRide
public Session getSession(String key) {
Session session = (Session) redisTemplate.opsForValue().get(key);
Long lastTime = lastTimeMap.get(key);
//5分钟后重新设置过期时间
if(lastTime!=null && System.currentTimeMillis()-lastTime>5_60_1000){
redisTemplate.expireAt(key, getSessionExpireDate());
lastTimeMap.put(key,System.currentTimeMillis());
}
return session;
}
@OverRide
public void removeSession(String key) {
redisTemplate.delete(key);
lastTimeMap.remove(key);
}
@Autowired
public void setRedisTemplate(RedisTemplate redisTemplate) {
this.redisTemplate = redisTemplate;
}
/**
/**
报错信息如上,该如何解决
Hi,
We are creating a tool that can detect bugs that related to the use of XML file. Our tool found two potential bugs in your fullRopConfig.xml file. There are two child nodes of , which are and . There are no field named as "securityManager" and "sessionChecker" or their setter methods in the java class of this bean. And also, no super class of this java class, which declared these two. In this case, can you have a property named as those in your corresponding xml file? We are very unsure about this bug. Could you please give some explanation on how do you construct this bean to help us improve our tool?
Thanks you very much.
Very respectful,
Hi,
We are creating a tool that can detect bugs that related to the use of XML file. Our tool found two potential bugs in your fullRopConfig.xml file. There are two child nodes of , which are and . There are no field named as "securityManager" and "sessionChecker" or their setter methods in the java class of this bean. And also, no super class of this java class, which declared these two. In this case, can you have a property named as those in your corresponding xml file? We are very unsure about this bug. Could you please give some explanation on how do you construct this bean to help us improve our tool?
Thanks you very much.
Very respectful,
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.