Skip to content

Commit

Permalink
fix rpc bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ansjsun committed Aug 8, 2016
1 parent 78793f6 commit af6e2fa
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 18 deletions.
48 changes: 32 additions & 16 deletions src/main/java/org/nlpcn/jcoder/controller/ApiAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,20 @@ public void jocderRpcSdkmaven(HttpServletRequest req, HttpServletResponse rep) t
rep.setContentType("application/octet-stream");

String pom = "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n"
+ " <modelVersion>4.0.0</modelVersion>\n" + " <groupId>org.nlpcn.jcoder</groupId>\n" + " <artifactId>jcoder-rpc-client</artifactId>\n"
+ " <version>1.0</version>\n" + "\n" + "\n" + " <dependencies>\n" + "\n" + " <dependency>\n" + " <groupId>io.netty</groupId>\n"
+ " <artifactId>netty-all</artifactId>\n" + " <version>4.1.2.Final</version>\n" + " <scope>compile</scope>\n" + " </dependency>\n" + "\n"
+ " <dependency>\n" + " <groupId>com.dyuproject.protostuff</groupId>\n" + " <artifactId>protostuff-core</artifactId>\n" + " <version>1.0.10</version>\n"
+ " <scope>compile</scope>\n" + " </dependency>\n" + "\n" + " <dependency>\n" + " <groupId>com.dyuproject.protostuff</groupId>\n"
+ " <artifactId>protostuff-runtime</artifactId>\n" + " <version>1.0.10</version>\n" + " <scope>compile</scope>\n" + " </dependency>\n" + "\n"
+ " <dependency>\n" + " <groupId>org.objenesis</groupId>\n" + " <artifactId>objenesis</artifactId>\n" + " <version>2.4</version>\n"
+ " <scope>compile</scope>\n" + " </dependency>\n" + "\n" + " </dependencies>\n" + "</project>";
+ " <modelVersion>4.0.0</modelVersion>\n" + " <groupId>org.nlpcn.jcoder</groupId>\n"
+ " <artifactId>jcoder-rpc-client</artifactId>\n" + " <version>1.0</version>\n" + "\n" + "\n" + " <dependencies>\n" + "\n"
+ " <dependency>\n" + " <groupId>io.netty</groupId>\n" + " <artifactId>netty-all</artifactId>\n"
+ " <version>4.1.2.Final</version>\n" + " <scope>compile</scope>\n" + " </dependency>\n" + "\n"
+ " <dependency>\n" + " <groupId>io.protostuff</groupId>\n"
+ " <artifactId>protostuff-core</artifactId>\n" + " <version>1.4.4</version>\n"
+ " <scope>compile</scope>\n" + " </dependency>\n" + "\n" + " <dependency>\n"
+ " <groupId>io.protostuff</groupId>\n" + " <artifactId>protostuff-runtime</artifactId>\n"
+ " <version>1.4.4</version>\n" + " <scope>compile</scope>\n" + " </dependency>\n" + "\n"
+ " <dependency>\n" + " <groupId>org.objenesis</groupId>\n" + " <artifactId>objenesis</artifactId>\n"
+ " <version>2.4</version>\n" + " <scope>compile</scope>\n" + " </dependency>\n" + "\n"
+ " <dependency>\n" + " <groupId>org.jasypt</groupId>\n" + " <artifactId>jasypt</artifactId>\n"
+ " <version>1.9.2</version>\n" + " <scope>compile</scope>\n" + " </dependency>\n" + "\n"
+ " </dependencies>\n" + "</project>";

ServletOutputStream outputStream = rep.getOutputStream();

Expand Down Expand Up @@ -329,6 +335,7 @@ public void jocderRpcSdkmaven(HttpServletRequest req, HttpServletResponse rep) t

