This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-samples.git
The following commit(s) were added to refs/heads/master by this push:
new d72433f Updating the version of servicecomb-java-chassis to 3.0.0 for
bmi project (#129)
d72433f is described below
commit d72433f40db4d6ba065743ea29cbc3d0b136c70a
Author: yanghao <[email protected]>
AuthorDate: Mon Nov 20 09:08:53 2023 +0800
Updating the version of servicecomb-java-chassis to 3.0.0 for bmi project
(#129)
---
bmi/calculator/pom.xml | 58 +++++++++
.../apache/servicecomb/samples/BMIViewObject.java | 60 +++++++++
.../servicecomb/samples/CalculatorApplication.java | 29 +++++
.../servicecomb/samples/CalculatorEndpoint.java | 29 +++++
.../samples/CalculatorRestEndpoint.java | 53 ++++++++
.../servicecomb/samples/CalculatorService.java | 29 +++++
.../servicecomb/samples/CalculatorServiceImpl.java | 44 +++++++
.../servicecomb/samples/InstanceInfoService.java | 26 ++++
.../samples/InstanceInfoServiceImpl.java | 44 +++++++
bmi/calculator/src/main/resources/application.yml | 32 +++++
bmi/pom.xml | 141 +++++++++++++++++++++
bmi/webapp/pom.xml | 50 ++++++++
.../servicecomb/samples/GatewayApplication.java | 29 +++++
.../samples/StaticWebpageDispatcher.java | 48 +++++++
...cecomb.transport.rest.vertx.VertxHttpDispatcher | 18 +++
bmi/webapp/src/main/resources/application.yml | 52 ++++++++
bmi/webapp/src/main/resources/static/index.html | 104 +++++++++++++++
.../src/main/resources/static/jquery-1.11.1.min.js | 4 +
18 files changed, 850 insertions(+)
diff --git a/bmi/calculator/pom.xml b/bmi/calculator/pom.xml
new file mode 100644
index 0000000..f6bced8
--- /dev/null
+++ b/bmi/calculator/pom.xml
@@ -0,0 +1,58 @@
+<?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 xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>bmi</artifactId>
+ <groupId>org.apache.servicecomb.samples</groupId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>bmi-calculator</artifactId>
+ <name>Java Chassis::Samples::BMI::Calculator</name>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>java-chassis-spring-boot-starter-servlet</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>handler-flowcontrol-qps</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>handler-tracing-zipkin</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git
a/bmi/calculator/src/main/java/org/apache/servicecomb/samples/BMIViewObject.java
b/bmi/calculator/src/main/java/org/apache/servicecomb/samples/BMIViewObject.java
new file mode 100644
index 0000000..8f6d1fd
--- /dev/null
+++
b/bmi/calculator/src/main/java/org/apache/servicecomb/samples/BMIViewObject.java
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+
+package org.apache.servicecomb.samples;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class BMIViewObject {
+
+ private double result;
+
+ private String instanceId;
+
+ private String callTime;
+
+ public BMIViewObject(double result, String instanceId, Date now) {
+ this.result = result;
+ this.instanceId = instanceId;
+ this.callTime = new SimpleDateFormat("HH:mm:ss").format(now);
+ }
+
+ public double getResult() {
+ return result;
+ }
+
+ public void setResult(double result) {
+ this.result = result;
+ }
+
+ public String getInstanceId() {
+ return instanceId;
+ }
+
+ public void setInstanceId(String instanceId) {
+ this.instanceId = instanceId;
+ }
+
+ public String getCallTime() {
+ return callTime;
+ }
+
+ public void setCallTime(String callTime) {
+ this.callTime = callTime;
+ }
+}
diff --git
a/bmi/calculator/src/main/java/org/apache/servicecomb/samples/CalculatorApplication.java
b/bmi/calculator/src/main/java/org/apache/servicecomb/samples/CalculatorApplication.java
new file mode 100644
index 0000000..388d4f2
--- /dev/null
+++
b/bmi/calculator/src/main/java/org/apache/servicecomb/samples/CalculatorApplication.java
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+package org.apache.servicecomb.samples;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class CalculatorApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(CalculatorApplication.class, args);
+ }
+}
diff --git
a/bmi/calculator/src/main/java/org/apache/servicecomb/samples/CalculatorEndpoint.java
b/bmi/calculator/src/main/java/org/apache/servicecomb/samples/CalculatorEndpoint.java
new file mode 100644
index 0000000..3363189
--- /dev/null
+++
b/bmi/calculator/src/main/java/org/apache/servicecomb/samples/CalculatorEndpoint.java
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+package org.apache.servicecomb.samples;
+
+/**
+ * {@link CalculatorEndpoint} provides the common interface for different
endpoint implementations.
+ * It needs to be declared as public.
+ */
+public interface CalculatorEndpoint {
+ /**
+ * Calculate the BMI(Body Mass Index).
+ */
+ BMIViewObject calculate(double height, double weight);
+}
diff --git
a/bmi/calculator/src/main/java/org/apache/servicecomb/samples/CalculatorRestEndpoint.java
b/bmi/calculator/src/main/java/org/apache/servicecomb/samples/CalculatorRestEndpoint.java
new file mode 100644
index 0000000..cbb7b1d
--- /dev/null
+++
b/bmi/calculator/src/main/java/org/apache/servicecomb/samples/CalculatorRestEndpoint.java
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+
+package org.apache.servicecomb.samples;
+
+import org.apache.servicecomb.provider.rest.common.RestSchema;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import java.util.Date;
+
+/**
+ * {@link CalculatorRestEndpoint} provides the rest implementation of {@link
CalculatorEndpoint}.
+ * The rest endpoint is accessed by /bmi?height={value}&weight={value} with
HTTP GET.
+ */
+@RestSchema(schemaId = "calculatorRestEndpoint")
+@RequestMapping(path = "/")
+public class CalculatorRestEndpoint implements CalculatorEndpoint {
+
+ private final CalculatorService calculatorService;
+
+ private final InstanceInfoService instanceInfoService;
+
+ @Autowired
+ public CalculatorRestEndpoint(CalculatorService calculatorService,
InstanceInfoService instanceInfoService) {
+ this.calculatorService = calculatorService;
+ this.instanceInfoService = instanceInfoService;
+ }
+
+ @GetMapping(path = "/bmi")
+ @Override
+ public BMIViewObject calculate(double height, double weight) {
+
+ String instanceId = instanceInfoService.getInstanceId();
+ double bmiResult = calculatorService.calculate(height, weight);
+ return new BMIViewObject(bmiResult, instanceId, new Date());
+ }
+}
diff --git
a/bmi/calculator/src/main/java/org/apache/servicecomb/samples/CalculatorService.java
b/bmi/calculator/src/main/java/org/apache/servicecomb/samples/CalculatorService.java
new file mode 100644
index 0000000..c18d187
--- /dev/null
+++
b/bmi/calculator/src/main/java/org/apache/servicecomb/samples/CalculatorService.java
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+package org.apache.servicecomb.samples;
+
+/**
+ * {@link CalculatorService} provides interface of actual BMI calculation.
+ */
+public interface CalculatorService {
+
+ /**
+ * @see CalculatorEndpoint#calculate(double, double)
+ */
+ double calculate(double height, double weight);
+}
diff --git
a/bmi/calculator/src/main/java/org/apache/servicecomb/samples/CalculatorServiceImpl.java
b/bmi/calculator/src/main/java/org/apache/servicecomb/samples/CalculatorServiceImpl.java
new file mode 100644
index 0000000..d0b865b
--- /dev/null
+++
b/bmi/calculator/src/main/java/org/apache/servicecomb/samples/CalculatorServiceImpl.java
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+
+package org.apache.servicecomb.samples;
+
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+
+@Service
+public class CalculatorServiceImpl implements CalculatorService {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public double calculate(double height, double weight) {
+ if (height <= 0 || weight <= 0) {
+ throw new IllegalArgumentException("Arguments must be above 0");
+ }
+ double heightInMeter = height / 100;
+ double bmi = weight / (heightInMeter * heightInMeter);
+ return roundToOnePrecision(bmi);
+ }
+
+ private double roundToOnePrecision(double value) {
+ return BigDecimal.valueOf(value).setScale(1,
RoundingMode.HALF_UP).doubleValue();
+ }
+}
diff --git
a/bmi/calculator/src/main/java/org/apache/servicecomb/samples/InstanceInfoService.java
b/bmi/calculator/src/main/java/org/apache/servicecomb/samples/InstanceInfoService.java
new file mode 100644
index 0000000..2e973d2
--- /dev/null
+++
b/bmi/calculator/src/main/java/org/apache/servicecomb/samples/InstanceInfoService.java
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+package org.apache.servicecomb.samples;
+
+/**
+ * {@link InstanceInfoService} provides interface of instance information.
+ */
+public interface InstanceInfoService {
+
+ String getInstanceId();
+}
diff --git
a/bmi/calculator/src/main/java/org/apache/servicecomb/samples/InstanceInfoServiceImpl.java
b/bmi/calculator/src/main/java/org/apache/servicecomb/samples/InstanceInfoServiceImpl.java
new file mode 100644
index 0000000..e1bb4e5
--- /dev/null
+++
b/bmi/calculator/src/main/java/org/apache/servicecomb/samples/InstanceInfoServiceImpl.java
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+
+package org.apache.servicecomb.samples;
+
+import org.apache.servicecomb.registry.sc.SCRegistration;
+import org.apache.servicecomb.registry.sc.SCRegistrationInstance;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class InstanceInfoServiceImpl implements InstanceInfoService {
+
+ @Autowired
+ private SCRegistration scRegistration;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getInstanceId() {
+
+ SCRegistrationInstance instance = scRegistration.getMicroserviceInstance();
+ if (instance == null) {
+ throw new IllegalStateException(
+ "unable to find any service instances, maybe there is problem
registering in service center?");
+ }
+ return instance.getInstanceId();
+ }
+}
diff --git a/bmi/calculator/src/main/resources/application.yml
b/bmi/calculator/src/main/resources/application.yml
new file mode 100644
index 0000000..879c927
--- /dev/null
+++ b/bmi/calculator/src/main/resources/application.yml
@@ -0,0 +1,32 @@
+#
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+server:
+ port: 7777
+
+servicecomb:
+ registry:
+ sc:
+ address: http://127.0.0.1:30100
+ service:
+ application: bmi
+ name: calculator
+ version: 0.0.1
+
+ rest:
+ address: 0.0.0.0:7777
\ No newline at end of file
diff --git a/bmi/pom.xml b/bmi/pom.xml
new file mode 100644
index 0000000..2698b97
--- /dev/null
+++ b/bmi/pom.xml
@@ -0,0 +1,141 @@
+<!--
+ ~ 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 xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.servicecomb.samples</groupId>
+ <artifactId>bmi</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ <name>Java Chassis::Samples::BMI</name>
+ <packaging>pom</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <servicecomb.version>3.0.0-SNAPSHOT</servicecomb.version>
+ <argLine>-Dfile.encoding=UTF-8</argLine>
+ <java.version>17</java.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>java-chassis-dependencies</artifactId>
+ <version>${servicecomb.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>registry-service-center</artifactId>
+ </dependency>
+ </dependencies>
+
+ <modules>
+ <module>calculator</module>
+ <module>webapp</module>
+ </modules>
+
+ <description>Quick Start Demo for Using ServiceComb Java
Chassis</description>
+
+ <build>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.1</version>
+ <configuration>
+ <source>17</source>
+ <target>17</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>2.1.2.RELEASE</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <mainClass>${start-class}</mainClass>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
+ <plugins>
+ <!-- 配置项目使用jdk1.8编译 -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.1</version>
+ <configuration>
+ <compilerArgument>-parameters</compilerArgument>
+ <encoding>UTF-8</encoding>
+ <source>17</source>
+ <target>17</target>
+ <compilerArgs>
+ <arg>-Werror</arg>
+ <arg>-Xlint:all</arg>
+ <!--not care for jdk8/jdk7 compatible problem-->
+ <arg>-Xlint:-classfile</arg>
+ <!--not care for annotation not processed-->
+ <arg>-Xlint:-processing</arg>
+ </compilerArgs>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <version>2.8.2</version>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <version>0.13</version>
+ <configuration>
+ <excludes>
+ <exclude>.travis.yml</exclude>
+ <exclude>**/*.md</exclude>
+ <exclude>**/target/*</exclude>
+ <!-- Skip the ssl configuration files -->
+ <exculde>**/resources/ssl/**</exculde>
+ <!-- Skip the protobuf files -->
+ <exclude>**/*.proto</exclude>
+ <!-- Skip the idl files -->
+ <exclude>**/*.idl</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/bmi/webapp/pom.xml b/bmi/webapp/pom.xml
new file mode 100644
index 0000000..fc82d4e
--- /dev/null
+++ b/bmi/webapp/pom.xml
@@ -0,0 +1,50 @@
+<?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 xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>bmi</artifactId>
+ <groupId>org.apache.servicecomb.samples</groupId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>webapp</artifactId>
+ <name>Java Chassis::Samples::BMI::Webapp</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+
<artifactId>java-chassis-spring-boot-starter-standalone</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicecomb</groupId>
+ <artifactId>edge-core</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git
a/bmi/webapp/src/main/java/org/apache/servicecomb/samples/GatewayApplication.java
b/bmi/webapp/src/main/java/org/apache/servicecomb/samples/GatewayApplication.java
new file mode 100644
index 0000000..97f6baf
--- /dev/null
+++
b/bmi/webapp/src/main/java/org/apache/servicecomb/samples/GatewayApplication.java
@@ -0,0 +1,29 @@
+/*
+ * 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.
+ */
+
+package org.apache.servicecomb.samples;
+
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+
+@SpringBootApplication
+public class GatewayApplication {
+ public static void main(String[] args) {
+ new
SpringApplicationBuilder().web(WebApplicationType.NONE).sources(GatewayApplication.class).run(args);
+ }
+}
diff --git
a/bmi/webapp/src/main/java/org/apache/servicecomb/samples/StaticWebpageDispatcher.java
b/bmi/webapp/src/main/java/org/apache/servicecomb/samples/StaticWebpageDispatcher.java
new file mode 100644
index 0000000..58ce2a2
--- /dev/null
+++
b/bmi/webapp/src/main/java/org/apache/servicecomb/samples/StaticWebpageDispatcher.java
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+package org.apache.servicecomb.samples;
+
+import org.apache.servicecomb.foundation.common.LegacyPropertyFactory;
+import org.apache.servicecomb.transport.rest.vertx.VertxHttpDispatcher;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.vertx.ext.web.Router;
+import io.vertx.ext.web.handler.StaticHandler;
+
+public class StaticWebpageDispatcher implements VertxHttpDispatcher {
+ private static final Logger LOGGER =
LoggerFactory.getLogger(StaticWebpageDispatcher.class);
+
+ private static final String WEB_ROOT = LegacyPropertyFactory
+ .getStringProperty("gateway.webroot", "/var/static");
+
+ @Override
+ public int getOrder() {
+ return Integer.MAX_VALUE / 2;
+ }
+
+ @Override
+ public void init(Router router) {
+ String regex = "/(.*)";
+ StaticHandler webpageHandler = StaticHandler.create(WEB_ROOT);
+ LOGGER.info("server static web page for WEB_ROOT={}", WEB_ROOT);
+ router.routeWithRegex(regex).failureHandler((context) -> {
+ LOGGER.error("", context.failure());
+ }).handler(webpageHandler);
+ }
+}
diff --git
a/bmi/webapp/src/main/resources/META-INF/services/org.apache.servicecomb.transport.rest.vertx.VertxHttpDispatcher
b/bmi/webapp/src/main/resources/META-INF/services/org.apache.servicecomb.transport.rest.vertx.VertxHttpDispatcher
new file mode 100644
index 0000000..36e6e96
--- /dev/null
+++
b/bmi/webapp/src/main/resources/META-INF/services/org.apache.servicecomb.transport.rest.vertx.VertxHttpDispatcher
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.servicecomb.samples.StaticWebpageDispatcher
\ No newline at end of file
diff --git a/bmi/webapp/src/main/resources/application.yml
b/bmi/webapp/src/main/resources/application.yml
new file mode 100644
index 0000000..230022a
--- /dev/null
+++ b/bmi/webapp/src/main/resources/application.yml
@@ -0,0 +1,52 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+servicecomb:
+ registry:
+ sc:
+ address: http://127.0.0.1:30100
+ service:
+ application: bmi
+ name: gateway
+ version: 0.0.1
+
+ rest:
+ address: 0.0.0.0:8889
+
+ tracing:
+ enabled: false
+
+ http:
+ dispatcher:
+ edge:
+ default:
+ enabled: false
+ prefix: api
+ withVersion: false
+ prefixSegmentCount: 1
+ url:
+ enabled: true
+ mappings:
+ calculator:
+ prefixSegmentCount: 1
+ path: "/calculator/.*"
+ microserviceName: calculator
+ versionRule: 0.0.0+
+
+# This is web root for windows server, change this path according to where you
put your source code
+gateway:
+ webroot:
/code/servicecomb-samples/java-chassis-samples/bmi/webapp/src/main/resources/static
\ No newline at end of file
diff --git a/bmi/webapp/src/main/resources/static/index.html
b/bmi/webapp/src/main/resources/static/index.html
new file mode 100644
index 0000000..8dcbd56
--- /dev/null
+++ b/bmi/webapp/src/main/resources/static/index.html
@@ -0,0 +1,104 @@
+<!DOCTYPE HTML>
+<!--
+ ~ 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.
+ -->
+<html>
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1,
shrink-to-fit=no">
+
+ <link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css"
integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M"
crossorigin="anonymous">
+ <!-- jQuery first, then Popper.js, then Bootstrap JS -->
+ <script src="jquery-1.11.1.min.js"></script>
+ <script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"
integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4"
crossorigin="anonymous"></script>
+ <script
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"
integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1"
crossorigin="anonymous"></script>
+ </head>
+ <body>
+ <div class="container">
+
+ <div class="col-md-1"></div>
+ <div class="col-md-10">
+ <h2 align="center">BMI Calculator</h2>
+
+ <div class="form-group">
+ <label for="height" class="col-form-label"><b>Height(cm):</b></label>
+ <input type="number" class="form-control" id="height" name="height"
placeholder="Please input your height">
+ </div>
+ <div class="form-group">
+ <label for="weight"
class="col-form-label"><b>Weight(kg):</b></label>
+ <input type="number" class="form-control" id="weight"
name="weight" placeholder="Please input your weight">
+ </div>
+ <button type="submit" class="btn btn-primary"
id="submit">Submit</button>
+
+ <br/>
+ <div class="alert alert-light" role="alert" id="bmi">
+ <h3>BMI Result: <span id="bmi_result"></span></h3>
+ <h3>BMI Instance ID: <span id="bmi_instanceId"></span></h3>
+ <h3>BMI Called Time: <span id="bmi_callTime"></span></h3>
+ </div>
+ <div class="alert alert-secondary" role="alert">
+ <b>Note: </b>Range of healthy weight is between <b>18.5</b> and
<b>24.9</b>.
+ </div>
+ <div id="error" class="alert alert-danger" role="alert"><p
id="error_message"></p></div>
+ </div>
+ </div>
+
+ </body>
+ <script>
+ $("#error").hide();
+ $("#submit").click(function () {
+ if ( !$("#height").val() || !$("#weight").val() ) {
+ alert("Please input both the height and weight");
+ return;
+ }
+ $.ajax({
+ url: "/calculator/bmi?height=" + $("#height").val() + "&weight=" +
$("#weight").val(),
+ type: "GET",
+ success: function (data) {
+ $("#error").hide();
+ $("#bmi_result").text(data.result);
+ $("#bmi_instanceId").text(data.instanceId);
+ $("#bmi_callTime").text(data.callTime);
+ if ( data.result < 18.5 || (data.result < 30 && data.result >= 25)
) {
+
$("#bmi").removeClass().addClass("alert").addClass("alert-warning");
+ } else if ( data.result < 25 && data.result >= 18.5 ) {
+
$("#bmi").removeClass().addClass("alert").addClass("alert-success");
+ } else {
+
$("#bmi").removeClass().addClass("alert").addClass("alert-danger");
+ }
+ },
+ error: function (xhr) {
+ $("#bmi").removeClass().addClass("alert").addClass("alert-light");
+ $("#bmi_result").text('');
+ if (xhr.responseText.length == 0) {
+ $("#error_message").text("empty fallback called");
+
$("#error").removeClass().addClass("alert").addClass("alert-success").show();
+ return;
+ }
+ var resp = JSON.parse(xhr.responseText);
+ if (xhr.status == 429) {
+ $("#error_message").text(resp.message);
+
$("#error").removeClass().addClass("alert").addClass("alert-danger").show();
+ } else {
+ $("#error_message").text(resp.error + ": " + resp.exception)
+
$("#error").removeClass().addClass("alert").addClass("alert-danger").show();
+ }
+ }
+ });
+ });
+ </script>
+
+</html>
diff --git a/bmi/webapp/src/main/resources/static/jquery-1.11.1.min.js
b/bmi/webapp/src/main/resources/static/jquery-1.11.1.min.js
new file mode 100644
index 0000000..ab28a24
--- /dev/null
+++ b/bmi/webapp/src/main/resources/static/jquery-1.11.1.min.js
@@ -0,0 +1,4 @@
+/*! jQuery v1.11.1 | (c) 2005, 2014 jQuery Foundation, Inc. |
jquery.org/license */
+!function(a,b){"object"==typeof module&&"object"==typeof
module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw
new Error("jQuery requires a window with a document");return
b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){var
c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf,h={},i=h.toString,j=h.hasOwnProperty,k={},l="1.11.1",m=function(a,b){return
new
m.fn.init(a,b)},n=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,o=/^-ms-/,p=/-([\da-z])/gi,q=function(a,b
[...]
+if(k&&j[k]&&(e||j[k].data)||void 0!==d||"string"!=typeof b)return
k||(k=i?a[h]=c.pop()||m.guid++:h),j[k]||(j[k]=i?{}:{toJSON:m.noop}),("object"==typeof
b||"function"==typeof
b)&&(e?j[k]=m.extend(j[k],b):j[k].data=m.extend(j[k].data,b)),g=j[k],e||(g.data||(g.data={}),g=g.data),void
0!==d&&(g[m.camelCase(b)]=d),"string"==typeof
b?(f=g[b],null==f&&(f=g[m.camelCase(b)])):f=g,f}}function
R(a,b,c){if(m.acceptData(a)){var
d,e,f=a.nodeType,g=f?m.cache:a,h=f?a[m.expando]:m.expando;if(g[h]){if(b&& [...]
+},cur:function(){var a=Zb.propHooks[this.prop];return
a&&a.get?a.get(this):Zb.propHooks._default.get(this)},run:function(a){var
b,c=Zb.propHooks[this.prop];return
this.pos=b=this.options.duration?m.easing[this.easing](a,this.options.duration*a,0,1,this.options.duration):a,this.now=(this.end-this.start)*b+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),c&&c.set?c.set(this):Zb.propHooks._default.set(this),this}},Zb.prototype.init.prototype=Zb.prototype,Zb.prop
[...]