Skip to content

Commit 247fbd4

Browse files
ccozzolinowing328
authored andcommitted
#7359 Fix - use reflection to instantiate non-generated class (#7360)
1 parent 65bda3e commit 247fbd4

File tree

11 files changed

+113
-52
lines changed

11 files changed

+113
-52
lines changed

modules/swagger-codegen/src/main/resources/JavaVertXServer/apiVerticle.mustache

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,17 @@ public class {{classname}}Verticle extends AbstractVerticle {
1919

2020
{{#operations}}{{#operation}}{{#vendorExtensions}}final static String {{x-serviceid-varname}} = "{{x-serviceid}}";
2121
{{/vendorExtensions}}{{/operation}}{{/operations}}
22-
//TODO : create Implementation
23-
{{classname}} service = new {{classname}}Impl();
22+
final {{classname}} service;
23+
24+
public {{classname}}Verticle() {
25+
try {
26+
Class serviceImplClass = getClass().getClassLoader().loadClass("{{package}}.{{classname}}Impl");
27+
service = ({{classname}})serviceImplClass.newInstance();
28+
} catch (Exception e) {
29+
logUnexpectedError("{{classname}}Verticle constructor", e);
30+
throw new RuntimeException(e);
31+
}
32+
}
2433

2534
@Override
2635
public void start() throws Exception {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.3.0-SNAPSHOT
1+
2.3.1-SNAPSHOT

samples/server/petstore/java-vertx/async/pom.xml

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<junit.version>4.12</junit.version>
1616
<vertx.version>3.4.1</vertx.version>
1717
<maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
18-
<vertx-swagger-router.version>1.2.0</vertx-swagger-router.version>
18+
<vertx-swagger-router.version>1.4.0</vertx-swagger-router.version>
1919
<maven-shade-plugin.version>2.3</maven-shade-plugin.version>
2020
<jackson-datatype-jsr310.version>2.7.4</jackson-datatype-jsr310.version>
2121
</properties>
@@ -28,25 +28,24 @@
2828
<scope>test</scope>
2929
</dependency>
3030

31-
<dependency>
32-
<groupId>io.vertx</groupId>
33-
<artifactId>vertx-unit</artifactId>
34-
<version>${vertx.version}</version>
35-
<scope>test</scope>
36-
</dependency>
37-
3831
<dependency>
39-
<groupId>com.github.phiz71</groupId>
40-
<artifactId>vertx-swagger-router</artifactId>
41-
<version>${vertx-swagger-router.version}</version>
42-
</dependency>
32+
<groupId>io.vertx</groupId>
33+
<artifactId>vertx-unit</artifactId>
34+
<version>${vertx.version}</version>
35+
<scope>test</scope>
36+
</dependency>
4337

44-
<dependency>
45-
<groupId>com.fasterxml.jackson.datatype</groupId>
46-
<artifactId>jackson-datatype-jsr310</artifactId>
47-
<version>${jackson-datatype-jsr310.version}</version>
48-
</dependency>
38+
<dependency>
39+
<groupId>com.github.phiz71</groupId>
40+
<artifactId>vertx-swagger-router</artifactId>
41+
<version>${vertx-swagger-router.version}</version>
42+
</dependency>
4943

44+
<dependency>
45+
<groupId>com.fasterxml.jackson.datatype</groupId>
46+
<artifactId>jackson-datatype-jsr310</artifactId>
47+
<version>${jackson-datatype-jsr310.version}</version>
48+
</dependency>
5049
</dependencies>
5150

5251
<build>
@@ -88,4 +87,4 @@
8887
</plugin>
8988
</plugins>
9089
</build>
91-
</project>
90+
</project>

samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/PetApiVerticle.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,17 @@ public class PetApiVerticle extends AbstractVerticle {
2828
final static String UPDATEPETWITHFORM_SERVICE_ID = "updatePetWithForm";
2929
final static String UPLOADFILE_SERVICE_ID = "uploadFile";
3030

31-
//TODO : create Implementation
32-
PetApi service = new PetApiImpl();
31+
final PetApi service;
32+
33+
public PetApiVerticle() {
34+
try {
35+
Class serviceImplClass = getClass().getClassLoader().loadClass("io.swagger.server.api.verticle.PetApiImpl");
36+
service = (PetApi)serviceImplClass.newInstance();
37+
} catch (Exception e) {
38+
logUnexpectedError("PetApiVerticle constructor", e);
39+
throw new RuntimeException(e);
40+
}
41+
}
3342

3443
@Override
3544
public void start() throws Exception {

samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/StoreApiVerticle.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,17 @@ public class StoreApiVerticle extends AbstractVerticle {
2222
final static String GETORDERBYID_SERVICE_ID = "getOrderById";
2323
final static String PLACEORDER_SERVICE_ID = "placeOrder";
2424

25-
//TODO : create Implementation
26-
StoreApi service = new StoreApiImpl();
25+
final StoreApi service;
26+
27+
public StoreApiVerticle() {
28+
try {
29+
Class serviceImplClass = getClass().getClassLoader().loadClass("io.swagger.server.api.verticle.StoreApiImpl");
30+
service = (StoreApi)serviceImplClass.newInstance();
31+
} catch (Exception e) {
32+
logUnexpectedError("StoreApiVerticle constructor", e);
33+
throw new RuntimeException(e);
34+
}
35+
}
2736

2837
@Override
2938
public void start() throws Exception {

samples/server/petstore/java-vertx/async/src/main/java/io/swagger/server/api/verticle/UserApiVerticle.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,17 @@ public class UserApiVerticle extends AbstractVerticle {
2626
final static String LOGOUTUSER_SERVICE_ID = "logoutUser";
2727
final static String UPDATEUSER_SERVICE_ID = "updateUser";
2828

29-
//TODO : create Implementation
30-
UserApi service = new UserApiImpl();
29+
final UserApi service;
30+
31+
public UserApiVerticle() {
32+
try {
33+
Class serviceImplClass = getClass().getClassLoader().loadClass("io.swagger.server.api.verticle.UserApiImpl");
34+
service = (UserApi)serviceImplClass.newInstance();
35+
} catch (Exception e) {
36+
logUnexpectedError("UserApiVerticle constructor", e);
37+
throw new RuntimeException(e);
38+
}
39+
}
3140

3241
@Override
3342
public void start() throws Exception {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.3.0-SNAPSHOT
1+
2.3.1-SNAPSHOT

samples/server/petstore/java-vertx/rx/pom.xml

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<junit.version>4.12</junit.version>
1616
<vertx.version>3.4.1</vertx.version>
1717
<maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
18-
<vertx-swagger-router.version>1.2.0</vertx-swagger-router.version>
18+
<vertx-swagger-router.version>1.4.0</vertx-swagger-router.version>
1919
<maven-shade-plugin.version>2.3</maven-shade-plugin.version>
2020
<jackson-datatype-jsr310.version>2.7.4</jackson-datatype-jsr310.version>
2121
</properties>
@@ -28,25 +28,24 @@
2828
<scope>test</scope>
2929
</dependency>
3030

31-
<dependency>
32-
<groupId>io.vertx</groupId>
33-
<artifactId>vertx-unit</artifactId>
34-
<version>${vertx.version}</version>
35-
<scope>test</scope>
36-
</dependency>
37-
3831
<dependency>
39-
<groupId>com.github.phiz71</groupId>
40-
<artifactId>vertx-swagger-router</artifactId>
41-
<version>${vertx-swagger-router.version}</version>
42-
</dependency>
32+
<groupId>io.vertx</groupId>
33+
<artifactId>vertx-unit</artifactId>
34+
<version>${vertx.version}</version>
35+
<scope>test</scope>
36+
</dependency>
4337

44-
<dependency>
45-
<groupId>com.fasterxml.jackson.datatype</groupId>
46-
<artifactId>jackson-datatype-jsr310</artifactId>
47-
<version>${jackson-datatype-jsr310.version}</version>
48-
</dependency>
38+
<dependency>
39+
<groupId>com.github.phiz71</groupId>
40+
<artifactId>vertx-swagger-router</artifactId>
41+
<version>${vertx-swagger-router.version}</version>
42+
</dependency>
4943

44+
<dependency>
45+
<groupId>com.fasterxml.jackson.datatype</groupId>
46+
<artifactId>jackson-datatype-jsr310</artifactId>
47+
<version>${jackson-datatype-jsr310.version}</version>
48+
</dependency>
5049
</dependencies>
5150

5251
<build>
@@ -88,4 +87,4 @@
8887
</plugin>
8988
</plugins>
9089
</build>
91-
</project>
90+
</project>

samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/PetApiVerticle.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,17 @@ public class PetApiVerticle extends AbstractVerticle {
2828
final static String UPDATEPETWITHFORM_SERVICE_ID = "updatePetWithForm";
2929
final static String UPLOADFILE_SERVICE_ID = "uploadFile";
3030

31-
//TODO : create Implementation
32-
PetApi service = new PetApiImpl();
31+
final PetApi service;
32+
33+
public PetApiVerticle() {
34+
try {
35+
Class serviceImplClass = getClass().getClassLoader().loadClass("io.swagger.server.api.verticle.PetApiImpl");
36+
service = (PetApi)serviceImplClass.newInstance();
37+
} catch (Exception e) {
38+
logUnexpectedError("PetApiVerticle constructor", e);
39+
throw new RuntimeException(e);
40+
}
41+
}
3342

3443
@Override
3544
public void start() throws Exception {

samples/server/petstore/java-vertx/rx/src/main/java/io/swagger/server/api/verticle/StoreApiVerticle.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,17 @@ public class StoreApiVerticle extends AbstractVerticle {
2222
final static String GETORDERBYID_SERVICE_ID = "getOrderById";
2323
final static String PLACEORDER_SERVICE_ID = "placeOrder";
2424

25-
//TODO : create Implementation
26-
StoreApi service = new StoreApiImpl();
25+
final StoreApi service;
26+
27+
public StoreApiVerticle() {
28+
try {
29+
Class serviceImplClass = getClass().getClassLoader().loadClass("io.swagger.server.api.verticle.StoreApiImpl");
30+
service = (StoreApi)serviceImplClass.newInstance();
31+
} catch (Exception e) {
32+
logUnexpectedError("StoreApiVerticle constructor", e);
33+
throw new RuntimeException(e);
34+
}
35+
}
2736

2837
@Override
2938
public void start() throws Exception {

0 commit comments

Comments
 (0)