Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java][Vertx] use reflection to instantiate non-generated class #7360

Merged
merged 1 commit into from
Jan 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@ public class {{classname}}Verticle extends AbstractVerticle {

{{#operations}}{{#operation}}{{#vendorExtensions}}final static String {{x-serviceid-varname}} = "{{x-serviceid}}";
{{/vendorExtensions}}{{/operation}}{{/operations}}
//TODO : create Implementation
{{classname}} service = new {{classname}}Impl();
final {{classname}} service;

public {{classname}}Verticle() {
try {
Class serviceImplClass = getClass().getClassLoader().loadClass("{{package}}.{{classname}}Impl");
service = ({{classname}})serviceImplClass.newInstance();
} catch (Exception e) {
logUnexpectedError("{{classname}}Verticle constructor", e);
throw new RuntimeException(e);
}
}

@Override
public void start() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.0-SNAPSHOT
2.3.1-SNAPSHOT
35 changes: 17 additions & 18 deletions samples/server/petstore/java-vertx/async/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<junit.version>4.12</junit.version>
<vertx.version>3.4.1</vertx.version>
<maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
<vertx-swagger-router.version>1.2.0</vertx-swagger-router.version>
<vertx-swagger-router.version>1.4.0</vertx-swagger-router.version>
<maven-shade-plugin.version>2.3</maven-shade-plugin.version>
<jackson-datatype-jsr310.version>2.7.4</jackson-datatype-jsr310.version>
</properties>
Expand All @@ -28,25 +28,24 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-unit</artifactId>
<version>${vertx.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.github.phiz71</groupId>
<artifactId>vertx-swagger-router</artifactId>
<version>${vertx-swagger-router.version}</version>
</dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-unit</artifactId>
<version>${vertx.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson-datatype-jsr310.version}</version>
</dependency>
<dependency>
<groupId>com.github.phiz71</groupId>
<artifactId>vertx-swagger-router</artifactId>
<version>${vertx-swagger-router.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson-datatype-jsr310.version}</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -88,4 +87,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,17 @@ public class PetApiVerticle extends AbstractVerticle {
final static String UPDATEPETWITHFORM_SERVICE_ID = "updatePetWithForm";
final static String UPLOADFILE_SERVICE_ID = "uploadFile";

//TODO : create Implementation
PetApi service = new PetApiImpl();
final PetApi service;

public PetApiVerticle() {
try {
Class serviceImplClass = getClass().getClassLoader().loadClass("io.swagger.server.api.verticle.PetApiImpl");
service = (PetApi)serviceImplClass.newInstance();
} catch (Exception e) {
logUnexpectedError("PetApiVerticle constructor", e);
throw new RuntimeException(e);
}
}

@Override
public void start() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,17 @@ public class StoreApiVerticle extends AbstractVerticle {
final static String GETORDERBYID_SERVICE_ID = "getOrderById";
final static String PLACEORDER_SERVICE_ID = "placeOrder";

//TODO : create Implementation
StoreApi service = new StoreApiImpl();
final StoreApi service;

public StoreApiVerticle() {
try {
Class serviceImplClass = getClass().getClassLoader().loadClass("io.swagger.server.api.verticle.StoreApiImpl");
service = (StoreApi)serviceImplClass.newInstance();
} catch (Exception e) {
logUnexpectedError("StoreApiVerticle constructor", e);
throw new RuntimeException(e);
}
}

@Override
public void start() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,17 @@ public class UserApiVerticle extends AbstractVerticle {
final static String LOGOUTUSER_SERVICE_ID = "logoutUser";
final static String UPDATEUSER_SERVICE_ID = "updateUser";

//TODO : create Implementation
UserApi service = new UserApiImpl();
final UserApi service;

public UserApiVerticle() {
try {
Class serviceImplClass = getClass().getClassLoader().loadClass("io.swagger.server.api.verticle.UserApiImpl");
service = (UserApi)serviceImplClass.newInstance();
} catch (Exception e) {
logUnexpectedError("UserApiVerticle constructor", e);
throw new RuntimeException(e);
}
}

@Override
public void start() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.0-SNAPSHOT
2.3.1-SNAPSHOT
35 changes: 17 additions & 18 deletions samples/server/petstore/java-vertx/rx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<junit.version>4.12</junit.version>
<vertx.version>3.4.1</vertx.version>
<maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
<vertx-swagger-router.version>1.2.0</vertx-swagger-router.version>
<vertx-swagger-router.version>1.4.0</vertx-swagger-router.version>
<maven-shade-plugin.version>2.3</maven-shade-plugin.version>
<jackson-datatype-jsr310.version>2.7.4</jackson-datatype-jsr310.version>
</properties>
Expand All @@ -28,25 +28,24 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-unit</artifactId>
<version>${vertx.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.github.phiz71</groupId>
<artifactId>vertx-swagger-router</artifactId>
<version>${vertx-swagger-router.version}</version>
</dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-unit</artifactId>
<version>${vertx.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson-datatype-jsr310.version}</version>
</dependency>
<dependency>
<groupId>com.github.phiz71</groupId>
<artifactId>vertx-swagger-router</artifactId>
<version>${vertx-swagger-router.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson-datatype-jsr310.version}</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -88,4 +87,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,17 @@ public class PetApiVerticle extends AbstractVerticle {
final static String UPDATEPETWITHFORM_SERVICE_ID = "updatePetWithForm";
final static String UPLOADFILE_SERVICE_ID = "uploadFile";

//TODO : create Implementation
PetApi service = new PetApiImpl();
final PetApi service;

public PetApiVerticle() {
try {
Class serviceImplClass = getClass().getClassLoader().loadClass("io.swagger.server.api.verticle.PetApiImpl");
service = (PetApi)serviceImplClass.newInstance();
} catch (Exception e) {
logUnexpectedError("PetApiVerticle constructor", e);
throw new RuntimeException(e);
}
}

@Override
public void start() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,17 @@ public class StoreApiVerticle extends AbstractVerticle {
final static String GETORDERBYID_SERVICE_ID = "getOrderById";
final static String PLACEORDER_SERVICE_ID = "placeOrder";

//TODO : create Implementation
StoreApi service = new StoreApiImpl();
final StoreApi service;

public StoreApiVerticle() {
try {
Class serviceImplClass = getClass().getClassLoader().loadClass("io.swagger.server.api.verticle.StoreApiImpl");
service = (StoreApi)serviceImplClass.newInstance();
} catch (Exception e) {
logUnexpectedError("StoreApiVerticle constructor", e);
throw new RuntimeException(e);
}
}

@Override
public void start() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,17 @@ public class UserApiVerticle extends AbstractVerticle {
final static String LOGOUTUSER_SERVICE_ID = "logoutUser";
final static String UPDATEUSER_SERVICE_ID = "updateUser";

//TODO : create Implementation
UserApi service = new UserApiImpl();
final UserApi service;

public UserApiVerticle() {
try {
Class serviceImplClass = getClass().getClassLoader().loadClass("io.swagger.server.api.verticle.UserApiImpl");
service = (UserApi)serviceImplClass.newInstance();
} catch (Exception e) {
logUnexpectedError("UserApiVerticle constructor", e);
throw new RuntimeException(e);
}
}

@Override
public void start() throws Exception {
Expand Down