Skip to content

Commit bae5602

Browse files
authored
Merge pull request #214 from Karm/tested-fixes-for-service-a-b-separation
Fixes service-a service-b separation, all servers tested
2 parents 376d514 + f81990b commit bae5602

33 files changed

+381
-441
lines changed

gencerts.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/sh
2+
3+
# Generates certificates for JWT_AUTH demo examples.
4+
5+
pushd src/main/resources/
6+
7+
openssl genrsa -out private.key 2048
8+
cat << EOF | openssl req -new -key private.key \
9+
-x509 -days 0 \
10+
-out publickey.cer
11+
--
12+
JWT
13+
JWT
14+
JWT
15+
JWT
16+
JWT
17+
JWT
18+
EOF
19+
20+
keytool -import -noprompt -alias theKeyId -keystore public.jks -file publickey.cer -storepass atbash
21+
22+
cat private.key | openssl pkcs8 -topk8 -nocrypt -out private.pem
23+
openssl rsa -in private.pem -outform PEM -pubout -out public.pem
24+
rm -rf private.key
25+
rm -rf publickey.cer
26+
mv public.jks ./files/liberty/public.jks.tpl
27+
mv private.pem ./files/privateKey.pem.tpl
28+
mv public.pem ./files/publicKey.pem.tpl
29+
30+
# As soon as we switch to VertX JWT https://github.com/eclipse/microprofile-starter/issues/206
31+
# This conversion won't be needed:
32+
# org.bouncycastle.asn1.pkcs.PrivateKeyInfo cannot be cast to org.bouncycastle.openssl.PEMKeyPair
33+
openssl rsa -in ./files/privateKey.pem.tpl -text -out ./files/privateKey.pem.tpl.long
34+
mv ./files/privateKey.pem.tpl.long ./files/privateKey.pem.tpl
35+
36+
# KumuluzEE needs pub key in config
37+
KEY=`cat ./files/publicKey.pem.tpl | grep -ve '^-' | tr -d '\n'`
38+
sed -i "s~[ ]*public-key:.*~ public-key: $KEY~g" ./files/kumuluzEE/service-b/config.yaml.tpl
39+
40+
popd

src/main/java/org/eclipse/microprofile/starter/addon/microprofile/servers/MicroprofileServersAddon.java

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,12 @@ public void adaptMavenModel(Model pomFile, JessieModel model, boolean mainProjec
150150
}
151151

152152
if (model.hasMainAndSecondaryProject()) {
153-
String artifactID = pomFile.getArtifactId();
154153
if (mainProject) {
155-
pomFile.setArtifactId(artifactID + "-" + JessieModel.MAIN_INDICATOR);
154+
pomFile.setArtifactId(model.getMaven().getArtifactId() + "-" + JessieModel.MAIN_INDICATOR);
156155
} else {
157-
pomFile.setArtifactId(artifactID + "-" + JessieModel.SECONDARY_INDICATOR);
156+
pomFile.setArtifactId(model.getMaven().getArtifactId() + "-" + JessieModel.SECONDARY_INDICATOR);
158157
}
159-
pomFile.getBuild().setFinalName(artifactID);
160158
}
161-
162159
}
163160

164161
private Profile findProfile(String profileName) {
@@ -186,6 +183,8 @@ public Set<String> alternativesNames(JessieModel model) {
186183
public void createFiles(JessieModel model) {
187184

188185
Set<String> alternatives = model.getParameter(JessieModel.Parameter.ALTERNATIVES);
186+
Set<String> bAlternatives = new HashSet<>(alternatives);
187+
bAlternatives.add(JessieModel.SECONDARY_INDICATOR);
189188
Map<String, String> variables = model.getVariables();
190189

191190
String serverName = model.getOptions().get("mp.server").getSingleValue();
@@ -194,8 +193,8 @@ public void createFiles(JessieModel model) {
194193
String artifactId = model.getMaven().getArtifactId();
195194
variables.put("jar_file", defineJarFileName(supportedServer, artifactId));
196195
variables.put("jar_parameters", defineJarParameters(supportedServer));
197-
variables.put("test_url", defineTestURL(supportedServer, artifactId));
198-
variables.put("secondary_url", defineSecondaryURL(supportedServer, artifactId));
196+
variables.put("port_service_a", supportedServer.getPortServiceA());
197+
variables.put("port_service_b", supportedServer.getPortServiceB());
199198
variables.put("artifact_id", artifactId);
200199

201200
String rootJava = getJavaApplicationRootPackage(model);
@@ -228,56 +227,49 @@ public void createFiles(JessieModel model) {
228227
processTemplateFile(faultDirectory, "ResilienceController.java", alternatives, variables);
229228
}
230229

231-
if (microprofileSpecs.contains(MicroprofileSpec.JWT_AUTH)) {
232-
String secureDirectory;
233-
234-
if (model.hasMainAndSecondaryProject()) {
235-
secureDirectory = model.getDirectory(false) + "/" + rootJava + "/secure";
236-
directoryCreator.createDirectory(secureDirectory);
237-
238-
processTemplateFile(secureDirectory, "ProtectedController.java", alternatives, variables);
239-
240-
}
241-
}
242-
243-
244230
if (microprofileSpecs.contains(MicroprofileSpec.REST_CLIENT)) {
245231
String clientMainDirectory = model.getDirectory(true) + "/" + rootJava + "/client";
246232
directoryCreator.createDirectory(clientMainDirectory);
247233

248234
String clientSecondaryDirectory = model.getDirectory(false) + "/" + rootJava + "/client";
249235
directoryCreator.createDirectory(clientSecondaryDirectory);
250236

251-
processTemplateFile(clientSecondaryDirectory, "ServiceController.java", alternatives, variables);
237+
processTemplateFile(clientSecondaryDirectory, "ServiceController.java", bAlternatives, variables);
252238
processTemplateFile(clientMainDirectory, "Service.java", alternatives, variables);
253239
processTemplateFile(clientMainDirectory, "ClientController.java", alternatives, variables);
254240
}
255241

256242
if (microprofileSpecs.contains(MicroprofileSpec.JWT_AUTH)) {
257-
String javaDirectory = model.getDirectory(true) + "/" + rootJava + "/secure";
243+
if (model.hasMainAndSecondaryProject()) {
244+
String bSecureDirectory = model.getDirectory(false) + "/" + rootJava + "/secure";
245+
directoryCreator.createDirectory(bSecureDirectory);
246+
processTemplateFile(bSecureDirectory, "ProtectedController.java", bAlternatives, variables);
247+
}
248+
249+
String aSecureDirectory = model.getDirectory(true) + "/" + rootJava + "/secure";
258250

259-
processTemplateFile(javaDirectory, "TestSecureController.java", alternatives, variables);
260-
processTemplateFile(javaDirectory, "MPJWTToken.java", alternatives, variables);
251+
processTemplateFile(aSecureDirectory, "TestSecureController.java", alternatives, variables);
252+
processTemplateFile(aSecureDirectory, "MPJWTToken.java", alternatives, variables);
261253

262254
String resourceDirectory = getResourceDirectory(model, true);
263255

264256
processTemplateFile(resourceDirectory, "privateKey.pem", alternatives, variables);
265-
266257
}
267258

268-
// TODO : Verify : This is for all specs?
259+
// With KumuluzEE, it properties are integrated within config.yaml
269260
if (supportedServer != SupportedServer.KUMULUZEE) {
270-
// With kumuluzEE, it properties are integrated within config.yaml
271261
String metaInfDirectory = getResourceDirectory(model, true) + "/META-INF";
272-
273262
directoryCreator.createDirectory(metaInfDirectory);
274263
processTemplateFile(metaInfDirectory, "microprofile-config.properties", alternatives, variables);
275264
}
276265

277-
// Demo index file to all endpoints
278-
String webDirectory = model.getDirectory(true) + "/" + MavenCreator.SRC_MAIN_WEBAPP;
279-
directoryCreator.createDirectory(webDirectory);
280-
processTemplateFile(webDirectory, "index.html", alternatives, variables);
266+
// Helidon should have it in src/main/resources/WEB
267+
if (supportedServer != SupportedServer.HELIDON) {
268+
// Demo index file to all endpoints
269+
String webDirectory = model.getDirectory(true) + "/" + MavenCreator.SRC_MAIN_WEBAPP;
270+
directoryCreator.createDirectory(webDirectory);
271+
processTemplateFile(webDirectory, "index.html", alternatives, variables);
272+
}
281273

282274
processTemplateFile(model.getDirectory(true), "readme.md", alternatives, variables);
283275
if (model.hasMainAndSecondaryProject()) {
@@ -293,13 +285,4 @@ private String defineJarFileName(SupportedServer supportedServer, String artifac
293285
private String defineJarParameters(SupportedServer supportedServer) {
294286
return supportedServer.getJarParameters();
295287
}
296-
297-
private String defineTestURL(SupportedServer supportedServer, String artifactId) {
298-
return String.format(supportedServer.getTestURL(), artifactId);
299-
}
300-
301-
private String defineSecondaryURL(SupportedServer supportedServer, String artifactId) {
302-
return String.format(supportedServer.getSecondaryURL(), artifactId);
303-
}
304-
305-
}
288+
}

src/main/java/org/eclipse/microprofile/starter/addon/microprofile/servers/model/SupportedServer.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,56 +34,56 @@ public enum SupportedServer {
3434
Collections.singletonList(MicroProfileVersion.MP12)
3535
, "%s-swarm.jar" //jarFileName
3636
, "-Dswarm.port.offset=100" //jarParameters
37-
, "http://localhost:8080" //testURL
38-
, "http://localhost:8180" //secondaryURL // This need to match with port value from defineJarParameters()
37+
, "8080" //portServiceA
38+
, "8180" //portServiceB
3939
)
4040
, THORNTAIL_V2("thorntail-v2", "Thorntail V2",
4141
Arrays.asList(MicroProfileVersion.MP12, MicroProfileVersion.MP13, MicroProfileVersion.MP21,
4242
MicroProfileVersion.MP22, MicroProfileVersion.MP30)
4343
, "%s-thorntail.jar" //jarFileName
4444
, "-Dswarm.port.offset=100" //jarParameters
45-
, "http://localhost:8080" //testURL
46-
, "http://localhost:8180" //secondaryURL // This need to match with port value from defineJarParameters()
45+
, "8080" //portServiceA
46+
, "8180" //portServiceB
4747
)
4848
, LIBERTY("liberty", "Open Liberty",
4949
Arrays.asList(MicroProfileVersion.MP12, MicroProfileVersion.MP13, MicroProfileVersion.MP14,
5050
MicroProfileVersion.MP20, MicroProfileVersion.MP21, MicroProfileVersion.MP22,
5151
MicroProfileVersion.MP30)
5252
, "%s.jar" //jarFileName
5353
, "" //jarParameters // Hard coded in server.xml since no way of overriding a default.
54-
, "http://localhost:8181/%s" //testURL
55-
, "http://localhost:8281/%s" //secondaryURL // This need to match with port value from server.xml
54+
, "8181" //portServiceA
55+
, "8281" //portServiceB
5656
)
5757
, KUMULUZEE("kumuluzEE", "KumuluzEE",
5858
Arrays.asList(MicroProfileVersion.MP12, MicroProfileVersion.MP13, MicroProfileVersion.MP14,
5959
MicroProfileVersion.MP20, MicroProfileVersion.MP21, MicroProfileVersion.MP22)
6060
, "%s.jar" //jarFileName
6161
, "" //jarParameters // Hard coded in config.xml since we needed a specific version for secondary app.
62-
, "http://localhost:8080" //testURL
63-
, "http://localhost:8180" //secondaryURL // This need to match with port value from secondary/config.yaml
62+
, "8080" //portServiceA
63+
, "8180" //portServiceB // This need to match with port value from secondary/config.yaml
6464
)
6565
, PAYARA_MICRO("payara-micro", "Payara Micro",
6666
Arrays.asList(MicroProfileVersion.MP12, MicroProfileVersion.MP13, MicroProfileVersion.MP14,
6767
MicroProfileVersion.MP20, MicroProfileVersion.MP21, MicroProfileVersion.MP22)
6868
, "%s-microbundle.jar" //jarFileName
6969
, "--port 8180" //jarParameters
70-
, "http://localhost:8080" //testURL
71-
, "http://localhost:8180" //secondaryURL // This need to match with port value from defineJarParameters()
70+
, "8080" //portServiceA
71+
, "8180" //portServiceB // This need to match with port value from defineJarParameters()
7272
)
7373
, TOMEE("tomee", "Apache TomEE 8.0.0-M3",
7474
Arrays.asList(MicroProfileVersion.MP12, MicroProfileVersion.MP13, MicroProfileVersion.MP14,
75-
MicroProfileVersion.MP20,MicroProfileVersion.MP21)
75+
MicroProfileVersion.MP20, MicroProfileVersion.MP21)
7676
, "%s-exec.jar" //jarFileName
7777
, "" //jarParameters // Done by TomeeServer.adaptMavenModel
78-
, "http://localhost:8080" // testURL
79-
, "http://localhost:8180" //secondaryURL // This need to match with Port value from TomeeServer.adjustPOM
78+
, "8080" // portServiceA
79+
, "8180" //portServiceB // This need to match with Port value from TomeeServer.adjustPOM
8080
)
8181
, HELIDON("helidon", "Helidon",
8282
Arrays.asList(MicroProfileVersion.MP12, MicroProfileVersion.MP22)
8383
, "%s.jar" //jarFileName
8484
, "" //jarParameters // Done by secondary/helidon/microprofile-config.properties
85-
, "http://localhost:8080" //testURL
86-
, "http://localhost:8180" //secondaryURL // This need to match Port vcalue from secondary/microprofile-config.proeprties
85+
, "8080" //portServiceA
86+
, "8180" //portServiceB // This need to match Port vcalue from secondary/microprofile-config.proeprties
8787
);
8888
// @formatter:on
8989

@@ -92,18 +92,18 @@ public enum SupportedServer {
9292
private List<MicroProfileVersion> mpVersions;
9393
private String jarFileName;
9494
private String jarParameters;
95-
private String testURL;
96-
private String secondaryURL;
95+
private String portServiceA;
96+
private String portServiceB;
9797

9898
SupportedServer(String code, String displayName, List<MicroProfileVersion> mpVersions, String jarFileName
99-
, String jarParameters, String testURL, String secondaryURL) {
99+
, String jarParameters, String portServiceA, String portServiceB) {
100100
this.code = code;
101101
this.displayName = displayName;
102102
this.mpVersions = mpVersions;
103103
this.jarFileName = jarFileName;
104104
this.jarParameters = jarParameters;
105-
this.testURL = testURL;
106-
this.secondaryURL = secondaryURL;
105+
this.portServiceA = portServiceA;
106+
this.portServiceB = portServiceB;
107107
}
108108

109109
public String getCode() {
@@ -126,12 +126,12 @@ public String getJarParameters() {
126126
return jarParameters;
127127
}
128128

129-
public String getTestURL() {
130-
return testURL;
129+
public String getPortServiceA() {
130+
return portServiceA;
131131
}
132132

133-
public String getSecondaryURL() {
134-
return secondaryURL;
133+
public String getPortServiceB() {
134+
return portServiceB;
135135
}
136136

137137
public static SupportedServer valueFor(String data) {

src/main/java/org/eclipse/microprofile/starter/addon/microprofile/servers/server/HelidonServer.java

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.apache.maven.model.Model;
2323
import org.eclipse.microprofile.starter.addon.microprofile.servers.AbstractMicroprofileAddon;
24+
import org.eclipse.microprofile.starter.addon.microprofile.servers.model.MicroprofileSpec;
2425
import org.eclipse.microprofile.starter.addon.microprofile.servers.model.SupportedServer;
2526
import org.eclipse.microprofile.starter.core.artifacts.CDICreator;
2627
import org.eclipse.microprofile.starter.core.artifacts.MavenCreator;
@@ -29,6 +30,8 @@
2930
import javax.annotation.PostConstruct;
3031
import javax.enterprise.context.ApplicationScoped;
3132
import javax.inject.Inject;
33+
import java.util.HashSet;
34+
import java.util.List;
3235
import java.util.Map;
3336
import java.util.Set;
3437

@@ -53,29 +56,54 @@ public void createFiles(JessieModel model) {
5356
Set<String> alternatives = model.getParameter(JessieModel.Parameter.ALTERNATIVES);
5457
Map<String, String> variables = model.getVariables();
5558

56-
// kumuluzEE is JAR based, so needs beans.xml within META-INF
59+
// Helidon's html files reside in resources/WEB; we can delete webapp dir.
60+
String webHtmlDir = model.getDirectory(true) + "/" + MavenCreator.SRC_MAIN_RESOURCES + "/" + "WEB";
61+
directoryCreator.createDirectory(webHtmlDir);
62+
processTemplateFile(webHtmlDir, "index.html", alternatives, variables);
63+
directoryCreator.removeDirectory(model.getDirectory(true) + "/" + MavenCreator.SRC_MAIN_WEBAPP);
64+
if (model.hasMainAndSecondaryProject()) {
65+
directoryCreator.removeDirectory(model.getDirectory(false) + "/" + MavenCreator.SRC_MAIN_WEBAPP);
66+
}
67+
68+
// Helidon is JAR based, so needs beans.xml within META-INF
5769
cdiCreator.createCDIFilesForJar(model, true);
70+
if (model.hasMainAndSecondaryProject()) {
71+
cdiCreator.createCDIFilesForJar(model, false);
72+
}
5873

5974
// Remove WEB-INF containing the beans.xml
6075
String webDirectory = model.getDirectory(true) + "/" + MavenCreator.SRC_MAIN_WEBAPP + "/WEB-INF";
6176
directoryCreator.removeDirectory(webDirectory);
6277

6378
String rootJava = MavenCreator.SRC_MAIN_JAVA + "/" + directoryCreator.createPathForGroupAndArtifact(model.getMaven());
64-
String viewDirectory = model.getDirectory(true) + "/" + rootJava;
6579

66-
String resourcesDirectory = model.getDirectory(true) + "/" + MavenCreator.SRC_MAIN_RESOURCES;
80+
String resourcesDirectory = model.getDirectory(true) + "/" + MavenCreator.SRC_MAIN_RESOURCES;
6781
directoryCreator.createDirectory(resourcesDirectory);
6882

69-
processTemplateFile(resourcesDirectory, "application.yaml", alternatives, variables);
7083
processTemplateFile(resourcesDirectory, "logging.properties", alternatives, variables);
71-
processTemplateFile(resourcesDirectory, "publicKey.pem", alternatives, variables);
84+
processTemplateFile(resourcesDirectory, "privateKey.pem", alternatives, variables);
7285

73-
String artifactId = variables.get("artifact");
86+
List<MicroprofileSpec> microprofileSpecs = model.getParameter(JessieModel.Parameter.MICROPROFILESPECS);
7487

75-
String restAppFile = thymeleafEngine.processFile("RestApplication.java", alternatives, variables);
76-
fileCreator.writeContents(viewDirectory, artifactId + "RestApplication.java", restAppFile);
88+
if (model.hasMainAndSecondaryProject()) {
89+
String viewDirectory = model.getDirectory(false) + "/" + rootJava;
90+
directoryCreator.createDirectory(viewDirectory);
91+
Set<String> tempAlternative = new HashSet<>(alternatives);
92+
tempAlternative.add(JessieModel.SECONDARY_INDICATOR);
93+
String javaFile = thymeleafEngine.processFile("RestApplication.java", tempAlternative, variables);
94+
fileCreator.writeContents(viewDirectory, variables.get("application") + "RestApplication.java", javaFile);
7795

96+
String bResourcesDir = model.getDirectory(false) + "/" + MavenCreator.SRC_MAIN_RESOURCES;
97+
String bResourcesMETAINFDir = bResourcesDir + "/META-INF";
98+
directoryCreator.createDirectory(bResourcesMETAINFDir);
7899

100+
if (microprofileSpecs.contains(MicroprofileSpec.JWT_AUTH)) {
101+
processTemplateFile(bResourcesDir, "publicKey.pem", alternatives, variables);
102+
}
103+
104+
String configFile = thymeleafEngine.processFile("microprofile-config.properties", tempAlternative, variables);
105+
fileCreator.writeContents(bResourcesMETAINFDir, "microprofile-config.properties", configFile);
106+
}
79107
}
80108

81109
@Override

0 commit comments

Comments
 (0)