diff --git a/pom.xml b/pom.xml index 4d4f655f49..78d26d5b51 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,5 @@ - + 4.0.0 @@ -12,6 +11,7 @@ scm-core + scm-agent scm-webapp @@ -59,8 +59,6 @@ - scm-webapp - diff --git a/scm-agent/pom.xml b/scm-agent/pom.xml new file mode 100644 index 0000000000..e806282470 --- /dev/null +++ b/scm-agent/pom.xml @@ -0,0 +1,81 @@ + + + + 4.0.0 + + + scm + sonia.scm + 1.0-SNAPSHOT + + + sonia.scm + scm-agent + 1.0-SNAPSHOT + scm-agent + + + + + sonia.scm + scm-core + 1.0-SNAPSHOT + + + + com.sun.jersey + jersey-server + 1.3 + + + + com.sun.grizzly + grizzly-servlet-webserver + 1.9.18-m + + + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.3.1 + + + true + + sonia.scm.agent.Main + true + lib/ + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.1 + + + package + + copy-dependencies + + + ${project.build.directory}/lib + + + + + + + + + + diff --git a/scm-agent/src/main/java/sonia/scm/agent/Main.java b/scm-agent/src/main/java/sonia/scm/agent/Main.java new file mode 100644 index 0000000000..ba4691dbca --- /dev/null +++ b/scm-agent/src/main/java/sonia/scm/agent/Main.java @@ -0,0 +1,103 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + + + +package sonia.scm.agent; + +//~--- JDK imports ------------------------------------------------------------ + +import com.sun.grizzly.http.SelectorThread; +import com.sun.jersey.api.container.grizzly.GrizzlyWebContainerFactory; + +import java.io.IOException; + +import java.text.MessageFormat; + +import java.util.HashMap; +import java.util.Map; + +/** + * + * @author Sebastian Sdorra + */ +public class Main +{ + + /** Field description */ + private static final int DEFAULT_PORT = 8989; + + /** Field description */ + private static final String DEFAULT_URI = "http://localhost:{0}/"; + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + * + * @param args + * + * @throws IOException + */ + public static void main(String[] args) throws IOException + { + SelectorThread threadSelector = startServer(); + + // TODO replace + System.in.read(); + System.out.println("Shutting down ..."); + threadSelector.stopEndpoint(); + System.exit(0); + } + + /** + * Method description + * + * + * @return + * + * @throws IOException + */ + protected static SelectorThread startServer() throws IOException + { + final Map initParams = new HashMap(); + + initParams.put("com.sun.jersey.config.property.packages", + "sonia.scm.agent.resources"); + System.out.println("Starting grizzly..."); + + int port = getPort(DEFAULT_PORT); + String uri = MessageFormat.format(DEFAULT_URI, String.valueOf(port)); + + return GrizzlyWebContainerFactory.create(uri, initParams); + } + + //~--- get methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @param defaultPort + * + * @return + */ + private static int getPort(int defaultPort) + { + String port = System.getenv("JERSEY_HTTP_PORT"); + + if (null != port) + { + try + { + return Integer.parseInt(port); + } + catch (NumberFormatException e) {} + } + + return defaultPort; + } +} diff --git a/scm-agent/src/main/java/sonia/scm/agent/resources/AgentResource.java b/scm-agent/src/main/java/sonia/scm/agent/resources/AgentResource.java new file mode 100644 index 0000000000..2d5603dc7f --- /dev/null +++ b/scm-agent/src/main/java/sonia/scm/agent/resources/AgentResource.java @@ -0,0 +1,36 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + + + +package sonia.scm.agent.resources; + +//~--- JDK imports ------------------------------------------------------------ + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; + +/** + * + * @author Sebastian Sdorra + */ +@Path("/agent") +public class AgentResource +{ + + /** + * Method description + * + * + * @return + */ + @GET + @Produces("text/plain") + public String hello() + { + return "Hello from Agent"; + } +}