Initial import (partially)

This commit is contained in:
2013-11-23 15:49:50 +01:00
parent 50d9edfb75
commit f5ee928477
183 changed files with 69850 additions and 0 deletions

75
org.migor.service/pom.xml Normal file
View File

@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<artifactId>org.migor.server</artifactId>
<groupId>org.migor.server</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>org.migor.service</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jsapi</artifactId>
<version>2.3.2.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.websocket</groupId>
<artifactId>javax.websocket-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.migor.server</groupId>
<artifactId>org.migor.core</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}-${project.version}.war</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>true</failOnMissingWebXml>
<webResources>
<resource>
<directory>src/main/webapp</directory>
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</webResources>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<!--suppress MavenModelInspection -->
<Implementation-Build>${buildNumber}</Implementation-Build>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,20 @@
package org.migor.service;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
/**
* @author Daniel Scheidle
* @since 11/23/13 3:35 PM
*/
@Path("/ping")
public class PingService {
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response ping() {
return Response.ok();
}
}

View File

@@ -0,0 +1,65 @@
package org.migor.service;
import org.codehaus.jackson.annotate.JsonProperty;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.migor.shared.StatusCode;
import java.util.Date;
/**
* @author Daniel Scheidle
* @since 11/4/13 10:21 PM
*/
public class Response {
@JsonProperty("status")
public int status;
@JsonProperty("message")
public String message;
//TODO format with timezone
@JsonProperty("timestamp")
public Date timestamp = new Date();
@JsonProperty("content")
public Object content;
protected Response(@NotNull final StatusCode status,
@Nullable final String message,
@Nullable final Object content) {
this.status = status.getCode();
this.message = message;
this.content = content;
}
public static Response ok() {
return new Response(StatusCode.OK, null, null);
}
public static Response ok(@NotNull final Object content) {
return new Response(StatusCode.OK, null, content);
}
public static Response error(@NotNull final String message) {
return new Response(StatusCode.ERROR, message, null);
}
public int getStatus() {
return status;
}
public String getMessage() {
return message;
}
public Date getTimestamp() {
return timestamp;
}
public Object getContent() {
return content;
}
}

View File

@@ -0,0 +1,36 @@
package org.migor.service.configuration;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
import java.text.SimpleDateFormat;
/**
* @author Daniel Scheidle
* @since 11/7/13 8:15 PM
*/
@Provider
@Produces(MediaType.APPLICATION_JSON)
public class JsonConfiguration implements ContextResolver<ObjectMapper>
{
private final ObjectMapper objectMapper;
public JsonConfiguration() throws Exception
{
this.objectMapper = new ObjectMapper();
this.objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"));
this.objectMapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
}
public ObjectMapper getContext(Class<?> objectType)
{
return objectMapper;
}
}

View File

@@ -0,0 +1,33 @@
package org.migor.service.configuration;
import org.apache.log4j.Logger;
import org.migor.core.MigorException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
/**
* @author Daniel Scheidle, daniel.scheidle@ucs.at
* 15:49, 09.07.12
*/
@Provider
public class JsonExceptionMapper implements ExceptionMapper<Throwable> {
private static final Logger logger = Logger.getLogger(JsonExceptionMapper.class);
@Override
public Response toResponse(Throwable throwable) {
if (throwable instanceof MigorException) {
logger.error(throwable.getMessage(), throwable);
} else {
logger.fatal(throwable.getMessage(), throwable);
}
return Response.serverError().build();
}
}

View File

@@ -0,0 +1,16 @@
package org.migor.service.configuration;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
/**
* @author Daniel Scheidle
* @since 11/4/13 10:20 PM
*/
@ApplicationPath("/rest")
public class ServiceApplication extends Application {
}

View File

@@ -0,0 +1,31 @@
package org.migor.service.listeners;
import org.apache.log4j.Logger;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
/**
* @author Daniel Scheidle
* @since 11/6/13 8:35 PM
*/
public class SessionListener implements HttpSessionListener {
private static final Logger logger = Logger.getLogger(SessionListener.class);
@Override
public void sessionCreated(HttpSessionEvent se) {
if (logger.isDebugEnabled()) {
logger.debug("Created session " + se.getSession().getId());
}
}
@Override
public void sessionDestroyed(HttpSessionEvent se) {
if (logger.isDebugEnabled()) {
logger.debug("Destroyed session " + se.getSession().getId());
}
}
}

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
<interceptors>
</interceptors>
</beans>

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.infinispan"/>
</dependencies>
</deployment>
</jboss-deployment-structure>

View File

@@ -0,0 +1,3 @@
<jboss-web>
<context-root>/migor/services</context-root>
</jboss-web>

View File

@@ -0,0 +1,30 @@
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<distributable/>
<session-config>
<session-timeout>5</session-timeout>
</session-config>
<listener>
<listener-class>org.migor.service.listeners.SessionListener</listener-class>
</listener>
<listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<!-- RESTeasy Servlet for generating js client stubs -->
<servlet>
<servlet-name>RESTEasy JSAPI</servlet-name>
<servlet-class>org.jboss.resteasy.jsapi.JSAPIServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RESTEasy JSAPI</servlet-name>
<url-pattern>/rest/js</url-pattern>
</servlet-mapping>
</web-app>

View File

@@ -0,0 +1,8 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=8">
</head>
<body>
</body>
</html>