Skip to content

Commit e9c853c

Browse files
author
dixyushi
committed
splitted the steps in sub steps
1 parent 82c82eb commit e9c853c

3 files changed

Lines changed: 77 additions & 32 deletions

File tree

devon4j-http-rest-client/files/server_application.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# want to touch the WAR file.
55

66
server.port=8080
7-
spring.application.name=httprestserver
87
server.servlet.context-path=/httprestserver
8+
spring.application.name=httprestserver
99

1010
security.expose.error.details=false
1111

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
* Once, application builds successfully. Open new terminal by clicking "+" and wait for it to load.
2+
* Now, Copy and execute below command to navigate into client server.
3+
`cd devonfw/workspaces/main/httprestclient/server`{{execute T1}}
4+
* Now, Copy and execute below command to start the application.
5+
`devon mvn spring-boot:run`{{execute T1}}
6+
To test Synchronous method, follow below steps.
7+
* Click on "+" next to terminal tab
8+
* Select "select port to view host"
9+
* Enter the port number "8081"
10+
* In the url, append "/httprestclient/services/rest/devon4jrestclient/response/"
11+
* Enter username as "admin" and password as "admin"
12+
* You will be able to see response "Welcome to rest api"

devon4j-http-rest-client/index.asciidoc

Lines changed: 64 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,57 @@ For more details on devon4j Service Client https://devonfw.com/website/pages/doc
3535
3636
## Create the devon4j REST SERVER
3737
As explained in REST document, With JAX-RS it is important to make sure that each service method is annotated with the proper HTTP annotation(@GET, @POST, etc).
38-
Let's create devon4j server. You have to modify BaseWebSecurityConfig file to allow application for basic authentication.
39-
In below example you will create VisitormanagementRestService and it's implementation i.e. VisitormanagementRestServiceImpl using JAX-RS standard.
38+
Let's create devon4j server.
4039
[step]
4140
== REST
4241
--
4342
createDevon4jProject("com.example.application.httprestserver")
43+
--
44+
In next step, you will add configuration to allow basic authentication.
45+
====
46+
47+
48+
Now, You have to modify BaseWebSecurityConfig file to allow application for basic authentication.
49+
[step]
50+
== Add configuration to allow basic authentication
51+
--
4452
changeFile("httprestserver/core/src/main/java/com/example/application/httprestserver/general/service/impl/config/BaseWebSecurityConfig.java", { "file": "files/BaseWebSecurityConfig.txt" })
53+
--
54+
55+
56+
Now, you will create VisitormanagementRestService to provide functionality using JAX-RS standard.
57+
[step]
58+
== Create service for REST server
59+
--
4560
createFile("httprestserver/api/src/main/java/com/example/application/httprestserver/visitormanagement/service/api/rest/VisitormanagementRestService.java", "files/VisitormanagementRestService.java")
61+
--
62+
63+
64+
====
65+
Now, you will create VisitormanagementRestServiceImpl, the implementation class of VisitormanagementRestService using JAX-RS standard.
66+
[step]
67+
== Create implementation class for Service
68+
--
4669
createFile("httprestserver/core/src/main/java/com/example/application/httprestserver/visitormanagement/service/impl/rest/VisitormanagementRestServiceImpl.java", "files/VisitormanagementRestServiceImpl.java")
47-
changeFile("httprestserver/core/src/main/resources/application.properties", { "file": "files/server_application.txt" })
48-
changeFile("httprestserver/core/src/main/resources/config/application.properties", { "file": "files/server_config_application.txt" })
4970
--
5071
Here , you can see "VisitormanagementRestServiceImpl.java" is annotated with @Named to make it a spring-bean. To get return response to client "returnResponseToClient()" can be accessed via HTTP GET under the URL path "/visitormanagement/v1/clientrequest". It will return its result (String) as JSON (see @Produces in VisitormanagementRestService).
5172
====
5273

5374

75+
Now, you will configure port in application properties.
76+
[step]
77+
== Modify properties files
78+
--
79+
changeFile("httprestserver/core/src/main/resources/application.properties", { "file": "files/server_application.txt" })
80+
changeFile("httprestserver/core/src/main/resources/config/application.properties", { "file": "files/server_config_application.txt" })
81+
--
82+
83+
84+
5485
====
5586
You have successfully built the REST-server. Now, you have to start the build and then, start the server as mentioned below.
5687
[step]
88+
== Build and Start devon4j REST Server
5789
--
5890
buildJava("httprestserver", false)
5991
runServerJava("httprestserver/server", { "startupTime": 1000, "port": 8080, "path": "httprestserver" })
@@ -91,21 +123,36 @@ Since in this tutorial you will build client on Synchronous call so, you have to
91123
Note: With devon4j we have already added the required dependency in pom.xml
92124
====
93125

