Skip to content

Commit 5b801fe

Browse files
Merge pull request #168 from ssarmokadam/main
modifying tutorial to fix errors
2 parents 72fba6f + 83e0ae7 commit 5b801fe

13 files changed

Lines changed: 120 additions & 97 deletions

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public abstract class BaseWebSecurityConfig extends WebSecurityConfigurerAdapter
3737
@Inject
3838
private WebSecurityConfigurer webSecurityConfigurer;
3939

40+
41+
4042
/**
4143
* Configure spring security to enable a simple webform-login + a simple rest login.
4244
*/
@@ -47,11 +49,11 @@ public abstract class BaseWebSecurityConfig extends WebSecurityConfigurerAdapter
4749
"/services/rest/logout" };
4850

4951
// disable CSRF protection by default, use csrf starter to override.
50-
http = http.csrf().disable();
52+
http = http.httpBasic().and().csrf().disable();
5153
// load starters as pluggins.
5254
http = this.webSecurityConfigurer.configure(http);
5355

54-
http.httpBasic().and()
56+
http
5557
//
5658
.userDetailsService(this.userDetailsService)
5759
// define all urls that are not to be secured
@@ -109,8 +111,7 @@ public abstract class BaseWebSecurityConfig extends WebSecurityConfigurerAdapter
109111
@SuppressWarnings("javadoc")
110112
@Inject
111113
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
112-
113-
auth.inMemoryAuthentication().withUser("admin").password(this.passwordEncoder.encode("admin")).roles("Admin");
114+
auth.inMemoryAuthentication().withUser("admin").password(this.passwordEncoder.encode("admin")).authorities("Admin");
114115
}
115116

116117
}

