[
https://issues.apache.org/jira/browse/SCB-568?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16496149#comment-16496149
]
ASF GitHub Bot commented on SCB-568:
------------------------------------
WillemJiang closed pull request #195: SCB-568 Provide web page for pack Demo
URL: https://github.com/apache/incubator-servicecomb-saga/pull/195
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/saga-demo/booking/README.md b/saga-demo/booking/README.md
index 161f886c..b72c62e6 100644
--- a/saga-demo/booking/README.md
+++ b/saga-demo/booking/README.md
@@ -91,7 +91,7 @@ You can run the demo using either docker compose or
executable files.
java -Dserver.port=8083 -Dalpha.cluster.address=${alpha_address}:8080
-Dcar.service.address=${host_address}:8082
-Dhotel.service.address=${host_address}:8081 -jar
pack-booking-${saga_version}-exec.jar
```
-## User Requests
+## User Requests by command line tools
1. Booking 2 rooms and 2 cars, this booking will be OK.
```
curl -X POST http://${host_address}:8083/booking/test/2/2
@@ -120,5 +120,8 @@ curl http://${host_address}:8082/bookings
```
The second car booking will be marked with **cancel:true**
+## User Requests by html page
+
+Open a browser with URL http://127.0.0.1:8083, You will get a html page. You
can use this page to invoke test cases, and then get results.
**Note** transactions and compensations implemented by services must be
idempotent.
diff --git
a/saga-demo/booking/booking/src/main/java/org/apache/servicecomb/saga/demo/pack/booking/MyConfiguration.java
b/saga-demo/booking/booking/src/main/java/org/apache/servicecomb/saga/demo/pack/booking/MyConfiguration.java
new file mode 100644
index 00000000..0fc5e09c
--- /dev/null
+++
b/saga-demo/booking/booking/src/main/java/org/apache/servicecomb/saga/demo/pack/booking/MyConfiguration.java
@@ -0,0 +1,36 @@
+/*
+ * 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.saga.demo.pack.booking;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+
+@Configuration
+public class MyConfiguration {
+ @Bean
+ public WebMvcConfigurer corsConfigurer() {
+ return new WebMvcConfigurerAdapter() {
+ @Override
+ public void addCorsMappings(CorsRegistry registry) {
+ registry.addMapping("/**");
+ }
+ };
+ }
+}
diff --git a/saga-demo/booking/booking/src/main/resources/static/index.html
b/saga-demo/booking/booking/src/main/resources/static/index.html
new file mode 100644
index 00000000..894667f0
--- /dev/null
+++ b/saga-demo/booking/booking/src/main/resources/static/index.html
@@ -0,0 +1,91 @@
+<!--
+ ~ 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.
+ -->
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <title>Saga-booking-demo</title>
+
+ <script type="text/javascript"
src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
+
+ <script type="text/javascript">
+ function testCase1() {
+ $.post("http://127.0.0.1:8083/booking/test/2/2", function(data) {
+ var msg = data;
+ $("#booking_result_1").html(msg);
+ });
+ }
+
+ function testCase2() {
+ $.post("http://127.0.0.1:8083/booking/test/3/2", function(data) {
+ var msg = data;
+ $("#booking_result_2").html(msg);
+ })
+ .fail(function(data) {
+ alert("The transaction is failed");
+ $("#booking_result_2").html("<li>" + JSON.stringify(data) +
"</li>");
+ });
+ }
+
+ function room_booking_result() {
+ $.get("http://127.0.0.1:8081/bookings", function(data) {
+ var msg = "<li>" + JSON.stringify(data) + "</li>";
+ $("#room_list").html(msg);
+ });
+ }
+
+ function car_booking_result() {
+ $.get("http://127.0.0.1:8082/bookings", function(data) {
+ var msg = "<li>" + JSON.stringify(data) + "</li>";
+ $("#car_list").html(msg);
+ });
+ }
+ </script>
+</head>
+<body>
+<p>Test cases of Sage booking demo:</p>
+<p>Case 1. <a href="javascript:void(0);" onclick="testCase1();">[Booking 2
rooms and 2 cars, will done successfully]</a> </p>
+<p>
+ Booking result: <span id="booking_result_1">###</span><br>
+</p>
+<br>
+<p>Case 2. <a href="javascript:void(0);" onclick="testCase2();">[Booking 3
rooms and 2 cars, hotel order service will failed.]</a> </p>
+<p>
+ Booking result: <span id="booking_result_2">###</span><br>
+</p>
+<br>
+<p><a href="javascript:void(0);" onclick="room_booking_result();">[Query the
room booking result]</a> </p>
+<p>
+ Room booking list:<br>
+<ul>
+ <li id="room_list">
+ #Name, Amount, Confirm status, Cancel Status
+ </li>
+</ul>
+</p>
+<br>
+<p><a href="javascript:void(0);" onclick="car_booking_result();">[Query the
car booking result]</a> </p>
+<p>
+ Car booking list:<br>
+<ul>
+ <li id="car_list">
+ #Name, Amount, Confirm status, Cancel Status
+ </li>
+</ul>
+</p>
+</body>
+</html>
diff --git
a/saga-demo/booking/car/src/main/java/org/apache/servicecomb/saga/demo/pack/car/CarBookingController.java
b/saga-demo/booking/car/src/main/java/org/apache/servicecomb/saga/demo/pack/car/CarBookingController.java
index 4528c223..9db37b3e 100644
---
a/saga-demo/booking/car/src/main/java/org/apache/servicecomb/saga/demo/pack/car/CarBookingController.java
+++
b/saga-demo/booking/car/src/main/java/org/apache/servicecomb/saga/demo/pack/car/CarBookingController.java
@@ -18,6 +18,7 @@
package org.apache.servicecomb.saga.demo.pack.car;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@@ -35,6 +36,7 @@
private final AtomicInteger id = new AtomicInteger(0);
+ @CrossOrigin
@GetMapping("/bookings") List<CarBooking> getAll() {
return new ArrayList<>(service.getAllBookings());
}
diff --git
a/saga-demo/booking/hotel/src/main/java/org/apache/servicecomb/saga/demo/pack/hotel/HotelBookingController.java
b/saga-demo/booking/hotel/src/main/java/org/apache/servicecomb/saga/demo/pack/hotel/HotelBookingController.java
index 22f9b2c7..6582819d 100644
---
a/saga-demo/booking/hotel/src/main/java/org/apache/servicecomb/saga/demo/pack/hotel/HotelBookingController.java
+++
b/saga-demo/booking/hotel/src/main/java/org/apache/servicecomb/saga/demo/pack/hotel/HotelBookingController.java
@@ -18,6 +18,7 @@
package org.apache.servicecomb.saga.demo.pack.hotel;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@@ -35,6 +36,7 @@
private final AtomicInteger id = new AtomicInteger(0);
+ @CrossOrigin
@GetMapping("/bookings")
List<HotelBooking> getAll() {
return new ArrayList<>(service.getAllBookings());
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Provide web page for pack Demo
> ------------------------------
>
> Key: SCB-568
> URL: https://issues.apache.org/jira/browse/SCB-568
> Project: Apache ServiceComb
> Issue Type: Improvement
> Components: Saga
> Reporter: Willem Jiang
> Assignee: longchun
> Priority: Major
> Fix For: saga-0.2.0
>
>
> It could be more straightforward if we can provide the web page for the user
> to access the services.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)