forked from apache/servicecomb-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
9c3d6e8
commit a77f15b
Showing
9 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM openjdk:8u181-jdk-alpine | ||
|
||
WORKDIR /home/apps/ | ||
|
||
COPY target/*.jar app.jar | ||
|
||
RUN sh -c 'touch app.jar' | ||
|
||
ENTRYPOINT [ "sh", "-c", "java -Djava.security.egd=file:/dev/./urandom -jar -Xmx256m app.jar" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Java CSE Spring MVC microservice | ||
|
||
| Language | Framework | Platform | ||
| -------- | -------- |--------| | ||
| Java | CSE Spring MVC | ServiceStage Container, CCE Cluster| | ||
|
||
This sample code helps get you started with a simple Java CSE microservice | ||
deployed by ServiceStage Container App to a CCE Cluster. | ||
|
||
This sample includes: | ||
|
||
* README.md | ||
* LICENSE | ||
* Dockerfile | ||
* pom.xml - this file is the Maven Project Object Model for the microservice | ||
* src/main - this directory contains your Java service source files | ||
* src/test - this directory contains your Java service unit test files | ||
|
||
## Getting Started | ||
|
||
Clone your code repository and start developing your application on IDE of your choice | ||
|
||
1. Install maven. See https://maven.apache.org/install.html for details. | ||
|
||
2. Download local-service-center from http://servicecomb.incubator.apache.org/release/. Read README.md to start local-service-center. | ||
|
||
3. Update the service registry address in microservice.yaml according to the README.md in local-service-center. | ||
|
||
4. Build the application. | ||
|
||
$ mvn -f pom.xml package | ||
|
||
5. Run the application in IDE or execute the jar. | ||
|
||
6. Open http://127.0.0.1:8080/rest/helloworld?name=hellworld in a web browser to view your application. | ||
|
||
if you want to deploy the sample code on servicestage, View your CI/CD pipeline and service stack on ServiceStage and customize it as per your needs | ||
|
||
## Contributing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Licensed to the Apache Software Foundation (ASF) under one or more | ||
~ contributor license agreements. See the NOTICE file distributed with | ||
~ this work for additional information regarding copyright ownership. | ||
~ The ASF licenses this file to You 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. | ||
--> | ||
|
||
<project | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.huawei</groupId> | ||
<artifactId>servicecomb</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>servicecomb</name> | ||
<url>http://maven.apache.org</url> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<demo.main>com.huawei.servicecomb.ServicecombspringmvcApplication</demo.main> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.servicecomb</groupId> | ||
<artifactId>java-chassis-dependencies</artifactId> | ||
<version>2.5.0</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.servicecomb</groupId> | ||
<artifactId>solution-basic</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.servicecomb</groupId> | ||
<artifactId>registry-service-center</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.servicecomb</groupId> | ||
<artifactId>servicestage-environment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.servicecomb</groupId> | ||
<artifactId>registry-service-center</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.servicecomb</groupId> | ||
<artifactId>java-chassis-spring-boot-starter-servlet</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<configuration> | ||
<mainClass>com.huawei.servicecomb.ServicecombspringmvcApplication</mainClass> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>repackage</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
13 changes: 13 additions & 0 deletions
13
...eComb-SpringMVC/src/main/java/com/huawei/servicecomb/ServicecombspringmvcApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.huawei.servicecomb; | ||
|
||
import org.apache.servicecomb.springboot2.starter.EnableServiceComb; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
@EnableServiceComb | ||
public class ServicecombspringmvcApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(ServicecombspringmvcApplication.class, args); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...ringMVC/src/main/java/com/huawei/servicecomb/controller/ServicecombspringmvcDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.huawei.servicecomb.controller; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
|
||
@Component | ||
public class ServicecombspringmvcDelegate { | ||
|
||
public String helloworld(String name) { | ||
|
||
// Do Some Magic Here! | ||
return name; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...b-SpringMVC/src/main/java/com/huawei/servicecomb/controller/ServicecombspringmvcImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.huawei.servicecomb.controller; | ||
|
||
|
||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import org.apache.servicecomb.provider.rest.common.RestSchema; | ||
|
||
@javax.annotation.Generated(value = "io.swagger.codegen.languages.CseSpringDemoCodegen", date = "2019-08-02T08:06:28.094Z") | ||
|
||
@RestSchema(schemaId = "servicecombspringmvc") | ||
@RequestMapping(path = "/rest", produces = MediaType.APPLICATION_JSON) | ||
public class ServicecombspringmvcImpl { | ||
|
||
@Autowired | ||
private ServicecombspringmvcDelegate userServicecombspringmvcDelegate; | ||
|
||
|
||
@RequestMapping(value = "/helloworld", | ||
produces = {"application/json"}, | ||
method = RequestMethod.GET) | ||
public String helloworld(@RequestParam(value = "name", required = true) String name) { | ||
|
||
return userServicecombspringmvcDelegate.helloworld(name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# LOG4J configuration | ||
log4j.rootCategory=INFO,stdout,file | ||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender | ||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n | ||
# save logs to file | ||
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender | ||
log4j.appender.file.file=../logs/cse.log | ||
log4j.appender.file.DatePattern='.'yyyy-MM-dd | ||
log4j.appender.file.layout=org.apache.log4j.PatternLayout | ||
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %c{1}:%L - %m%n |
28 changes: 28 additions & 0 deletions
28
ServiceComb-SpringMVC/src/main/resources/microservice.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
APPLICATION_ID: springmvc | ||
service_description: | ||
name: servicecombspringmvc | ||
version: 0.0.1 | ||
properties: | ||
allowCrossApp: false | ||
cse: | ||
service: | ||
registry: | ||
address: http://127.0.0.1:30100 | ||
instance: | ||
watch: false | ||
config: | ||
client: | ||
serverUri: http://127.0.0.1:30113 | ||
refreshMode: 1 | ||
refresh_interval: 5000 | ||
#monitor: | ||
#client: | ||
#serverUri: https://cse.cn-north-1.myhuaweicloud.com | ||
rest: | ||
address: 0.0.0.0:8080 | ||
#When a local project is deployed as a container outside a cluster, you need to delete all monitor and credentials comments and configure the AK/SK. | ||
#credentials: | ||
#accessKey: ak | ||
#secretKey: sk | ||
#akskCustomCipher: default | ||
#project: cn-north-1 |
23 changes: 23 additions & 0 deletions
23
...b-SpringMVC/src/test/java/com/huawei/servicecomb/controller/TestServicecombspringmvc.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.huawei.servicecomb.controller; | ||
|
||
|
||
import static org.junit.Assert.*; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class TestServicecombspringmvc { | ||
|
||
ServicecombspringmvcDelegate servicecombspringmvcDelegate = new ServicecombspringmvcDelegate(); | ||
|
||
|
||
@Test | ||
public void testhelloworld() { | ||
|
||
String expactReturnValue = "hello"; // You should put the expect String type value here. | ||
|
||
String returnValue = servicecombspringmvcDelegate.helloworld("hello"); | ||
|
||
assertEquals(expactReturnValue, returnValue); | ||
} | ||
} |