14 |
15 | |Project Codename|HoChiMinh|
16 | |--|--|
17 | | Blog Post URL | http://www.techilashots.com/2015/03/rest-using-apache-wink-xmljson.html |
18 | |Blog Short URL |https://goo.gl/fSmu7c|
19 | |Package Prefix|me.sumithpuri.github.hochiminh|
20 | |GitHub URL|https://github.com/sumithpuri/skp-code-marathon-hochiminh|
21 | |Contact E-Mail |code@sumithpuri.xyz|
22 | |Contact Number|+91 9591497974 (WhatsApp, Viber, Telegram)|
23 | |Historical|✅ Started this Movement of 1000s of Lines of Java/EE* Code to GitHub
✅ Was a Senior Software Architect (Java/EE) in Manila*, 2018 (At Start)
✅ Named this Initial Code Journey as [ Manila Code Marathon - 2018 ]
✅ Code Is Non-Proprietary / Non-Copyright from my Work Experience.
✅ Was Back to Bangalore, Named as [ Bangalore Code Nights - 2019. ]
✅ Added More Code under [ -20 Days of Code in Benglauru- ] in 2020
✅ Celebration of Java/Java EE Code as Java Turned 25 in the Year 2020! |
24 |
25 |
26 |
27 |
28 |
31 |
32 |
33 |  |
34 |
35 | ❤️ Ex-Yahoo, Symantec, Huawei, Oracle*, OpenText*, Finastra*, Atos* 🧡 Xth, XIIth (Computer Science) - Naval Public School, Kochi, India 💛 Bachelor of Engineering (Computer Science)* - SRSIT, Bangalore 💜 Executive Program ( Data Mining and Analytics ) - [IIT, Roorkee] 💚 Executive Certificate Program (Entrepreneurship) - IIM, Kashipur
💙 Proficience (Cryptography & Network Security) - IISc, Bangalore 🤎 Proficience (Innovative Product Design & Dev.) - IISc, Bangalore 🖤 Proficience (Artficial Intelligence/Intelli Agents) - IISc, Bangalore
💎 Sun Certified Java Programmer 1.4 (Core Java) 💎 Sun Certified Java Programmer 5.0 (Core Java) 💎 Sun Certified Business Component Developer 1.3 (EJB/J2EE) 💎 Sun Certified Business Component Developer 5.0 (EJB/J2EE) 💎 Brainbench Spring 2.x Certification*, ( J2EE/Spring ) 💎 Brainbench Hibernate 3.x Certification* (Hibernate) 💎 Brainbench Java EE 6.x Certification*, ( J2EE ) 💎 Quest C Lang. Certification (C Programming) 💎 Quest C++ Certification (C++ Programming) 💎 Quest Data Structures Certification ( C/C++ )
36 | 🏁 Highest IQ (147) ~ Among Entire Secondary School Batch ~ (Xth) 🏁 MVIT Inter-Collegiate C Programming Contest (Finalist, Top 8) 🏁 SJCIT Inter-Collegiate Web Design (Runners-Up) 🏁 Google India Code Jam 2005 (#376/14,000) - India + SE Asia 🏁 Microsoft Bizspark Startup 2011-'12 (Shortlisted/Recognized) 🏁 Societe Generale Brainwaves Hackathon 2015 (Corp Finalist, AI) 🏁 Mphasis Internal Hackathon Challenge, Season-07 (#07/106)* 🏁 Techgig Code Gladiators 2015 (Open, Top 500) 🏁 Accenture in India YouTube Contest 2015 (BigData, Winner) 🏁 Xebia-Microsoft-GitHub Blogathon 2022 (Microservices, Winner)
🏆 Senior Member, ACM (Elevated) and Senior Member, IEEE (Elevated) 🏆 Author/Blogger, Technology Advice (Developer.com and jGuru) 🏆 DZone Most Valuable Blogger and DZone Core (Elevated)** 🏆 Author and Blogger, Friends of Open JDK Community (Foojay.IO) 🏆 Blogger, Java Code Geeks Program (Shortlisted/Recognized) 🏆 Paid Blogger, Developer.com and jGuru; Blogger, HackerNoon; 🎯 19y Across Associate/Engineer (2003) to Java Practice Leader (2024) |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
🔴 ALL COPYRIGHTS FOR THE ABOVE PUBLICLY AVAILABLE IMAGE OR PARTS OF THE IMAGE ARE WITH THEIR RESPECTIVE OWNERS, SOURCED/USED FROM GOOGLE SEARCH
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 |
6 | me.sumithpuri.github
7 | skp-code-marathon-hochiminh
8 | 0.0.1-SNAPSHOT
9 | war
10 |
11 | HoChiMinh : REST Using Apache Wink (XML/JSON)
12 | http://maven.apache.org
13 |
14 |
15 | UTF-8
16 | 9
17 | 9
18 | false
19 |
20 |
21 |
22 |
23 | junit
24 | junit
25 | 3.8.1
26 | test
27 |
28 |
29 | org.apache.wink
30 | wink-server
31 | 1.4
32 |
33 |
34 | org.apache.wink
35 | wink-common
36 | 1.4
37 |
38 |
39 | javax.xml.stream
40 | stax-api
41 | 1.0-2
42 |
43 |
44 | org.slf4j
45 | slf4j-simple
46 | 1.6.1
47 |
48 |
49 | org.slf4j
50 | slf4j-api
51 | 1.6.1
52 |
53 |
54 | com.sun.xml.bind
55 | jaxb-impl
56 | 2.2.1
57 |
58 |
59 | org.apache.geronimo.specs
60 | geronimo-jaxrs_1.1_spec
61 | 1.0
62 |
63 |
64 | commons-lang
65 | commons-lang
66 | 2.3
67 |
68 |
69 | javax.activation
70 | activation
71 | 1.1.1
72 |
73 |
74 | org.apache.wink
75 | wink-jackson-provider
76 | 1.4
77 |
78 |
79 | org.codehaus.jackson
80 | jackson-xc
81 | 1.9.13
82 |
83 |
84 | org.codehaus.jackson
85 | jackson-mapper-asl
86 | 1.9.13
87 |
88 |
89 | org.codehaus.jackson
90 | jackson-jaxrs
91 | 1.9.13
92 |
93 |
94 | org.codehaus.jackson
95 | jackson-core-asl
96 | 1.9.13
97 |
98 |
99 | org.apache.wink
100 | wink-client
101 | 1.4
102 |
103 |
104 |
105 |
106 | hochiminh
107 |
108 |
109 | org.apache.maven.plugins
110 | maven-compiler-plugin
111 | 3.1
112 |
113 |
114 |
115 | src/main/client/
116 |
117 |
118 |
119 |
120 |
121 | Code Samples for the Blog Article [REST Using Apache Wink (XML/JSON)]
122 |
123 |
--------------------------------------------------------------------------------
/src/main/java/me/sumithpuri/github/hochiminh/rest/webservice/HoChiMinhWebService.java:
--------------------------------------------------------------------------------
1 | package me.sumithpuri.github.hochiminh.rest.webservice;
2 |
3 |
4 | import java.util.List;
5 |
6 | import javax.ws.rs.DELETE;
7 | import javax.ws.rs.GET;
8 | import javax.ws.rs.POST;
9 | import javax.ws.rs.PUT;
10 | import javax.ws.rs.Path;
11 | import javax.ws.rs.PathParam;
12 | import javax.ws.rs.Produces;
13 | import javax.ws.rs.core.MediaType;
14 |
15 | import me.sumithpuri.github.hochiminh.rest.persistence.HoChiMinhPersistenceManager;
16 | import me.sumithpuri.github.hochiminh.rest.vo.Product;
17 |
18 | /**
19 | * MIT License
20 | *
21 | * Copyright (c) 2018-19, Sumith Kumar Puri
22 |
23 | * GitHub URL https://github.com/sumithpuri
24 | * Blog Post URL http://www.techilashots.com/2015/03/rest-using-apache-wink-xmljson.html
25 | * Blog Short URL https://goo.gl/fSmu7c
26 | * Package Prefix me.sumithpuri.github.hochiminh
27 | * Project Codename hochiminh
28 | * Contact E-Mail code@sumithpuri.me
29 | * Contact WhatsApp +91 9591497974
30 | *
31 | *
32 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
33 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
34 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit
35 | * persons to whom the Software is furnished to do so, subject to the following conditions:
36 | *
37 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
38 | * Software.
39 | *
40 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
41 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
42 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
43 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44 | */
45 | @Path("hochiminh")
46 | public class HoChiMinhWebService {
47 |
48 | HoChiMinhPersistenceManager persistenceManager = HoChiMinhPersistenceManager.getInstance();
49 |
50 | static {
51 |
52 | System.out.println("Copyright (c) 2018-19, Sumith Kumar Puri");
53 | System.out.println();
54 | System.out.println("Project Codename HoChiMinh (REST Web Service)");
55 | System.out.println("Project Description REST Using Apache Wink (XML/JSON) Demo Code");
56 | System.out.println("Technical Blog http://www.techilashots.com");
57 | System.out.println("Technical Blog Post https://goo.gl/fSmu7c");
58 | System.out.println("[Developer Notes] [01] Use Java Version 9.0+ Compiler");
59 | System.out.println();
60 | }
61 |
62 | @GET
63 | @Produces(MediaType.TEXT_PLAIN)
64 | public String getProducts() {
65 |
66 | List
products = persistenceManager.get();
67 | String productList = new String();
68 |
69 | for(Product producti: products) {
70 | productList+=producti.toString() + "\n";
71 | }
72 |
73 | // return as plain text - other types include xml, json
74 | return productList;
75 | }
76 |
77 | @GET
78 | @Path("/{id}")
79 | @Produces(MediaType.APPLICATION_XML)
80 | public Product getProductById(@PathParam(value="id") long id) {
81 | Product product = persistenceManager.getProduct(id);
82 | return product;
83 | }
84 |
85 | @GET
86 | @Path("/json/{id}")
87 | @Produces(MediaType.APPLICATION_JSON)
88 | public Product getProductJsonById(@PathParam(value="id") long id) {
89 | Product product = persistenceManager.getProduct(id);
90 | return product;
91 | }
92 |
93 |
94 | @POST
95 | public String addProducts(String productStr) {
96 |
97 | Product product = new Product();
98 | product.setName(productStr);
99 | persistenceManager.add(product);
100 |
101 | return productStr;
102 | }
103 |
104 | @DELETE
105 | @Path("/{id}")
106 | public void deleteProduct(@PathParam(value="id") long id) {
107 |
108 | persistenceManager.delete(id);
109 | return;
110 | }
111 |
112 | @PUT
113 | @Path("/{id}")
114 | public void modifyProduct(@PathParam(value="id") long id, String productName) {
115 |
116 | persistenceManager.update(id, productName);
117 | return;
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/src/main/client/me/sumithpuri/github/hochiminh/client/HoChiMinhRestClient.java:
--------------------------------------------------------------------------------
1 | package me.sumithpuri.github.hochiminh.client;
2 |
3 | import javax.ws.rs.core.MediaType;
4 |
5 | import org.apache.wink.client.ClientConfig;
6 | import org.apache.wink.client.ClientResponse;
7 | import org.apache.wink.client.Resource;
8 | import org.apache.wink.client.RestClient;
9 |
10 | /**
11 | * MIT License
12 | *
13 | * Copyright (c) 2018-19, Sumith Kumar Puri
14 |
15 | * GitHub URL https://github.com/sumithpuri
16 | * Blog Post URL http://www.techilashots.com/2015/03/rest-using-apache-wink-xmljson.html
17 | * Blog Short URL https://goo.gl/fSmu7c
18 | * Package Prefix me.sumithpuri.github.hochiminh
19 | * Project Codename hochiminh
20 | * Contact E-Mail code@sumithpuri.me
21 | * Contact WhatsApp +91 9591497974
22 | *
23 | *
24 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
25 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
26 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit
27 | * persons to whom the Software is furnished to do so, subject to the following conditions:
28 | *
29 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
30 | * Software.
31 | *
32 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
33 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
34 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
35 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 | */
37 | public class HoChiMinhRestClient {
38 |
39 | static String REST_WEB_SERVICE = "http://localhost:8080/hochiminh/rest/hochiminh";
40 | static ClientConfig clientConfig = new ClientConfig();
41 |
42 | /**
43 | * @param args
44 | */
45 | public static void main(String[] args) throws Exception {
46 |
47 | try {
48 |
49 | HoChiMinhRestClient restClient = new HoChiMinhRestClient();
50 |
51 | System.out.println("Copyright (c) 2018-19, Sumith Kumar Puri");
52 | System.out.println();
53 | System.out.println("Project Codename HoChiMinh (REST Web Service Client)");
54 | System.out.println("Project Description REST Using Apache Wink (XML/JSON) Demo Code");
55 | System.out.println("Technical Blog http://www.techilashots.com");
56 | System.out.println("Technical Blog Post https://goo.gl/fSmu7c");
57 | System.out.println("[Developer Notes] [01] Use Java Version 9.0+ Compiler");
58 | System.out.println();
59 |
60 | restClient.configureClient();
61 | System.out.println();
62 |
63 | restClient.invokeGET();
64 | System.out.println();
65 |
66 | String product = "Sumith Puri" + (int) (Math.random() * 9999);
67 | restClient.invokePOST(product);
68 |
69 | System.out.println();
70 | product = "Sumith Puri" + (int) (Math.random() * 9999);
71 | restClient.invokePOST(product);
72 |
73 | System.out.println();
74 | product = "Sumith Puri" + (int) (Math.random() * 9999);
75 | restClient.invokePOST(product);
76 |
77 | System.out.println();
78 | product = "Sumith Puri" + (int) (Math.random() * 9999);
79 | restClient.invokePOST(product);
80 |
81 | System.out.println();
82 | restClient.invokeGET();
83 |
84 | System.out.println();
85 | restClient.invokeDELETE(2L);
86 |
87 | System.out.println();
88 | restClient.invokeGET();
89 |
90 | System.out.println();
91 | product = "Sumith Puri" + (int) (Math.random() * 9999);
92 | restClient.invokePOST(product);
93 |
94 | System.out.println();
95 | product = "Sumith Puri" + (int) (Math.random() * 9999);
96 | restClient.invokePOST(product);
97 |
98 | System.out.println();
99 | restClient.invokeDELETE(4L);
100 |
101 | System.out.println();
102 | restClient.invokeGET();
103 |
104 | System.out.println();
105 | restClient.invokePUT(3L, "Sumith Puri");
106 |
107 | System.out.println();
108 | restClient.invokeGET();
109 |
110 | System.out.println();
111 | restClient.invokeJSONGET(3);
112 |
113 | System.out.println();
114 | restClient.invokeJSONGET(2);
115 |
116 | } catch (Exception e) {
117 |
118 | e.printStackTrace();
119 | }
120 | }
121 |
122 | public void configureClient() {
123 |
124 | }
125 |
126 | public void invokeGET() {
127 |
128 | System.out.println("Testing GET command....");
129 | RestClient restClient = new RestClient(clientConfig);
130 | Resource resource = restClient.resource(REST_WEB_SERVICE);
131 | String response = resource.accept("text/plain").get(String.class);
132 | System.out.printf(response);
133 | System.out.println("...GET command is successful");
134 | }
135 |
136 | public void invokePOST(String product) {
137 |
138 | System.out.println("Testing POST command...");
139 | RestClient restClient = new RestClient(clientConfig);
140 | Resource resource = restClient.resource(REST_WEB_SERVICE);
141 | resource.contentType(MediaType.TEXT_PLAIN).accept(MediaType.TEXT_PLAIN).post(String.class, product);
142 | System.out.println("...POST command is successful");
143 | }
144 |
145 | public void invokePUT(Long id, String productName) {
146 |
147 | System.out.println("Testing PUT command...");
148 | RestClient restClient = new RestClient(clientConfig);
149 | Resource resource = restClient.resource(REST_WEB_SERVICE + "/" + id);
150 | resource.contentType(MediaType.TEXT_PLAIN).accept(MediaType.TEXT_PLAIN).put(String.class, productName);
151 | System.out.println("...PUT command is successful");
152 | }
153 |
154 | public void invokeDELETE(Long id) {
155 |
156 | System.out.println("Testing DELETE command...");
157 | RestClient restClient = new RestClient(clientConfig);
158 | Resource resource = restClient.resource(REST_WEB_SERVICE + "/" + id);
159 | resource.contentType(MediaType.TEXT_PLAIN).accept(MediaType.TEXT_PLAIN).delete();
160 | System.out.println("...DELETE command is successful");
161 | }
162 |
163 | public void invokeJSONGET(long id) {
164 | System.out.println("Testing JSON GET command....");
165 | RestClient restClient = new RestClient(clientConfig);
166 | Resource resource = restClient.resource(REST_WEB_SERVICE + "/json/" + id);
167 | ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).get();
168 | System.out.println("...JSON GET command is successful");
169 | }
170 |
171 | public void invokeJAXBGET(long id) {
172 | System.out.println("Testing JAXB GET command....");
173 | RestClient restClient = new RestClient(clientConfig);
174 | Resource resource = restClient.resource(REST_WEB_SERVICE + "/" + id);
175 | ClientResponse response = resource.accept(MediaType.APPLICATION_XML).get();
176 | System.out.println("...JAXB GET command is successful");
177 | }
178 | }
179 |
--------------------------------------------------------------------------------