From 5adaf4fa48c5c56562e404be06e23aa151801f87 Mon Sep 17 00:00:00 2001 From: qiaoxibj Date: Mon, 18 Apr 2016 13:11:42 +0800 Subject: [PATCH 01/13] Create new Jersey project --- .../.gitignore | 7 ++ .../build.gradle | 44 +++++++ .../repository/0.0.1/compile-pom.xml | 39 ++++++ .../repository/0.0.1/provided-pom.xml | 46 +++++++ .../repository/0.0.1/runtime-pom.xml | 34 +++++ .../service/springboot/api/TechnologyAPI.java | 25 ++++ .../springboot/api/v1/ProviderEndpoint.java | 117 ++++++++++++++++++ .../src/main/webapp/.gitignore | 1 + .../src/main/webapp/META-INF/.gitignore | 1 + .../main/webapp/WEB-INF/classes/.gitignore | 1 + .../webapp/WEB-INF/classes/description.html | 25 ++++ .../web/LibertyHelloController.java | 29 +++++ .../web/SpringBootLibertyApplication.java | 31 +++++ .../springboot/web/HelloControllerTest.java | 36 ++++++ .../springboot/api/v1/it/EndpointTest.java | 87 +++++++++++++ .../springboot/api/v1/it/TestApplication.java | 90 ++++++++++++++ 16 files changed, 613 insertions(+) create mode 100644 starter-microservice-springboot-jersey/.gitignore create mode 100644 starter-microservice-springboot-jersey/build.gradle create mode 100644 starter-microservice-springboot-jersey/repository/0.0.1/compile-pom.xml create mode 100644 starter-microservice-springboot-jersey/repository/0.0.1/provided-pom.xml create mode 100644 starter-microservice-springboot-jersey/repository/0.0.1/runtime-pom.xml create mode 100644 starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/api/TechnologyAPI.java create mode 100644 starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/api/v1/ProviderEndpoint.java create mode 100644 starter-microservice-springboot-jersey/src/main/webapp/.gitignore create mode 100644 starter-microservice-springboot-jersey/src/main/webapp/META-INF/.gitignore create mode 100644 starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/.gitignore create mode 100644 starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/description.html create mode 100644 starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/web/LibertyHelloController.java create mode 100644 starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/web/SpringBootLibertyApplication.java create mode 100644 starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/web/HelloControllerTest.java create mode 100644 starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/EndpointTest.java create mode 100644 starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/TestApplication.java diff --git a/starter-microservice-springboot-jersey/.gitignore b/starter-microservice-springboot-jersey/.gitignore new file mode 100644 index 0000000..f5d14ab --- /dev/null +++ b/starter-microservice-springboot-jersey/.gitignore @@ -0,0 +1,7 @@ +/target +/pom.xml +/build +/.settings +/.classpath +/.project +/bin diff --git a/starter-microservice-springboot-jersey/build.gradle b/starter-microservice-springboot-jersey/build.gradle new file mode 100644 index 0000000..b7c15f8 --- /dev/null +++ b/starter-microservice-springboot-jersey/build.gradle @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +apply from: '../common-java.gradle' +apply from: '../common-war.gradle' + +import com.ibm.liberty.starter.gradle.MavenTask +import com.ibm.liberty.starter.gradle.FvtTask + +dependencies { + providedCompile group:'javax.ws.rs', name:'javax.ws.rs-api', version: '2.0' + providedCompile group:'javax.json', name:'javax.json-api', version:'1.0' +} + +buildutils { + contextRoot = '/springbootweb' +} + +task installAllPOMs(type: MavenTask) { + id 'springbootweb' + hasProvided true + hasRuntime true + hasCompile true +} + +task fvt(type: FvtTask) { + id 'starter-microservice-springboot-web' + finalizedBy libertyStop +} + +apply from: '../tech-type-task-graph.gradle' diff --git a/starter-microservice-springboot-jersey/repository/0.0.1/compile-pom.xml b/starter-microservice-springboot-jersey/repository/0.0.1/compile-pom.xml new file mode 100644 index 0000000..34e89d8 --- /dev/null +++ b/starter-microservice-springboot-jersey/repository/0.0.1/compile-pom.xml @@ -0,0 +1,39 @@ + + 4.0.0 + + net.wasdev.wlp.starters.springboot + compile-pom + 0.0.1 + + compile-pom + + + + The Apache Software License, Version 2.0 + https://raw.github.com/WASdev/tool.artisan.core/master/LICENSE + repo + + + + + scm:git:git@github.com:WASdev/tool.artisan.core.git + scm:git@github.com:WASdev/tool.artisan.core.git + git@github.com:WASdev/tool.artisan.core.git + + + + + org.springframework.boot + spring-boot-starter-web + 1.3.0.RELEASE + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + + \ No newline at end of file diff --git a/starter-microservice-springboot-jersey/repository/0.0.1/provided-pom.xml b/starter-microservice-springboot-jersey/repository/0.0.1/provided-pom.xml new file mode 100644 index 0000000..ea88f27 --- /dev/null +++ b/starter-microservice-springboot-jersey/repository/0.0.1/provided-pom.xml @@ -0,0 +1,46 @@ + + 4.0.0 + + net.wasdev.wlp.starters.springboot + provided-pom + 0.0.1 + + provided-pom + + + + The Apache Software License, Version 2.0 + https://raw.github.com/WASdev/tool.artisan.core/master/LICENSE + repo + + + + + scm:git:git@github.com:WASdev/tool.artisan.core.git + scm:git@github.com:WASdev/tool.artisan.core.git + git@github.com:WASdev/tool.artisan.core.git + + + + + ibm-maven-repo + ibm-maven-repo + https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/maven/repository/ + + + + + + javax.servlet + javax.servlet-api + 3.1.0 + + + com.ibm.websphere.appserver.api + com.ibm.websphere.appserver.api.servlet + 1.0.10 + + + + \ No newline at end of file diff --git a/starter-microservice-springboot-jersey/repository/0.0.1/runtime-pom.xml b/starter-microservice-springboot-jersey/repository/0.0.1/runtime-pom.xml new file mode 100644 index 0000000..52a1d99 --- /dev/null +++ b/starter-microservice-springboot-jersey/repository/0.0.1/runtime-pom.xml @@ -0,0 +1,34 @@ + + 4.0.0 + + net.wasdev.wlp.starters.springboot + runtime-pom + 0.0.1 + + runtime-pom + + + + The Apache Software License, Version 2.0 + https://raw.github.com/WASdev/tool.artisan.core/master/LICENSE + repo + + + + + scm:git:git@github.com:WASdev/tool.artisan.core.git + scm:git@github.com:WASdev/tool.artisan.core.git + git@github.com:WASdev/tool.artisan.core.git + + + + + net.wasdev.wlp.starters.web + server-snippet + xml + 0.0.1 + + + + \ No newline at end of file diff --git a/starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/api/TechnologyAPI.java b/starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/api/TechnologyAPI.java new file mode 100644 index 0000000..082b598 --- /dev/null +++ b/starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/api/TechnologyAPI.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +package com.ibm.liberty.starter.service.springboot.api; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +@ApplicationPath("api") +public class TechnologyAPI extends Application { + + +} diff --git a/starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/api/v1/ProviderEndpoint.java b/starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/api/v1/ProviderEndpoint.java new file mode 100644 index 0000000..a994dcb --- /dev/null +++ b/starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/api/v1/ProviderEndpoint.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +package com.ibm.liberty.starter.service.springboot.api.v1; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +import com.ibm.liberty.starter.api.v1.model.provider.Dependency; +import com.ibm.liberty.starter.api.v1.model.provider.Dependency.Scope; +import com.ibm.liberty.starter.api.v1.model.provider.Location; +import com.ibm.liberty.starter.api.v1.model.provider.Provider; +import com.ibm.liberty.starter.api.v1.model.provider.ServerConfig; +import com.ibm.liberty.starter.api.v1.model.provider.Tag; + +@Path("v1/provider") +public class ProviderEndpoint { + + private static final String DEPENDENCY_URL = "http://localhost:9082/springboot/artifacts/net/wasdev/wlp/starters/springboot"; + + @GET + @Path("/") + @Produces(MediaType.APPLICATION_JSON) + public Provider details(@Context UriInfo info) { + Provider details = new Provider(); + String description = getStringResource("/description.html"); + details.setDescription(description); + + Location repoLocation = new Location(); + String url = info.getBaseUri().resolve("../artifacts").toString(); + repoLocation.setUrl(url); + details.setRepoUrl(repoLocation); + Dependency providedDependency = new Dependency(); + providedDependency.setScope(Scope.PROVIDED); + providedDependency.setGroupId("net.wasdev.wlp.starters.springboot"); + providedDependency.setArtifactId("provided-pom"); + providedDependency.setVersion("0.0.1"); + + Dependency runtimeDependency = new Dependency(); + runtimeDependency.setScope(Scope.RUNTIME); + runtimeDependency.setGroupId("net.wasdev.wlp.starters.springboot"); + runtimeDependency.setArtifactId("runtime-pom"); + runtimeDependency.setVersion("0.0.1"); + + Dependency compileDependency = new Dependency(); + compileDependency.setScope(Scope.COMPILE); + compileDependency.setGroupId("net.wasdev.wlp.starters.springboot"); + compileDependency.setArtifactId("compile-pom"); + compileDependency.setVersion("0.0.1"); + + Dependency[] dependencies = {providedDependency, runtimeDependency, compileDependency}; + details.setDependencies(dependencies); + return details; + } + + //read the description contained in the index.html file + private String getStringResource(String path) { + InputStream in = getClass().getResourceAsStream(path); + + StringBuilder index = new StringBuilder(); + char[] buffer = new char[1024]; + int read = 0; + try(InputStreamReader reader = new InputStreamReader(in)){ + while((read = reader.read(buffer)) != -1) { + index.append(buffer, 0, read); + } + } catch (IOException e) { + //just return what we've got + return index.toString(); + } + return index.toString(); + } + + @GET + @Path("samples") + @Produces(MediaType.APPLICATION_JSON) + public Response constructSample(@Context UriInfo info) { + StringBuilder json = new StringBuilder("{\n"); + String base = info.getBaseUri().resolve("../sample").toString(); + json.append("\"base\" : \"" + base + "\",\n"); + json.append(getStringResource("/locations.json")); + json.append("}\n"); + return Response.ok(json.toString()).build(); + } + + @GET + @Path("config") + @Produces(MediaType.APPLICATION_JSON) + public ServerConfig getServerConfig() throws Exception { + ServerConfig config = new ServerConfig(); + Tag[] tags = new Tag[]{new Tag("featureManager")}; + tags[0].setTags(new Tag[]{new Tag("feature", "websocket-1.1")}); + config.setTags(tags); + return config; + } +} \ No newline at end of file diff --git a/starter-microservice-springboot-jersey/src/main/webapp/.gitignore b/starter-microservice-springboot-jersey/src/main/webapp/.gitignore new file mode 100644 index 0000000..5d43caf --- /dev/null +++ b/starter-microservice-springboot-jersey/src/main/webapp/.gitignore @@ -0,0 +1 @@ +/artifacts diff --git a/starter-microservice-springboot-jersey/src/main/webapp/META-INF/.gitignore b/starter-microservice-springboot-jersey/src/main/webapp/META-INF/.gitignore new file mode 100644 index 0000000..f67faf7 --- /dev/null +++ b/starter-microservice-springboot-jersey/src/main/webapp/META-INF/.gitignore @@ -0,0 +1 @@ +/swagger.json diff --git a/starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/.gitignore b/starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/.gitignore new file mode 100644 index 0000000..5342fdc --- /dev/null +++ b/starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/.gitignore @@ -0,0 +1 @@ +/locations.json diff --git a/starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/description.html b/starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/description.html new file mode 100644 index 0000000..77dea01 --- /dev/null +++ b/starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/description.html @@ -0,0 +1,25 @@ + +
+

Spring Boot with Spring MVC

+

Inside the application project there is a application.springboot.web package + containing two classes:

+ +

Inside the wlpcfg project there is the it.springboot.web.HelloControllerTest that will test the Spring MVC endpoint to ensure it is working.

+
diff --git a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/web/LibertyHelloController.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/web/LibertyHelloController.java new file mode 100644 index 0000000..aff3e2f --- /dev/null +++ b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/web/LibertyHelloController.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +package application.springboot.web; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class LibertyHelloController { + + @RequestMapping("/springbootweb") + public String hello() { + return "Hello from Spring Boot MVC running on Liberty!"; + } + +} \ No newline at end of file diff --git a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/web/SpringBootLibertyApplication.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/web/SpringBootLibertyApplication.java new file mode 100644 index 0000000..9d6ca91 --- /dev/null +++ b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/web/SpringBootLibertyApplication.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +package application.springboot.web; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration; +import org.springframework.boot.context.web.SpringBootServletInitializer; + +@SpringBootApplication(exclude = MessageSourceAutoConfiguration.class) +public class SpringBootLibertyApplication extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(SpringBootLibertyApplication.class); + } + +} \ No newline at end of file diff --git a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/web/HelloControllerTest.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/web/HelloControllerTest.java new file mode 100644 index 0000000..2b9f1b8 --- /dev/null +++ b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/web/HelloControllerTest.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +package it.springboot.web; + +import static org.junit.Assert.assertTrue; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Invocation; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Response; +import it.EndpointTest; + +import org.junit.Test; + +public class HelloControllerTest extends EndpointTest { + + + @Test + public void testDeployment() { + testEndpoint("/springbootweb", "Hello from Spring Boot MVC running on Liberty!"); + } +} \ No newline at end of file diff --git a/starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/EndpointTest.java b/starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/EndpointTest.java new file mode 100644 index 0000000..02f80bd --- /dev/null +++ b/starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/EndpointTest.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +package com.ibm.liberty.starter.service.springboot.api.v1.it; + +import static org.junit.Assert.assertTrue; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Invocation; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Response; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class EndpointTest { + + //use this to give the REST endpoint a chance to come up after the server has reported it's started + public void checkAvailability(String endpoint) { + String ep = getEndPoint(endpoint); + for(int x = 0; x < 3; x++) { + Response response = null; + try { + response = sendRequest(ep, "GET"); + if(response.getStatus() == 200) { + return; + } + } finally { + if(response != null) { + response.close(); + } + } + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + //just exit + } + } + } + + private String getEndPoint(String endpoint) { + String port = System.getProperty("liberty.test.port"); + String war = System.getProperty("war.name"); + return "http://localhost:" + port + "/" + war + endpoint; + } + + @SuppressWarnings("unchecked") + public T testEndpoint(String endpoint, Class entity) throws Exception { + String url = getEndPoint(endpoint); + System.out.println("Testing " + url); + Response response = null; + try { + response = sendRequest(url, "GET"); + int responseCode = response.getStatus(); + assertTrue("Incorrect response code for " + url + ": " + responseCode, + responseCode == 200); + String json = response.readEntity(String.class); + ObjectMapper mapper = new ObjectMapper(); + return (T) mapper.readValue(json, entity); + } finally { + if(response != null) { + response.close(); + } + } + } + + public Response sendRequest(String url, String requestType) { + Client client = ClientBuilder.newClient(); + System.out.println("Testing " + url); + WebTarget target = client.target(url); + Invocation.Builder invoBuild = target.request(); + Response response = invoBuild.build(requestType).invoke(); + return response; + } +} diff --git a/starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/TestApplication.java b/starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/TestApplication.java new file mode 100644 index 0000000..8a8e3ce --- /dev/null +++ b/starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/TestApplication.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +package com.ibm.liberty.starter.service.springboot.api.v1.it; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +import com.ibm.liberty.starter.api.v1.model.provider.Dependency; +import com.ibm.liberty.starter.api.v1.model.provider.Provider; +import com.ibm.liberty.starter.api.v1.model.provider.Sample; +import com.ibm.liberty.starter.api.v1.model.provider.ServerConfig; + +/** + * Test the deployed service responds as expected + * + */ +public class TestApplication extends EndpointTest { + + @Before + public void checkSetup() { + checkAvailability("/api/v1/provider/"); + } + + @Test + public void testProvider() throws Exception { + Provider provider = testEndpoint("/api/v1/provider/", Provider.class); + assertNotNull("No response from API for provider", provider); + assertTrue("Description was not found.", provider.getDescription().contains("

Spring Boot with Spring MVC

")); + Dependency[] dependencies = provider.getDependencies(); + boolean providedDependency = false; + boolean runtimeDependency = false; + boolean compileDependency = false; + for (Dependency dependency : dependencies) { + if (Dependency.Scope.PROVIDED.equals(dependency.getScope())) { + assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springboot".equals(dependency.getGroupId())); + assertTrue("artifactId incorrect.", "provided-pom".equals(dependency.getArtifactId())); + assertTrue("version incorrect.", "0.0.1".equals(dependency.getVersion())); + providedDependency = true; + } + if (Dependency.Scope.RUNTIME.equals(dependency.getScope())) { + assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springboot".equals(dependency.getGroupId())); + assertTrue("artifactId incorrect.", "runtime-pom".equals(dependency.getArtifactId())); + assertTrue("version incorrect.", "0.0.1".equals(dependency.getVersion())); + runtimeDependency = true; + } + if (Dependency.Scope.COMPILE.equals(dependency.getScope())) { + assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springboot".equals(dependency.getGroupId())); + assertTrue("artifactId incorrect.", "compile-pom".equals(dependency.getArtifactId())); + assertTrue("version incorrect.", "0.0.1".equals(dependency.getVersion())); + compileDependency = true; + } + } + assertTrue("Provided dependencies weren't specified.", providedDependency); + assertTrue("Runtime dependencies weren't specified.", runtimeDependency); + assertTrue("Compile dependencies weren't specified.", compileDependency); + } + + @Test + public void testConfig() throws Exception { + ServerConfig config = testEndpoint("/api/v1/provider/config", ServerConfig.class); + assertNotNull("No response from API for configuration", config); + String actual = config.getTags()[0].getTags()[0].getValue(); + String expected = "websocket-1.1"; + assertEquals("Incorrect feature specified", expected , actual); + } + + @Test + public void testSamples() throws Exception { + Sample sample = testEndpoint("/api/v1/provider/samples", Sample.class); + assertNotNull("No response from API for sample", sample); + assertNotNull("Expected locations", sample.getLocations()); + assertEquals("No files were expected for sample", 3, sample.getLocations().length); + } + +} From 1b0af18bb9d318f9fe2d2be4181868081e13f626 Mon Sep 17 00:00:00 2001 From: qiaoxibj Date: Mon, 18 Apr 2016 16:19:01 +0800 Subject: [PATCH 02/13] Update with Jersey code --- README.md | 9 +++ liberty-starter-application/build.gradle | 2 +- .../src/main/resources/services.json | 6 ++ .../servers/StarterServer/server.xml | 1 + settings.gradle | 2 +- .../build.gradle | 6 +- .../repository/0.0.1/compile-pom.xml | 2 +- .../{ => jersey}/api/TechnologyAPI.java | 2 +- .../{ => jersey}/api/v1/ProviderEndpoint.java | 2 +- .../webapp/WEB-INF/classes/description.html | 8 +-- .../springboot/jersey/Endpoint.java | 64 ++++++++++++++++++ .../springboot/jersey/JerseyConfig.java | 31 +++++++++ .../jersey/ObjectMapperContextResolver.java | 25 +++++++ .../springboot/jersey/ReverseEndpoint.java | 35 ++++++++++ .../SampleJerseyApplication.java} | 31 +++++---- .../springboot/jersey/Service.java | 32 +++++++++ .../web/LibertyHelloController.java | 29 -------- .../jersey/SampleJerseyApplicationTests.java | 66 +++++++++++++++++++ .../springboot/web/HelloControllerTest.java | 36 ---------- .../{ => jersey}/api/v1/it/EndpointTest.java | 2 +- .../api/v1/it/TestApplication.java | 2 +- 21 files changed, 301 insertions(+), 92 deletions(-) rename starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/{ => jersey}/api/TechnologyAPI.java (93%) rename starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/{ => jersey}/api/v1/ProviderEndpoint.java (98%) create mode 100644 starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Endpoint.java create mode 100644 starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/JerseyConfig.java create mode 100644 starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/ObjectMapperContextResolver.java create mode 100644 starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/ReverseEndpoint.java rename starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/{web/SpringBootLibertyApplication.java => jersey/SampleJerseyApplication.java} (50%) create mode 100644 starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Service.java delete mode 100644 starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/web/LibertyHelloController.java create mode 100644 starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/jersey/SampleJerseyApplicationTests.java delete mode 100644 starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/web/HelloControllerTest.java rename starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/{ => jersey}/api/v1/it/EndpointTest.java (97%) rename starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/{ => jersey}/api/v1/it/TestApplication.java (98%) diff --git a/README.md b/README.md index f4693f1..98699e8 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,15 @@ Inside the application project there is a application.springboot.web package con Inside the wlpcfg project there is the it.springboot.web.HelloControllerTest that will test the Spring MVC endpoint to ensure it is working. +## Spring Boot with Jersey +This provides you with a SpringBoot application that will run on WebSphere Liberty. + +Inside the application project there is a application.springboot.jersey package containing 6 classes: +* SampleJerseyApplication: The entry point for the SpringBoot application. +* Endpoint: A Jersey endpoint which you can access at /springbootjersey. + +Inside the wlpcfg project there is the it.springboot.jersey.SampleJerseyApplicationTests that will test the Jersey endpoint to ensure it is working. + ## Websockets This provides you with the websocket-1.1 feature. diff --git a/liberty-starter-application/build.gradle b/liberty-starter-application/build.gradle index 7fa228a..d996757 100644 --- a/liberty-starter-application/build.gradle +++ b/liberty-starter-application/build.gradle @@ -108,7 +108,7 @@ liberty { } clean.dependsOn(':liberty-starter-wlpcfg:cleanServer') -war.dependsOn(':liberty-filter-application:publishWar', ':starter-microservice-test:publishTestWar', ':starter-microservice-web:publishWar', ':starter-microservice-persistence:publishWar', ':starter-microservice-rest:publishWar', ':starter-microservice-websocket:publishWar', ':starter-microservice-springboot-web:publishWar', ':starter-microservice-watsonsdk:publishWar', 'compressSkeletonBuildImage', 'copySpecialFiles', 'createSwaggerJSON') +war.dependsOn(':liberty-filter-application:publishWar', ':starter-microservice-test:publishTestWar', ':starter-microservice-web:publishWar', ':starter-microservice-persistence:publishWar', ':starter-microservice-rest:publishWar', ':starter-microservice-websocket:publishWar', ':starter-microservice-springboot-web:publishWar', ':starter-microservice-springboot-jersey:publishWar', ':starter-microservice-watsonsdk:publishWar', 'compressSkeletonBuildImage', 'copySpecialFiles', 'createSwaggerJSON') installFeature.dependsOn('installLiberty') libertyStart.dependsOn('installFeature', 'addServerEnv', 'publishWar') fvt.dependsOn('libertyStart', 'testClasses') diff --git a/liberty-starter-application/src/main/resources/services.json b/liberty-starter-application/src/main/resources/services.json index c06aed3..30f8548 100644 --- a/liberty-starter-application/src/main/resources/services.json +++ b/liberty-starter-application/src/main/resources/services.json @@ -30,6 +30,12 @@ "description": "Spring Boot with Spring MVC", "endpoint" : "/springbootweb" }, + { + "id": "springbootjersey", + "name": "Spring Boot with Jersey", + "description": "Spring Boot with Jersey", + "endpoint" : "/springbootjersey" + }, { "id": "watsonsdk", "name": "Watson SDK", diff --git a/liberty-starter-wlpcfg/servers/StarterServer/server.xml b/liberty-starter-wlpcfg/servers/StarterServer/server.xml index bd3020d..6ce0f50 100644 --- a/liberty-starter-wlpcfg/servers/StarterServer/server.xml +++ b/liberty-starter-wlpcfg/servers/StarterServer/server.xml @@ -39,4 +39,5 @@ + \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 5af1dad..bbf1090 100644 --- a/settings.gradle +++ b/settings.gradle @@ -22,4 +22,4 @@ include 'services:webservice' */ rootProject.name = 'LibertyUserExperience' -include 'liberty-starter-wlpcfg', 'liberty-filter-application', 'liberty-starter-application', 'starter-microservice-test', 'starter-microservice-web', 'starter-microservice-persistence', 'starter-microservice-rest', 'starter-microservice-websocket', 'starter-microservice-watsonsdk', 'starter-microservice-springboot-web', 'liberty-starter-model', 'liberty-starter-common' +include 'liberty-starter-wlpcfg', 'liberty-filter-application', 'liberty-starter-application', 'starter-microservice-test', 'starter-microservice-web', 'starter-microservice-persistence', 'starter-microservice-rest', 'starter-microservice-websocket', 'starter-microservice-watsonsdk', 'starter-microservice-springboot-web', 'starter-microservice-springboot-jersey', 'liberty-starter-model', 'liberty-starter-common' diff --git a/starter-microservice-springboot-jersey/build.gradle b/starter-microservice-springboot-jersey/build.gradle index b7c15f8..7bc8c8d 100644 --- a/starter-microservice-springboot-jersey/build.gradle +++ b/starter-microservice-springboot-jersey/build.gradle @@ -26,18 +26,18 @@ dependencies { } buildutils { - contextRoot = '/springbootweb' + contextRoot = '/springbootjersey' } task installAllPOMs(type: MavenTask) { - id 'springbootweb' + id 'springbootjersey' hasProvided true hasRuntime true hasCompile true } task fvt(type: FvtTask) { - id 'starter-microservice-springboot-web' + id 'starter-microservice-springboot-jersey' finalizedBy libertyStop } diff --git a/starter-microservice-springboot-jersey/repository/0.0.1/compile-pom.xml b/starter-microservice-springboot-jersey/repository/0.0.1/compile-pom.xml index 34e89d8..5d8ef97 100644 --- a/starter-microservice-springboot-jersey/repository/0.0.1/compile-pom.xml +++ b/starter-microservice-springboot-jersey/repository/0.0.1/compile-pom.xml @@ -25,7 +25,7 @@ org.springframework.boot - spring-boot-starter-web + spring-boot-starter-jersey 1.3.0.RELEASE diff --git a/starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/api/TechnologyAPI.java b/starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/jersey/api/TechnologyAPI.java similarity index 93% rename from starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/api/TechnologyAPI.java rename to starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/jersey/api/TechnologyAPI.java index 082b598..b0d2a76 100644 --- a/starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/api/TechnologyAPI.java +++ b/starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/jersey/api/TechnologyAPI.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ -package com.ibm.liberty.starter.service.springboot.api; +package com.ibm.liberty.starter.service.springboot.jersey.api; import javax.ws.rs.ApplicationPath; import javax.ws.rs.core.Application; diff --git a/starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/api/v1/ProviderEndpoint.java b/starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/jersey/api/v1/ProviderEndpoint.java similarity index 98% rename from starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/api/v1/ProviderEndpoint.java rename to starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/jersey/api/v1/ProviderEndpoint.java index a994dcb..f7b8b72 100644 --- a/starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/api/v1/ProviderEndpoint.java +++ b/starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/jersey/api/v1/ProviderEndpoint.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ -package com.ibm.liberty.starter.service.springboot.api.v1; +package com.ibm.liberty.starter.service.springboot.jersey.api.v1; import java.io.IOException; import java.io.InputStream; diff --git a/starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/description.html b/starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/description.html index 77dea01..021bfa2 100644 --- a/starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/description.html +++ b/starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/description.html @@ -15,11 +15,11 @@ -->

Spring Boot with Spring MVC

-

Inside the application project there is a application.springboot.web package +

Inside the application project there is a application.springboot.jersey package containing two classes:

    -
  • SpringBootLibertyApplication: The entry point for the SpringBoot application.
  • -
  • LibertyHelloController: A Spring MVC endpoint which you can access at /springbootweb
  • +
  • SampleJerseyApplication: The entry point for the SpringBoot application.
  • +
  • Endpoint: A Spring Jersey endpoint which you can access at /springbootjersey
-

Inside the wlpcfg project there is the it.springboot.web.HelloControllerTest that will test the Spring MVC endpoint to ensure it is working.

+

Inside the wlpcfg project there is the it.springboot.jersey.SampleJerseyApplicationTests that will test the Spring Jersey endpoint to ensure it is working.

diff --git a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Endpoint.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Endpoint.java new file mode 100644 index 0000000..430f89f --- /dev/null +++ b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Endpoint.java @@ -0,0 +1,64 @@ +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package application.springboot.jersey; + + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.fasterxml.jackson.databind.ObjectMapper; + +@Component +@Path("/springbootjersey") +public class Endpoint { + + private final Service service; + private final ObjectMapper objectMapper; + + @Autowired + public Endpoint(Service service, ObjectMapper objectMapper) { + this.service = service; + this.objectMapper = objectMapper; + } + + @GET + public String message() { + return "Hello " + this.service.message(); + } + + private class SimpleClass { + @SuppressWarnings("unused") + public String foo = "bar"; + @SuppressWarnings("unused") + public String foo2 = "ba2r"; + } + + @GET + @Path("world") + @Produces(MediaType.APPLICATION_JSON) + public SimpleClass messageJson() { + SimpleClass simpleClass = new SimpleClass(); + simpleClass.foo2 = objectMapper.toString(); + return simpleClass; + } + +} diff --git a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/JerseyConfig.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/JerseyConfig.java new file mode 100644 index 0000000..1f541c7 --- /dev/null +++ b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/JerseyConfig.java @@ -0,0 +1,31 @@ +/* + * Copyright 2012-2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package application.springboot.jersey; + +import org.glassfish.jersey.server.ResourceConfig; +import org.springframework.stereotype.Component; + +@Component +public class JerseyConfig extends ResourceConfig { + + public JerseyConfig() { + register(Endpoint.class); + register(ReverseEndpoint.class); + register(ObjectMapperContextResolver.class); + } + +} diff --git a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/ObjectMapperContextResolver.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/ObjectMapperContextResolver.java new file mode 100644 index 0000000..94daf2b --- /dev/null +++ b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/ObjectMapperContextResolver.java @@ -0,0 +1,25 @@ +package application.springboot.jersey; + +import javax.ws.rs.ext.ContextResolver; +import javax.ws.rs.ext.Provider; + +import org.springframework.beans.factory.annotation.Autowired; + +import com.fasterxml.jackson.databind.ObjectMapper; + +@Provider +public class ObjectMapperContextResolver implements ContextResolver { + + private final ObjectMapper mapper; + + @Autowired + public ObjectMapperContextResolver(ObjectMapper objectMapper) { + this.mapper = objectMapper; + } + + @Override + public ObjectMapper getContext(Class type) { + System.out.println("********* " + mapper.toString()); + return mapper; + } +} diff --git a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/ReverseEndpoint.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/ReverseEndpoint.java new file mode 100644 index 0000000..8412efd --- /dev/null +++ b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/ReverseEndpoint.java @@ -0,0 +1,35 @@ +/* + * Copyright 2012-2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package application.springboot.jersey; + +import javax.validation.constraints.NotNull; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + +import org.springframework.stereotype.Component; + +@Component +@Path("/reverse") +public class ReverseEndpoint { + + @GET + public String reverse(@QueryParam("input") @NotNull String input) { + return new StringBuilder(input).reverse().toString(); + } + +} diff --git a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/web/SpringBootLibertyApplication.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/SampleJerseyApplication.java similarity index 50% rename from starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/web/SpringBootLibertyApplication.java rename to starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/SampleJerseyApplication.java index 9d6ca91..7e8aa34 100644 --- a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/web/SpringBootLibertyApplication.java +++ b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/SampleJerseyApplication.java @@ -1,31 +1,36 @@ -/******************************************************************************* - * Copyright (c) 2016 IBM Corp. +/* + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - *******************************************************************************/ -package application.springboot.web; + */ + +package application.springboot.jersey; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration; import org.springframework.boot.context.web.SpringBootServletInitializer; -@SpringBootApplication(exclude = MessageSourceAutoConfiguration.class) -public class SpringBootLibertyApplication extends SpringBootServletInitializer { +@SpringBootApplication +public class SampleJerseyApplication extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(SampleJerseyApplication.class); + } - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(SpringBootLibertyApplication.class); - } + public static void main(String[] args) { + new SampleJerseyApplication().configure( + new SpringApplicationBuilder(SampleJerseyApplication.class)).run(args); + } -} \ No newline at end of file +} diff --git a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Service.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Service.java new file mode 100644 index 0000000..9583c9d --- /dev/null +++ b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Service.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package application.springboot.jersey; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class Service { + + @Value("${message:World}") + private String msg; + + public String message() { + return this.msg; + } + +} diff --git a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/web/LibertyHelloController.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/web/LibertyHelloController.java deleted file mode 100644 index aff3e2f..0000000 --- a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/web/LibertyHelloController.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ -package application.springboot.web; - -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class LibertyHelloController { - - @RequestMapping("/springbootweb") - public String hello() { - return "Hello from Spring Boot MVC running on Liberty!"; - } - -} \ No newline at end of file diff --git a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/jersey/SampleJerseyApplicationTests.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/jersey/SampleJerseyApplicationTests.java new file mode 100644 index 0000000..e9e8f59 --- /dev/null +++ b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/jersey/SampleJerseyApplicationTests.java @@ -0,0 +1,66 @@ +/* + * Copyright 2012-2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package it.springboot.jersey; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.IntegrationTest; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.web.client.RestTemplate; + +import static org.junit.Assert.assertEquals; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = SampleJerseyApplication.class) +@IntegrationTest("server.port=0") +@WebAppConfiguration +public class SampleJerseyApplicationTests { + + @Value("${local.server.port}") + private int port; + + private RestTemplate restTemplate = new TestRestTemplate(); + + @Test + public void contextLoads() { + ResponseEntity entity = this.restTemplate.getForEntity( + "http://localhost:" + this.port + "/springbootjersey", String.class); + assertEquals(HttpStatus.OK, entity.getStatusCode()); + } + + @Test + public void reverse() { + ResponseEntity entity = this.restTemplate.getForEntity( + "http://localhost:" + this.port + "/reverse?input=olleh", String.class); + assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertEquals("hello", entity.getBody()); + } + + @Test + public void validation() { + ResponseEntity entity = this.restTemplate.getForEntity( + "http://localhost:" + this.port + "/reverse", String.class); + assertEquals(HttpStatus.BAD_REQUEST, entity.getStatusCode()); + } + +} diff --git a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/web/HelloControllerTest.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/web/HelloControllerTest.java deleted file mode 100644 index 2b9f1b8..0000000 --- a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/web/HelloControllerTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ -package it.springboot.web; - -import static org.junit.Assert.assertTrue; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.Response; -import it.EndpointTest; - -import org.junit.Test; - -public class HelloControllerTest extends EndpointTest { - - - @Test - public void testDeployment() { - testEndpoint("/springbootweb", "Hello from Spring Boot MVC running on Liberty!"); - } -} \ No newline at end of file diff --git a/starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/EndpointTest.java b/starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/jersey/api/v1/it/EndpointTest.java similarity index 97% rename from starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/EndpointTest.java rename to starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/jersey/api/v1/it/EndpointTest.java index 02f80bd..8bcc320 100644 --- a/starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/EndpointTest.java +++ b/starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/jersey/api/v1/it/EndpointTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ -package com.ibm.liberty.starter.service.springboot.api.v1.it; +package com.ibm.liberty.starter.service.springboot.jersey.api.v1.it; import static org.junit.Assert.assertTrue; diff --git a/starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/TestApplication.java b/starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/jersey/api/v1/it/TestApplication.java similarity index 98% rename from starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/TestApplication.java rename to starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/jersey/api/v1/it/TestApplication.java index 8a8e3ce..d275bc4 100644 --- a/starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/TestApplication.java +++ b/starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/jersey/api/v1/it/TestApplication.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. *******************************************************************************/ -package com.ibm.liberty.starter.service.springboot.api.v1.it; +package com.ibm.liberty.starter.service.springboot.jersey.api.v1.it; import static org.junit.Assert.*; From eb94ea8a2c9f6235502b1e5a7d2691a34ba95eab Mon Sep 17 00:00:00 2001 From: qiaoxibj Date: Mon, 25 Apr 2016 10:37:03 +0800 Subject: [PATCH 03/13] Update with Spring Boot Jersey sample code --- .../servers/StarterServer/server.xml | 2 +- .../repository/0.0.1/compile-pom.xml | 2 +- .../repository/0.0.1/provided-pom.xml | 2 +- .../repository/0.0.1/runtime-pom.xml | 2 +- .../jersey/api/v1/ProviderEndpoint.java | 8 +-- .../webapp/WEB-INF/classes/description.html | 7 ++- .../springboot/jersey/Endpoint.java | 19 +----- .../springboot/jersey/JerseyConfig.java | 7 ++- .../jersey/ObjectMapperContextResolver.java | 25 -------- .../springboot/jersey/ReverseEndpoint.java | 35 ----------- .../jersey/SampleJerseyApplicationTests.java | 59 +++++-------------- .../jersey/api/v1/it/TestApplication.java | 10 ++-- 12 files changed, 36 insertions(+), 142 deletions(-) delete mode 100644 starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/ObjectMapperContextResolver.java delete mode 100644 starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/ReverseEndpoint.java diff --git a/liberty-starter-wlpcfg/servers/StarterServer/server.xml b/liberty-starter-wlpcfg/servers/StarterServer/server.xml index 6ce0f50..f610447 100644 --- a/liberty-starter-wlpcfg/servers/StarterServer/server.xml +++ b/liberty-starter-wlpcfg/servers/StarterServer/server.xml @@ -39,5 +39,5 @@ - + \ No newline at end of file diff --git a/starter-microservice-springboot-jersey/repository/0.0.1/compile-pom.xml b/starter-microservice-springboot-jersey/repository/0.0.1/compile-pom.xml index 5d8ef97..d32de8f 100644 --- a/starter-microservice-springboot-jersey/repository/0.0.1/compile-pom.xml +++ b/starter-microservice-springboot-jersey/repository/0.0.1/compile-pom.xml @@ -2,7 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - net.wasdev.wlp.starters.springboot + net.wasdev.wlp.starters.springboot.jersey compile-pom 0.0.1 diff --git a/starter-microservice-springboot-jersey/repository/0.0.1/provided-pom.xml b/starter-microservice-springboot-jersey/repository/0.0.1/provided-pom.xml index ea88f27..e924198 100644 --- a/starter-microservice-springboot-jersey/repository/0.0.1/provided-pom.xml +++ b/starter-microservice-springboot-jersey/repository/0.0.1/provided-pom.xml @@ -2,7 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - net.wasdev.wlp.starters.springboot + net.wasdev.wlp.starters.springboot.jersey provided-pom 0.0.1 diff --git a/starter-microservice-springboot-jersey/repository/0.0.1/runtime-pom.xml b/starter-microservice-springboot-jersey/repository/0.0.1/runtime-pom.xml index 52a1d99..d6ab4a2 100644 --- a/starter-microservice-springboot-jersey/repository/0.0.1/runtime-pom.xml +++ b/starter-microservice-springboot-jersey/repository/0.0.1/runtime-pom.xml @@ -2,7 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - net.wasdev.wlp.starters.springboot + net.wasdev.wlp.starters.springboot.jersey runtime-pom 0.0.1 diff --git a/starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/jersey/api/v1/ProviderEndpoint.java b/starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/jersey/api/v1/ProviderEndpoint.java index f7b8b72..4b3f2ac 100644 --- a/starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/jersey/api/v1/ProviderEndpoint.java +++ b/starter-microservice-springboot-jersey/src/main/java/com/ibm/liberty/starter/service/springboot/jersey/api/v1/ProviderEndpoint.java @@ -37,7 +37,7 @@ @Path("v1/provider") public class ProviderEndpoint { - private static final String DEPENDENCY_URL = "http://localhost:9082/springboot/artifacts/net/wasdev/wlp/starters/springboot"; + private static final String DEPENDENCY_URL = "http://localhost:9082/springboot/artifacts/net/wasdev/wlp/starters/springboot/jersey"; @GET @Path("/") @@ -53,19 +53,19 @@ public Provider details(@Context UriInfo info) { details.setRepoUrl(repoLocation); Dependency providedDependency = new Dependency(); providedDependency.setScope(Scope.PROVIDED); - providedDependency.setGroupId("net.wasdev.wlp.starters.springboot"); + providedDependency.setGroupId("net.wasdev.wlp.starters.springboot.jersey"); providedDependency.setArtifactId("provided-pom"); providedDependency.setVersion("0.0.1"); Dependency runtimeDependency = new Dependency(); runtimeDependency.setScope(Scope.RUNTIME); - runtimeDependency.setGroupId("net.wasdev.wlp.starters.springboot"); + runtimeDependency.setGroupId("net.wasdev.wlp.starters.springboot.jersey"); runtimeDependency.setArtifactId("runtime-pom"); runtimeDependency.setVersion("0.0.1"); Dependency compileDependency = new Dependency(); compileDependency.setScope(Scope.COMPILE); - compileDependency.setGroupId("net.wasdev.wlp.starters.springboot"); + compileDependency.setGroupId("net.wasdev.wlp.starters.springboot.jersey"); compileDependency.setArtifactId("compile-pom"); compileDependency.setVersion("0.0.1"); diff --git a/starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/description.html b/starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/description.html index 021bfa2..6d5e4dc 100644 --- a/starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/description.html +++ b/starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/description.html @@ -14,12 +14,13 @@ limitations under the License. -->
-

Spring Boot with Spring MVC

+

Spring Boot with Jersey

Inside the application project there is a application.springboot.jersey package - containing two classes:

+ containing 6 classes:

    -
  • SampleJerseyApplication: The entry point for the SpringBoot application.
  • +
  • JerseyConfig: Configuration for Jersey
  • Endpoint: A Spring Jersey endpoint which you can access at /springbootjersey
  • +
  • Service: Service implements of Jersey

Inside the wlpcfg project there is the it.springboot.jersey.SampleJerseyApplicationTests that will test the Spring Jersey endpoint to ensure it is working.

diff --git a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Endpoint.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Endpoint.java index 430f89f..0fdec22 100644 --- a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Endpoint.java +++ b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Endpoint.java @@ -28,7 +28,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; @Component -@Path("/springbootjersey") +@Path("/") public class Endpoint { private final Service service; @@ -44,21 +44,4 @@ public Endpoint(Service service, ObjectMapper objectMapper) { public String message() { return "Hello " + this.service.message(); } - - private class SimpleClass { - @SuppressWarnings("unused") - public String foo = "bar"; - @SuppressWarnings("unused") - public String foo2 = "ba2r"; - } - - @GET - @Path("world") - @Produces(MediaType.APPLICATION_JSON) - public SimpleClass messageJson() { - SimpleClass simpleClass = new SimpleClass(); - simpleClass.foo2 = objectMapper.toString(); - return simpleClass; - } - } diff --git a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/JerseyConfig.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/JerseyConfig.java index 1f541c7..b52c976 100644 --- a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/JerseyConfig.java +++ b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/JerseyConfig.java @@ -16,16 +16,17 @@ package application.springboot.jersey; +import javax.ws.rs.ApplicationPath; + import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.servlet.ServletProperties; import org.springframework.stereotype.Component; @Component +@ApplicationPath("/springbootjersey/") public class JerseyConfig extends ResourceConfig { public JerseyConfig() { register(Endpoint.class); - register(ReverseEndpoint.class); - register(ObjectMapperContextResolver.class); } - } diff --git a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/ObjectMapperContextResolver.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/ObjectMapperContextResolver.java deleted file mode 100644 index 94daf2b..0000000 --- a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/ObjectMapperContextResolver.java +++ /dev/null @@ -1,25 +0,0 @@ -package application.springboot.jersey; - -import javax.ws.rs.ext.ContextResolver; -import javax.ws.rs.ext.Provider; - -import org.springframework.beans.factory.annotation.Autowired; - -import com.fasterxml.jackson.databind.ObjectMapper; - -@Provider -public class ObjectMapperContextResolver implements ContextResolver { - - private final ObjectMapper mapper; - - @Autowired - public ObjectMapperContextResolver(ObjectMapper objectMapper) { - this.mapper = objectMapper; - } - - @Override - public ObjectMapper getContext(Class type) { - System.out.println("********* " + mapper.toString()); - return mapper; - } -} diff --git a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/ReverseEndpoint.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/ReverseEndpoint.java deleted file mode 100644 index 8412efd..0000000 --- a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/ReverseEndpoint.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2012-2015 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package application.springboot.jersey; - -import javax.validation.constraints.NotNull; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.QueryParam; - -import org.springframework.stereotype.Component; - -@Component -@Path("/reverse") -public class ReverseEndpoint { - - @GET - public String reverse(@QueryParam("input") @NotNull String input) { - return new StringBuilder(input).reverse().toString(); - } - -} diff --git a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/jersey/SampleJerseyApplicationTests.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/jersey/SampleJerseyApplicationTests.java index e9e8f59..6ded3eb 100644 --- a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/jersey/SampleJerseyApplicationTests.java +++ b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/jersey/SampleJerseyApplicationTests.java @@ -16,51 +16,20 @@ package it.springboot.jersey; +import static org.junit.Assert.assertTrue; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Invocation; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Response; +import it.EndpointTest; import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.test.IntegrationTest; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.boot.test.TestRestTemplate; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.web.client.RestTemplate; - -import static org.junit.Assert.assertEquals; - -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = SampleJerseyApplication.class) -@IntegrationTest("server.port=0") -@WebAppConfiguration -public class SampleJerseyApplicationTests { - - @Value("${local.server.port}") - private int port; - - private RestTemplate restTemplate = new TestRestTemplate(); - - @Test - public void contextLoads() { - ResponseEntity entity = this.restTemplate.getForEntity( - "http://localhost:" + this.port + "/springbootjersey", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - } - - @Test - public void reverse() { - ResponseEntity entity = this.restTemplate.getForEntity( - "http://localhost:" + this.port + "/reverse?input=olleh", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertEquals("hello", entity.getBody()); - } - - @Test - public void validation() { - ResponseEntity entity = this.restTemplate.getForEntity( - "http://localhost:" + this.port + "/reverse", String.class); - assertEquals(HttpStatus.BAD_REQUEST, entity.getStatusCode()); - } + +public class SampleJerseyApplicationTests extends EndpointTest { + @Test + public void testJerseyApplication() { + testEndpoint("/springbootjersey", "Hello World"); + } } diff --git a/starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/jersey/api/v1/it/TestApplication.java b/starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/jersey/api/v1/it/TestApplication.java index d275bc4..0d80921 100644 --- a/starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/jersey/api/v1/it/TestApplication.java +++ b/starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/jersey/api/v1/it/TestApplication.java @@ -40,26 +40,26 @@ public void checkSetup() { public void testProvider() throws Exception { Provider provider = testEndpoint("/api/v1/provider/", Provider.class); assertNotNull("No response from API for provider", provider); - assertTrue("Description was not found.", provider.getDescription().contains("

Spring Boot with Spring MVC

")); + assertTrue("Description was not found.", provider.getDescription().contains("

Spring Boot with Jersey

")); Dependency[] dependencies = provider.getDependencies(); boolean providedDependency = false; boolean runtimeDependency = false; boolean compileDependency = false; for (Dependency dependency : dependencies) { if (Dependency.Scope.PROVIDED.equals(dependency.getScope())) { - assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springboot".equals(dependency.getGroupId())); + assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springboot.jersey".equals(dependency.getGroupId())); assertTrue("artifactId incorrect.", "provided-pom".equals(dependency.getArtifactId())); assertTrue("version incorrect.", "0.0.1".equals(dependency.getVersion())); providedDependency = true; } if (Dependency.Scope.RUNTIME.equals(dependency.getScope())) { - assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springboot".equals(dependency.getGroupId())); + assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springboot.jersey".equals(dependency.getGroupId())); assertTrue("artifactId incorrect.", "runtime-pom".equals(dependency.getArtifactId())); assertTrue("version incorrect.", "0.0.1".equals(dependency.getVersion())); runtimeDependency = true; } if (Dependency.Scope.COMPILE.equals(dependency.getScope())) { - assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springboot".equals(dependency.getGroupId())); + assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springboot.jersey".equals(dependency.getGroupId())); assertTrue("artifactId incorrect.", "compile-pom".equals(dependency.getArtifactId())); assertTrue("version incorrect.", "0.0.1".equals(dependency.getVersion())); compileDependency = true; @@ -84,7 +84,7 @@ public void testSamples() throws Exception { Sample sample = testEndpoint("/api/v1/provider/samples", Sample.class); assertNotNull("No response from API for sample", sample); assertNotNull("Expected locations", sample.getLocations()); - assertEquals("No files were expected for sample", 3, sample.getLocations().length); + assertEquals("No files were expected for sample", 5, sample.getLocations().length); } } From eed51464d5de37f49157580573bdf58a0ff4bd69 Mon Sep 17 00:00:00 2001 From: qiaoxibj Date: Tue, 10 May 2016 12:45:18 +0800 Subject: [PATCH 04/13] SpringBoot security --- README.md | 9 ++ liberty-starter-application/build.gradle | 2 +- .../src/main/resources/services.json | 6 + .../servers/StarterServer/server.xml | 3 +- settings.gradle | 2 +- .../.gitignore | 7 ++ .../build.gradle | 44 +++++++ .../repository/0.0.1/compile-pom.xml | 49 ++++++++ .../repository/0.0.1/provided-pom.xml | 46 +++++++ .../repository/0.0.1/runtime-pom.xml | 34 +++++ .../security/api/TechnologyAPI.java | 25 ++++ .../security/api/v1/ProviderEndpoint.java | 117 ++++++++++++++++++ .../resources/templates/security-hello.html | 13 ++ .../resources/templates/security-home.html | 12 ++ .../resources/templates/security-login.html | 20 +++ .../src/main/webapp/.gitignore | 1 + .../src/main/webapp/META-INF/.gitignore | 1 + .../main/webapp/WEB-INF/classes/.gitignore | 1 + .../webapp/WEB-INF/classes/description.html | 25 ++++ .../springboot/security/Application.java | 19 +++ .../springboot/security/MvcConfig.java | 19 +++ .../security/WebSecurityConfig.java | 34 +++++ .../security/HelloControllerTest.java | 36 ++++++ .../security/api/v1/it/EndpointTest.java | 87 +++++++++++++ .../security/api/v1/it/TestApplication.java | 90 ++++++++++++++ 25 files changed, 699 insertions(+), 3 deletions(-) create mode 100644 starter-microservice-springboot-security/.gitignore create mode 100644 starter-microservice-springboot-security/build.gradle create mode 100644 starter-microservice-springboot-security/repository/0.0.1/compile-pom.xml create mode 100644 starter-microservice-springboot-security/repository/0.0.1/provided-pom.xml create mode 100644 starter-microservice-springboot-security/repository/0.0.1/runtime-pom.xml create mode 100644 starter-microservice-springboot-security/src/main/java/com/ibm/liberty/starter/service/springboot/security/api/TechnologyAPI.java create mode 100644 starter-microservice-springboot-security/src/main/java/com/ibm/liberty/starter/service/springboot/security/api/v1/ProviderEndpoint.java create mode 100644 starter-microservice-springboot-security/src/main/resources/templates/security-hello.html create mode 100644 starter-microservice-springboot-security/src/main/resources/templates/security-home.html create mode 100644 starter-microservice-springboot-security/src/main/resources/templates/security-login.html create mode 100644 starter-microservice-springboot-security/src/main/webapp/.gitignore create mode 100644 starter-microservice-springboot-security/src/main/webapp/META-INF/.gitignore create mode 100644 starter-microservice-springboot-security/src/main/webapp/WEB-INF/classes/.gitignore create mode 100644 starter-microservice-springboot-security/src/main/webapp/WEB-INF/classes/description.html create mode 100644 starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/security/Application.java create mode 100644 starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/security/MvcConfig.java create mode 100644 starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/security/WebSecurityConfig.java create mode 100644 starter-microservice-springboot-security/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/security/HelloControllerTest.java create mode 100644 starter-microservice-springboot-security/src/test/java/com/ibm/liberty/starter/service/springboot/security/api/v1/it/EndpointTest.java create mode 100644 starter-microservice-springboot-security/src/test/java/com/ibm/liberty/starter/service/springboot/security/api/v1/it/TestApplication.java diff --git a/README.md b/README.md index 98699e8..6d4ce74 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,15 @@ Inside the application project there is a application.springboot.jersey package Inside the wlpcfg project there is the it.springboot.jersey.SampleJerseyApplicationTests that will test the Jersey endpoint to ensure it is working. +## Spring Boot with Security +This provides you with a SpringBoot application that will run on WebSphere Liberty. + +Inside the application project there is a application.springboot.jersey package containing 6 classes: +* SampleJerseyApplication: The entry point for the SpringBoot application. +* Endpoint: A Jersey endpoint which you can access at home.html. + +Inside the wlpcfg project there is the it.springboot.jersey.SampleJerseyApplicationTests that will test the Jersey endpoint to ensure it is working. + ## Websockets This provides you with the websocket-1.1 feature. diff --git a/liberty-starter-application/build.gradle b/liberty-starter-application/build.gradle index d996757..0846925 100644 --- a/liberty-starter-application/build.gradle +++ b/liberty-starter-application/build.gradle @@ -108,7 +108,7 @@ liberty { } clean.dependsOn(':liberty-starter-wlpcfg:cleanServer') -war.dependsOn(':liberty-filter-application:publishWar', ':starter-microservice-test:publishTestWar', ':starter-microservice-web:publishWar', ':starter-microservice-persistence:publishWar', ':starter-microservice-rest:publishWar', ':starter-microservice-websocket:publishWar', ':starter-microservice-springboot-web:publishWar', ':starter-microservice-springboot-jersey:publishWar', ':starter-microservice-watsonsdk:publishWar', 'compressSkeletonBuildImage', 'copySpecialFiles', 'createSwaggerJSON') +war.dependsOn(':liberty-filter-application:publishWar', ':starter-microservice-test:publishTestWar', ':starter-microservice-web:publishWar', ':starter-microservice-persistence:publishWar', ':starter-microservice-rest:publishWar', ':starter-microservice-websocket:publishWar', ':starter-microservice-springboot-web:publishWar', ':starter-microservice-springboot-jersey:publishWar', ':starter-microservice-springboot-security:publishWar', ':starter-microservice-watsonsdk:publishWar', 'compressSkeletonBuildImage', 'copySpecialFiles', 'createSwaggerJSON') installFeature.dependsOn('installLiberty') libertyStart.dependsOn('installFeature', 'addServerEnv', 'publishWar') fvt.dependsOn('libertyStart', 'testClasses') diff --git a/liberty-starter-application/src/main/resources/services.json b/liberty-starter-application/src/main/resources/services.json index 30f8548..144466d 100644 --- a/liberty-starter-application/src/main/resources/services.json +++ b/liberty-starter-application/src/main/resources/services.json @@ -35,6 +35,12 @@ "name": "Spring Boot with Jersey", "description": "Spring Boot with Jersey", "endpoint" : "/springbootjersey" + }, + { + "id": "springbootsecure", + "name": "Spring Boot with Security", + "description": "Spring Boot with Security", + "endpoint" : "/springbootsecurity" }, { "id": "watsonsdk", diff --git a/liberty-starter-wlpcfg/servers/StarterServer/server.xml b/liberty-starter-wlpcfg/servers/StarterServer/server.xml index f610447..bae7287 100644 --- a/liberty-starter-wlpcfg/servers/StarterServer/server.xml +++ b/liberty-starter-wlpcfg/servers/StarterServer/server.xml @@ -39,5 +39,6 @@ - + + \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index bbf1090..1c2ec54 100644 --- a/settings.gradle +++ b/settings.gradle @@ -22,4 +22,4 @@ include 'services:webservice' */ rootProject.name = 'LibertyUserExperience' -include 'liberty-starter-wlpcfg', 'liberty-filter-application', 'liberty-starter-application', 'starter-microservice-test', 'starter-microservice-web', 'starter-microservice-persistence', 'starter-microservice-rest', 'starter-microservice-websocket', 'starter-microservice-watsonsdk', 'starter-microservice-springboot-web', 'starter-microservice-springboot-jersey', 'liberty-starter-model', 'liberty-starter-common' +include 'liberty-starter-wlpcfg', 'liberty-filter-application', 'liberty-starter-application', 'starter-microservice-test', 'starter-microservice-web', 'starter-microservice-persistence', 'starter-microservice-rest', 'starter-microservice-websocket', 'starter-microservice-watsonsdk', 'starter-microservice-springboot-web', 'starter-microservice-springboot-jersey', 'starter-microservice-springboot-security', 'liberty-starter-model', 'liberty-starter-common' diff --git a/starter-microservice-springboot-security/.gitignore b/starter-microservice-springboot-security/.gitignore new file mode 100644 index 0000000..f5d14ab --- /dev/null +++ b/starter-microservice-springboot-security/.gitignore @@ -0,0 +1,7 @@ +/target +/pom.xml +/build +/.settings +/.classpath +/.project +/bin diff --git a/starter-microservice-springboot-security/build.gradle b/starter-microservice-springboot-security/build.gradle new file mode 100644 index 0000000..b6985a6 --- /dev/null +++ b/starter-microservice-springboot-security/build.gradle @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +apply from: '../common-java.gradle' +apply from: '../common-war.gradle' + +import com.ibm.liberty.starter.gradle.MavenTask +import com.ibm.liberty.starter.gradle.FvtTask + +dependencies { + providedCompile group:'javax.ws.rs', name:'javax.ws.rs-api', version: '2.0' + providedCompile group:'javax.json', name:'javax.json-api', version:'1.0' +} + +buildutils { + contextRoot = '/springbootsecurity' +} + +task installAllPOMs(type: MavenTask) { + id 'springbootsecure' + hasProvided true + hasRuntime true + hasCompile true +} + +task fvt(type: FvtTask) { + id 'starter-microservice-springboot-security' + finalizedBy libertyStop +} + +apply from: '../tech-type-task-graph.gradle' diff --git a/starter-microservice-springboot-security/repository/0.0.1/compile-pom.xml b/starter-microservice-springboot-security/repository/0.0.1/compile-pom.xml new file mode 100644 index 0000000..35cf2ca --- /dev/null +++ b/starter-microservice-springboot-security/repository/0.0.1/compile-pom.xml @@ -0,0 +1,49 @@ + + 4.0.0 + + net.wasdev.wlp.starters.springboot.secure + compile-pom + 0.0.1 + + compile-pom + + + + The Apache Software License, Version 2.0 + https://raw.github.com/WASdev/tool.artisan.core/master/LICENSE + repo + + + + + scm:git:git@github.com:WASdev/tool.artisan.core.git + scm:git@github.com:WASdev/tool.artisan.core.git + git@github.com:WASdev/tool.artisan.core.git + + + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.spring-webmvc + spring-webmvc + 4.2.5.RELEASE + + + org.springframework.boot + spring-boot-starter-security + 1.3.0.RELEASE + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + + + \ No newline at end of file diff --git a/starter-microservice-springboot-security/repository/0.0.1/provided-pom.xml b/starter-microservice-springboot-security/repository/0.0.1/provided-pom.xml new file mode 100644 index 0000000..570a483 --- /dev/null +++ b/starter-microservice-springboot-security/repository/0.0.1/provided-pom.xml @@ -0,0 +1,46 @@ + + 4.0.0 + + net.wasdev.wlp.starters.springboot.secure + provided-pom + 0.0.1 + + provided-pom + + + + The Apache Software License, Version 2.0 + https://raw.github.com/WASdev/tool.artisan.core/master/LICENSE + repo + + + + + scm:git:git@github.com:WASdev/tool.artisan.core.git + scm:git@github.com:WASdev/tool.artisan.core.git + git@github.com:WASdev/tool.artisan.core.git + + + + + ibm-maven-repo + ibm-maven-repo + https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/maven/repository/ + + + + + + javax.servlet + javax.servlet-api + 3.1.0 + + + com.ibm.websphere.appserver.api + com.ibm.websphere.appserver.api.servlet + 1.0.10 + + + + \ No newline at end of file diff --git a/starter-microservice-springboot-security/repository/0.0.1/runtime-pom.xml b/starter-microservice-springboot-security/repository/0.0.1/runtime-pom.xml new file mode 100644 index 0000000..f1b30fa --- /dev/null +++ b/starter-microservice-springboot-security/repository/0.0.1/runtime-pom.xml @@ -0,0 +1,34 @@ + + 4.0.0 + + net.wasdev.wlp.starters.springboot.secure + runtime-pom + 0.0.1 + + runtime-pom + + + + The Apache Software License, Version 2.0 + https://raw.github.com/WASdev/tool.artisan.core/master/LICENSE + repo + + + + + scm:git:git@github.com:WASdev/tool.artisan.core.git + scm:git@github.com:WASdev/tool.artisan.core.git + git@github.com:WASdev/tool.artisan.core.git + + + + + net.wasdev.wlp.starters.web + server-snippet + xml + 0.0.1 + + + + \ No newline at end of file diff --git a/starter-microservice-springboot-security/src/main/java/com/ibm/liberty/starter/service/springboot/security/api/TechnologyAPI.java b/starter-microservice-springboot-security/src/main/java/com/ibm/liberty/starter/service/springboot/security/api/TechnologyAPI.java new file mode 100644 index 0000000..c1d5af3 --- /dev/null +++ b/starter-microservice-springboot-security/src/main/java/com/ibm/liberty/starter/service/springboot/security/api/TechnologyAPI.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +package com.ibm.liberty.starter.service.springboot.security.api; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +@ApplicationPath("api") +public class TechnologyAPI extends Application { + + +} diff --git a/starter-microservice-springboot-security/src/main/java/com/ibm/liberty/starter/service/springboot/security/api/v1/ProviderEndpoint.java b/starter-microservice-springboot-security/src/main/java/com/ibm/liberty/starter/service/springboot/security/api/v1/ProviderEndpoint.java new file mode 100644 index 0000000..bc70c65 --- /dev/null +++ b/starter-microservice-springboot-security/src/main/java/com/ibm/liberty/starter/service/springboot/security/api/v1/ProviderEndpoint.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +package com.ibm.liberty.starter.service.springboot.security.api.v1; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +import com.ibm.liberty.starter.api.v1.model.provider.Dependency; +import com.ibm.liberty.starter.api.v1.model.provider.Dependency.Scope; +import com.ibm.liberty.starter.api.v1.model.provider.Location; +import com.ibm.liberty.starter.api.v1.model.provider.Provider; +import com.ibm.liberty.starter.api.v1.model.provider.ServerConfig; +import com.ibm.liberty.starter.api.v1.model.provider.Tag; + +@Path("v1/provider") +public class ProviderEndpoint { + + private static final String DEPENDENCY_URL = "http://localhost:9082/springboot/artifacts/net/wasdev/wlp/starters/springbootsecure"; + + @GET + @Path("/") + @Produces(MediaType.APPLICATION_JSON) + public Provider details(@Context UriInfo info) { + Provider details = new Provider(); + String description = getStringResource("/description.html"); + details.setDescription(description); + + Location repoLocation = new Location(); + String url = info.getBaseUri().resolve("../artifacts").toString(); + repoLocation.setUrl(url); + details.setRepoUrl(repoLocation); + Dependency providedDependency = new Dependency(); + providedDependency.setScope(Scope.PROVIDED); + providedDependency.setGroupId("net.wasdev.wlp.starters.springboot.secure"); + providedDependency.setArtifactId("provided-pom"); + providedDependency.setVersion("0.0.1"); + + Dependency runtimeDependency = new Dependency(); + runtimeDependency.setScope(Scope.RUNTIME); + runtimeDependency.setGroupId("net.wasdev.wlp.starters.springboot.secure"); + runtimeDependency.setArtifactId("runtime-pom"); + runtimeDependency.setVersion("0.0.1"); + + Dependency compileDependency = new Dependency(); + compileDependency.setScope(Scope.COMPILE); + compileDependency.setGroupId("net.wasdev.wlp.starters.springboot.secure"); + compileDependency.setArtifactId("compile-pom"); + compileDependency.setVersion("0.0.1"); + + Dependency[] dependencies = {providedDependency, runtimeDependency, compileDependency}; + details.setDependencies(dependencies); + return details; + } + + //read the description contained in the index.html file + private String getStringResource(String path) { + InputStream in = getClass().getResourceAsStream(path); + + StringBuilder index = new StringBuilder(); + char[] buffer = new char[1024]; + int read = 0; + try(InputStreamReader reader = new InputStreamReader(in)){ + while((read = reader.read(buffer)) != -1) { + index.append(buffer, 0, read); + } + } catch (IOException e) { + //just return what we've got + return index.toString(); + } + return index.toString(); + } + + @GET + @Path("samples") + @Produces(MediaType.APPLICATION_JSON) + public Response constructSample(@Context UriInfo info) { + StringBuilder json = new StringBuilder("{\n"); + String base = info.getBaseUri().resolve("../sample").toString(); + json.append("\"base\" : \"" + base + "\",\n"); + json.append(getStringResource("/locations.json")); + json.append("}\n"); + return Response.ok(json.toString()).build(); + } + + @GET + @Path("config") + @Produces(MediaType.APPLICATION_JSON) + public ServerConfig getServerConfig() throws Exception { + ServerConfig config = new ServerConfig(); + Tag[] tags = new Tag[]{new Tag("featureManager")}; + tags[0].setTags(new Tag[]{new Tag("feature", "websocket-1.1")}); + config.setTags(tags); + return config; + } +} \ No newline at end of file diff --git a/starter-microservice-springboot-security/src/main/resources/templates/security-hello.html b/starter-microservice-springboot-security/src/main/resources/templates/security-hello.html new file mode 100644 index 0000000..917e7cd --- /dev/null +++ b/starter-microservice-springboot-security/src/main/resources/templates/security-hello.html @@ -0,0 +1,13 @@ + + + + Hello World! + + +

Hello [[${#httpServletRequest.remoteUser}]]!

+
+ +
+ + \ No newline at end of file diff --git a/starter-microservice-springboot-security/src/main/resources/templates/security-home.html b/starter-microservice-springboot-security/src/main/resources/templates/security-home.html new file mode 100644 index 0000000..d743f18 --- /dev/null +++ b/starter-microservice-springboot-security/src/main/resources/templates/security-home.html @@ -0,0 +1,12 @@ + + + + Spring Security Example + + +

Welcome!

+ +

Click here to see a greeting.

+

On the log in page, try to use username "andmin" and password "admin" to log in.

+ + \ No newline at end of file diff --git a/starter-microservice-springboot-security/src/main/resources/templates/security-login.html b/starter-microservice-springboot-security/src/main/resources/templates/security-login.html new file mode 100644 index 0000000..4388a5c --- /dev/null +++ b/starter-microservice-springboot-security/src/main/resources/templates/security-login.html @@ -0,0 +1,20 @@ + + + + Spring Security Example + + +
+ Invalid username and password. +
+
+ You have been logged out. +
+
+
+
+
+
+ + \ No newline at end of file diff --git a/starter-microservice-springboot-security/src/main/webapp/.gitignore b/starter-microservice-springboot-security/src/main/webapp/.gitignore new file mode 100644 index 0000000..5d43caf --- /dev/null +++ b/starter-microservice-springboot-security/src/main/webapp/.gitignore @@ -0,0 +1 @@ +/artifacts diff --git a/starter-microservice-springboot-security/src/main/webapp/META-INF/.gitignore b/starter-microservice-springboot-security/src/main/webapp/META-INF/.gitignore new file mode 100644 index 0000000..f67faf7 --- /dev/null +++ b/starter-microservice-springboot-security/src/main/webapp/META-INF/.gitignore @@ -0,0 +1 @@ +/swagger.json diff --git a/starter-microservice-springboot-security/src/main/webapp/WEB-INF/classes/.gitignore b/starter-microservice-springboot-security/src/main/webapp/WEB-INF/classes/.gitignore new file mode 100644 index 0000000..5342fdc --- /dev/null +++ b/starter-microservice-springboot-security/src/main/webapp/WEB-INF/classes/.gitignore @@ -0,0 +1 @@ +/locations.json diff --git a/starter-microservice-springboot-security/src/main/webapp/WEB-INF/classes/description.html b/starter-microservice-springboot-security/src/main/webapp/WEB-INF/classes/description.html new file mode 100644 index 0000000..1fe5c99 --- /dev/null +++ b/starter-microservice-springboot-security/src/main/webapp/WEB-INF/classes/description.html @@ -0,0 +1,25 @@ + +
+

Spring Boot with Security

+

Inside the application project there is a application.springboot.web package + containing two classes:

+
    +
  • SpringBootLibertyApplication: The entry point for the SpringBoot application.
  • +
  • LibertyHelloController: A Spring MVC endpoint which you can access at /springbootweb
  • +
+

Inside the wlpcfg project there is the it.springboot.web.HelloControllerTest that will test the Spring MVC endpoint to ensure it is working.

+
diff --git a/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/security/Application.java b/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/security/Application.java new file mode 100644 index 0000000..ed24ca0 --- /dev/null +++ b/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/security/Application.java @@ -0,0 +1,19 @@ +package application.springboot.security; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.context.web.SpringBootServletInitializer; + +@SpringBootApplication +public class Application extends SpringBootServletInitializer{ + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(Application.class); + } + + public static void main(String[] args) throws Throwable { + SpringApplication.run(Application.class, args); + } +} diff --git a/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/security/MvcConfig.java b/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/security/MvcConfig.java new file mode 100644 index 0000000..4ed8a06 --- /dev/null +++ b/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/security/MvcConfig.java @@ -0,0 +1,19 @@ +package application.springboot.security; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; + +@Configuration +public class MvcConfig extends WebMvcConfigurerAdapter { + + @Override + public void addViewControllers(ViewControllerRegistry registry) { + registry.addViewController("/springbootsecurity/home").setViewName("security-home"); + registry.addViewController("/springbootsecurity").setViewName("security-home"); + registry.addViewController("/springbootsecurity/hello").setViewName("security-hello"); + registry.addViewController("/springbootsecurity/login").setViewName("security-login"); + registry.addViewController("/springbootsecurity/logout").setViewName("security-home"); + } + +} diff --git a/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/security/WebSecurityConfig.java b/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/security/WebSecurityConfig.java new file mode 100644 index 0000000..9e644ba --- /dev/null +++ b/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/security/WebSecurityConfig.java @@ -0,0 +1,34 @@ +package application.springboot.security; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; + +@Configuration +@EnableWebSecurity +public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + @Override + protected void configure(HttpSecurity http) throws Exception { + http + .authorizeRequests() + .antMatchers("/springbootsecurity", "/springbootsecurity/home").permitAll() + .anyRequest().authenticated() + .and() + .formLogin() + .loginPage("/springbootsecurity/login") + .permitAll() + .and() + .logout() + .permitAll(); + } + + @Autowired + public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { + auth + .inMemoryAuthentication() + .withUser("admin").password("admin").roles("USER"); + } +} diff --git a/starter-microservice-springboot-security/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/security/HelloControllerTest.java b/starter-microservice-springboot-security/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/security/HelloControllerTest.java new file mode 100644 index 0000000..d666256 --- /dev/null +++ b/starter-microservice-springboot-security/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/security/HelloControllerTest.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +package it.springboot.security; + +import static org.junit.Assert.assertTrue; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Invocation; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Response; +import it.EndpointTest; + +import org.junit.Test; + +public class HelloControllerTest extends EndpointTest { + + + @Test + public void testDeployment() { + testEndpoint("/springbootsecurity", "Welcome!"); + } +} \ No newline at end of file diff --git a/starter-microservice-springboot-security/src/test/java/com/ibm/liberty/starter/service/springboot/security/api/v1/it/EndpointTest.java b/starter-microservice-springboot-security/src/test/java/com/ibm/liberty/starter/service/springboot/security/api/v1/it/EndpointTest.java new file mode 100644 index 0000000..aa84a85 --- /dev/null +++ b/starter-microservice-springboot-security/src/test/java/com/ibm/liberty/starter/service/springboot/security/api/v1/it/EndpointTest.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +package com.ibm.liberty.starter.service.springboot.security.api.v1.it; + +import static org.junit.Assert.assertTrue; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Invocation; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Response; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class EndpointTest { + + //use this to give the REST endpoint a chance to come up after the server has reported it's started + public void checkAvailability(String endpoint) { + String ep = getEndPoint(endpoint); + for(int x = 0; x < 3; x++) { + Response response = null; + try { + response = sendRequest(ep, "GET"); + if(response.getStatus() == 200) { + return; + } + } finally { + if(response != null) { + response.close(); + } + } + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + //just exit + } + } + } + + private String getEndPoint(String endpoint) { + String port = System.getProperty("liberty.test.port"); + String war = System.getProperty("war.name"); + return "http://localhost:" + port + "/" + war + endpoint; + } + + @SuppressWarnings("unchecked") + public T testEndpoint(String endpoint, Class entity) throws Exception { + String url = getEndPoint(endpoint); + System.out.println("Testing " + url); + Response response = null; + try { + response = sendRequest(url, "GET"); + int responseCode = response.getStatus(); + assertTrue("Incorrect response code for " + url + ": " + responseCode, + responseCode == 200); + String json = response.readEntity(String.class); + ObjectMapper mapper = new ObjectMapper(); + return (T) mapper.readValue(json, entity); + } finally { + if(response != null) { + response.close(); + } + } + } + + public Response sendRequest(String url, String requestType) { + Client client = ClientBuilder.newClient(); + System.out.println("Testing " + url); + WebTarget target = client.target(url); + Invocation.Builder invoBuild = target.request(); + Response response = invoBuild.build(requestType).invoke(); + return response; + } +} diff --git a/starter-microservice-springboot-security/src/test/java/com/ibm/liberty/starter/service/springboot/security/api/v1/it/TestApplication.java b/starter-microservice-springboot-security/src/test/java/com/ibm/liberty/starter/service/springboot/security/api/v1/it/TestApplication.java new file mode 100644 index 0000000..bf10e0a --- /dev/null +++ b/starter-microservice-springboot-security/src/test/java/com/ibm/liberty/starter/service/springboot/security/api/v1/it/TestApplication.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +package com.ibm.liberty.starter.service.springboot.security.api.v1.it; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +import com.ibm.liberty.starter.api.v1.model.provider.Dependency; +import com.ibm.liberty.starter.api.v1.model.provider.Provider; +import com.ibm.liberty.starter.api.v1.model.provider.Sample; +import com.ibm.liberty.starter.api.v1.model.provider.ServerConfig; + +/** + * Test the deployed service responds as expected + * + */ +public class TestApplication extends EndpointTest { + + @Before + public void checkSetup() { + checkAvailability("/api/v1/provider/"); + } + + @Test + public void testProvider() throws Exception { + Provider provider = testEndpoint("/api/v1/provider/", Provider.class); + assertNotNull("No response from API for provider", provider); + assertTrue("Description was not found.", provider.getDescription().contains("

Spring Boot with Security

")); + Dependency[] dependencies = provider.getDependencies(); + boolean providedDependency = false; + boolean runtimeDependency = false; + boolean compileDependency = false; + for (Dependency dependency : dependencies) { + if (Dependency.Scope.PROVIDED.equals(dependency.getScope())) { + assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springboot.secure".equals(dependency.getGroupId())); + assertTrue("artifactId incorrect.", "provided-pom".equals(dependency.getArtifactId())); + assertTrue("version incorrect.", "0.0.1".equals(dependency.getVersion())); + providedDependency = true; + } + if (Dependency.Scope.RUNTIME.equals(dependency.getScope())) { + assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springboot.secure".equals(dependency.getGroupId())); + assertTrue("artifactId incorrect.", "runtime-pom".equals(dependency.getArtifactId())); + assertTrue("version incorrect.", "0.0.1".equals(dependency.getVersion())); + runtimeDependency = true; + } + if (Dependency.Scope.COMPILE.equals(dependency.getScope())) { + assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springboot.secure".equals(dependency.getGroupId())); + assertTrue("artifactId incorrect.", "compile-pom".equals(dependency.getArtifactId())); + assertTrue("version incorrect.", "0.0.1".equals(dependency.getVersion())); + compileDependency = true; + } + } + assertTrue("Provided dependencies weren't specified.", providedDependency); + assertTrue("Runtime dependencies weren't specified.", runtimeDependency); + assertTrue("Compile dependencies weren't specified.", compileDependency); + } + + @Test + public void testConfig() throws Exception { + ServerConfig config = testEndpoint("/api/v1/provider/config", ServerConfig.class); + assertNotNull("No response from API for configuration", config); + String actual = config.getTags()[0].getTags()[0].getValue(); + String expected = "websocket-1.1"; + assertEquals("Incorrect feature specified", expected , actual); + } + + @Test + public void testSamples() throws Exception { + Sample sample = testEndpoint("/api/v1/provider/samples", Sample.class); + assertNotNull("No response from API for sample", sample); + assertNotNull("Expected locations", sample.getLocations()); + assertEquals("No files were expected for sample", 4, sample.getLocations().length); + } + +} From 0ab347f1440c5a69d2986abe6d80482f588af952 Mon Sep 17 00:00:00 2001 From: qiaoxi Date: Wed, 25 May 2016 11:22:49 +0800 Subject: [PATCH 05/13] Update with Springboot Security --- build.gradle | 2 +- .../src/main/resources/services.json | 2 +- .../servers/StarterServer/.gitignore | 1 - .../resources/security/.gitignore | 2 -- .../build.gradle | 3 +- .../repository/0.0.1/compile-pom.xml | 28 +++++++++++++------ .../repository/0.0.1/provided-pom.xml | 2 +- .../repository/0.0.1/runtime-pom.xml | 2 +- .../security/api/v1/ProviderEndpoint.java | 8 +++--- .../resources/templates/security-hello.html | 13 --------- .../resources/templates/security-home.html | 12 -------- .../resources/templates/security-login.html | 20 ------------- .../webapp/WEB-INF/classes/description.html | 6 ++-- .../security/WebSecurityConfig.java | 5 ++-- .../security/api/v1/it/TestApplication.java | 8 +++--- .../repository/0.0.1/compile-pom.xml | 2 +- .../repository/0.0.1/provided-pom.xml | 2 +- .../repository/0.0.1/runtime-pom.xml | 2 +- .../springboot/api/v1/ProviderEndpoint.java | 6 ++-- .../springboot/api/v1/it/TestApplication.java | 6 ++-- 20 files changed, 47 insertions(+), 85 deletions(-) delete mode 100644 liberty-starter-wlpcfg/servers/StarterServer/.gitignore delete mode 100644 liberty-starter-wlpcfg/servers/StarterServer/resources/security/.gitignore delete mode 100644 starter-microservice-springboot-security/src/main/resources/templates/security-hello.html delete mode 100644 starter-microservice-springboot-security/src/main/resources/templates/security-home.html delete mode 100644 starter-microservice-springboot-security/src/main/resources/templates/security-login.html diff --git a/build.gradle b/build.gradle index 4b6b418..8cb5156 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,7 @@ allprojects { mavenCentral() } dependencies { - classpath 'net.wasdev.wlp.gradle.plugins:liberty-gradle-plugin:1.1-SNAPSHOT' + classpath 'net.wasdev.wlp.gradle.plugins:liberty-gradle-plugin:1.0' classpath files('gradle/wlp-anttasks.jar') } } diff --git a/liberty-starter-application/src/main/resources/services.json b/liberty-starter-application/src/main/resources/services.json index 144466d..50b60c9 100644 --- a/liberty-starter-application/src/main/resources/services.json +++ b/liberty-starter-application/src/main/resources/services.json @@ -37,7 +37,7 @@ "endpoint" : "/springbootjersey" }, { - "id": "springbootsecure", + "id": "springbootsecurity", "name": "Spring Boot with Security", "description": "Spring Boot with Security", "endpoint" : "/springbootsecurity" diff --git a/liberty-starter-wlpcfg/servers/StarterServer/.gitignore b/liberty-starter-wlpcfg/servers/StarterServer/.gitignore deleted file mode 100644 index fb6290b..0000000 --- a/liberty-starter-wlpcfg/servers/StarterServer/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/server.env diff --git a/liberty-starter-wlpcfg/servers/StarterServer/resources/security/.gitignore b/liberty-starter-wlpcfg/servers/StarterServer/resources/security/.gitignore deleted file mode 100644 index 11d60b9..0000000 --- a/liberty-starter-wlpcfg/servers/StarterServer/resources/security/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/ltpa.keys -/key.jks diff --git a/starter-microservice-springboot-security/build.gradle b/starter-microservice-springboot-security/build.gradle index b6985a6..6a4f318 100644 --- a/starter-microservice-springboot-security/build.gradle +++ b/starter-microservice-springboot-security/build.gradle @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - apply from: '../common-java.gradle' apply from: '../common-war.gradle' @@ -30,7 +29,7 @@ buildutils { } task installAllPOMs(type: MavenTask) { - id 'springbootsecure' + id 'springbootsecurity' hasProvided true hasRuntime true hasCompile true diff --git a/starter-microservice-springboot-security/repository/0.0.1/compile-pom.xml b/starter-microservice-springboot-security/repository/0.0.1/compile-pom.xml index 35cf2ca..ed84603 100644 --- a/starter-microservice-springboot-security/repository/0.0.1/compile-pom.xml +++ b/starter-microservice-springboot-security/repository/0.0.1/compile-pom.xml @@ -2,7 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - net.wasdev.wlp.starters.springboot.secure + net.wasdev.wlp.starters.springbootsecurity compile-pom 0.0.1 @@ -23,15 +23,25 @@ - - org.springframework.boot - spring-boot-starter-thymeleaf - - - org.springframework.spring-webmvc - spring-webmvc - 4.2.5.RELEASE + + + + + org.springframework.boot + spring-boot-starter-thymeleaf + 1.3.0.RELEASE + org.springframework.boot spring-boot-starter-security diff --git a/starter-microservice-springboot-security/repository/0.0.1/provided-pom.xml b/starter-microservice-springboot-security/repository/0.0.1/provided-pom.xml index 570a483..c0b7250 100644 --- a/starter-microservice-springboot-security/repository/0.0.1/provided-pom.xml +++ b/starter-microservice-springboot-security/repository/0.0.1/provided-pom.xml @@ -2,7 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - net.wasdev.wlp.starters.springboot.secure + net.wasdev.wlp.starters.springbootsecurity provided-pom 0.0.1 diff --git a/starter-microservice-springboot-security/repository/0.0.1/runtime-pom.xml b/starter-microservice-springboot-security/repository/0.0.1/runtime-pom.xml index f1b30fa..28e8b09 100644 --- a/starter-microservice-springboot-security/repository/0.0.1/runtime-pom.xml +++ b/starter-microservice-springboot-security/repository/0.0.1/runtime-pom.xml @@ -2,7 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - net.wasdev.wlp.starters.springboot.secure + net.wasdev.wlp.starters.springbootsecurity runtime-pom 0.0.1 diff --git a/starter-microservice-springboot-security/src/main/java/com/ibm/liberty/starter/service/springboot/security/api/v1/ProviderEndpoint.java b/starter-microservice-springboot-security/src/main/java/com/ibm/liberty/starter/service/springboot/security/api/v1/ProviderEndpoint.java index bc70c65..6adeca6 100644 --- a/starter-microservice-springboot-security/src/main/java/com/ibm/liberty/starter/service/springboot/security/api/v1/ProviderEndpoint.java +++ b/starter-microservice-springboot-security/src/main/java/com/ibm/liberty/starter/service/springboot/security/api/v1/ProviderEndpoint.java @@ -37,7 +37,7 @@ @Path("v1/provider") public class ProviderEndpoint { - private static final String DEPENDENCY_URL = "http://localhost:9082/springboot/artifacts/net/wasdev/wlp/starters/springbootsecure"; + private static final String DEPENDENCY_URL = "http://localhost:9082/springboot/artifacts/net/wasdev/wlp/starters/springbootsecurity"; @GET @Path("/") @@ -53,19 +53,19 @@ public Provider details(@Context UriInfo info) { details.setRepoUrl(repoLocation); Dependency providedDependency = new Dependency(); providedDependency.setScope(Scope.PROVIDED); - providedDependency.setGroupId("net.wasdev.wlp.starters.springboot.secure"); + providedDependency.setGroupId("net.wasdev.wlp.starters.springbootsecurity"); providedDependency.setArtifactId("provided-pom"); providedDependency.setVersion("0.0.1"); Dependency runtimeDependency = new Dependency(); runtimeDependency.setScope(Scope.RUNTIME); - runtimeDependency.setGroupId("net.wasdev.wlp.starters.springboot.secure"); + runtimeDependency.setGroupId("net.wasdev.wlp.starters.springbootsecurity"); runtimeDependency.setArtifactId("runtime-pom"); runtimeDependency.setVersion("0.0.1"); Dependency compileDependency = new Dependency(); compileDependency.setScope(Scope.COMPILE); - compileDependency.setGroupId("net.wasdev.wlp.starters.springboot.secure"); + compileDependency.setGroupId("net.wasdev.wlp.starters.springbootsecurity"); compileDependency.setArtifactId("compile-pom"); compileDependency.setVersion("0.0.1"); diff --git a/starter-microservice-springboot-security/src/main/resources/templates/security-hello.html b/starter-microservice-springboot-security/src/main/resources/templates/security-hello.html deleted file mode 100644 index 917e7cd..0000000 --- a/starter-microservice-springboot-security/src/main/resources/templates/security-hello.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - Hello World! - - -

Hello [[${#httpServletRequest.remoteUser}]]!

-
- -
- - \ No newline at end of file diff --git a/starter-microservice-springboot-security/src/main/resources/templates/security-home.html b/starter-microservice-springboot-security/src/main/resources/templates/security-home.html deleted file mode 100644 index d743f18..0000000 --- a/starter-microservice-springboot-security/src/main/resources/templates/security-home.html +++ /dev/null @@ -1,12 +0,0 @@ - - - - Spring Security Example - - -

Welcome!

- -

Click here to see a greeting.

-

On the log in page, try to use username "andmin" and password "admin" to log in.

- - \ No newline at end of file diff --git a/starter-microservice-springboot-security/src/main/resources/templates/security-login.html b/starter-microservice-springboot-security/src/main/resources/templates/security-login.html deleted file mode 100644 index 4388a5c..0000000 --- a/starter-microservice-springboot-security/src/main/resources/templates/security-login.html +++ /dev/null @@ -1,20 +0,0 @@ - - - - Spring Security Example - - -
- Invalid username and password. -
-
- You have been logged out. -
-
-
-
-
-
- - \ No newline at end of file diff --git a/starter-microservice-springboot-security/src/main/webapp/WEB-INF/classes/description.html b/starter-microservice-springboot-security/src/main/webapp/WEB-INF/classes/description.html index 1fe5c99..7e8dfb2 100644 --- a/starter-microservice-springboot-security/src/main/webapp/WEB-INF/classes/description.html +++ b/starter-microservice-springboot-security/src/main/webapp/WEB-INF/classes/description.html @@ -18,8 +18,10 @@

Spring Boot with Security

Inside the application project there is a application.springboot.web package containing two classes:

    -
  • SpringBootLibertyApplication: The entry point for the SpringBoot application.
  • -
  • LibertyHelloController: A Spring MVC endpoint which you can access at /springbootweb
  • +
  • Application: The entry point for the SpringBoot application.
  • +
  • MvcConfig: Config url mapping to static html page
  • +
  • WebSecurityConfig: Config security setting for application
  • +
  • View how application work at:/springbootsecurity

Inside the wlpcfg project there is the it.springboot.web.HelloControllerTest that will test the Spring MVC endpoint to ensure it is working.

diff --git a/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/security/WebSecurityConfig.java b/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/security/WebSecurityConfig.java index 9e644ba..b221036 100644 --- a/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/security/WebSecurityConfig.java +++ b/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/security/WebSecurityConfig.java @@ -14,15 +14,14 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() - .antMatchers("/springbootsecurity", "/springbootsecurity/home").permitAll() - .anyRequest().authenticated() + .antMatchers("/springbootsecurity/hello").hasRole("USER") .and() .formLogin() .loginPage("/springbootsecurity/login") .permitAll() .and() .logout() - .permitAll(); + .permitAll(); } @Autowired diff --git a/starter-microservice-springboot-security/src/test/java/com/ibm/liberty/starter/service/springboot/security/api/v1/it/TestApplication.java b/starter-microservice-springboot-security/src/test/java/com/ibm/liberty/starter/service/springboot/security/api/v1/it/TestApplication.java index bf10e0a..a1675fa 100644 --- a/starter-microservice-springboot-security/src/test/java/com/ibm/liberty/starter/service/springboot/security/api/v1/it/TestApplication.java +++ b/starter-microservice-springboot-security/src/test/java/com/ibm/liberty/starter/service/springboot/security/api/v1/it/TestApplication.java @@ -47,19 +47,19 @@ public void testProvider() throws Exception { boolean compileDependency = false; for (Dependency dependency : dependencies) { if (Dependency.Scope.PROVIDED.equals(dependency.getScope())) { - assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springboot.secure".equals(dependency.getGroupId())); + assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springbootsecurity".equals(dependency.getGroupId())); assertTrue("artifactId incorrect.", "provided-pom".equals(dependency.getArtifactId())); assertTrue("version incorrect.", "0.0.1".equals(dependency.getVersion())); providedDependency = true; } if (Dependency.Scope.RUNTIME.equals(dependency.getScope())) { - assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springboot.secure".equals(dependency.getGroupId())); + assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springbootsecurity".equals(dependency.getGroupId())); assertTrue("artifactId incorrect.", "runtime-pom".equals(dependency.getArtifactId())); assertTrue("version incorrect.", "0.0.1".equals(dependency.getVersion())); runtimeDependency = true; } if (Dependency.Scope.COMPILE.equals(dependency.getScope())) { - assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springboot.secure".equals(dependency.getGroupId())); + assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springbootsecurity".equals(dependency.getGroupId())); assertTrue("artifactId incorrect.", "compile-pom".equals(dependency.getArtifactId())); assertTrue("version incorrect.", "0.0.1".equals(dependency.getVersion())); compileDependency = true; @@ -84,7 +84,7 @@ public void testSamples() throws Exception { Sample sample = testEndpoint("/api/v1/provider/samples", Sample.class); assertNotNull("No response from API for sample", sample); assertNotNull("Expected locations", sample.getLocations()); - assertEquals("No files were expected for sample", 4, sample.getLocations().length); + assertEquals("No files were expected for sample", 8, sample.getLocations().length); } } diff --git a/starter-microservice-springboot-web/repository/0.0.1/compile-pom.xml b/starter-microservice-springboot-web/repository/0.0.1/compile-pom.xml index 34e89d8..9367247 100644 --- a/starter-microservice-springboot-web/repository/0.0.1/compile-pom.xml +++ b/starter-microservice-springboot-web/repository/0.0.1/compile-pom.xml @@ -2,7 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - net.wasdev.wlp.starters.springboot + net.wasdev.wlp.starters.springbootweb compile-pom 0.0.1 diff --git a/starter-microservice-springboot-web/repository/0.0.1/provided-pom.xml b/starter-microservice-springboot-web/repository/0.0.1/provided-pom.xml index ea88f27..9bc42b8 100644 --- a/starter-microservice-springboot-web/repository/0.0.1/provided-pom.xml +++ b/starter-microservice-springboot-web/repository/0.0.1/provided-pom.xml @@ -2,7 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - net.wasdev.wlp.starters.springboot + net.wasdev.wlp.starters.springbootweb provided-pom 0.0.1 diff --git a/starter-microservice-springboot-web/repository/0.0.1/runtime-pom.xml b/starter-microservice-springboot-web/repository/0.0.1/runtime-pom.xml index 52a1d99..3014b88 100644 --- a/starter-microservice-springboot-web/repository/0.0.1/runtime-pom.xml +++ b/starter-microservice-springboot-web/repository/0.0.1/runtime-pom.xml @@ -2,7 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - net.wasdev.wlp.starters.springboot + net.wasdev.wlp.starters.springbootweb runtime-pom 0.0.1 diff --git a/starter-microservice-springboot-web/src/main/java/com/ibm/liberty/starter/service/springboot/api/v1/ProviderEndpoint.java b/starter-microservice-springboot-web/src/main/java/com/ibm/liberty/starter/service/springboot/api/v1/ProviderEndpoint.java index a994dcb..6bbfea2 100644 --- a/starter-microservice-springboot-web/src/main/java/com/ibm/liberty/starter/service/springboot/api/v1/ProviderEndpoint.java +++ b/starter-microservice-springboot-web/src/main/java/com/ibm/liberty/starter/service/springboot/api/v1/ProviderEndpoint.java @@ -53,19 +53,19 @@ public Provider details(@Context UriInfo info) { details.setRepoUrl(repoLocation); Dependency providedDependency = new Dependency(); providedDependency.setScope(Scope.PROVIDED); - providedDependency.setGroupId("net.wasdev.wlp.starters.springboot"); + providedDependency.setGroupId("net.wasdev.wlp.starters.springbootweb"); providedDependency.setArtifactId("provided-pom"); providedDependency.setVersion("0.0.1"); Dependency runtimeDependency = new Dependency(); runtimeDependency.setScope(Scope.RUNTIME); - runtimeDependency.setGroupId("net.wasdev.wlp.starters.springboot"); + runtimeDependency.setGroupId("net.wasdev.wlp.starters.springbootweb"); runtimeDependency.setArtifactId("runtime-pom"); runtimeDependency.setVersion("0.0.1"); Dependency compileDependency = new Dependency(); compileDependency.setScope(Scope.COMPILE); - compileDependency.setGroupId("net.wasdev.wlp.starters.springboot"); + compileDependency.setGroupId("net.wasdev.wlp.starters.springbootweb"); compileDependency.setArtifactId("compile-pom"); compileDependency.setVersion("0.0.1"); diff --git a/starter-microservice-springboot-web/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/TestApplication.java b/starter-microservice-springboot-web/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/TestApplication.java index 8a8e3ce..fbc2757 100644 --- a/starter-microservice-springboot-web/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/TestApplication.java +++ b/starter-microservice-springboot-web/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/TestApplication.java @@ -47,19 +47,19 @@ public void testProvider() throws Exception { boolean compileDependency = false; for (Dependency dependency : dependencies) { if (Dependency.Scope.PROVIDED.equals(dependency.getScope())) { - assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springboot".equals(dependency.getGroupId())); + assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springbootweb".equals(dependency.getGroupId())); assertTrue("artifactId incorrect.", "provided-pom".equals(dependency.getArtifactId())); assertTrue("version incorrect.", "0.0.1".equals(dependency.getVersion())); providedDependency = true; } if (Dependency.Scope.RUNTIME.equals(dependency.getScope())) { - assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springboot".equals(dependency.getGroupId())); + assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springbootweb".equals(dependency.getGroupId())); assertTrue("artifactId incorrect.", "runtime-pom".equals(dependency.getArtifactId())); assertTrue("version incorrect.", "0.0.1".equals(dependency.getVersion())); runtimeDependency = true; } if (Dependency.Scope.COMPILE.equals(dependency.getScope())) { - assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springboot".equals(dependency.getGroupId())); + assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springbootweb".equals(dependency.getGroupId())); assertTrue("artifactId incorrect.", "compile-pom".equals(dependency.getArtifactId())); assertTrue("version incorrect.", "0.0.1".equals(dependency.getVersion())); compileDependency = true; From 6cf5f7bb513d58297972de8600c5afea0a24b4b1 Mon Sep 17 00:00:00 2001 From: qiaoxi Date: Fri, 27 May 2016 10:58:24 +0800 Subject: [PATCH 06/13] Optimize code to make muti srpingboot technology work together better and update the description --- README.md | 21 ++++++---- .../StarterServer/resources/security/key.jks | Bin 0 -> 2169 bytes .../resources/security/ltpa.keys | 8 ++++ .../webapp/WEB-INF/classes/description.html | 5 ++- .../application/springboot}/Application.java | 2 +- .../springboot/jersey/Endpoint.java | 12 ++---- .../jersey/SampleJerseyApplication.java | 36 ------------------ .../springboot/jersey/Service.java | 32 ---------------- .../jersey/api/v1/it/TestApplication.java | 2 +- .../webapp/WEB-INF/classes/description.html | 8 ++-- .../application/springboot/Application.java | 19 +++++++++ .../src/main/resources/application.properties | 1 + .../resources/templates/security-hello.html | 13 +++++++ .../resources/templates/security-home.html | 12 ++++++ .../resources/templates/security-login.html | 20 ++++++++++ .../webapp/WEB-INF/classes/description.html | 2 +- .../application/springboot/Application.java | 19 +++++++++ .../web/SpringBootLibertyApplication.java | 31 --------------- 18 files changed, 119 insertions(+), 124 deletions(-) create mode 100644 liberty-starter-wlpcfg/servers/StarterServer/resources/security/key.jks create mode 100644 liberty-starter-wlpcfg/servers/StarterServer/resources/security/ltpa.keys rename {starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/security => starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot}/Application.java (93%) delete mode 100644 starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/SampleJerseyApplication.java delete mode 100644 starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Service.java create mode 100644 starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/Application.java create mode 100644 starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/resources/application.properties create mode 100644 starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/resources/templates/security-hello.html create mode 100644 starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/resources/templates/security-home.html create mode 100644 starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/resources/templates/security-login.html create mode 100644 starter-microservice-springboot-web/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/Application.java delete mode 100644 starter-microservice-springboot-web/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/web/SpringBootLibertyApplication.java diff --git a/README.md b/README.md index 6d4ce74..e779957 100644 --- a/README.md +++ b/README.md @@ -25,28 +25,35 @@ For the complete feature documentation, see the Serving Web Content with Spring MVC ## Spring Boot with Jersey This provides you with a SpringBoot application that will run on WebSphere Liberty. -Inside the application project there is a application.springboot.jersey package containing 6 classes: -* SampleJerseyApplication: The entry point for the SpringBoot application. +Inside the application project there is a application.springboot.jersey package containing 4 classes: +* Application: The entry point for the SpringBoot application. * Endpoint: A Jersey endpoint which you can access at /springbootjersey. +* JerseyConfig: Jersey configuration class. Inside the wlpcfg project there is the it.springboot.jersey.SampleJerseyApplicationTests that will test the Jersey endpoint to ensure it is working. +For the complete feature documentation, see the Building a RESTful Web Service + ## Spring Boot with Security This provides you with a SpringBoot application that will run on WebSphere Liberty. -Inside the application project there is a application.springboot.jersey package containing 6 classes: -* SampleJerseyApplication: The entry point for the SpringBoot application. -* Endpoint: A Jersey endpoint which you can access at home.html. +Inside the application project there is a application.springboot.security package containing 3 classes: +* Application: The entry point for the SpringBoot application. +* MvcConfig: Map each uri to static html resources +* WebSecurityConfig: Seucirty configuration for Springboot application -Inside the wlpcfg project there is the it.springboot.jersey.SampleJerseyApplicationTests that will test the Jersey endpoint to ensure it is working. +Inside the wlpcfg project there is the it.springboot.security.HelloControllerTest that will test the /springbootsecurity endpoint to ensure it is working. + +For the complete feature documentation, see the Securing a Web Application ## Websockets This provides you with the websocket-1.1 feature. diff --git a/liberty-starter-wlpcfg/servers/StarterServer/resources/security/key.jks b/liberty-starter-wlpcfg/servers/StarterServer/resources/security/key.jks new file mode 100644 index 0000000000000000000000000000000000000000..996dcf21b325f6a06e8cc48e9aff7b1e43d2d671 GIT binary patch literal 2169 zcmb`H=|9wq7suy2#@O8$rZQ$^EynU4yDX)_Om3F!>qHq#_OUNvhRBlaQfSa*X_5Gq zH8e=JYbhc^qYPfQA}Q(WKI#wnJva~E=gE1U&pEI6{_6fJ1OkB`6!2ehd5}Hb!~8-I z*rvi~6AyuKLO>d94-|y+V&MP`P=E>n04D@SgRw8j$=#)}7|hREmqo;>Jx8}^9j0Vv z25JB>JT_Z+Un2F_h^dD4er}5PW45cGFQ}Gqek}iTd2vAT#8s|Y2DxTMS=#{5Oj z>VC6^D;4vipo(UFt4RRn)Z_jowbRQJ(hs`z!l;Z4Lw>~hA{|Ny)FU1M<=cYcG~?kFcKz=bkQ;m#q$(*nOY<1rM7!GCBA-m%H1@RC~mC&|>kE z`D|?dulVOs9AfNx!KCu1f|47>&i9^ss^-KREqN3)+7vo%(vpT>%6sPSk(N?xNi0AQ5(liObfT42`QjRP<;1qn`A;DTX;^`eE#kJ6h`T4sr+>NJ-?W0kt-dg6?U_$%rhoj|5KPFz&Zr zYGs7xDlcqfZR9ci)=B33YwM-sxlBVzfi@+q*#_)uNV&r5S(V<~(OHYj0qrwp-=<{S zF-E8p(ReFDi$L?}$+sp3sywJT(dMrb<))sv0QClq^`$ENicxy*U98C#`pyh4=tr8_~Nthma94@Wy1 zrY*#Lm|i}U+-@;v@P8@eyDW60o>4vHq2se;kqPI`sg#!W*X0{O$>(j-W)N= z&B*Ve^iDIcmfHheq}zMhPsMuTRO08hWybc21(&TdRyK7$^b$9mFPNc1#|F#VYFF>7 z%rm~B3`B=C__a6q1R_I|2Z}cOXmxjt}I4bJ)V*2xwRcjvwUx4ZH{rpNsxD zBq;Km_z(itq3)DWGR2xq2`5uQJ$PD8vE42_EZ=*#CjBJ~9f0lFv z-L?-VBvqtfpgGA;AAY}MV;t2_l0B+3VQvw9)9WLJLgETKj=0c{wrmYR<1@qpW>?0mTD<9baB=o) zwEt-M4b2@P!mDZ@rguZ1gKc6RlmmbO6_TI?h(0(HS`dbWi7YGq8d#_^4+)E7xoPwN zEumTWZuQR)4?f`_L;ynYKnf?GK}6k34lg)a7CMq-qi2-#X{}H>wwK)$(Tza&UZI&! z_$S@8q3CYoQd7LX?>(mnE`%py(06)`Gwmh!IFZlnay`2Z$B}Jzf(m7q0+`KxdZ}EB z6MZ6=*?g{~+EINTkypL^>=J&X4`V?S{Ig)eyTmD#I`w)xUBzsh70(BD17}!8qFdEz zdWy~unbXIDH@LU0j1)~J8*Q=HrUQekceE>Ox{7P;kxmi!x7v3LnjY3?hqX+`VA+V> z5VzeE7a0Zkw2*~?4_0%GE!!Af?P3vxAwq78vZT|ve1jq0I literal 0 HcmV?d00001 diff --git a/liberty-starter-wlpcfg/servers/StarterServer/resources/security/ltpa.keys b/liberty-starter-wlpcfg/servers/StarterServer/resources/security/ltpa.keys new file mode 100644 index 0000000..a885ece --- /dev/null +++ b/liberty-starter-wlpcfg/servers/StarterServer/resources/security/ltpa.keys @@ -0,0 +1,8 @@ +#Thu May 12 13:21:50 CST 2016 +com.ibm.websphere.CreationDate=Thu May 12 13\:21\:50 CST 2016 +com.ibm.websphere.ltpa.version=1.0 +com.ibm.websphere.ltpa.3DESKey=/5lYlRUbtjnQsmnDuWcC5MXyJZ/0dNaj3/cGjIn+mR4\= +com.ibm.websphere.CreationHost=localhost +com.ibm.websphere.ltpa.PrivateKey=gNhxF0iXkTRpWYguRUEzivGiITbpefFvF9EXuoDPcfs7oCIWBJgzjE04IHULyHaXzDaSiGhN0n6StEyec/AdyhGGnS9+p/DmTmgliVq0jEwIVeJXYy4iurJt8u8S2AA6dQh+3Kkt8DPdJDQsxgsJeYt0P9EQpAvFCyRhqTfickd0gW3wQ7/gRHp3+44mj3ZXQf/lMaha5Zn7QyBTw1wMgEH+JqstyF4df73PGQhiyC2EBNmZ8rQmveZwEUYmRtYxS7xxUL1ZX+q8cIZ0ehJfEMWaKFqCs4amGLmt9Iynapgiwa6I7VqztuArTMwlsN4f+8satUK3i2DvXYDCapgIKyBp4lXenoG74Imnby8O3bE\= +com.ibm.websphere.ltpa.Realm=ibm/api +com.ibm.websphere.ltpa.PublicKey=ALnKghsaCBy3d3ctnHCKF3kAnDgJeFbor68DZpXEfmXk1YQ3WJxv+kV9pl/jVGCEHTCaEYqF9o2Uw4V/cIXSTAABW0dY16ocs4uueNWYm37NN6H/y5OQfRz/NSHh4md83a2K88FpEDbsrWm3sW21uvvImQvMbjlCbmniG77m9cDPAQAB diff --git a/starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/description.html b/starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/description.html index 6d5e4dc..32ee210 100644 --- a/starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/description.html +++ b/starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/description.html @@ -16,11 +16,12 @@

Spring Boot with Jersey

Inside the application project there is a application.springboot.jersey package - containing 6 classes:

+ containing 3 classes:

    +
  • Application: The entry point for the SpringBoot application
  • JerseyConfig: Configuration for Jersey
  • Endpoint: A Spring Jersey endpoint which you can access at /springbootjersey
  • -
  • Service: Service implements of Jersey
  • +

Inside the wlpcfg project there is the it.springboot.jersey.SampleJerseyApplicationTests that will test the Spring Jersey endpoint to ensure it is working.

diff --git a/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/security/Application.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/Application.java similarity index 93% rename from starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/security/Application.java rename to starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/Application.java index ed24ca0..4c77aa6 100644 --- a/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/security/Application.java +++ b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/Application.java @@ -1,4 +1,4 @@ -package application.springboot.security; +package application.springboot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Endpoint.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Endpoint.java index 0fdec22..645c7a4 100644 --- a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Endpoint.java +++ b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Endpoint.java @@ -16,11 +16,8 @@ package application.springboot.jersey; - import javax.ws.rs.GET; import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -30,18 +27,15 @@ @Component @Path("/") public class Endpoint { - - private final Service service; - private final ObjectMapper objectMapper; + private ObjectMapper objectMapper; @Autowired - public Endpoint(Service service, ObjectMapper objectMapper) { - this.service = service; + public Endpoint(ObjectMapper objectMapper) { this.objectMapper = objectMapper; } @GET public String message() { - return "Hello " + this.service.message(); + return "Hello World"; } } diff --git a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/SampleJerseyApplication.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/SampleJerseyApplication.java deleted file mode 100644 index 7e8aa34..0000000 --- a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/SampleJerseyApplication.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2012-2014 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package application.springboot.jersey; - -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.web.SpringBootServletInitializer; - -@SpringBootApplication -public class SampleJerseyApplication extends SpringBootServletInitializer { - - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(SampleJerseyApplication.class); - } - - public static void main(String[] args) { - new SampleJerseyApplication().configure( - new SpringApplicationBuilder(SampleJerseyApplication.class)).run(args); - } - -} diff --git a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Service.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Service.java deleted file mode 100644 index 9583c9d..0000000 --- a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Service.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2012-2014 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package application.springboot.jersey; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -@Component -public class Service { - - @Value("${message:World}") - private String msg; - - public String message() { - return this.msg; - } - -} diff --git a/starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/jersey/api/v1/it/TestApplication.java b/starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/jersey/api/v1/it/TestApplication.java index 0d80921..69c3e89 100644 --- a/starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/jersey/api/v1/it/TestApplication.java +++ b/starter-microservice-springboot-jersey/src/test/java/com/ibm/liberty/starter/service/springboot/jersey/api/v1/it/TestApplication.java @@ -84,7 +84,7 @@ public void testSamples() throws Exception { Sample sample = testEndpoint("/api/v1/provider/samples", Sample.class); assertNotNull("No response from API for sample", sample); assertNotNull("Expected locations", sample.getLocations()); - assertEquals("No files were expected for sample", 5, sample.getLocations().length); + assertEquals("No files were expected for sample", 4, sample.getLocations().length); } } diff --git a/starter-microservice-springboot-security/src/main/webapp/WEB-INF/classes/description.html b/starter-microservice-springboot-security/src/main/webapp/WEB-INF/classes/description.html index 7e8dfb2..d11117d 100644 --- a/starter-microservice-springboot-security/src/main/webapp/WEB-INF/classes/description.html +++ b/starter-microservice-springboot-security/src/main/webapp/WEB-INF/classes/description.html @@ -15,13 +15,13 @@ -->

Spring Boot with Security

-

Inside the application project there is a application.springboot.web package - containing two classes:

+

Inside the application project there is a application.springboot.security package + containing three classes:

    -
  • Application: The entry point for the SpringBoot application.
  • +
  • Application: The entry point for the SpringBoot application
  • MvcConfig: Config url mapping to static html page
  • WebSecurityConfig: Config security setting for application
  • View how application work at:/springbootsecurity
-

Inside the wlpcfg project there is the it.springboot.web.HelloControllerTest that will test the Spring MVC endpoint to ensure it is working.

+

Inside the wlpcfg project there is the it.springboot.security.HelloControllerTest that will test the Springboot security endpoint to ensure it is working.

diff --git a/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/Application.java b/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/Application.java new file mode 100644 index 0000000..4c77aa6 --- /dev/null +++ b/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/Application.java @@ -0,0 +1,19 @@ +package application.springboot; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.context.web.SpringBootServletInitializer; + +@SpringBootApplication +public class Application extends SpringBootServletInitializer{ + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(Application.class); + } + + public static void main(String[] args) throws Throwable { + SpringApplication.run(Application.class, args); + } +} diff --git a/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/resources/application.properties b/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/resources/application.properties new file mode 100644 index 0000000..409b428 --- /dev/null +++ b/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/resources/application.properties @@ -0,0 +1 @@ +server.contextPath=/myLibertyApp \ No newline at end of file diff --git a/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/resources/templates/security-hello.html b/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/resources/templates/security-hello.html new file mode 100644 index 0000000..917e7cd --- /dev/null +++ b/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/resources/templates/security-hello.html @@ -0,0 +1,13 @@ + + + + Hello World! + + +

Hello [[${#httpServletRequest.remoteUser}]]!

+
+ +
+ + \ No newline at end of file diff --git a/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/resources/templates/security-home.html b/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/resources/templates/security-home.html new file mode 100644 index 0000000..d743f18 --- /dev/null +++ b/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/resources/templates/security-home.html @@ -0,0 +1,12 @@ + + + + Spring Security Example + + +

Welcome!

+ +

Click here to see a greeting.

+

On the log in page, try to use username "andmin" and password "admin" to log in.

+ + \ No newline at end of file diff --git a/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/resources/templates/security-login.html b/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/resources/templates/security-login.html new file mode 100644 index 0000000..4388a5c --- /dev/null +++ b/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/resources/templates/security-login.html @@ -0,0 +1,20 @@ + + + + Spring Security Example + + +
+ Invalid username and password. +
+
+ You have been logged out. +
+
+
+
+
+
+ + \ No newline at end of file diff --git a/starter-microservice-springboot-web/src/main/webapp/WEB-INF/classes/description.html b/starter-microservice-springboot-web/src/main/webapp/WEB-INF/classes/description.html index 77dea01..bf62063 100644 --- a/starter-microservice-springboot-web/src/main/webapp/WEB-INF/classes/description.html +++ b/starter-microservice-springboot-web/src/main/webapp/WEB-INF/classes/description.html @@ -18,7 +18,7 @@

Spring Boot with Spring MVC

Inside the application project there is a application.springboot.web package containing two classes:

    -
  • SpringBootLibertyApplication: The entry point for the SpringBoot application.
  • +
  • Application: The entry point for the SpringBoot application
  • LibertyHelloController: A Spring MVC endpoint which you can access at /springbootweb

Inside the wlpcfg project there is the it.springboot.web.HelloControllerTest that will test the Spring MVC endpoint to ensure it is working.

diff --git a/starter-microservice-springboot-web/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/Application.java b/starter-microservice-springboot-web/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/Application.java new file mode 100644 index 0000000..4c77aa6 --- /dev/null +++ b/starter-microservice-springboot-web/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/Application.java @@ -0,0 +1,19 @@ +package application.springboot; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.context.web.SpringBootServletInitializer; + +@SpringBootApplication +public class Application extends SpringBootServletInitializer{ + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(Application.class); + } + + public static void main(String[] args) throws Throwable { + SpringApplication.run(Application.class, args); + } +} diff --git a/starter-microservice-springboot-web/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/web/SpringBootLibertyApplication.java b/starter-microservice-springboot-web/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/web/SpringBootLibertyApplication.java deleted file mode 100644 index 9d6ca91..0000000 --- a/starter-microservice-springboot-web/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/web/SpringBootLibertyApplication.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2016 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ -package application.springboot.web; - -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration; -import org.springframework.boot.context.web.SpringBootServletInitializer; - -@SpringBootApplication(exclude = MessageSourceAutoConfiguration.class) -public class SpringBootLibertyApplication extends SpringBootServletInitializer { - - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(SpringBootLibertyApplication.class); - } - -} \ No newline at end of file From 35e1561475fda0d894da027c357546cf8787e38f Mon Sep 17 00:00:00 2001 From: qiaoxi Date: Fri, 27 May 2016 15:17:34 +0800 Subject: [PATCH 07/13] Update description --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e779957..e69af15 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ For the complete feature documentation, see the

Hello [[${#httpServletRequest.remoteUser}]]!

-
+
diff --git a/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/resources/templates/security-home.html b/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/resources/templates/security-home.html index d743f18..07f2a45 100644 --- a/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/resources/templates/security-home.html +++ b/starter-microservice-springboot-security/src/main/webapp/sample/myProject-application/src/main/resources/templates/security-home.html @@ -7,6 +7,6 @@

Welcome!

Click here to see a greeting.

-

On the log in page, try to use username "andmin" and password "admin" to log in.

+

On the log in page, try to use username "admin" and password "admin" to log in.

\ No newline at end of file From 27a0172d8a592843d8d9476d9aa4262d95de021b Mon Sep 17 00:00:00 2001 From: qiaoxi Date: Wed, 15 Jun 2016 15:17:58 +0800 Subject: [PATCH 09/13] Add Springboot JDBC and fix some problem for Jersy and security --- README.md | 28 ++++- liberty-starter-application/build.gradle | 2 +- .../src/main/resources/services.json | 7 ++ .../servers/StarterServer/server.xml | 2 + settings.gradle | 2 +- .../.gitignore | 6 + .../build.gradle | 44 +++++++ .../repository/0.0.1/compile-pom.xml | 49 ++++++++ .../repository/0.0.1/provided-pom.xml | 46 +++++++ .../repository/0.0.1/runtime-pom.xml | 34 +++++ .../service/springboot/api/TechnologyAPI.java | 25 ++++ .../springboot/api/v1/ProviderEndpoint.java | 117 ++++++++++++++++++ .../src/main/webapp/.gitignore | 1 + .../src/main/webapp/META-INF/.gitignore | 1 + .../main/webapp/WEB-INF/classes/.gitignore | 1 + .../webapp/WEB-INF/classes/description.html | 27 ++++ .../application/springboot/Application.java | 19 +++ .../application/springboot/jdbc/Customer.java | 22 ++++ .../springboot/jdbc/JDBCController.java | 86 +++++++++++++ .../springboot/jdbc/HelloControllerTest.java | 36 ++++++ .../springboot/api/v1/it/EndpointTest.java | 87 +++++++++++++ .../springboot/api/v1/it/TestApplication.java | 90 ++++++++++++++ .../.gitignore | 1 - .../repository/0.0.1/compile-pom.xml | 2 +- .../webapp/WEB-INF/classes/description.html | 11 +- .../springboot/jersey/Endpoint.java | 2 +- .../springboot/jersey/JerseyConfig.java | 2 +- .../jersey/SampleJerseyApplicationTests.java | 2 +- .../.gitignore | 1 - .../repository/0.0.1/compile-pom.xml | 34 ++--- .../webapp/WEB-INF/classes/description.html | 11 +- .../.gitignore | 1 - .../repository/0.0.1/compile-pom.xml | 2 +- .../webapp/WEB-INF/classes/description.html | 9 +- 34 files changed, 760 insertions(+), 50 deletions(-) create mode 100644 starter-microservice-springboot-jdbc/.gitignore create mode 100644 starter-microservice-springboot-jdbc/build.gradle create mode 100644 starter-microservice-springboot-jdbc/repository/0.0.1/compile-pom.xml create mode 100644 starter-microservice-springboot-jdbc/repository/0.0.1/provided-pom.xml create mode 100644 starter-microservice-springboot-jdbc/repository/0.0.1/runtime-pom.xml create mode 100644 starter-microservice-springboot-jdbc/src/main/java/com/ibm/liberty/starter/service/springboot/api/TechnologyAPI.java create mode 100644 starter-microservice-springboot-jdbc/src/main/java/com/ibm/liberty/starter/service/springboot/api/v1/ProviderEndpoint.java create mode 100644 starter-microservice-springboot-jdbc/src/main/webapp/.gitignore create mode 100644 starter-microservice-springboot-jdbc/src/main/webapp/META-INF/.gitignore create mode 100644 starter-microservice-springboot-jdbc/src/main/webapp/WEB-INF/classes/.gitignore create mode 100644 starter-microservice-springboot-jdbc/src/main/webapp/WEB-INF/classes/description.html create mode 100644 starter-microservice-springboot-jdbc/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/Application.java create mode 100644 starter-microservice-springboot-jdbc/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jdbc/Customer.java create mode 100644 starter-microservice-springboot-jdbc/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jdbc/JDBCController.java create mode 100644 starter-microservice-springboot-jdbc/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/jdbc/HelloControllerTest.java create mode 100644 starter-microservice-springboot-jdbc/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/EndpointTest.java create mode 100644 starter-microservice-springboot-jdbc/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/TestApplication.java diff --git a/README.md b/README.md index e69af15..4a024e8 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,9 @@ Inside the application project there is a application.servlet package containing For the complete feature documentation, see the servlet-3.1 feature description in IBM Knowledge Center. ## Spring Boot with Spring MVC -This provides you with a SpringBoot application that will run on WebSphere Liberty. - +This project demonstrate a "hello world" web site with Spring technology and run on IBM WebSphere Liberty Server +Learn more about IBM WebSphere Liberty, visit https://developer.ibm.com/wasdev/ + Inside the application project there is a application.springboot.web package containing two classes: * Application: The entry point for the SpringBoot application. * LibertyHelloController: A Spring MVC endpoint which you can access at /springbootweb. @@ -32,7 +33,9 @@ Inside the wlpcfg project there is the it.springboot.web.HelloControllerTe For the complete feature documentation, see the Serving Web Content with Spring MVC ## Spring Boot with Jersey -This provides you with a SpringBoot application that will run on WebSphere Liberty. +This project demonstrate creating a "hello world" RESTful web service with Spring technology and run on IBM WebSphere Liberty Server +Learn more about IBM WebSphere Liberty, visit https://developer.ibm.com/wasdev/ + Inside the application project there is a application.springboot.jersey package containing 3 classes: * Application: The entry point for the SpringBoot application. @@ -44,8 +47,10 @@ Inside the wlpcfg project there is the it.springboot.jersey.SampleJerseyAp For the complete feature documentation, see the Building a RESTful Web Service ## Spring Boot with Security -This provides you with a SpringBoot application that will run on WebSphere Liberty. - +This project demonstrate creating a simple web application with resources that are protected by Spring Security and run on IBM WebSphere Liberty Server +Learn more about IBM WebSphere Liberty, visit https://developer.ibm.com/wasdev/ + + Inside the application project there is a application.springboot.security package containing 3 classes: * Application: The entry point for the SpringBoot application. * MvcConfig: Map each uri to static html resources @@ -55,6 +60,19 @@ Inside the wlpcfg project there is the it.springboot.security.HelloControl For the complete feature documentation, see the Securing a Web Application +## Spring Boot with JDBC +This project demonstrate how to accessing relational data with Spring technology and run on IBM WebSphere Liberty Server +Learn more about IBM WebSphere Liberty, visit https://developer.ibm.com/wasdev/ + +Inside the application project there is a application.springboot.jdbc package containing 3 classes: +* Application: The entry point for the SpringBoot application. +* Customer: POJO class for DB table +* JDBCController: A Springboot JDBC endpoint which implements the JDBC DB access + +Inside the wlpcfg project there is the it.springboot.jdbc.HelloControllerTest that will test the /springbootjdbc endpoint to ensure it is working. + +For the complete feature documentation, see the Accessing Relational Data using JDBC with Spring + ## Websockets This provides you with the websocket-1.1 feature. diff --git a/liberty-starter-application/build.gradle b/liberty-starter-application/build.gradle index 0846925..93be9e6 100644 --- a/liberty-starter-application/build.gradle +++ b/liberty-starter-application/build.gradle @@ -108,7 +108,7 @@ liberty { } clean.dependsOn(':liberty-starter-wlpcfg:cleanServer') -war.dependsOn(':liberty-filter-application:publishWar', ':starter-microservice-test:publishTestWar', ':starter-microservice-web:publishWar', ':starter-microservice-persistence:publishWar', ':starter-microservice-rest:publishWar', ':starter-microservice-websocket:publishWar', ':starter-microservice-springboot-web:publishWar', ':starter-microservice-springboot-jersey:publishWar', ':starter-microservice-springboot-security:publishWar', ':starter-microservice-watsonsdk:publishWar', 'compressSkeletonBuildImage', 'copySpecialFiles', 'createSwaggerJSON') +war.dependsOn(':liberty-filter-application:publishWar', ':starter-microservice-test:publishTestWar', ':starter-microservice-web:publishWar', ':starter-microservice-persistence:publishWar', ':starter-microservice-rest:publishWar', ':starter-microservice-websocket:publishWar', ':starter-microservice-springboot-web:publishWar', ':starter-microservice-springboot-jersey:publishWar', ':starter-microservice-springboot-security:publishWar',':starter-microservice-springboot-jdbc:publishWar', ':starter-microservice-watsonsdk:publishWar', 'compressSkeletonBuildImage', 'copySpecialFiles', 'createSwaggerJSON') installFeature.dependsOn('installLiberty') libertyStart.dependsOn('installFeature', 'addServerEnv', 'publishWar') fvt.dependsOn('libertyStart', 'testClasses') diff --git a/liberty-starter-application/src/main/resources/services.json b/liberty-starter-application/src/main/resources/services.json index 50b60c9..12f26e6 100644 --- a/liberty-starter-application/src/main/resources/services.json +++ b/liberty-starter-application/src/main/resources/services.json @@ -42,6 +42,13 @@ "description": "Spring Boot with Security", "endpoint" : "/springbootsecurity" }, + { + "id": "springbootjdbc", + "name": "Spring Boot with JDBC", + "description": "Spring Boot with JDBC", + "endpoint" : "/springbootjdbc" + }, + { "id": "watsonsdk", "name": "Watson SDK", diff --git a/liberty-starter-wlpcfg/servers/StarterServer/server.xml b/liberty-starter-wlpcfg/servers/StarterServer/server.xml index bae7287..d9e8149 100644 --- a/liberty-starter-wlpcfg/servers/StarterServer/server.xml +++ b/liberty-starter-wlpcfg/servers/StarterServer/server.xml @@ -41,4 +41,6 @@ + + \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 1c2ec54..9835b3f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -22,4 +22,4 @@ include 'services:webservice' */ rootProject.name = 'LibertyUserExperience' -include 'liberty-starter-wlpcfg', 'liberty-filter-application', 'liberty-starter-application', 'starter-microservice-test', 'starter-microservice-web', 'starter-microservice-persistence', 'starter-microservice-rest', 'starter-microservice-websocket', 'starter-microservice-watsonsdk', 'starter-microservice-springboot-web', 'starter-microservice-springboot-jersey', 'starter-microservice-springboot-security', 'liberty-starter-model', 'liberty-starter-common' +include 'liberty-starter-wlpcfg', 'liberty-filter-application', 'liberty-starter-application', 'starter-microservice-test', 'starter-microservice-web', 'starter-microservice-persistence', 'starter-microservice-rest', 'starter-microservice-websocket', 'starter-microservice-watsonsdk', 'starter-microservice-springboot-web', 'starter-microservice-springboot-jersey', 'starter-microservice-springboot-security','starter-microservice-springboot-jdbc', 'liberty-starter-model', 'liberty-starter-common' diff --git a/starter-microservice-springboot-jdbc/.gitignore b/starter-microservice-springboot-jdbc/.gitignore new file mode 100644 index 0000000..5854a45 --- /dev/null +++ b/starter-microservice-springboot-jdbc/.gitignore @@ -0,0 +1,6 @@ +/target +/build +/.settings +/.classpath +/.project +/bin diff --git a/starter-microservice-springboot-jdbc/build.gradle b/starter-microservice-springboot-jdbc/build.gradle new file mode 100644 index 0000000..6a48f5e --- /dev/null +++ b/starter-microservice-springboot-jdbc/build.gradle @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +apply from: '../common-java.gradle' +apply from: '../common-war.gradle' + +import com.ibm.liberty.starter.gradle.MavenTask +import com.ibm.liberty.starter.gradle.FvtTask + +dependencies { + providedCompile group:'javax.ws.rs', name:'javax.ws.rs-api', version: '2.0' + providedCompile group:'javax.json', name:'javax.json-api', version:'1.0' +} + +buildutils { + contextRoot = '/springbootjdbc' +} + +task installAllPOMs(type: MavenTask) { + id 'springbootjdbc' + hasProvided true + hasRuntime true + hasCompile true +} + +task fvt(type: FvtTask) { + id 'starter-microservice-springboot-jdbc' + finalizedBy libertyStop +} + +apply from: '../tech-type-task-graph.gradle' diff --git a/starter-microservice-springboot-jdbc/repository/0.0.1/compile-pom.xml b/starter-microservice-springboot-jdbc/repository/0.0.1/compile-pom.xml new file mode 100644 index 0000000..5ec8134 --- /dev/null +++ b/starter-microservice-springboot-jdbc/repository/0.0.1/compile-pom.xml @@ -0,0 +1,49 @@ + + 4.0.0 + + net.wasdev.wlp.starters.springbootjdbc + compile-pom + 0.0.1 + + compile-pom + + + + The Apache Software License, Version 2.0 + https://raw.github.com/WASdev/tool.artisan.core/master/LICENSE + repo + + + + + scm:git:git@github.com:WASdev/tool.artisan.core.git + scm:git@github.com:WASdev/tool.artisan.core.git + git@github.com:WASdev/tool.artisan.core.git + + + + + org.springframework.boot + spring-boot-starter-web + 1.3.5.RELEASE + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + + org.springframework + spring-jdbc + 4.2.6.RELEASE + + + org.apache.derby + derby + 10.12.1.1 + + + \ No newline at end of file diff --git a/starter-microservice-springboot-jdbc/repository/0.0.1/provided-pom.xml b/starter-microservice-springboot-jdbc/repository/0.0.1/provided-pom.xml new file mode 100644 index 0000000..ab69f6f --- /dev/null +++ b/starter-microservice-springboot-jdbc/repository/0.0.1/provided-pom.xml @@ -0,0 +1,46 @@ + + 4.0.0 + + net.wasdev.wlp.starters.springbootjdbc + provided-pom + 0.0.1 + + provided-pom + + + + The Apache Software License, Version 2.0 + https://raw.github.com/WASdev/tool.artisan.core/master/LICENSE + repo + + + + + scm:git:git@github.com:WASdev/tool.artisan.core.git + scm:git@github.com:WASdev/tool.artisan.core.git + git@github.com:WASdev/tool.artisan.core.git + + + + + ibm-maven-repo + ibm-maven-repo + https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/maven/repository/ + + + + + + javax.servlet + javax.servlet-api + 3.1.0 + + + com.ibm.websphere.appserver.api + com.ibm.websphere.appserver.api.servlet + 1.0.10 + + + + \ No newline at end of file diff --git a/starter-microservice-springboot-jdbc/repository/0.0.1/runtime-pom.xml b/starter-microservice-springboot-jdbc/repository/0.0.1/runtime-pom.xml new file mode 100644 index 0000000..675245d --- /dev/null +++ b/starter-microservice-springboot-jdbc/repository/0.0.1/runtime-pom.xml @@ -0,0 +1,34 @@ + + 4.0.0 + + net.wasdev.wlp.starters.springbootjdbc + runtime-pom + 0.0.1 + + runtime-pom + + + + The Apache Software License, Version 2.0 + https://raw.github.com/WASdev/tool.artisan.core/master/LICENSE + repo + + + + + scm:git:git@github.com:WASdev/tool.artisan.core.git + scm:git@github.com:WASdev/tool.artisan.core.git + git@github.com:WASdev/tool.artisan.core.git + + + + + net.wasdev.wlp.starters.web + server-snippet + xml + 0.0.1 + + + + \ No newline at end of file diff --git a/starter-microservice-springboot-jdbc/src/main/java/com/ibm/liberty/starter/service/springboot/api/TechnologyAPI.java b/starter-microservice-springboot-jdbc/src/main/java/com/ibm/liberty/starter/service/springboot/api/TechnologyAPI.java new file mode 100644 index 0000000..082b598 --- /dev/null +++ b/starter-microservice-springboot-jdbc/src/main/java/com/ibm/liberty/starter/service/springboot/api/TechnologyAPI.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +package com.ibm.liberty.starter.service.springboot.api; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +@ApplicationPath("api") +public class TechnologyAPI extends Application { + + +} diff --git a/starter-microservice-springboot-jdbc/src/main/java/com/ibm/liberty/starter/service/springboot/api/v1/ProviderEndpoint.java b/starter-microservice-springboot-jdbc/src/main/java/com/ibm/liberty/starter/service/springboot/api/v1/ProviderEndpoint.java new file mode 100644 index 0000000..f501f79 --- /dev/null +++ b/starter-microservice-springboot-jdbc/src/main/java/com/ibm/liberty/starter/service/springboot/api/v1/ProviderEndpoint.java @@ -0,0 +1,117 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +package com.ibm.liberty.starter.service.springboot.api.v1; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +import com.ibm.liberty.starter.api.v1.model.provider.Dependency; +import com.ibm.liberty.starter.api.v1.model.provider.Dependency.Scope; +import com.ibm.liberty.starter.api.v1.model.provider.Location; +import com.ibm.liberty.starter.api.v1.model.provider.Provider; +import com.ibm.liberty.starter.api.v1.model.provider.ServerConfig; +import com.ibm.liberty.starter.api.v1.model.provider.Tag; + +@Path("v1/provider") +public class ProviderEndpoint { + + private static final String DEPENDENCY_URL = "http://localhost:9082/springboot/artifacts/net/wasdev/wlp/starters/springboot/jdbc"; + + @GET + @Path("/") + @Produces(MediaType.APPLICATION_JSON) + public Provider details(@Context UriInfo info) { + Provider details = new Provider(); + String description = getStringResource("/description.html"); + details.setDescription(description); + + Location repoLocation = new Location(); + String url = info.getBaseUri().resolve("../artifacts").toString(); + repoLocation.setUrl(url); + details.setRepoUrl(repoLocation); + Dependency providedDependency = new Dependency(); + providedDependency.setScope(Scope.PROVIDED); + providedDependency.setGroupId("net.wasdev.wlp.starters.springbootjdbc"); + providedDependency.setArtifactId("provided-pom"); + providedDependency.setVersion("0.0.1"); + + Dependency runtimeDependency = new Dependency(); + runtimeDependency.setScope(Scope.RUNTIME); + runtimeDependency.setGroupId("net.wasdev.wlp.starters.springbootjdbc"); + runtimeDependency.setArtifactId("runtime-pom"); + runtimeDependency.setVersion("0.0.1"); + + Dependency compileDependency = new Dependency(); + compileDependency.setScope(Scope.COMPILE); + compileDependency.setGroupId("net.wasdev.wlp.starters.springbootjdbc"); + compileDependency.setArtifactId("compile-pom"); + compileDependency.setVersion("0.0.1"); + + Dependency[] dependencies = {providedDependency, runtimeDependency, compileDependency}; + details.setDependencies(dependencies); + return details; + } + + //read the description contained in the index.html file + private String getStringResource(String path) { + InputStream in = getClass().getResourceAsStream(path); + + StringBuilder index = new StringBuilder(); + char[] buffer = new char[1024]; + int read = 0; + try(InputStreamReader reader = new InputStreamReader(in)){ + while((read = reader.read(buffer)) != -1) { + index.append(buffer, 0, read); + } + } catch (IOException e) { + //just return what we've got + return index.toString(); + } + return index.toString(); + } + + @GET + @Path("samples") + @Produces(MediaType.APPLICATION_JSON) + public Response constructSample(@Context UriInfo info) { + StringBuilder json = new StringBuilder("{\n"); + String base = info.getBaseUri().resolve("../sample").toString(); + json.append("\"base\" : \"" + base + "\",\n"); + json.append(getStringResource("/locations.json")); + json.append("}\n"); + return Response.ok(json.toString()).build(); + } + + @GET + @Path("config") + @Produces(MediaType.APPLICATION_JSON) + public ServerConfig getServerConfig() throws Exception { + ServerConfig config = new ServerConfig(); + Tag[] tags = new Tag[]{new Tag("featureManager")}; + tags[0].setTags(new Tag[]{new Tag("feature", "websocket-1.1")}); + config.setTags(tags); + return config; + } +} \ No newline at end of file diff --git a/starter-microservice-springboot-jdbc/src/main/webapp/.gitignore b/starter-microservice-springboot-jdbc/src/main/webapp/.gitignore new file mode 100644 index 0000000..5d43caf --- /dev/null +++ b/starter-microservice-springboot-jdbc/src/main/webapp/.gitignore @@ -0,0 +1 @@ +/artifacts diff --git a/starter-microservice-springboot-jdbc/src/main/webapp/META-INF/.gitignore b/starter-microservice-springboot-jdbc/src/main/webapp/META-INF/.gitignore new file mode 100644 index 0000000..f67faf7 --- /dev/null +++ b/starter-microservice-springboot-jdbc/src/main/webapp/META-INF/.gitignore @@ -0,0 +1 @@ +/swagger.json diff --git a/starter-microservice-springboot-jdbc/src/main/webapp/WEB-INF/classes/.gitignore b/starter-microservice-springboot-jdbc/src/main/webapp/WEB-INF/classes/.gitignore new file mode 100644 index 0000000..5342fdc --- /dev/null +++ b/starter-microservice-springboot-jdbc/src/main/webapp/WEB-INF/classes/.gitignore @@ -0,0 +1 @@ +/locations.json diff --git a/starter-microservice-springboot-jdbc/src/main/webapp/WEB-INF/classes/description.html b/starter-microservice-springboot-jdbc/src/main/webapp/WEB-INF/classes/description.html new file mode 100644 index 0000000..0a54d62 --- /dev/null +++ b/starter-microservice-springboot-jdbc/src/main/webapp/WEB-INF/classes/description.html @@ -0,0 +1,27 @@ + +
+

Spring Boot with JDBC

+

This project demonstrate how to accessing relational data with Spring technology and run on IBM WebSphere Liberty Server

+

Learn more about IBM WebSphere Liberty, visit https://developer.ibm.com/wasdev/

+

Inside the application project contains three classes:

+
    +
  • application.springboot.Application: The entry point for the SpringBoot application
  • +
  • application.springboot.jdbc.JDBCController: A Springboot JDBC endpoint which you can access at /springbootjdbc
  • +
  • application.springboot.jdbc.Customer: POJO class for DB table
  • +
+

Inside the wlpcfg project there is the it.springboot.jdbc.HelloControllerTest that will test the Springboot jdbc endpoint to ensure it is working.

+
diff --git a/starter-microservice-springboot-jdbc/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/Application.java b/starter-microservice-springboot-jdbc/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/Application.java new file mode 100644 index 0000000..4c77aa6 --- /dev/null +++ b/starter-microservice-springboot-jdbc/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/Application.java @@ -0,0 +1,19 @@ +package application.springboot; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.context.web.SpringBootServletInitializer; + +@SpringBootApplication +public class Application extends SpringBootServletInitializer{ + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(Application.class); + } + + public static void main(String[] args) throws Throwable { + SpringApplication.run(Application.class, args); + } +} diff --git a/starter-microservice-springboot-jdbc/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jdbc/Customer.java b/starter-microservice-springboot-jdbc/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jdbc/Customer.java new file mode 100644 index 0000000..5003274 --- /dev/null +++ b/starter-microservice-springboot-jdbc/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jdbc/Customer.java @@ -0,0 +1,22 @@ +package application.springboot.jdbc; + +public class Customer { + private long id; + private String firstName, lastName; + + public Customer(long id, String firstName, String lastName) { + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + } + + @Override + public String toString() { + return String.format( + "Customer[id=%d, firstName='%s', lastName='%s']", + id, firstName, lastName); + } + + // getters & setters omitted for brevity +} + diff --git a/starter-microservice-springboot-jdbc/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jdbc/JDBCController.java b/starter-microservice-springboot-jdbc/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jdbc/JDBCController.java new file mode 100644 index 0000000..e663126 --- /dev/null +++ b/starter-microservice-springboot-jdbc/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jdbc/JDBCController.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +package application.springboot.jdbc; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.jdbc.core.RowMapperResultSetExtractor; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class JDBCController { + @Autowired + JdbcTemplate jdbcTemplate; + + @RequestMapping("/springbootjdbc") + public String executeJDBC() { + try { + String result = "Welcome to Springboot JDBC running on Liberty!
splitUpNames = new ArrayList(); + String[] names = new String[] { "John Woo", "Jeff Dean", "Josh Bloch", "Josh Long" }; + + for (String name : names) { + splitUpNames.add(name.split(" ")); + } + + for (Object[] obj : splitUpNames) { + result += String.format("Inserting customer record for %s %s
", obj[0], obj[1]); + } + + // Uses JdbcTemplate's batchUpdate operation to bulk load data + jdbcTemplate.batchUpdate("INSERT INTO customers(first_name, last_name) VALUES (?,?)", splitUpNames); + + result += "
Querying for customer records where first_name = 'Josh':
"; + + @SuppressWarnings({ "unchecked", "rawtypes" }) + List cusList = (List) jdbcTemplate.query( + "SELECT id, first_name, last_name FROM customers WHERE first_name = ?", new Object[] { "Josh" }, + new RowMapperResultSetExtractor(new RowMapper() { + public Object mapRow(ResultSet rs, int index) throws SQLException { + Customer c = new Customer(rs.getLong("id"), rs.getString("first_name"), + rs.getString("last_name")); + + return c; + } + })); + + for (Customer cus : cusList) { + result += cus.toString() + "
"; + } + + // Clear environment for next execution + jdbcTemplate.execute("DROP TABLE customers"); + jdbcTemplate.execute("DROP SCHEMA sa RESTRICT"); + return result; + } catch (Exception e) { + e.printStackTrace(); + return "Error happened during JDBC execution"; + } + } +} \ No newline at end of file diff --git a/starter-microservice-springboot-jdbc/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/jdbc/HelloControllerTest.java b/starter-microservice-springboot-jdbc/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/jdbc/HelloControllerTest.java new file mode 100644 index 0000000..9b1953e --- /dev/null +++ b/starter-microservice-springboot-jdbc/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/jdbc/HelloControllerTest.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +package it.springboot.jdbc; + +import static org.junit.Assert.assertTrue; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Invocation; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Response; +import it.EndpointTest; + +import org.junit.Test; + +public class HelloControllerTest extends EndpointTest { + + + @Test + public void testDeployment() { + testEndpoint("/springbootjdbc", "Welcome to Springboot JDBC running on Liberty!"); + } +} \ No newline at end of file diff --git a/starter-microservice-springboot-jdbc/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/EndpointTest.java b/starter-microservice-springboot-jdbc/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/EndpointTest.java new file mode 100644 index 0000000..02f80bd --- /dev/null +++ b/starter-microservice-springboot-jdbc/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/EndpointTest.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +package com.ibm.liberty.starter.service.springboot.api.v1.it; + +import static org.junit.Assert.assertTrue; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Invocation; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Response; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class EndpointTest { + + //use this to give the REST endpoint a chance to come up after the server has reported it's started + public void checkAvailability(String endpoint) { + String ep = getEndPoint(endpoint); + for(int x = 0; x < 3; x++) { + Response response = null; + try { + response = sendRequest(ep, "GET"); + if(response.getStatus() == 200) { + return; + } + } finally { + if(response != null) { + response.close(); + } + } + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + //just exit + } + } + } + + private String getEndPoint(String endpoint) { + String port = System.getProperty("liberty.test.port"); + String war = System.getProperty("war.name"); + return "http://localhost:" + port + "/" + war + endpoint; + } + + @SuppressWarnings("unchecked") + public T testEndpoint(String endpoint, Class entity) throws Exception { + String url = getEndPoint(endpoint); + System.out.println("Testing " + url); + Response response = null; + try { + response = sendRequest(url, "GET"); + int responseCode = response.getStatus(); + assertTrue("Incorrect response code for " + url + ": " + responseCode, + responseCode == 200); + String json = response.readEntity(String.class); + ObjectMapper mapper = new ObjectMapper(); + return (T) mapper.readValue(json, entity); + } finally { + if(response != null) { + response.close(); + } + } + } + + public Response sendRequest(String url, String requestType) { + Client client = ClientBuilder.newClient(); + System.out.println("Testing " + url); + WebTarget target = client.target(url); + Invocation.Builder invoBuild = target.request(); + Response response = invoBuild.build(requestType).invoke(); + return response; + } +} diff --git a/starter-microservice-springboot-jdbc/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/TestApplication.java b/starter-microservice-springboot-jdbc/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/TestApplication.java new file mode 100644 index 0000000..e20a8fd --- /dev/null +++ b/starter-microservice-springboot-jdbc/src/test/java/com/ibm/liberty/starter/service/springboot/api/v1/it/TestApplication.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +package com.ibm.liberty.starter.service.springboot.api.v1.it; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +import com.ibm.liberty.starter.api.v1.model.provider.Dependency; +import com.ibm.liberty.starter.api.v1.model.provider.Provider; +import com.ibm.liberty.starter.api.v1.model.provider.Sample; +import com.ibm.liberty.starter.api.v1.model.provider.ServerConfig; + +/** + * Test the deployed service responds as expected + * + */ +public class TestApplication extends EndpointTest { + + @Before + public void checkSetup() { + checkAvailability("/api/v1/provider/"); + } + + @Test + public void testProvider() throws Exception { + Provider provider = testEndpoint("/api/v1/provider/", Provider.class); + assertNotNull("No response from API for provider", provider); + assertTrue("Description was not found.", provider.getDescription().contains("

Spring Boot with JDBC

")); + Dependency[] dependencies = provider.getDependencies(); + boolean providedDependency = false; + boolean runtimeDependency = false; + boolean compileDependency = false; + for (Dependency dependency : dependencies) { + if (Dependency.Scope.PROVIDED.equals(dependency.getScope())) { + assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springbootjdbc".equals(dependency.getGroupId())); + assertTrue("artifactId incorrect.", "provided-pom".equals(dependency.getArtifactId())); + assertTrue("version incorrect.", "0.0.1".equals(dependency.getVersion())); + providedDependency = true; + } + if (Dependency.Scope.RUNTIME.equals(dependency.getScope())) { + assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springbootjdbc".equals(dependency.getGroupId())); + assertTrue("artifactId incorrect.", "runtime-pom".equals(dependency.getArtifactId())); + assertTrue("version incorrect.", "0.0.1".equals(dependency.getVersion())); + runtimeDependency = true; + } + if (Dependency.Scope.COMPILE.equals(dependency.getScope())) { + assertTrue("groupId incorrect.", "net.wasdev.wlp.starters.springbootjdbc".equals(dependency.getGroupId())); + assertTrue("artifactId incorrect.", "compile-pom".equals(dependency.getArtifactId())); + assertTrue("version incorrect.", "0.0.1".equals(dependency.getVersion())); + compileDependency = true; + } + } + assertTrue("Provided dependencies weren't specified.", providedDependency); + assertTrue("Runtime dependencies weren't specified.", runtimeDependency); + assertTrue("Compile dependencies weren't specified.", compileDependency); + } + + @Test + public void testConfig() throws Exception { + ServerConfig config = testEndpoint("/api/v1/provider/config", ServerConfig.class); + assertNotNull("No response from API for configuration", config); + String actual = config.getTags()[0].getTags()[0].getValue(); + String expected = "websocket-1.1"; + assertEquals("Incorrect feature specified", expected , actual); + } + + @Test + public void testSamples() throws Exception { + Sample sample = testEndpoint("/api/v1/provider/samples", Sample.class); + assertNotNull("No response from API for sample", sample); + assertNotNull("Expected locations", sample.getLocations()); + assertEquals("No files were expected for sample", 4, sample.getLocations().length); + } + +} diff --git a/starter-microservice-springboot-jersey/.gitignore b/starter-microservice-springboot-jersey/.gitignore index f5d14ab..5854a45 100644 --- a/starter-microservice-springboot-jersey/.gitignore +++ b/starter-microservice-springboot-jersey/.gitignore @@ -1,5 +1,4 @@ /target -/pom.xml /build /.settings /.classpath diff --git a/starter-microservice-springboot-jersey/repository/0.0.1/compile-pom.xml b/starter-microservice-springboot-jersey/repository/0.0.1/compile-pom.xml index d32de8f..554810d 100644 --- a/starter-microservice-springboot-jersey/repository/0.0.1/compile-pom.xml +++ b/starter-microservice-springboot-jersey/repository/0.0.1/compile-pom.xml @@ -26,7 +26,7 @@ org.springframework.boot spring-boot-starter-jersey - 1.3.0.RELEASE + 1.3.5.RELEASE org.springframework.boot diff --git a/starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/description.html b/starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/description.html index 32ee210..9f17f14 100644 --- a/starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/description.html +++ b/starter-microservice-springboot-jersey/src/main/webapp/WEB-INF/classes/description.html @@ -15,12 +15,13 @@ -->

Spring Boot with Jersey

-

Inside the application project there is a application.springboot.jersey package - containing 3 classes:

+

This project demonstrate creating a "hello world" RESTful web service with Spring technology and run on IBM WebSphere Liberty Server

+

Learn more about IBM WebSphere Liberty, visit https://developer.ibm.com/wasdev/

+

Inside the application project contains three classes:

    -
  • Application: The entry point for the SpringBoot application
  • -
  • JerseyConfig: Configuration for Jersey
  • -
  • Endpoint: A Spring Jersey endpoint which you can access at /springbootjersey
  • +
  • application.springboot.Application: The entry point for the SpringBoot application
  • +
  • application.springboot.jersey.JerseyConfig: Configuration for Jersey
  • +
  • application.springboot.jersey.Endpoint: A Spring Jersey endpoint which you can access at /springbootjersey

Inside the wlpcfg project there is the it.springboot.jersey.SampleJerseyApplicationTests that will test the Spring Jersey endpoint to ensure it is working.

diff --git a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Endpoint.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Endpoint.java index 645c7a4..2ac4891 100644 --- a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Endpoint.java +++ b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/Endpoint.java @@ -36,6 +36,6 @@ public Endpoint(ObjectMapper objectMapper) { @GET public String message() { - return "Hello World"; + return "Hello from the SpringBoot Jersey endpoint!"; } } diff --git a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/JerseyConfig.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/JerseyConfig.java index b52c976..37e4189 100644 --- a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/JerseyConfig.java +++ b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-application/src/main/java/application/springboot/jersey/JerseyConfig.java @@ -23,7 +23,7 @@ import org.springframework.stereotype.Component; @Component -@ApplicationPath("/springbootjersey/") +@ApplicationPath("/springbootjersey") public class JerseyConfig extends ResourceConfig { public JerseyConfig() { diff --git a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/jersey/SampleJerseyApplicationTests.java b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/jersey/SampleJerseyApplicationTests.java index 6ded3eb..bd9f928 100644 --- a/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/jersey/SampleJerseyApplicationTests.java +++ b/starter-microservice-springboot-jersey/src/main/webapp/sample/myProject-wlpcfg/src/test/java/it/springboot/jersey/SampleJerseyApplicationTests.java @@ -30,6 +30,6 @@ public class SampleJerseyApplicationTests extends EndpointTest { @Test public void testJerseyApplication() { - testEndpoint("/springbootjersey", "Hello World"); + testEndpoint("/springbootjersey", "Hello from the SpringBoot Jersey endpoint!"); } } diff --git a/starter-microservice-springboot-security/.gitignore b/starter-microservice-springboot-security/.gitignore index f5d14ab..5854a45 100644 --- a/starter-microservice-springboot-security/.gitignore +++ b/starter-microservice-springboot-security/.gitignore @@ -1,5 +1,4 @@ /target -/pom.xml /build /.settings /.classpath diff --git a/starter-microservice-springboot-security/repository/0.0.1/compile-pom.xml b/starter-microservice-springboot-security/repository/0.0.1/compile-pom.xml index ed84603..1132144 100644 --- a/starter-microservice-springboot-security/repository/0.0.1/compile-pom.xml +++ b/starter-microservice-springboot-security/repository/0.0.1/compile-pom.xml @@ -23,29 +23,10 @@ - - - - - org.springframework.boot - spring-boot-starter-thymeleaf - 1.3.0.RELEASE - - org.springframework.boot - spring-boot-starter-security - 1.3.0.RELEASE + spring-boot-starter-thymeleaf + 1.3.5.RELEASE org.springframework.boot @@ -54,6 +35,17 @@ + + org.springframework.boot + spring-boot-starter-security + 1.3.5.RELEASE + + + org.springframework.boot + spring-boot-starter-tomcat + + + \ No newline at end of file diff --git a/starter-microservice-springboot-security/src/main/webapp/WEB-INF/classes/description.html b/starter-microservice-springboot-security/src/main/webapp/WEB-INF/classes/description.html index d11117d..590b679 100644 --- a/starter-microservice-springboot-security/src/main/webapp/WEB-INF/classes/description.html +++ b/starter-microservice-springboot-security/src/main/webapp/WEB-INF/classes/description.html @@ -15,12 +15,13 @@ -->

Spring Boot with Security

-

Inside the application project there is a application.springboot.security package - containing three classes:

+

This project demonstrate creating a simple web application with resources that are protected by Spring Security and run on IBM WebSphere Liberty Server

+

Learn more about IBM WebSphere Liberty, visit https://developer.ibm.com/wasdev/

+

Inside the application project contains three classes:

    -
  • Application: The entry point for the SpringBoot application
  • -
  • MvcConfig: Config url mapping to static html page
  • -
  • WebSecurityConfig: Config security setting for application
  • +
  • application.springboot.Application: The entry point for the SpringBoot application
  • +
  • application.springboot.security.MvcConfig: Config url mapping to static html page
  • +
  • application.springboot.security.WebSecurityConfig: Config security setting for application
  • View how application work at:/springbootsecurity

Inside the wlpcfg project there is the it.springboot.security.HelloControllerTest that will test the Springboot security endpoint to ensure it is working.

diff --git a/starter-microservice-springboot-web/.gitignore b/starter-microservice-springboot-web/.gitignore index f5d14ab..5854a45 100644 --- a/starter-microservice-springboot-web/.gitignore +++ b/starter-microservice-springboot-web/.gitignore @@ -1,5 +1,4 @@ /target -/pom.xml /build /.settings /.classpath diff --git a/starter-microservice-springboot-web/repository/0.0.1/compile-pom.xml b/starter-microservice-springboot-web/repository/0.0.1/compile-pom.xml index 9367247..b5316ce 100644 --- a/starter-microservice-springboot-web/repository/0.0.1/compile-pom.xml +++ b/starter-microservice-springboot-web/repository/0.0.1/compile-pom.xml @@ -26,7 +26,7 @@ org.springframework.boot spring-boot-starter-web - 1.3.0.RELEASE + 1.3.5.RELEASE org.springframework.boot diff --git a/starter-microservice-springboot-web/src/main/webapp/WEB-INF/classes/description.html b/starter-microservice-springboot-web/src/main/webapp/WEB-INF/classes/description.html index bf62063..25340f8 100644 --- a/starter-microservice-springboot-web/src/main/webapp/WEB-INF/classes/description.html +++ b/starter-microservice-springboot-web/src/main/webapp/WEB-INF/classes/description.html @@ -15,11 +15,12 @@ -->

Spring Boot with Spring MVC

-

Inside the application project there is a application.springboot.web package - containing two classes:

+

This project demonstrate a "hello world" web site with Spring technology and run on IBM WebSphere Liberty Server

+

Learn more about IBM WebSphere Liberty, visit https://developer.ibm.com/wasdev/

+

Inside the application project contains two classes:

    -
  • Application: The entry point for the SpringBoot application
  • -
  • LibertyHelloController: A Spring MVC endpoint which you can access at /springbootweb
  • +
  • application.springboot.Application: The entry point for the SpringBoot application
  • +
  • application.springboot.web.LibertyHelloController: A Spring MVC endpoint which you can access at /springbootweb

Inside the wlpcfg project there is the it.springboot.web.HelloControllerTest that will test the Spring MVC endpoint to ensure it is working.

From fa103314834eb00f0457776b7b8ac54170980c6c Mon Sep 17 00:00:00 2001 From: qiaoxi Date: Mon, 20 Jun 2016 13:43:02 +0800 Subject: [PATCH 10/13] Update README.md file for description --- README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 4a024e8..56bd07b 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,9 @@ For the complete feature documentation, see the https://developer.ibm.com/wasdev/ -Inside the application project there is a application.springboot.web package containing two classes: -* Application: The entry point for the SpringBoot application. -* LibertyHelloController: A Spring MVC endpoint which you can access at /springbootweb. +Inside the application project containing two classes: +* application.springboot.Application: The entry point for the SpringBoot application. +* application.springboot.web.LibertyHelloController: A Spring MVC endpoint which you can access at /springbootweb. Inside the wlpcfg project there is the it.springboot.web.HelloControllerTest that will test the Spring MVC endpoint to ensure it is working. For the complete feature documentation, see the Serving Web Content with Spring MVC @@ -37,10 +37,10 @@ This project demonstrate creating a "hello world" RESTful web service with Sprin Learn more about IBM WebSphere Liberty, visit https://developer.ibm.com/wasdev/ -Inside the application project there is a application.springboot.jersey package containing 3 classes: -* Application: The entry point for the SpringBoot application. -* Endpoint: A Jersey endpoint which you can access at /springbootjersey. -* JerseyConfig: Jersey configuration class. +Inside the application project containing 3 classes: +* application.springboot.Application: The entry point for the SpringBoot application. +* application.springboot.jersey.Endpoint: A Jersey endpoint which you can access at /springbootjersey. +* application.springboot.jersey.JerseyConfig: Jersey configuration class. Inside the wlpcfg project there is the it.springboot.jersey.SampleJerseyApplicationTests that will test the Jersey endpoint to ensure it is working. @@ -51,10 +51,10 @@ This project demonstrate creating a simple web application with resources that a Learn more about IBM WebSphere Liberty, visit https://developer.ibm.com/wasdev/ -Inside the application project there is a application.springboot.security package containing 3 classes: -* Application: The entry point for the SpringBoot application. -* MvcConfig: Map each uri to static html resources -* WebSecurityConfig: Seucirty configuration for Springboot application +Inside the application project containing 3 classes: +* application.springboot.Application: The entry point for the SpringBoot application. +* application.springboot.securityMvcConfig: Map each uri to static html resources +* application.springboot.security.WebSecurityConfig: Seucirty configuration for Springboot application Inside the wlpcfg project there is the it.springboot.security.HelloControllerTest that will test the /springbootsecurity endpoint to ensure it is working. @@ -64,10 +64,10 @@ For the complete feature documentation, see the https://developer.ibm.com/wasdev/ -Inside the application project there is a application.springboot.jdbc package containing 3 classes: -* Application: The entry point for the SpringBoot application. -* Customer: POJO class for DB table -* JDBCController: A Springboot JDBC endpoint which implements the JDBC DB access +Inside the application project containing 3 classes: +* application.springboot.Application: The entry point for the SpringBoot application. +* application.springboot.jdbc.Customer: POJO class for DB table +* application.springboot.jdbc.JDBCController: A Springboot JDBC endpoint which implements the JDBC DB access Inside the wlpcfg project there is the it.springboot.jdbc.HelloControllerTest that will test the /springbootjdbc endpoint to ensure it is working. From ce5f51520b78a729f0efab7482a1bf24fc429a79 Mon Sep 17 00:00:00 2001 From: qiaoxi Date: Mon, 20 Jun 2016 15:20:56 +0800 Subject: [PATCH 11/13] ignore security keys from project --- .../servers/StarterServer/resources/security/.gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 liberty-starter-wlpcfg/servers/StarterServer/resources/security/.gitignore diff --git a/liberty-starter-wlpcfg/servers/StarterServer/resources/security/.gitignore b/liberty-starter-wlpcfg/servers/StarterServer/resources/security/.gitignore new file mode 100644 index 0000000..14f955d --- /dev/null +++ b/liberty-starter-wlpcfg/servers/StarterServer/resources/security/.gitignore @@ -0,0 +1,2 @@ +/ltpa.keys +/key.jks \ No newline at end of file From 52ec9776f70eedf6115a9d792a8bd6aaf1a6fc42 Mon Sep 17 00:00:00 2001 From: qiaoxi Date: Mon, 20 Jun 2016 15:49:58 +0800 Subject: [PATCH 12/13] Remove security keys --- .../StarterServer/resources/security/key.jks | Bin 2169 -> 0 bytes .../StarterServer/resources/security/ltpa.keys | 8 -------- 2 files changed, 8 deletions(-) delete mode 100644 liberty-starter-wlpcfg/servers/StarterServer/resources/security/key.jks delete mode 100644 liberty-starter-wlpcfg/servers/StarterServer/resources/security/ltpa.keys diff --git a/liberty-starter-wlpcfg/servers/StarterServer/resources/security/key.jks b/liberty-starter-wlpcfg/servers/StarterServer/resources/security/key.jks deleted file mode 100644 index 996dcf21b325f6a06e8cc48e9aff7b1e43d2d671..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2169 zcmb`H=|9wq7suy2#@O8$rZQ$^EynU4yDX)_Om3F!>qHq#_OUNvhRBlaQfSa*X_5Gq zH8e=JYbhc^qYPfQA}Q(WKI#wnJva~E=gE1U&pEI6{_6fJ1OkB`6!2ehd5}Hb!~8-I z*rvi~6AyuKLO>d94-|y+V&MP`P=E>n04D@SgRw8j$=#)}7|hREmqo;>Jx8}^9j0Vv z25JB>JT_Z+Un2F_h^dD4er}5PW45cGFQ}Gqek}iTd2vAT#8s|Y2DxTMS=#{5Oj z>VC6^D;4vipo(UFt4RRn)Z_jowbRQJ(hs`z!l;Z4Lw>~hA{|Ny)FU1M<=cYcG~?kFcKz=bkQ;m#q$(*nOY<1rM7!GCBA-m%H1@RC~mC&|>kE z`D|?dulVOs9AfNx!KCu1f|47>&i9^ss^-KREqN3)+7vo%(vpT>%6sPSk(N?xNi0AQ5(liObfT42`QjRP<;1qn`A;DTX;^`eE#kJ6h`T4sr+>NJ-?W0kt-dg6?U_$%rhoj|5KPFz&Zr zYGs7xDlcqfZR9ci)=B33YwM-sxlBVzfi@+q*#_)uNV&r5S(V<~(OHYj0qrwp-=<{S zF-E8p(ReFDi$L?}$+sp3sywJT(dMrb<))sv0QClq^`$ENicxy*U98C#`pyh4=tr8_~Nthma94@Wy1 zrY*#Lm|i}U+-@;v@P8@eyDW60o>4vHq2se;kqPI`sg#!W*X0{O$>(j-W)N= z&B*Ve^iDIcmfHheq}zMhPsMuTRO08hWybc21(&TdRyK7$^b$9mFPNc1#|F#VYFF>7 z%rm~B3`B=C__a6q1R_I|2Z}cOXmxjt}I4bJ)V*2xwRcjvwUx4ZH{rpNsxD zBq;Km_z(itq3)DWGR2xq2`5uQJ$PD8vE42_EZ=*#CjBJ~9f0lFv z-L?-VBvqtfpgGA;AAY}MV;t2_l0B+3VQvw9)9WLJLgETKj=0c{wrmYR<1@qpW>?0mTD<9baB=o) zwEt-M4b2@P!mDZ@rguZ1gKc6RlmmbO6_TI?h(0(HS`dbWi7YGq8d#_^4+)E7xoPwN zEumTWZuQR)4?f`_L;ynYKnf?GK}6k34lg)a7CMq-qi2-#X{}H>wwK)$(Tza&UZI&! z_$S@8q3CYoQd7LX?>(mnE`%py(06)`Gwmh!IFZlnay`2Z$B}Jzf(m7q0+`KxdZ}EB z6MZ6=*?g{~+EINTkypL^>=J&X4`V?S{Ig)eyTmD#I`w)xUBzsh70(BD17}!8qFdEz zdWy~unbXIDH@LU0j1)~J8*Q=HrUQekceE>Ox{7P;kxmi!x7v3LnjY3?hqX+`VA+V> z5VzeE7a0Zkw2*~?4_0%GE!!Af?P3vxAwq78vZT|ve1jq0I diff --git a/liberty-starter-wlpcfg/servers/StarterServer/resources/security/ltpa.keys b/liberty-starter-wlpcfg/servers/StarterServer/resources/security/ltpa.keys deleted file mode 100644 index a885ece..0000000 --- a/liberty-starter-wlpcfg/servers/StarterServer/resources/security/ltpa.keys +++ /dev/null @@ -1,8 +0,0 @@ -#Thu May 12 13:21:50 CST 2016 -com.ibm.websphere.CreationDate=Thu May 12 13\:21\:50 CST 2016 -com.ibm.websphere.ltpa.version=1.0 -com.ibm.websphere.ltpa.3DESKey=/5lYlRUbtjnQsmnDuWcC5MXyJZ/0dNaj3/cGjIn+mR4\= -com.ibm.websphere.CreationHost=localhost -com.ibm.websphere.ltpa.PrivateKey=gNhxF0iXkTRpWYguRUEzivGiITbpefFvF9EXuoDPcfs7oCIWBJgzjE04IHULyHaXzDaSiGhN0n6StEyec/AdyhGGnS9+p/DmTmgliVq0jEwIVeJXYy4iurJt8u8S2AA6dQh+3Kkt8DPdJDQsxgsJeYt0P9EQpAvFCyRhqTfickd0gW3wQ7/gRHp3+44mj3ZXQf/lMaha5Zn7QyBTw1wMgEH+JqstyF4df73PGQhiyC2EBNmZ8rQmveZwEUYmRtYxS7xxUL1ZX+q8cIZ0ehJfEMWaKFqCs4amGLmt9Iynapgiwa6I7VqztuArTMwlsN4f+8satUK3i2DvXYDCapgIKyBp4lXenoG74Imnby8O3bE\= -com.ibm.websphere.ltpa.Realm=ibm/api -com.ibm.websphere.ltpa.PublicKey=ALnKghsaCBy3d3ctnHCKF3kAnDgJeFbor68DZpXEfmXk1YQ3WJxv+kV9pl/jVGCEHTCaEYqF9o2Uw4V/cIXSTAABW0dY16ocs4uueNWYm37NN6H/y5OQfRz/NSHh4md83a2K88FpEDbsrWm3sW21uvvImQvMbjlCbmniG77m9cDPAQAB From a2606b5426aeb16f80a54db87ed3247086818003 Mon Sep 17 00:00:00 2001 From: qiaoxi Date: Tue, 21 Jun 2016 16:45:55 +0800 Subject: [PATCH 13/13] Commit with Jordan's UI enhancement: mark conflict features --- .../src/main/resources/services.json | 19 +++++----- .../src/main/webapp/css/style.css | 15 ++++++++ .../src/main/webapp/js/logic.js | 36 ++++++++++++++++++- 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/liberty-starter-application/src/main/resources/services.json b/liberty-starter-application/src/main/resources/services.json index 12f26e6..a91030d 100644 --- a/liberty-starter-application/src/main/resources/services.json +++ b/liberty-starter-application/src/main/resources/services.json @@ -3,52 +3,51 @@ { "id" : "rest", "name" : "REST", - "description" : "JAX-RS implementation", + "description" : "REST technology allows to create a simple JAX-RS application by using Liberty jaxrs-2.0 feature. \nNotice that REST technology cannot co-exist with Spring Boot with Jersey technology.", "endpoint" : "/rest" }, { "id" : "websocket", "name" : "Web Sockets", - "description" : "WebSocket implementation", + "description" : "Web Sockets technology allows to create a simple WebSocket application by using Liberty websocket-1.1 feature.", "endpoint" : "/websocket" }, { "id" : "persistence", "name" : "Persistence", - "description" : "JPA data persistence", + "description" : "Persistence technology allows to create a simple JPA data persistence application by using Liberty jpa-2.1 feature.", "endpoint" : "/persistence" }, { "id": "web", "name" : "Servlet", - "description": "Servlet 3.1", + "description": "Servlet technology allows to create a simple Servlet 3.1 application by using Liberty servlet-3.1 feature.", "endpoint" : "/web" }, { "id": "springbootweb", "name": "Spring Boot with Spring MVC", - "description": "Spring Boot with Spring MVC", + "description": "Spring Boot with Spring MVC technology allows to create a hello world web application with SpringBoot MVC.", "endpoint" : "/springbootweb" }, { "id": "springbootjersey", "name": "Spring Boot with Jersey", - "description": "Spring Boot with Jersey", + "description": "Spring Boot with Jersey technology allows to create a JAX-RS application with SpringBoot Jersey support. \nNotice that Spring Boot with Jersey technology cannot co-exist with REST technology.", "endpoint" : "/springbootjersey" }, { "id": "springbootsecurity", "name": "Spring Boot with Security", - "description": "Spring Boot with Security", + "description": "Spring Boot with Security technology allows to create a simple web application with resources that are protected by Spring Security.", "endpoint" : "/springbootsecurity" }, - { + { "id": "springbootjdbc", "name": "Spring Boot with JDBC", - "description": "Spring Boot with JDBC", + "description": "Spring Boot with JDBC technology allows to create a simple Derby DB and do some SQL operation on it.", "endpoint" : "/springbootjdbc" }, - { "id": "watsonsdk", "name": "Watson SDK", diff --git a/liberty-starter-application/src/main/webapp/css/style.css b/liberty-starter-application/src/main/webapp/css/style.css index e7472e7..8060867 100644 --- a/liberty-starter-application/src/main/webapp/css/style.css +++ b/liberty-starter-application/src/main/webapp/css/style.css @@ -232,6 +232,21 @@ body { padding-bottom: 8px; } +#step1TechnologiesContainer .step1TechnologyDisabled { + height: 80px; + width: 297px; + padding-left: 26px; + color: #CCCCCC; + font-size: 18px; + border: solid 1px #BEBEBE; + line-height: 80px; + display: inline-block; + margin-right: 40px; + text-decoration: none; + margin-bottom: 34px; + position: relative; +} + #step1TechnologiesContainer .step1Technology { height: 80px; width: 297px; diff --git a/liberty-starter-application/src/main/webapp/js/logic.js b/liberty-starter-application/src/main/webapp/js/logic.js index 213d126..b38478e 100644 --- a/liberty-starter-application/src/main/webapp/js/logic.js +++ b/liberty-starter-application/src/main/webapp/js/logic.js @@ -26,7 +26,7 @@ $(document).ready(function() { step1TechnologiesContainer.empty(); for(var i = 0; i < technologies.length; i++) { var technology = technologies[i]; - var technologyTag = $("" + technology.name + ""); + var technologyTag = $("" + technology.name + ""); technologyTag.append(''); step1TechnologiesContainer.append(technologyTag); } @@ -108,14 +108,48 @@ $(document).ready(function() { var updateStep1Summary = function() { var selectedTechnologies = $("#step1TechnologiesContainer .step1Technology.selected"); var selectedTechnologiesText = ""; + var restSelected = false; + var springbootjerseySelected = false; for(var i = 0; i < selectedTechnologies.size(); i++) { selectedTechnologiesText += selectedTechnologies.get(i).dataset.technologyname; if(i + 1 < selectedTechnologies.size()) { selectedTechnologiesText += ", "; } + + if(selectedTechnologies.get(i).dataset.technologyid == "rest"){ + restSelected = true; + } + if(selectedTechnologies.get(i).dataset.technologyid == "springbootjersey"){ + springbootjerseySelected = true; + } } $("#navigationTop1 .variableContent").text(selectedTechnologiesText); + + updateStep1Conflict(restSelected, "springbootjersey"); + updateStep1Conflict(springbootjerseySelected, "rest"); }; + + var updateStep1Conflict = function(selected, id) { + if(selected){ + var enabledTechnologies = $("#step1TechnologiesContainer .step1Technology"); + for(var i = 0; i < enabledTechnologies.size(); i++) { + var technology = enabledTechnologies[i]; + if(technology.dataset.technologyid == id){ + technology.className = "step1TechnologyDisabled"; + break; + } + } + } else { + var disabledTechnologies = $("#step1TechnologiesContainer .step1TechnologyDisabled"); + for(var i = 0; i < disabledTechnologies.size(); i++) { + var technology = disabledTechnologies[i]; + if(technology.dataset.technologyid == id){ + technology.className = "step1Technology"; + break; + } + } + } + }; var refreshSectionVisibility = function() { var currentlyVisibleSections = $(".step:not(.hidden)").size();