Commit 87be1fa0 authored by Stig B. Dørmænen's avatar Stig B. Dørmænen
Browse files

Add first working version of service

parent 3fe4f3b0
......@@ -3,7 +3,9 @@ all: run
up:
vagrant up
run: up
run: up run-services run-patron-client
run-patron-client:
vagrant ssh -c 'cd /vagrant/patron-client && make run'
echo "open http://192.168.50.50:8000/ for patron-client service in PROD mode"
......@@ -16,3 +18,10 @@ log-f:
inspect-patron-client:
vagrant ssh -c 'cd /vagrant/patron-client && make inspect'
inspect-services:
vagrant ssh -c 'cd /vagrant/services && make inspect'
run-services:
vagrant ssh -c 'cd /vagrant/services && make'
echo "open http://192.168.50.50:8080/ for services service in PROD mode"
......@@ -16,5 +16,7 @@ Vagrant.configure(2) do |config|
config.vm.provision "shell", path: "upgrade_once.sh"
config.vm.provision "shell", path: "install_docker.sh"
config.vm.provision "shell", path: "install_jdk.sh"
config.vm.provision "shell", path: "install_maven.sh"
end
end
#!/bin/bash
if [ command -v javac >/dev/null 2>&1 ]; then
echo "JDK already installed.";
else
echo "Installing jdk ..."
sudo apt-get install --quiet --assume-yes openjdk-7-jdk
echo "JDK installed."
fi
#!/bin/bash
if [ command -v mvn >/dev/null 2>&1 ]; then
echo "Maven already installed.";
else
echo "Installing maven ..."
sudo apt-get install --quiet --assume-yes maven
echo "Maven installed."
fi
Makefile
README.md
\ No newline at end of file
target
nbactions.xml
FROM java:8
ADD ./target/services-1.0-SNAPSHOT.jar /services/
WORKDIR /services
ENTRYPOINT ["java", "-jar", "/services/services-1.0-SNAPSHOT.jar"]
CMD [""]
\ No newline at end of file
all: build run
build:
mvn clean install
sudo docker build --tag redef-services /vagrant/services
stop:
sudo docker stop redef-services || true
rm: stop
sudo docker rm redef-services || true
run: build rm
sudo docker run -d -p 8080:8080 --name redef-services redef-services
log-f:
sudo docker logs -f redef-services
inspect:
sudo docker exec -it redef-services /bin/bash
Service layer/backend (JVM).
See [Makefile](Makefile).
<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>no.deichman.services</groupId>
<artifactId>services</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>services</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jetty.version>9.2.10.v20150310</jetty.version>
<jersey.version>2.16</jersey.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-jetty-http</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.11</version>
<scope>test</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.3.3</version>
<scope>test</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.11</version>
<scope>test</scope>
<type>jar</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>no.deichman.services.App</Main-Class>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
package no.deichman.services;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
public class App {
public static void main(String[] args) throws Exception {
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
Server jettyServer = new Server(8080);
jettyServer.setHandler(context);
ServletHolder jerseyServlet = context.addServlet(
org.glassfish.jersey.servlet.ServletContainer.class, "/*");
jerseyServlet.setInitOrder(0);
// Tells the Jersey Servlet which REST service/class to load.
jerseyServlet.setInitParameter(
"jersey.config.server.provider.classnames",
Work.class.getCanonicalName());
try {
jettyServer.start();
jettyServer.join();
} finally {
jettyServer.destroy();
}
}
}
package no.deichman.services;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@Path("/work")
public class Work {
@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public Response listWork() {
String jsonString = "{\"message\":\"Hello,client!\"}";
return Response.ok(jsonString).build();
}
}
\ No newline at end of file
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package no.deichman.services;
import com.fasterxml.jackson.core.JsonParseException;
import java.io.IOException;
import javax.ws.rs.core.Response;
import junit.framework.TestCase;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.map.ObjectMapper;
/**
*
* @author sbd
*/
public class WorkTest extends TestCase {
public WorkTest(String testName) {
super(testName);
}
@Override
protected void setUp() throws Exception {
super.setUp();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
/**
* Test of listWork method, of class Work.
*/
public void testListWork() {
System.out.println("listWork");
Work instance = new Work();
Response expResult = null;
Response result = instance.listWork();
assertNotNull(result);
assertEquals(200, result.getStatus());
assertTrue(isValidJSON(result.getEntity().toString()));
}
public boolean isValidJSON(final String json) {
boolean valid = false;
try {
final JsonParser parser = new ObjectMapper().getJsonFactory()
.createJsonParser(json);
while (parser.nextToken() != null) {
}
valid = true;
} catch (JsonParseException jpe) {
jpe.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
return valid;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment