[
https://issues.apache.org/jira/browse/SCB-74?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16630404#comment-16630404
]
ASF GitHub Bot commented on SCB-74:
-----------------------------------
wujimin closed pull request #925: [SCB-74] POJO static method is export as an
operation
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/925
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java
b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java
index 37e5df892..db9c1fcc4 100644
---
a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java
+++
b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/ConsumerMain.java
@@ -27,6 +27,7 @@
import org.apache.servicecomb.it.testcase.TestDefaultJsonValueJaxrsSchema;
import org.apache.servicecomb.it.testcase.TestDefaultValue;
import org.apache.servicecomb.it.testcase.TestIgnoreMethod;
+import org.apache.servicecomb.it.testcase.TestIgnoreStaticMethod;
import org.apache.servicecomb.it.testcase.TestParamCodec;
import org.apache.servicecomb.it.testcase.TestParamCodecEdge;
import org.apache.servicecomb.it.testcase.TestRestServerConfig;
@@ -65,7 +66,7 @@ protected static void run() throws Throwable {
// if not ready, will start a new instance and wait for ready
deploys.getEdge().ensureReady();
// deploys.getZuul().ensureReady(zuul);
-
+ ITJUnitUtils.run(TestIgnoreStaticMethod.class);
ITJUnitUtils.run(TestIgnoreMethod.class);
ITJUnitUtils.run(TestApiParam.class);
diff --git
a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/schema/IgnoreStaticMethodJaxrsSchema.java
b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/schema/IgnoreStaticMethodJaxrsSchema.java
new file mode 100644
index 000000000..74ed1c6ba
--- /dev/null
+++
b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/schema/IgnoreStaticMethodJaxrsSchema.java
@@ -0,0 +1,33 @@
+package org.apache.servicecomb.it.schema;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
+
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+
+@RestSchema(schemaId = "ignoreStaticMethodJaxrsSchema")
+@Path("/ignoreStaticMethodJaxrsSchema")
+public class IgnoreStaticMethodJaxrsSchema {
+
+ private IgnoreStaticMethodJaxrsSchema() {
+ }
+
+ private static IgnoreStaticMethodJaxrsSchema INSTANCE = new
IgnoreStaticMethodJaxrsSchema();
+
+ public static IgnoreStaticMethodJaxrsSchema getINSTANCE() {
+ return INSTANCE;
+ }
+
+ @GET
+ @Path("staticSub")
+ public static int staticSub(@QueryParam("num1") int num1,
@QueryParam("num2") int num2) {
+ return num1 - num2;
+ }
+
+ @GET
+ @Path("add")
+ public int add(@QueryParam("num1") int num1, @QueryParam("num2") int num2) {
+ return num1 + num2;
+ }
+}
diff --git
a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/schema/IgnoreStaticMethodPojoSchema.java
b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/schema/IgnoreStaticMethodPojoSchema.java
new file mode 100644
index 000000000..f84b56fa5
--- /dev/null
+++
b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/schema/IgnoreStaticMethodPojoSchema.java
@@ -0,0 +1,27 @@
+package org.apache.servicecomb.it.schema;
+
+import org.apache.servicecomb.provider.pojo.RpcSchema;
+
+import io.swagger.annotations.SwaggerDefinition;
+
+@RpcSchema(schemaId = "ignoreStaticMethodPojoSchema")
+@SwaggerDefinition(basePath = "/ignoreStaticMethodPojoSchema")
+public class IgnoreStaticMethodPojoSchema {
+
+ private IgnoreStaticMethodPojoSchema() {
+ }
+
+ private static IgnoreStaticMethodPojoSchema INSTANCE = new
IgnoreStaticMethodPojoSchema();
+
+ public static IgnoreStaticMethodPojoSchema getINSTANCE() {
+ return INSTANCE;
+ }
+
+ public static int staticSub(int num1, int num2) {
+ return num1 - num2;
+ }
+
+ public int add(int num1, int num2) {
+ return num1 + num2;
+ }
+}
diff --git
a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/schema/IgnoreStaticMethodSpringmvcSchema.java
b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/schema/IgnoreStaticMethodSpringmvcSchema.java
new file mode 100644
index 000000000..5c46082a5
--- /dev/null
+++
b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/schema/IgnoreStaticMethodSpringmvcSchema.java
@@ -0,0 +1,29 @@
+package org.apache.servicecomb.it.schema;
+
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@RestSchema(schemaId = "ignoreStaticMethodSpringmvcSchema")
+@RequestMapping(path = "/ignoreStaticMethodSpringmvcSchema")
+public class IgnoreStaticMethodSpringmvcSchema {
+
+ private IgnoreStaticMethodSpringmvcSchema() {
+ }
+
+ private static IgnoreStaticMethodSpringmvcSchema INSTANCE = new
IgnoreStaticMethodSpringmvcSchema();
+
+ public static IgnoreStaticMethodSpringmvcSchema getINSTANCE() {
+ return INSTANCE;
+ }
+
+ @GetMapping("staticSub")
+ public static int staticSub(int num1, int num2) {
+ return num1 - num2;
+ }
+
+ @GetMapping("add")
+ public int add(int num1, int num2) {
+ return num1 + num2;
+ }
+}
diff --git
a/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestIgnoreStaticMethod.java
b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestIgnoreStaticMethod.java
new file mode 100644
index 000000000..a25f6cca4
--- /dev/null
+++
b/integration-tests/it-consumer/src/main/java/org/apache/servicecomb/it/testcase/TestIgnoreStaticMethod.java
@@ -0,0 +1,43 @@
+package org.apache.servicecomb.it.testcase;
+
+import org.apache.servicecomb.core.SCBEngine;
+import org.apache.servicecomb.core.definition.MicroserviceMeta;
+import org.apache.servicecomb.core.definition.OperationMeta;
+import org.apache.servicecomb.core.definition.SchemaMeta;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestIgnoreStaticMethod {
+ private MicroserviceMeta microserviceMeta =
SCBEngine.getInstance().getProducerMicroserviceMeta();
+
+ @Test
+ public void ignoreStaticMethod_pojo() {
+ SchemaMeta schemaMeta =
microserviceMeta.findSchemaMeta("ignoreStaticMethodPojoSchema");
+ OperationMeta add = schemaMeta.findOperation("add");
+ Assert.assertNotNull(add);
+
+ OperationMeta sub = schemaMeta.findOperation("staticSub");
+ Assert.assertNull(sub);
+ }
+
+
+ @Test
+ public void ignoreStaticMethod_Jaxrs() {
+ SchemaMeta schemaMeta =
microserviceMeta.findSchemaMeta("ignoreStaticMethodJaxrsSchema");
+ OperationMeta add = schemaMeta.findOperation("add");
+ Assert.assertNotNull(add);
+
+ OperationMeta sub = schemaMeta.findOperation("staticSub");
+ Assert.assertNull(sub);
+ }
+
+ @Test
+ public void ignoreStaticMethod_Springmvc() {
+ SchemaMeta schemaMeta =
microserviceMeta.findSchemaMeta("ignoreStaticMethodSpringmvcSchema");
+ OperationMeta add = schemaMeta.findOperation("add");
+ Assert.assertNotNull(add);
+
+ OperationMeta sub = schemaMeta.findOperation("staticSub");
+ Assert.assertNull(sub);
+ }
+}
diff --git
a/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/generator/core/SwaggerGenerator.java
b/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/generator/core/SwaggerGenerator.java
index aa472fd25..8dac32af8 100644
---
a/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/generator/core/SwaggerGenerator.java
+++
b/swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/generator/core/SwaggerGenerator.java
@@ -19,6 +19,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
@@ -222,6 +223,11 @@ protected boolean isSkipMethod(Method method) {
if (method.getDeclaringClass().getName().equals(Object.class.getName())) {
return true;
}
+ // skip static method
+ int modifiers = method.getModifiers();
+ if (Modifier.isStatic(modifiers)) {
+ return true;
+ }
ApiOperation apiOperation = method.getAnnotation(ApiOperation.class);
if (apiOperation != null && apiOperation.hidden()) {
@@ -239,7 +245,6 @@ protected void scanMethods() {
if (isSkipMethod(method)) {
continue;
}
-
OperationGenerator operationGenerator = new OperationGenerator(this,
method);
operationGenerator.setHttpMethod(httpMethod);
try {
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> POJO static method is export as an operation
> --------------------------------------------
>
> Key: SCB-74
> URL: https://issues.apache.org/jira/browse/SCB-74
> Project: Apache ServiceComb
> Issue Type: Bug
> Components: Java-Chassis
> Reporter: Bo Li
> Priority: Major
> Labels: newbie
>
> When using @rpcschema to expose a singleton POJO as schema interface, then
> call the public method of the class which the method belong to, exception
> occurs as follow:
> {code}
> Exception in thread "main" java.lang.NullPointerException
> at
> io.servicecomb.swagger.generator.core.utils.ClassUtils.getOrCreateClass(ClassUtils.java:135)
> at
> io.servicecomb.swagger.converter.model.ModelImplConverter.doConvert(ModelImplConverter.java:55)
> at
> io.servicecomb.swagger.converter.AbstractConverter.convert(AbstractConverter.java:42)
> at
> io.servicecomb.swagger.converter.ConverterMgr.findJavaType(ConverterMgr.java:188)
> at
> io.servicecomb.swagger.converter.ConverterMgr.findByRef(ConverterMgr.java:196)
> at
> io.servicecomb.swagger.converter.property.RefPropertyConverter.doConvert(RefPropertyConverter.java:30)
> at
> io.servicecomb.swagger.converter.AbstractConverter.convert(AbstractConverter.java:42)
> at
> io.servicecomb.swagger.converter.ConverterMgr.findJavaType(ConverterMgr.java:188)
> at
> io.servicecomb.swagger.generator.core.utils.ClassUtils.createInterface(ClassUtils.java:252)
> at
> io.servicecomb.swagger.generator.core.utils.ClassUtils.getOrCreateInterface(ClassUtils.java:237)
> at io.servicecomb.core.definition.SchemaMeta.(SchemaMeta.java:65)
> at
> io.servicecomb.core.definition.loader.SchemaLoader.registerSchema(SchemaLoader.java:92)
> at
> io.servicecomb.core.definition.schema.ConsumerSchemaFactory.createSchema(ConsumerSchemaFactory.java:132)
> at
> io.servicecomb.core.definition.schema.ConsumerSchemaFactory.createSchema(ConsumerSchemaFactory.java:33)
> at
> io.servicecomb.core.definition.schema.AbstractSchemaFactory.getOrCreateSchema(AbstractSchemaFactory.java:59)
> at
> io.servicecomb.core.definition.schema.ConsumerSchemaFactory.getOrCreateConsumerSchema(ConsumerSchemaFactory.java:122)
> at
> io.servicecomb.core.definition.schema.ConsumerSchemaFactory.getOrCreateMicroserviceMeta(ConsumerSchemaFactory.java:78)
> at
> io.servicecomb.core.provider.consumer.ReferenceConfig.(ReferenceConfig.java:35)
> at
> io.servicecomb.core.provider.consumer.ConsumerProviderManager.getReferenceConfig(ConsumerProviderManager.java:82)
> at
> io.servicecomb.core.provider.consumer.ReferenceConfigUtils.getForInvoke(ReferenceConfigUtils.java:42)
> at io.servicecomb.provider.pojo.Invoker.prepare(Invoker.java:59)
> at io.servicecomb.provider.pojo.Invoker.invoke(Invoker.java:81)
> at com.sun.proxy.$Proxy17.selectByPrimaryKey(Unknown Source)
> at com.ceewa.cloud.consumer.DubboxConsumer.testMycat(DubboxConsumer.java:49)
> at com.ceewa.cloud.consumer.DubboxConsumer.main(DubboxConsumer.java:38)
> {code}
> Problem is fixed after adding {code}@apioperation(value = "getInstance is not
> an endpoint", hidden = true){code} tag for method getInstance, is there any
> good suggestions for that question?
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)