Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions MrBean.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package koddas.web.war;

import java.io.Serializable;

/**
* MrBean is a simple example of a Java bean; a small class that encapsulates a
* number of values. It exposes an empty constructor and has a number of
* members that are accessible through getters and setters.
*
* @author Johan Holmberg
*/
public class MrBean implements Serializable {
/**
* Being a serializable class, the bean needs a unique identification
* number in order for the Java system to recreate saved objects.
*/
private static final long serialVersionUID = -3168349974480377280L;

private String name;
private int age;
private String nationality;
private String carBrand;

/**
* Empty constructor.
*
* Gson uses reflection to construct beans. In order to be able to do so, a
* bean must expose a constructor that doesn't take any arguments. Its
* attributes will be set by Gson upon object creation.
*/
public MrBean() {
// Let's just give the class members some standard values
name = "Rowan Atkinson";
age = 60;
nationality = "British";
carBrand = "Leyland Mini";
}

/**
* Returns the name of the bean.
*
* @return The name.
*/
public String getName() {
return name;
}

/**
* Gives the bean a new name.
*
* @param name The new name.
*/
public void setName(String name) {
this.name = name;
}

/**
* Returns the age of the bean.
*
* @return The age.
*/
public int getAge() {
return age;
}

/**
* Gives the bean a new age.
*
* @param age The new age.
*/
public void setAge(int age) {
this.age = age;
}

/**
* Returns the nationality of the bean.
*
* @return The nationality.
*/
public String getNationality() {
return nationality;
}

/**
* Gives the bean a new nationality.
*
* @param nationality The new nationality.
*/
public void setNationality(String nationality) {
this.nationality = nationality;
}

/**
* Returns the car brand of the bean.
*
* @return The car brand.
*/
public String getCarBrand() {
return carBrand;
}

/**
* Gives the bean a new car brand.
*
* @param carBrand The new car brand.
*/
public void setCarBrand(String carBrand) {
this.carBrand = carBrand;
}
}
136 changes: 136 additions & 0 deletions WebService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package koddas.web.war;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.google.gson.Gson;

/**
* A very simple web service.
*
* @author Johan Holmberg
*/
@Path("service") // By altering the argument, you'll change the service's URL
public class WebService {

/**
* Prints "It's working" when /wwp-1.0.0/webapi/service is accessed.
*
* @return A web response.
*/
@GET // This endpoint will be available using GET and GET only
@Produces(MediaType.TEXT_PLAIN) // The response will be in plain text.
public Response root() {
return Response.ok("It's working").build();
}

/**
* Prints "Hello, World!" when /wwp-1.0.0/webapi/service/hello is accessed.
*
* @return A web response.
*/
@GET
@Path("/hello") // This is appended to your URL, that is "service/hello"
@Produces(MediaType.TEXT_PLAIN)
public Response hello() {
return Response.ok("Hello, World!").build();
}

/**
* Prints current time when /wwp-1.0.0/webapi/service/time is accessed.
*
* @return A web response.
*/
@GET
@Path("/time")
@Produces(MediaType.TEXT_PLAIN)
public Response time() {
Response response = null;
DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
Date dateobj = new Date();

response = Response.ok(df.format(dateobj)).build();

return response;
}

/**
* Returns a JSON representation of a MrBean object when
* /wwp-1.0.0/webapi/service/send is accessed.
*
* @param name Mr Bean's new name
* @param age Mr Bean's new age
* @param nationality Mr Bean's new nationality
* @param carBrand The brand of Mr Bean's new car
* @return A web response.
*/
@POST
@Path("/send")
@Produces(MediaType.APPLICATION_JSON)
public Response send(@FormParam("name") String name,
@FormParam("age") int age,
@FormParam("nationality") String nationality,
@FormParam("car_brand") String carBrand) {
Gson gson = new Gson();
MrBean bean = new MrBean();

bean.setName(name);
bean.setAge(age);
bean.setNationality(nationality);
bean.setCarBrand(carBrand);

gson.toJson(bean);

return Response.ok(gson.toJson(bean)).build();
}

/**
* Returns a JSON representation of a MrBean object and a recipient when
* /wwp-1.0.0/webapi/service/send/{to} is accessed.
*
* The {to} part of the URL can be any URL-encoded string.
*
* @param to The name of the recipient of the Mr Bean object
* @param name Mr Bean's new name
* @param age Mr Bean's new age
* @param nationality Mr Bean's new nationality
* @param carBrand The brand of Mr Bean's new car
* @return A web response.
*/
@POST
@Path("/send/{to}") // {to} will map to the to parameter.
@Produces(MediaType.APPLICATION_JSON)
public Response send(@PathParam("to") String to,
@FormParam("name") String name,
@FormParam("age") int age,
@FormParam("nationality") String nationality,
@FormParam("car_brand") String carBrand) {
Gson gson = new Gson();
MrBean bean = new MrBean();
Map<String, Object> map = new HashMap<String, Object>();

bean.setName(name);
bean.setAge(age);
bean.setNationality(nationality);
bean.setCarBrand(carBrand);

map.put("to", to);
map.put("mr_bean", bean);

gson.toJson(map);

return Response.ok(gson.toJson(map)).build();
}
}
10 changes: 10 additions & 0 deletions backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
mkdir -p /home/ec2-user/tmp2
cd /home/ec2-user/tmp2
git clone https://github.com/vinaycit/backup.git
echo "WELCOME"
cd backup
sudo cp -r /var/lib/jenkins /home/ec2-user/tmp2/backup/
sudo git add .
sudo git commit -m "committed"
sudo git push https://github.com/vinaycit/backup.git master
35 changes: 35 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>koddas.web.war</groupId>
<artifactId>wwp</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<name>WAR Web Project</name>
<description>A very simple Maven-enabled WAR web project</description>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>