├── .gitignore ├── src └── main │ ├── webapp │ └── WEB-INF │ │ ├── application │ │ └── web.xml │ ├── java │ └── me │ │ └── sumithpuri │ │ └── github │ │ └── hochiminh │ │ └── rest │ │ ├── vo │ │ └── Product.java │ │ ├── app │ │ └── HoChiMinhApplication.java │ │ ├── persistence │ │ └── HoChiMinhPersistenceManager.java │ │ └── webservice │ │ └── HoChiMinhWebService.java │ └── client │ └── me │ └── sumithpuri │ └── github │ └── hochiminh │ └── client │ └── HoChiMinhRestClient.java ├── LICENSE ├── README.md └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/application: -------------------------------------------------------------------------------- 1 | me.sumithpuri.github.hochiminh.rest.webservice.HoChiMinhWebService -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Sumith Kumar Puri 4 | 5 | [Refer Each Code File for the Actual Licence Statement] 6 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | products 4 | 5 | restService 6 | org.apache.wink.server.internal.servlet.RestServlet 7 | 8 | javax.ws.rs.Application 9 | me.sumithpuri.github.hochiminh.rest.app.HoChiMinhApplication 10 | 11 | 12 | 13 | restService 14 | /rest/* 15 | 16 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/hochiminh/rest/vo/Product.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.hochiminh.rest.vo; 2 | 3 | import javax.xml.bind.annotation.XmlAttribute; 4 | import javax.xml.bind.annotation.XmlElement; 5 | import javax.xml.bind.annotation.XmlRootElement; 6 | 7 | /** 8 | * MIT License 9 | * 10 | * Copyright (c) 2018-19, Sumith Kumar Puri 11 | 12 | * GitHub URL https://github.com/sumithpuri 13 | * Blog Post URL http://www.techilashots.com/2015/03/rest-using-apache-wink-xmljson.html 14 | * Blog Short URL https://goo.gl/fSmu7c 15 | * Package Prefix me.sumithpuri.github.hochiminh 16 | * Project Codename hochiminh 17 | * Contact E-Mail code@sumithpuri.me 18 | * Contact WhatsApp +91 9591497974 19 | * 20 | * 21 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 22 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 23 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 24 | * persons to whom the Software is furnished to do so, subject to the following conditions: 25 | * 26 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 27 | * Software. 28 | * 29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 30 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 31 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 32 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 33 | */ 34 | @XmlRootElement(name="product") 35 | public class Product { 36 | 37 | long id; 38 | String name; 39 | 40 | @XmlAttribute 41 | public long getId() { 42 | return id; 43 | } 44 | 45 | public void setId(long id) { 46 | this.id = id; 47 | } 48 | 49 | @XmlElement(name="name") 50 | public String getName() { 51 | return name; 52 | } 53 | 54 | public void setName(String name) { 55 | this.name = name; 56 | } 57 | 58 | public String toString() { 59 | String productStr="ID:" + this.id + ", NAME: " + this.name; 60 | return productStr; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/hochiminh/rest/app/HoChiMinhApplication.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.hochiminh.rest.app; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | import javax.ws.rs.core.Application; 7 | 8 | import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider; 9 | import org.codehaus.jackson.map.AnnotationIntrospector; 10 | import org.codehaus.jackson.map.ObjectMapper; 11 | import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; 12 | 13 | import me.sumithpuri.github.hochiminh.rest.webservice.HoChiMinhWebService; 14 | 15 | /** 16 | * MIT License 17 | * 18 | * Copyright (c) 2018-19, Sumith Kumar Puri 19 | 20 | * GitHub URL https://github.com/sumithpuri 21 | * Blog Post URL http://www.techilashots.com/2015/03/rest-using-apache-wink-xmljson.html 22 | * Blog Short URL https://goo.gl/fSmu7c 23 | * Package Prefix me.sumithpuri.github.hochiminh 24 | * Project Codename hochiminh 25 | * Contact E-Mail code@sumithpuri.me 26 | * Contact WhatsApp +91 9591497974 27 | * 28 | * 29 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 30 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 31 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 32 | * persons to whom the Software is furnished to do so, subject to the following conditions: 33 | * 34 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 35 | * Software. 36 | * 37 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 38 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 39 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 40 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 41 | */ 42 | public class HoChiMinhApplication extends Application { 43 | 44 | @Override 45 | public Set> getClasses() { 46 | Set> classes = new HashSet>(); 47 | classes.add(HoChiMinhWebService.class); 48 | return classes; 49 | } 50 | 51 | @Override 52 | public Set getSingletons() { 53 | 54 | Set s = new HashSet<>(); 55 | ObjectMapper objMapper = new ObjectMapper(); 56 | AnnotationIntrospector primary = new JaxbAnnotationIntrospector(); 57 | AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(); 58 | 59 | AnnotationIntrospector pair = AnnotationIntrospector.pair(primary, secondary); 60 | objMapper.getDeserializationConfig().withAnnotationIntrospector(pair); 61 | objMapper.getSerializationConfig().withAnnotationIntrospector(pair); 62 | 63 | JacksonJaxbJsonProvider jaxbProvider = new JacksonJaxbJsonProvider(); 64 | jaxbProvider.setMapper(objMapper); 65 | 66 | s.add(jaxbProvider); 67 | 68 | return s; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/me/sumithpuri/github/hochiminh/rest/persistence/HoChiMinhPersistenceManager.java: -------------------------------------------------------------------------------- 1 | package me.sumithpuri.github.hochiminh.rest.persistence; 2 | 3 | 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import me.sumithpuri.github.hochiminh.rest.vo.Product; 8 | 9 | /** 10 | * MIT License 11 | * 12 | * Copyright (c) 2018-19, Sumith Kumar Puri 13 | 14 | * GitHub URL https://github.com/sumithpuri 15 | * Blog Post URL http://www.techilashots.com/2015/03/rest-using-apache-wink-xmljson.html 16 | * Blog Short URL https://goo.gl/fSmu7c 17 | * Package Prefix me.sumithpuri.github.hochiminh 18 | * Project Codename hochiminh 19 | * Contact E-Mail code@sumithpuri.me 20 | * Contact WhatsApp +91 9591497974 21 | * 22 | * 23 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 24 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 25 | * rights to use, copy, modify, merge, publish, distribute, sub-license and/or sell copies of the Software and to permit 26 | * persons to whom the Software is furnished to do so, subject to the following conditions: 27 | * 28 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 29 | * Software. 30 | * 31 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 32 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 33 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 34 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 35 | */ 36 | public class HoChiMinhPersistenceManager { 37 | 38 | private List productDatabase = new ArrayList(); 39 | private static HoChiMinhPersistenceManager persistenceManager; 40 | private static int id=0; 41 | 42 | private HoChiMinhPersistenceManager() { 43 | 44 | } 45 | 46 | public Product getProduct(long productId) { 47 | 48 | System.out.println("Database: Retrieving Product " + productId); 49 | Product product = null; 50 | boolean found = false; 51 | for(int i=0;i get() { 74 | System.out.println("Database: Retrieved All Products"); 75 | return productDatabase; 76 | } 77 | 78 | public void update(long productId, String productName) { 79 | System.out.println("Database: Modified One Product"); 80 | 81 | for(int i=0;i 4 | MIT License, Copyright (c) 2018-19, Sumith Kumar Puri
5 | https://github.com/sumithpuri 6 |
7 | 8 |

9 | 10 |

11 | 12 |
13 |
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 |
29 | 30 |
31 | 32 | 33 | 34 | 35 | 37 |

❤️ 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)

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 | --------------------------------------------------------------------------------