/**
* 编译class类到jar中
*
* @return
* @throws IOException
*/
Expand Down Expand Up @@ -394,6 +401,7 @@ private byte[] makeRpcClientJar() throws IOException {

/**
* 编译class类到jar中
*
* @return
* @throws IOException
*/
Expand Down Expand Up @@ -434,6 +442,7 @@ private byte[] toSHA1(byte[] bytes) {

/**
* 执行测试用户的api
*
* @param jsonTask
* @return
*/
Expand Down Expand Up @@ -506,14 +515,21 @@ public Object stopApi(@Param("json") String jsonTask) {

public static void main(String[] args) {
String pom = "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n"
+ " <modelVersion>4.0.0</modelVersion>\n" + " <groupId>org.nlpcn.jcoder</groupId>\n" + " <artifactId>jcoder-rpc-client</artifactId>\n"
+ " <version>1.0</version>\n" + "\n" + "\n" + " <dependencies>\n" + "\n" + " <dependency>\n" + " <groupId>io.netty</groupId>\n"
+ " <artifactId>netty-all</artifactId>\n" + " <version>4.1.2.Final</version>\n" + " <scope>compile</scope>\n" + " </dependency>\n" + "\n"
+ " <dependency>\n" + " <groupId>com.dyuproject.protostuff</groupId>\n" + " <artifactId>protostuff-core</artifactId>\n" + " <version>1.0.10</version>\n"
+ " <scope>compile</scope>\n" + " </dependency>\n" + "\n" + " <dependency>\n" + " <groupId>com.dyuproject.protostuff</groupId>\n"
+ " <artifactId>protostuff-runtime</artifactId>\n" + " <version>1.0.10</version>\n" + " <scope>compile</scope>\n" + " </dependency>\n" + "\n"
+ " <dependency>\n" + " <groupId>org.objenesis</groupId>\n" + " <artifactId>objenesis</artifactId>\n" + " <version>2.4</version>\n"
+ " <scope>compile</scope>\n" + " </dependency>\n" + "\n" + " </dependencies>\n" + "</project>";
+ " <modelVersion>4.0.0</modelVersion>\n" + " <groupId>org.nlpcn.jcoder</groupId>\n"
+ " <artifactId>jcoder-rpc-client</artifactId>\n" + " <version>1.0</version>\n" + "\n" + "\n" + " <dependencies>\n" + "\n"
+ " <dependency>\n" + " <groupId>io.netty</groupId>\n" + " <artifactId>netty-all</artifactId>\n"
+ " <version>4.1.2.Final</version>\n" + " <scope>compile</scope>\n" + " </dependency>\n" + "\n"
+ " <dependency>\n" + " <groupId>io.protostuff</groupId>\n"
+ " <artifactId>protostuff-core</artifactId>\n" + " <version>1.4.4</version>\n"
+ " <scope>compile</scope>\n" + " </dependency>\n" + "\n" + " <dependency>\n"
+ " <groupId>io.protostuff</groupId>\n" + " <artifactId>protostuff-runtime</artifactId>\n"
+ " <version>1.4.4</version>\n" + " <scope>compile</scope>\n" + " </dependency>\n" + "\n"
+ " <dependency>\n" + " <groupId>org.objenesis</groupId>\n" + " <artifactId>objenesis</artifactId>\n"
+ " <version>2.4</version>\n" + " <scope>compile</scope>\n" + " </dependency>\n" + "\n"
+ " <dependency>\n" + " <groupId>org.jasypt</groupId>\n" + " <artifactId>jasypt</artifactId>\n"
+ " <version>1.9.2</version>\n" + " <scope>compile</scope>\n" + " </dependency>\n" + "\n"
+ " </dependencies>\n" + "</project>";

System.out.println(pom);
}
}
16 changes: 15 additions & 1 deletion src/main/java/org/nlpcn/jcoder/util/JavaSource2RpcUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public class JavaSource2RpcUtil {
+ " this.__JCODER__timeout = timeout;\n" + " }\n" + "\n" + " private boolean __JCODER__syn = true;\n" + "\n" + " private long __JCODER__timeout = 60000L;\n" + "\n"
+ " public void set__JCODER__syn(boolean syn) {\n" + " this.__JCODER__syn = syn;\n" + " }\n" + "\n" + " public void set__JCODER__timeout(long timeout) {\n"
+ " this.__JCODER__timeout = timeout;\n" + " }\n";


public static void main(String[] args) {
System.out.println(METHOD_TEMPLATE);
}

public static String makeRpcSource(Task task) throws Exception {
if (task.codeInfo().getClassz() == null) {
Expand Down Expand Up @@ -140,8 +145,17 @@ private static String explainMethod(MethodDeclaration method) {
args = Joiner.on(" , ").join(parameters);
argsName = Joiner.on(" , ").join(parameters.stream().map(p -> p.getId()).collect(Collectors.toList()));
}

String returnType = method.getType().toString() ;


if("void".equals(returnType)){
methodCode = methodCode.replace("return ([RETURN]) ", "");
}

methodCode = methodCode.replace("[RETURN]", returnType) ;

return methodCode.replace("[RETURN]", method.getType().toString()).replace("[METHOD_NAME]", method.getName()).replace("[ARGS]", args).replace("[ARGS_NAME]", argsName);
return methodCode.replace("[METHOD_NAME]", method.getName()).replace("[ARGS]", args).replace("[ARGS_NAME]", argsName);

}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/jcoder.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.6_201608081436
version=1.7_201608081622

0 comments on commit af6e2fa

Please sign in to comment.