94-
====
95-
You have to create a Java interface VisitormanagementRestService to invoke.
96-
You have to create rest client i.e. Devon4jRestClient.java and it's implementation class i.e. Devon4jRestClientImpl.java.
126+
127+
Now, You will create a Java interface VisitormanagementRestService to invoke inside client.
97128
[step]
129+
== Create service to invoke
98130
--
99131
createFile("httprestclient/api/src/main/java/com/sample/application/httprestclient/general/service/api/rest/VisitormanagementRestService.java", "files/VisitorManagementRestServiceClient.txt")
132+
--
133+
134+
135+
Now, you will create service for client i.e. Devon4jRestClient.java to provide functionality using JAX-RS standard.
136+
[step]
137+
== Create service for CXF REST Client
138+
--
100139
createFile("httprestclient/api/src/main/java/com/sample/application/httprestclient/general/service/api/rest/Devon4jRestClient.java", "files/Devon4jRestClient.java")
140+
--
141+
142+
143+
====
144+
Now, you will create Devon4jRestClientImpl, the implementation class of Devon4jRestClient using JAX-RS standard.
145+
146+
[step]
147+
== Create implementation class for service
148+
--
101149
createFile("httprestclient/core/src/main/java/com/sample/application/httprestclient/general/service/impl/rest/Devon4jRestClientImpl.java", "files/Devon4jRestClientImpl.java")
102150
--
103151
104152
As you can see synchronous invocation of a service is very simple and type-safe. The actual call of showResponse will technically call the remote service(i.e. VisitormanagementRestService) over the wire ( via HTTP) including marshaling the arguments (converting String to JSON) and un-marshalling the result (e.g. converting the received JSON to String).
105153
Here in Devon4jRestClientImpl, there is a method "callSynchronous" which will call the VisitormanagementRestService and return the object of VisitormanagementRestService to visitormanagementRestService.
106154
With visitormanagementRestService, it is calling the method "returnResponseToClient(String)" of server.
107155
The response from server will be stored in "resultFromAPICall" as the return type of result is String.
108-
109156
After getting response, you can handle the response further in your implementation. Here, you can see that response is getting handled in "showResponse" method.
110157
====
111158

@@ -114,59 +161,45 @@ After getting response, you can handle the response further in your implementati
114161
An application needs to be configurable in order to allow internal setup but also to allow externalized configuration of a deployed package (e.g. integration into runtime environment).
115162
Now, You need to modify the content of existing properties files and add configuration for Server.
116163
[step]
164+
== Modify properties for server configuration
117165
--
118166
changeFile("httprestclient/core/src/main/resources/application.properties", { "file": "files/client_application.txt" })
119167
changeFile("httprestclient/core/src/main/resources/config/application.properties", { "file": "files/client_config_application.txt" })
120168
--
121-
122169
## Service Discovery
123170
**service.client.default.url** :- It is used to set the default url of server and it is added for service discovery.
171+
124172
**service.client.app.httprestserver.url** :- This property provide base url of REST in your application. It follows format such as "service.client.app.«application».url". Here, «application» refers to the technical name of the application providing the service.
125173
126174
## Timeouts
127175
**service.client.default.timeout.connection** :- It is used to set the default timeout for particular connection.
176+
128177
**service.client.default.timeout.response** :- It is used to set the default timeout for particular response.
129178
130179
## Headers
131180
**service.client.app.httprestserver.auth** :- It is used for customization of Service Header. Here it is used for basic authentication.
132181
133182
## Authentication
134-
**service.client.app.httprestserver.user.login** :- It is used to set username of server for authentication
183+
**service.client.app.httprestserver.user.login** :- It is used to set username of server for authentication.
184+
135185
**service.client.app.httprestserver.user.password** :- It is used to set password.
136-
Now, after configuration you have to build and then start the client application.
137186
====
138187

139-
====
140-
You have successfully built the devon4j rest client.
141-
Let's build and start the service client application.
188+
189+
Now, Let's build and start the service client application.
142190
This might take some time for application to start.
143191
[step]
144-
== Build and Start devon4j REST Client
192+
== Build devon4j CXF REST Client
145193
--
146194
buildJava("httprestclient", false)
147195
--
148196

149-
* Once, application builds successfully. Open new terminal by clicking "+" and wait for it to load.
150-
* Now, Copy and execute below command to navigate into client server.
151-
`cd devonfw/workspaces/main/httprestclient/server`
152-
====
153-
154-
====
155-
Now, Execute below command to start the application.
156197

157198
[step]
158199
--
159-
runServerJava("httprestclient/server", { "startupTime": 1000, "port": 8081, "path": "httprestclient" })
200+
nextKatacodaStep("Start the CXF CLient Server", [{ "file": "files/startServer.md" }])
160201
--
161202

162-
To test Synchronous method, follow below steps.
163-
* Click on "+" next to terminal tab
164-
* Select "select port to view host"
165-
* Enter the port number "8081"
166-
* In the url, append "/httprestclient/services/rest/devon4jrestclient/response/"
167-
* Enter username as "admin" and password as "admin"
168-
* You will be able to see response "Welcome to rest api"
169-
====
170203

171204
====
172205
You have successfully created devon4j CXF REST Client.

0 commit comments

Comments
 (0)