Skip to content

Commit 71e7a7e

Browse files
SpringBootJsonXmlRequestResponseExample
1 parent 1826419 commit 71e7a7e

File tree

14 files changed

+763
-0
lines changed

14 files changed

+763
-0
lines changed
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
2+
3+
to build the jar file
4+
-------------------------
5+
> mvn package
6+
7+
To Execute the Application
8+
---------------------------
9+
>mvn spring-boot:run
10+
11+
To get the output
12+
-------------------------
13+
url http://localhost:8080/
14+
15+
To exit from Execution
16+
--------------------------
17+
ctrl-c
18+
19+
To execute the jar file
20+
-----------------------------
21+
>java -jar target/SpringBootJsonXmlRequestResponseExample.jar
22+
23+
or create a jar and execute a file
24+
--------------------------------------
25+
>mvn package && java -jar target/SpringBootJsonXmlRequestResponseExample.jar
26+
27+
-----------------------------------------------------------------------------------------
28+
To get the output message
29+
-------------------------
30+
Get Request Url => http://localhost:8080/application/message
31+
32+
Hello Adarsh Welcome To Spring Boot
33+
-----------------------------------------------------------------------------------------
34+
Get Request Url => http://localhost:8080/application/user/list
35+
Header Values
36+
Accept : application/json
37+
38+
Output of the Service
39+
40+
[
41+
{
42+
"userId": 100,
43+
"firstName": "adarsh",
44+
"lastName": "kumar",
45+
"email": "adarsh@kumar"
46+
},
47+
{
48+
"userId": 101,
49+
"firstName": "amit",
50+
"lastName": "kumar",
51+
"email": "amit@kumar"
52+
},
53+
{
54+
"userId": 102,
55+
"firstName": "radha",
56+
"lastName": "singh",
57+
"email": "radha@singh"
58+
},
59+
{
60+
"userId": 104,
61+
"firstName": "sonu",
62+
"lastName": "singh",
63+
"email": "sonu@singh"
64+
}
65+
]
66+
-----------------------------------------------------------------------------------------
67+
Get Request Url => http://localhost:8080/application/user/list
68+
69+
Header Values
70+
Accept : application/xml
71+
72+
<List xmlns="">
73+
<item>
74+
<userId>100</userId>
75+
<firstName>adarsh</firstName>
76+
<lastName>kumar</lastName>
77+
<email>adarsh@kumar</email>
78+
</item>
79+
<item>
80+
<userId>101</userId>
81+
<firstName>amit</firstName>
82+
<lastName>kumar</lastName>
83+
<email>amit@kumar</email>
84+
</item>
85+
<item>
86+
<userId>102</userId>
87+
<firstName>radha</firstName>
88+
<lastName>singh</lastName>
89+
<email>radha@singh</email>
90+
</item>
91+
</List>
92+
-----------------------------------------------------------------------------------------
93+
Post Request Url => http://localhost:8080/application/user/save
94+
Header values
95+
Accept : application/json
96+
Content-Type : application/json
97+
98+
Post Request Body Value
99+
{
100+
"userId": 104,
101+
"firstName": "sonu",
102+
"lastName": "singh",
103+
"email": "sonu@singh"
104+
}
105+
106+
Output of the Request
107+
{
108+
"message": "User Saved ",
109+
"httpStatus": "200"
110+
}
111+
-----------------------------------------------------------------------------------------
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
5+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
7+
<modelVersion>4.0.0</modelVersion>
8+
9+
<groupId>SpringBootJsonXmlRequestResponseExample</groupId>
10+
<artifactId>SpringBootJsonXmlRequestResponseExample</artifactId>
11+
<version>1.0-SNAPSHOT</version>
12+
13+
<parent>
14+
<groupId>org.springframework.boot</groupId>
15+
<artifactId>spring-boot-starter-parent</artifactId>
16+
<version>1.3.1.RELEASE</version>
17+
</parent>
18+
19+
<organization>
20+
<name>ESpark</name>
21+
<url>http://adarshkumarsingh83.blogspot.in/</url>
22+
</organization>
23+
24+
<licenses>
25+
<license>
26+
<name>ESpark</name>
27+
<url>http://adarshkumarsingh83.blogspot.in/licenses/LICENSE-2.0.txt</url>
28+
<distribution>repo</distribution>
29+
</license>
30+
</licenses>
31+
32+
<developers>
33+
<developer>
34+
<id>adarshkumarsingh83</id>
35+
<name>Adarsh Kumar</name>
36+
<email>adarshkumarsingh83@gmail.com</email>
37+
<roles>
38+
<role>project architect</role>
39+
</roles>
40+
</developer>
41+
</developers>
42+
43+
<repositories>
44+
<repository>
45+
<id>maven2-repository.java.net</id>
46+
<name>Java.net Repository for Maven</name>
47+
<url>http://download.java.net/maven/2/</url>
48+
</repository>
49+
50+
<repository>
51+
<id>JBoss repository</id>
52+
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
53+
</repository>
54+
55+
<repository>
56+
<id>java.net</id>
57+
<url>https://maven.java.net/content/repositories/public/</url>
58+
</repository>
59+
60+
</repositories>
61+
62+
<properties>
63+
<project.name>SpringBootJsonXmlRequestResponseExample</project.name>
64+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
65+
<java.version>1.7</java.version>
66+
<junit.version>4.11</junit.version>
67+
<slf4j.version>1.6.1</slf4j.version>
68+
<log4j.version>1.2.17</log4j.version>
69+
</properties>
70+
71+
<dependencies>
72+
73+
<dependency>
74+
<groupId>org.springframework.boot</groupId>
75+
<artifactId>spring-boot-starter-web</artifactId>
76+
<version>1.3.1.RELEASE</version>
77+
</dependency>
78+
79+
<dependency>
80+
<groupId>org.springframework.boot</groupId>
81+
<artifactId>spring-boot-starter-test</artifactId>
82+
<version>1.2.6.RELEASE</version>
83+
</dependency>
84+
85+
<dependency>
86+
<groupId>com.fasterxml.jackson.dataformat</groupId>
87+
<artifactId>jackson-dataformat-xml</artifactId>
88+
<version>2.7.0</version>
89+
</dependency>
90+
91+
<dependency>
92+
<groupId>junit</groupId>
93+
<artifactId>junit</artifactId>
94+
<version>${junit.version}</version>
95+
</dependency>
96+
97+
<dependency>
98+
<groupId>org.slf4j</groupId>
99+
<artifactId>slf4j-api</artifactId>
100+
<version>${slf4j.version}</version>
101+
</dependency>
102+
103+
<dependency>
104+
<groupId>log4j</groupId>
105+
<artifactId>log4j</artifactId>
106+
<version>${log4j.version}</version>
107+
</dependency>
108+
109+
</dependencies>
110+
111+
<build>
112+
<finalName>${project.name}</finalName>
113+
<outputDirectory>target/classes</outputDirectory>
114+
<resources>
115+
<resource>
116+
<directory>src/main/resources</directory>
117+
<filtering>true</filtering>
118+
</resource>
119+
</resources>
120+
<plugins>
121+
<plugin>
122+
<artifactId>maven-compiler-plugin</artifactId>
123+
<configuration>
124+
<source>${java.version}</source>
125+
<target>${java.version}</target>
126+
<encoding>${project.build.sourceEncoding}</encoding>
127+
</configuration>
128+
</plugin>
129+
130+
<plugin>
131+
<groupId>org.springframework.boot</groupId>
132+
<artifactId>spring-boot-maven-plugin</artifactId>
133+
</plugin>
134+
</plugins>
135+
</build>
136+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright (c) 2015 Espark And ©Adarsh Development Services @copyright All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
*
8+
* - Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
*
11+
* - Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
*
15+
* - Neither the name of Espark nor the names of its
16+
* contributors may be used to endorse or promote products derived
17+
* from this software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20+
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
package com.espark.adarsh.bean;
32+
33+
import java.io.Serializable;
34+
35+
/**
36+
* @author Adarsh Kumar
37+
* @author $LastChangedBy: Adarsh Kumar$
38+
* @version $Revision: 0001 $, $Date:: 1/1/10 0:00 AM#$
39+
* @Espark @copyright all right reserve
40+
*/
41+
public class ResponseBean implements Serializable {
42+
43+
private String message;
44+
private String httpStatus;
45+
46+
public ResponseBean() {
47+
}
48+
49+
public ResponseBean(String message, String httpStatus) {
50+
this.message = message;
51+
this.httpStatus = httpStatus;
52+
}
53+
54+
public String getMessage() {
55+
return message;
56+
}
57+
58+
public void setMessage(String message) {
59+
this.message = message;
60+
}
61+
62+
public String getHttpStatus() {
63+
return httpStatus;
64+
}
65+
66+
public void setHttpStatus(String httpStatus) {
67+
this.httpStatus = httpStatus;
68+
}
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2015 Espark And ©Adarsh Development Services @copyright All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
*
8+
* - Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
*
11+
* - Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
*
15+
* - Neither the name of Espark nor the names of its
16+
* contributors may be used to endorse or promote products derived
17+
* from this software without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20+
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
package com.espark.adarsh.controller;
32+
33+
import com.espark.adarsh.bean.ResponseBean;
34+
import com.espark.adarsh.entity.User;
35+
36+
import java.util.List;
37+
import java.util.Map;
38+
39+
/**
40+
* @author Adarsh Kumar
41+
* @author $LastChangedBy: Adarsh Kumar$
42+
* @version $Revision: 0001 $, $Date:: 1/1/10 0:00 AM#$
43+
* @Espark @copyright all right reserve
44+
*/
45+
public interface ApplicationController {
46+
47+
public String welcomeMessage();
48+
49+
public List<User> getUserData();
50+
51+
public ResponseBean saveUser(User user);
52+
}

0 commit comments

Comments
 (0)