15 |
16 |
--------------------------------------------------------------------------------
/webservices/rest-client/rest-client/src/app/users.component.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 | import {UserService, User} from './app.service';
3 |
4 | @Component({
5 | selector: 'users-page',
6 | providers: [UserService],
7 | templateUrl: './users.component.html',
8 | styleUrls: ['./app.component.css']
9 | })
10 | export class UsersComponent {
11 | title = 'Users';
12 |
13 | constructor(
14 | private _service:UserService){}
15 |
16 | public user = {email: "", name: ""};
17 | public res=[];
18 |
19 | addUser() {
20 | this._service.addUser(this.user)
21 | .subscribe( () => this.getUsers());
22 | }
23 |
24 | getUsers() {
25 | this._service.getUsers()
26 | .subscribe(
27 | users => {
28 | this.res=[];
29 | users.forEach(usr => {
30 | this.res.push(
31 | new User(
32 | usr.email,
33 | usr.name
34 | )
35 | )
36 | });
37 | });
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/webservices/rest-client/rest-client/src/assets/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Baeldung/stackify/8e84872a1d27a10d08b75fdbcceff092e74637dc/webservices/rest-client/rest-client/src/assets/.gitkeep
--------------------------------------------------------------------------------
/webservices/rest-client/rest-client/src/environments/environment.prod.ts:
--------------------------------------------------------------------------------
1 | export const environment = {
2 | production: true
3 | };
4 |
--------------------------------------------------------------------------------
/webservices/rest-client/rest-client/src/environments/environment.ts:
--------------------------------------------------------------------------------
1 | // The file contents for the current environment will overwrite these during build.
2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do
3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead.
4 | // The list of which env maps to which file can be found in `.angular-cli.json`.
5 |
6 | export const environment = {
7 | production: false
8 | };
9 |
--------------------------------------------------------------------------------
/webservices/rest-client/rest-client/src/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Baeldung/stackify/8e84872a1d27a10d08b75fdbcceff092e74637dc/webservices/rest-client/rest-client/src/favicon.ico
--------------------------------------------------------------------------------
/webservices/rest-client/rest-client/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | RestClient
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/webservices/rest-client/rest-client/src/main.ts:
--------------------------------------------------------------------------------
1 | import { enableProdMode } from '@angular/core';
2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3 |
4 | import { AppModule } from './app/app.module';
5 | import { environment } from './environments/environment';
6 |
7 | if (environment.production) {
8 | enableProdMode();
9 | }
10 |
11 | platformBrowserDynamic().bootstrapModule(AppModule);
12 |
--------------------------------------------------------------------------------
/webservices/rest-client/rest-client/src/polyfills.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * This file includes polyfills needed by Angular and is loaded before the app.
3 | * You can add your own extra polyfills to this file.
4 | *
5 | * This file is divided into 2 sections:
6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
8 | * file.
9 | *
10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
13 | *
14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
15 | */
16 |
17 | /***************************************************************************************************
18 | * BROWSER POLYFILLS
19 | */
20 |
21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/
22 | // import 'core-js/es6/symbol';
23 | // import 'core-js/es6/object';
24 | // import 'core-js/es6/function';
25 | // import 'core-js/es6/parse-int';
26 | // import 'core-js/es6/parse-float';
27 | // import 'core-js/es6/number';
28 | // import 'core-js/es6/math';
29 | // import 'core-js/es6/string';
30 | // import 'core-js/es6/date';
31 | // import 'core-js/es6/array';
32 | // import 'core-js/es6/regexp';
33 | // import 'core-js/es6/map';
34 | // import 'core-js/es6/weak-map';
35 | // import 'core-js/es6/set';
36 |
37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */
38 | // import 'classlist.js'; // Run `npm install --save classlist.js`.
39 |
40 | /** IE10 and IE11 requires the following to support `@angular/animation`. */
41 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
42 |
43 |
44 | /** Evergreen browsers require these. **/
45 | import 'core-js/es6/reflect';
46 | import 'core-js/es7/reflect';
47 |
48 |
49 | /** ALL Firefox browsers require the following to support `@angular/animation`. **/
50 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`.
51 |
52 |
53 |
54 | /***************************************************************************************************
55 | * Zone JS is required by Angular itself.
56 | */
57 | import 'zone.js/dist/zone'; // Included with Angular CLI.
58 |
59 |
60 |
61 | /***************************************************************************************************
62 | * APPLICATION IMPORTS
63 | */
64 |
65 | /**
66 | * Date, currency, decimal and percent pipes.
67 | * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
68 | */
69 | // import 'intl'; // Run `npm install --save intl`.
70 | /**
71 | * Need to import at least one locale-data with intl.
72 | */
73 | // import 'intl/locale-data/jsonp/en';
74 |
--------------------------------------------------------------------------------
/webservices/rest-client/rest-client/src/styles.css:
--------------------------------------------------------------------------------
1 | /* You can add global styles to this file, and also import other style files */
2 |
--------------------------------------------------------------------------------
/webservices/rest-client/rest-client/src/test.ts:
--------------------------------------------------------------------------------
1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2 |
3 | import 'zone.js/dist/long-stack-trace-zone';
4 | import 'zone.js/dist/proxy.js';
5 | import 'zone.js/dist/sync-test';
6 | import 'zone.js/dist/jasmine-patch';
7 | import 'zone.js/dist/async-test';
8 | import 'zone.js/dist/fake-async-test';
9 | import { getTestBed } from '@angular/core/testing';
10 | import {
11 | BrowserDynamicTestingModule,
12 | platformBrowserDynamicTesting
13 | } from '@angular/platform-browser-dynamic/testing';
14 |
15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
16 | declare const __karma__: any;
17 | declare const require: any;
18 |
19 | // Prevent Karma from running prematurely.
20 | __karma__.loaded = function () {};
21 |
22 | // First, initialize the Angular testing environment.
23 | getTestBed().initTestEnvironment(
24 | BrowserDynamicTestingModule,
25 | platformBrowserDynamicTesting()
26 | );
27 | // Then we find all the tests.
28 | const context = require.context('./', true, /\.spec\.ts$/);
29 | // And load the modules.
30 | context.keys().map(context);
31 | // Finally, start Karma to run the tests.
32 | __karma__.start();
33 |
--------------------------------------------------------------------------------
/webservices/rest-client/rest-client/src/tsconfig.app.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/app",
5 | "module": "es2015",
6 | "baseUrl": "",
7 | "types": []
8 | },
9 | "exclude": [
10 | "test.ts",
11 | "**/*.spec.ts"
12 | ]
13 | }
14 |
--------------------------------------------------------------------------------
/webservices/rest-client/rest-client/src/tsconfig.spec.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../tsconfig.json",
3 | "compilerOptions": {
4 | "outDir": "../out-tsc/spec",
5 | "module": "commonjs",
6 | "target": "es5",
7 | "baseUrl": "",
8 | "types": [
9 | "jasmine",
10 | "node"
11 | ]
12 | },
13 | "files": [
14 | "test.ts"
15 | ],
16 | "include": [
17 | "**/*.spec.ts",
18 | "**/*.d.ts"
19 | ]
20 | }
21 |
--------------------------------------------------------------------------------
/webservices/rest-client/rest-client/src/typings.d.ts:
--------------------------------------------------------------------------------
1 | /* SystemJS module definition */
2 | declare var module: NodeModule;
3 | interface NodeModule {
4 | id: string;
5 | }
6 |
--------------------------------------------------------------------------------
/webservices/rest-client/rest-client/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compileOnSave": false,
3 | "compilerOptions": {
4 | "outDir": "./dist/out-tsc",
5 | "baseUrl": "src",
6 | "sourceMap": true,
7 | "declaration": false,
8 | "moduleResolution": "node",
9 | "emitDecoratorMetadata": true,
10 | "experimentalDecorators": true,
11 | "target": "es5",
12 | "typeRoots": [
13 | "node_modules/@types"
14 | ],
15 | "lib": [
16 | "es2016",
17 | "dom"
18 | ]
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/webservices/rest-server/WebContent/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Class-Path:
3 |
4 |
--------------------------------------------------------------------------------
/webservices/rest-server/WebContent/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 | rest-server
7 |
8 | rest-server
9 | org.glassfish.jersey.servlet.ServletContainer
10 |
11 | javax.ws.rs.Application
12 | com.stackify.ApplicationInitializer
13 |
14 | 1
15 |
16 |
17 | rest-server
18 | /*
19 |
20 |
--------------------------------------------------------------------------------
/webservices/rest-server/src/main/java/com/stackify/ApplicationInitializer.java:
--------------------------------------------------------------------------------
1 | package com.stackify;
2 |
3 | import org.glassfish.jersey.server.ResourceConfig;
4 |
5 | public class ApplicationInitializer extends ResourceConfig {
6 | public ApplicationInitializer() {
7 | packages("com.stackify.services");
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/webservices/rest-server/src/main/java/com/stackify/models/User.java:
--------------------------------------------------------------------------------
1 | package com.stackify.models;
2 |
3 | import javax.ws.rs.core.Link;
4 |
5 | public class User {
6 | private String email;
7 | private String name;
8 | private Link link;
9 |
10 | public User() {
11 | }
12 |
13 | public User(String email, String name) {
14 | super();
15 | this.email = email;
16 | this.name = name;
17 | }
18 |
19 | public String getEmail() {
20 | return email;
21 | }
22 |
23 | public void setEmail(String email) {
24 | this.email = email;
25 | }
26 |
27 | public String getName() {
28 | return name;
29 | }
30 |
31 | public void setName(String name) {
32 | this.name = name;
33 | }
34 |
35 | public Link getLink() {
36 | return link;
37 | }
38 |
39 | public void setLink(Link link) {
40 | this.link = link;
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/webservices/rest-server/src/main/java/com/stackify/services/CorsFilter.java:
--------------------------------------------------------------------------------
1 | package com.stackify.services;
2 |
3 | import java.io.IOException;
4 |
5 | import javax.ws.rs.container.ContainerRequestContext;
6 | import javax.ws.rs.container.ContainerResponseContext;
7 | import javax.ws.rs.container.ContainerResponseFilter;
8 | import javax.ws.rs.ext.Provider;
9 |
10 | @Provider
11 | public class CorsFilter implements ContainerResponseFilter {
12 |
13 | @Override
14 | public void filter(final ContainerRequestContext requestContext,
15 | final ContainerResponseContext response) throws IOException {
16 | response.getHeaders().add("Access-Control-Allow-Origin", "*");
17 | response.getHeaders().add("Access-Control-Allow-Headers", "origin, content-type, accept");
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/webservices/rest-server/src/main/java/com/stackify/services/UserService.java:
--------------------------------------------------------------------------------
1 | package com.stackify.services;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import javax.ws.rs.Consumes;
7 | import javax.ws.rs.GET;
8 | import javax.ws.rs.POST;
9 | import javax.ws.rs.Path;
10 | import javax.ws.rs.Produces;
11 | import javax.ws.rs.core.MediaType;
12 | import javax.ws.rs.core.Response;
13 |
14 | import com.stackify.models.User;
15 |
16 | @Path("/users")
17 | public class UserService {
18 | private static List users = new ArrayList<>();
19 |
20 | @POST
21 | @Consumes(MediaType.APPLICATION_JSON)
22 | public Response addUser(User user) {
23 | users.add(user);
24 | return Response.ok()
25 | .build();
26 | }
27 |
28 | @GET
29 | @Produces(MediaType.APPLICATION_JSON)
30 | public List getUsers() {
31 | return users;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/webservices/rest-server/src/test/java/com/stackify/services/UserServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.stackify.services;
2 |
3 | import org.junit.Test;
4 |
5 | import io.restassured.RestAssured;
6 | import static io.restassured.RestAssured.*;
7 | import static org.hamcrest.CoreMatchers.*;
8 |
9 | public class UserServiceTest {
10 | @Test
11 | public void whenAddUser_thenGetUserOk() {
12 | RestAssured.baseURI = "http://localhost:8080/rest-server";
13 |
14 | //@formatter:off
15 |
16 | String json = "{\"email\":\"john@gmail.com\",\"name\":\"John\"}";
17 | given()
18 | .contentType("application/json")
19 | .body(json)
20 | .when()
21 | .post("/users")
22 | .then()
23 | .statusCode(200);
24 |
25 | when()
26 | .get("/users")
27 | .then()
28 | .contentType("application/json")
29 | .body("name", hasItem("John"))
30 | .body("email", hasItem("john@gmail.com"));
31 |
32 | //@formatter:on
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/webservices/soap_client/src/main/java/com/stackify/JAXWSClient.java:
--------------------------------------------------------------------------------
1 | package com.stackify;
2 |
3 | import com.stackify.services.DefaultUserImplService;
4 | import com.stackify.services.User;
5 | import com.stackify.services.UserService;
6 | import com.stackify.services.Users;
7 |
8 | public class JAXWSClient {
9 | public static void main(String[] args) {
10 | DefaultUserImplService service = new DefaultUserImplService();
11 | User user = new User();
12 | user.setEmail("john@gmail.com");
13 | user.setName("John");
14 | UserService port = service.getDefaultUserImplPort();
15 | port.addUser(user);
16 | Users users = port.getUsers();
17 | System.out.println(users.getUsers().iterator().next().getName());
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/webservices/soap_client/src/main/java/com/stackify/services/ObjectFactory.java:
--------------------------------------------------------------------------------
1 |
2 | package com.stackify.services;
3 |
4 | import javax.xml.bind.annotation.XmlRegistry;
5 |
6 |
7 | /**
8 | * This object contains factory methods for each
9 | * Java content interface and Java element interface
10 | * generated in the com.stackify.services package.
11 | *
An ObjectFactory allows you to programatically
12 | * construct new instances of the Java representation
13 | * for XML content. The Java representation of XML
14 | * content can consist of schema derived interfaces
15 | * and classes representing the binding of schema
16 | * type definitions, element declarations and model
17 | * groups. Factory methods for each of these are
18 | * provided in this class.
19 | *
20 | */
21 | @XmlRegistry
22 | public class ObjectFactory {
23 |
24 |
25 | /**
26 | * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.stackify.services
27 | *
28 | */
29 | public ObjectFactory() {
30 | }
31 |
32 | /**
33 | * Create an instance of {@link User }
34 | *
35 | */
36 | public User createUser() {
37 | return new User();
38 | }
39 |
40 | /**
41 | * Create an instance of {@link Users }
42 | *
43 | */
44 | public Users createUsers() {
45 | return new Users();
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/webservices/soap_client/src/main/java/com/stackify/services/User.java:
--------------------------------------------------------------------------------
1 |
2 | package com.stackify.services;
3 |
4 | import javax.xml.bind.annotation.XmlAccessType;
5 | import javax.xml.bind.annotation.XmlAccessorType;
6 | import javax.xml.bind.annotation.XmlType;
7 |
8 |
9 | /**
10 | *
Java class for user complex type.
11 | *
12 | *
The following schema fragment specifies the expected content contained within this class.
13 | *
14 | *
28 | *
29 | *
30 | */
31 | @XmlAccessorType(XmlAccessType.FIELD)
32 | @XmlType(name = "users", propOrder = {
33 | "users"
34 | })
35 | public class Users {
36 |
37 | @XmlElement(nillable = true)
38 | protected List users;
39 |
40 | /**
41 | * Gets the value of the users property.
42 | *
43 | *
44 | * This accessor method returns a reference to the live list,
45 | * not a snapshot. Therefore any modification you make to the
46 | * returned list will be present inside the JAXB object.
47 | * This is why there is not a set method for the users property.
48 | *
49 | *
50 | * For example, to add a new item, do as follows:
51 | *