devon4j-http-rest-client/files/Devon4jRestClientImpl.java

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
package com.sample.application.httprestclient.general.service.api.rest;
2-
3-
import javax.ws.rs.Consumes;
4-
import javax.ws.rs.GET;
5-
import javax.ws.rs.Path;
6-
import javax.ws.rs.Produces;
7-
import javax.ws.rs.core.MediaType;
8-
9-
@Path("/devon4jrestclient")
10-
@Consumes(MediaType.APPLICATION_JSON)
11-
@Produces(MediaType.APPLICATION_JSON)
12-
public interface Devon4jRestClient {
13-
14-
@GET
15-
@Path("/response")
16-
public String showResponse();
17-
18-
@GET
19-
@Path("/clientService")
20-
public String returnServiceDetail();
21-
}
1+
package com.example.application.httprestclient.general.service.api.rest;
2+
3+
import javax.ws.rs.Consumes;
4+
import javax.ws.rs.GET;
5+
import javax.ws.rs.Path;
6+
import javax.ws.rs.Produces;
7+
import javax.ws.rs.core.MediaType;
8+
9+
@Path("/testrest/v1")
10+
@Consumes(MediaType.APPLICATION_JSON)
11+
@Produces(MediaType.APPLICATION_JSON)
12+
public interface TestRestService {
13+
14+
@GET
15+
@Path("/response/")
16+
public String showResponse();
17+
18+
@GET
19+
@Path("/verify/")
20+
public String verifyServiceWork();
21+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.example.application.httprestclient.general.service.impl.rest;
2+
3+
import javax.inject.Inject;
4+
import javax.inject.Named;
5+
6+
import com.devonfw.module.service.common.api.client.ServiceClientFactory;
7+
import com.devonfw.module.service.common.api.client.config.ServiceClientConfigBuilder;
8+
import com.example.application.httprestclient.general.service.api.rest.TestRestService;
9+
import com.example.application.httprestclient.general.service.api.rest.VisitormanagementRestService;
10+
11+
@Named("TestRestService")
12+
public class TestRestServiceImpl implements TestRestService {
13+
14+
@Inject
15+
private ServiceClientFactory serviceClientFactory;
16+
17+
@Override
18+
public String showResponse() {
19+
20+
String result = callSynchronous();
21+
System.out.println("**********inside client method***********");
22+
System.out.println(result);
23+
System.out.println("************Thank you for choosing devon4j ****************");
24+
return result;
25+
26+
}
27+
28+
private String callSynchronous() {
29+
30+
System.out.println("***********inside synchronous call************");
31+
VisitormanagementRestService visitormanagementRestService = this.serviceClientFactory.create(
32+
VisitormanagementRestService.class,
33+
new ServiceClientConfigBuilder().authBasic().userLogin("admin").userPassword("admin").buildMap());
34+
// call of service over the wire, synchronously blocking until result is received or error occurred
35+
String resultFromAPICall = visitormanagementRestService.returnResponseToClient();
36+
System.out.println("************************got result from api" + resultFromAPICall + "***************");
37+
return resultFromAPICall;
38+
}
39+
40+
@Override
41+
public String verifyServiceWork() {
42+
43+
return "Verified... service is working";
44+
}
45+
46+
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
package com.sample.application.httprestclient.general.service.api.rest;
1+
package com.example.application.httprestclient.general.service.api.rest;
22

33
import javax.ws.rs.Consumes;
44
import javax.ws.rs.GET;
55
import javax.ws.rs.Path;
66
import javax.ws.rs.Produces;
77
import javax.ws.rs.core.MediaType;
88

9-
10-
@Path("/visitormanagement")
9+
@Path("/visitormanagement/v1")
1110
@Consumes(MediaType.APPLICATION_JSON)
1211
@Produces(MediaType.APPLICATION_JSON)
1312
public interface VisitormanagementRestService {
1413

1514
@GET
16-
@Path("/clientrequest")
15+
@Path("/clientrequest/")
16+
@Consumes(MediaType.APPLICATION_JSON)
17+
@Produces(MediaType.APPLICATION_JSON)
1718
public String returnResponseToClient();
1819

1920
}

devon4j-http-rest-client/files/VisitormanagementRestService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
import javax.ws.rs.Produces;
77
import javax.ws.rs.core.MediaType;
88

9-
10-
@Path("/visitormanagement")
9+
@Path("/visitormanagement/v1")
1110
@Consumes(MediaType.APPLICATION_JSON)
1211
@Produces(MediaType.APPLICATION_JSON)
1312
public interface VisitormanagementRestService {
1413

1514
@GET
16-
@Path("/clientrequest")
15+
@Path("/clientrequest/")
16+
@Consumes(MediaType.APPLICATION_JSON)
17+
@Produces(MediaType.APPLICATION_JSON)
1718
public String returnResponseToClient();
1819

1920
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.example.application.httprestserver.visitormanagement.service.impl.rest;
22

3-
import javax.inject.Inject;
43
import javax.inject.Named;
54

65
import com.example.application.httprestserver.visitormanagement.service.api.rest.VisitormanagementRestService;
@@ -10,7 +9,8 @@ public class VisitormanagementRestServiceImpl implements VisitormanagementRestSe
109

1110
@Override
1211
public String returnResponseToClient() {
13-
String args = "welcome to rest api";
14-
return args;
12+
13+
return "Welcome to REST API world";
1514
}
16-
}
15+
16+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# If you are running in a servlet container you may add this to lib/config/application.properties in case you do not
44
# want to touch the WAR file.
55

6-
server.port=8081
6+
server.port=8080
77
spring.application.name=httprestclient
88
server.servlet.context-path=/httprestclient
99

@@ -35,8 +35,8 @@ spring.batch.job.enabled=false
3535
spring.flyway.locations=classpath:db/migration
3636

3737
# rest client setup
38-
service.client.default.url=https://[[HOST_SUBDOMAIN]]-8080-[[KATACODA_HOST]].environments.katacoda.com/httprestserver/services/rest
39-
service.client.app.httprestserver.url=https://[[HOST_SUBDOMAIN]]-8080-[[KATACODA_HOST]].environments.katacoda.com/httprestserver/services/rest
38+
service.client.default.url=https://[[HOST_SUBDOMAIN]]-8081-[[KATACODA_HOST]].environments.katacoda.com/httprestserver/services/rest
39+
service.client.app.httprestserver.url=https://[[HOST_SUBDOMAIN]]-8081-[[KATACODA_HOST]].environments.katacoda.com/httprestserver/services/rest
4040
service.client.default.timeout.connection=120
4141
service.client.default.timeout.response=3600
4242
service.client.app.httprestserver.auth=basic

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# the same container (not recommended by default) you need to ensure the WARs are extracted in webapps folder and locate
66
# the config folder inside the WEB-INF/classes folder of the webapplication.
77

8-
server.port=8081
8+
server.port=8080
99
server.servlet.context-path=/httprestclient
1010

1111
# Datasource for accessing the database
@@ -27,8 +27,8 @@ spring.flyway.enabled=true
2727
spring.flyway.clean-on-validation-error=true
2828

2929
# rest client setup
30-
service.client.default.url=https://[[HOST_SUBDOMAIN]]-8080-[[KATACODA_HOST]].environments.katacoda.com/httprestserver/services/rest
31-
service.client.app.httprestserver.url=https://[[HOST_SUBDOMAIN]]-8080-[[KATACODA_HOST]].environments.katacoda.com/httprestserver/services/rest
30+
service.client.default.url=https://[[HOST_SUBDOMAIN]]-8081-[[KATACODA_HOST]].environments.katacoda.com/httprestserver/services/rest
31+
service.client.app.httprestserver.url=https://[[HOST_SUBDOMAIN]]-8081-[[KATACODA_HOST]].environments.katacoda.com/httprestserver/services/rest
3232
service.client.default.timeout.connection=120
3333
service.client.default.timeout.response=3600
3434
service.client.app.httprestserver.auth=basic
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<dependencies>
2+
<dependency>
3+
<groupId>com.devonfw.java.starters</groupId>
4+
<artifactId>devon4j-starter-cxf-client-rest</artifactId>
5+
</dependency>

0 commit comments

Comments
 (0)