Skip to content

Commit dea9682

Browse files
committed
16:45 21/10/2018
1 parent cdad47b commit dea9682

20 files changed

Lines changed: 918 additions & 0 deletions

‎messenger-master/pom.xml‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.koushik.javabrains</groupId>
8+
<artifactId>messenger</artifactId>
9+
<packaging>war</packaging>
10+
<version>0.0.1-SNAPSHOT</version>
11+
<name>messenger</name>
12+
13+
<build>
14+
<finalName>messenger</finalName>
15+
<plugins>
16+
<plugin>
17+
<groupId>org.apache.maven.plugins</groupId>
18+
<artifactId>maven-compiler-plugin</artifactId>
19+
<version>3.7.0</version>
20+
<inherited>true</inherited>
21+
<configuration>
22+
<source>1.8</source>
23+
<target>1.8</target>
24+
</configuration>
25+
</plugin>
26+
</plugins>
27+
</build>
28+
29+
<dependencyManagement>
30+
<dependencies>
31+
<dependency>
32+
<groupId>org.glassfish.jersey</groupId>
33+
<artifactId>jersey-bom</artifactId>
34+
<version>${jersey.version}</version>
35+
<type>pom</type>
36+
<scope>import</scope>
37+
</dependency>
38+
</dependencies>
39+
</dependencyManagement>
40+
41+
<dependencies>
42+
<dependency>
43+
<groupId>org.glassfish.jersey.containers</groupId>
44+
<artifactId>jersey-container-servlet-core</artifactId>
45+
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
46+
<!-- artifactId>jersey-container-servlet</artifactId -->
47+
</dependency>
48+
<dependency>
49+
<groupId>org.glassfish.jersey.inject</groupId>
50+
<artifactId>jersey-hk2</artifactId>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.glassfish.jersey.media</groupId>
54+
<artifactId>jersey-media-moxy</artifactId>
55+
</dependency>
56+
</dependencies>
57+
<properties>
58+
<jersey.version>2.26</jersey.version>
59+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
60+
</properties>
61+
</project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.koushik.javabrains.messenger.database;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import org.koushik.javabrains.messenger.model.Message;
7+
import org.koushik.javabrains.messenger.model.Profile;
8+
9+
public class DatabaseClass {
10+
11+
private static Map<Long, Message> messages = new HashMap<>();
12+
private static Map<String, Profile> profiles = new HashMap<>();
13+
14+
15+
public static Map<Long, Message> getMessages() {
16+
return messages;
17+
}
18+
19+
public static Map<String, Profile> getProfiles() {
20+
return profiles;
21+
}
22+
23+
24+
25+
26+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.koushik.javabrains.messenger.exception;
2+
3+
public class DataNotFoundException extends RuntimeException {
4+
5+
/**
6+
*
7+
*/
8+
private static final long serialVersionUID = -6328286661536343936L;
9+
10+
11+
public DataNotFoundException(String message) {
12+
super(message);
13+
}
14+
15+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package org.koushik.javabrains.messenger.exception;
2+
3+
import javax.ws.rs.core.Response;
4+
import javax.ws.rs.core.Response.Status;
5+
import javax.ws.rs.ext.ExceptionMapper;
6+
import javax.ws.rs.ext.Provider;
7+
8+
import org.koushik.javabrains.messenger.model.ErrorMessage;
9+
10+
@Provider
11+
public class DataNotFoundExceptionMapper implements ExceptionMapper<DataNotFoundException> {
12+
13+
@Override
14+
public Response toResponse(DataNotFoundException ex) {
15+
ErrorMessage errorMessage = new ErrorMessage(ex.getMessage(), 404, "http://javabrains.koushik.org");
16+
return Response.status(Status.NOT_FOUND)
17+
.entity(errorMessage)
18+
.build();
19+
}
20+
21+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.koushik.javabrains.messenger.exception;
2+
3+
import javax.ws.rs.core.Response;
4+
import javax.ws.rs.core.Response.Status;
5+
import javax.ws.rs.ext.ExceptionMapper;
6+
7+
import org.koushik.javabrains.messenger.model.ErrorMessage;
8+
9+
// This class intentionally doesn't have the @Provider annotation.
10+
// It has been disabled in order to try out other ways of throwing exceptions in JAX-RS
11+
12+
// @Provider
13+
public class GenericExceptionMapper implements ExceptionMapper<Throwable> {
14+
15+
@Override
16+
public Response toResponse(Throwable ex) {
17+
ErrorMessage errorMessage = new ErrorMessage(ex.getMessage(), 500, "http://javabrains.koushik.org");
18+
return Response.status(Status.INTERNAL_SERVER_ERROR)
19+
.entity(errorMessage)
20+
.build();
21+
}
22+
23+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.koushik.javabrains.messenger.model;
2+
3+
import java.util.Date;
4+
5+
public class Comment {
6+
7+
private long id;
8+
private String message;
9+
private Date created;
10+
private String author;
11+
12+
public Comment() {
13+
14+
}
15+
16+
public Comment(long id, String message, String author) {
17+
this.id = id;
18+
this.message = message;
19+
this.author = author;
20+
this.created = new Date();
21+
}
22+
23+
public long getId() {
24+
return id;
25+
}
26+
27+
public void setId(long id) {
28+
this.id = id;
29+
}
30+
31+
public String getMessage() {
32+
return message;
33+
}
34+
35+
public void setMessage(String message) {
36+
this.message = message;
37+
}
38+
39+
public Date getCreated() {
40+
return created;
41+
}
42+
43+
public void setCreated(Date created) {
44+
this.created = created;
45+
}
46+
47+
public String getAuthor() {
48+
return author;
49+
}
50+
51+
public void setAuthor(String author) {
52+
this.author = author;
53+
}
54+
55+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.koushik.javabrains.messenger.model;
2+
3+
import javax.xml.bind.annotation.XmlRootElement;
4+
5+
@XmlRootElement
6+
public class ErrorMessage {
7+
8+
private String errorMessage;
9+
private int errorCode;
10+
private String documentation;
11+
12+
public ErrorMessage() {
13+
14+
}
15+
16+
public ErrorMessage(String errorMessage, int errorCode, String documentation) {
17+
super();
18+
this.errorMessage = errorMessage;
19+
this.errorCode = errorCode;
20+
this.documentation = documentation;
21+
}
22+
23+
public String getErrorMessage() {
24+
return errorMessage;
25+
}
26+
27+
public void setErrorMessage(String errorMessage) {
28+
this.errorMessage = errorMessage;
29+
}
30+
31+
public int getErrorCode() {
32+
return errorCode;
33+
}
34+
35+
public void setErrorCode(int errorCode) {
36+
this.errorCode = errorCode;
37+
}
38+
39+
public String getDocumentation() {
40+
return documentation;
41+
}
42+
43+
public void setDocumentation(String documentation) {
44+
this.documentation = documentation;
45+
}
46+
47+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.koushik.javabrains.messenger.model;
2+
3+
public class Link {
4+
5+
private String link;
6+
private String rel;
7+
8+
public String getLink() {
9+
return link;
10+
}
11+
12+
public void setLink(String link) {
13+
this.link = link;
14+
}
15+
16+
public String getRel() {
17+
return rel;
18+
}
19+
20+
public void setRel(String rel) {
21+
this.rel = rel;
22+
}
23+
24+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package org.koushik.javabrains.messenger.model;
2+
3+
import java.util.ArrayList;
4+
import java.util.Date;
5+
import java.util.HashMap;
6+
import java.util.List;
7+
import java.util.Map;
8+
9+
import javax.xml.bind.annotation.XmlRootElement;
10+
import javax.xml.bind.annotation.XmlTransient;
11+
12+
13+
@XmlRootElement
14+
public class Message {
15+
16+
private long id;
17+
private String message;
18+
private Date created;
19+
private String author;
20+
private Map<Long, Comment> comments = new HashMap<>();
21+
private List<Link> links = new ArrayList<>();
22+
23+
public Message() {
24+
25+
}
26+
27+
public Message(long id, String message, String author) {
28+
this.id = id;
29+
this.message = message;
30+
this.author = author;
31+
this.created = new Date();
32+
}
33+
34+
public long getId() {
35+
return id;
36+
}
37+
38+
public void setId(long id) {
39+
this.id = id;
40+
}
41+
42+
public String getMessage() {
43+
return message;
44+
}
45+
46+
public void setMessage(String message) {
47+
this.message = message;
48+
}
49+
50+
public Date getCreated() {
51+
return created;
52+
}
53+
54+
public void setCreated(Date created) {
55+
this.created = created;
56+
}
57+
58+
public String getAuthor() {
59+
return author;
60+
}
61+
62+
public void setAuthor(String author) {
63+
this.author = author;
64+
}
65+
66+
@XmlTransient
67+
public Map<Long, Comment> getComments() {
68+
return comments;
69+
}
70+
71+
public void setComments(Map<Long, Comment> comments) {
72+
this.comments = comments;
73+
}
74+
75+
public List<Link> getLinks() {
76+
return links;
77+
}
78+
79+
public void setLinks(List<Link> links) {
80+
this.links = links;
81+
}
82+
83+
public void addLink(String url, String rel) {
84+
Link link = new Link();
85+
link.setLink(url);
86+
link.setRel(rel);
87+
links.add(link);
88+
}
89+
90+
}

0 commit comments

Comments
 (0)