diff --git a/jersey-service/jersey-service.iml b/jersey-service/jersey-service.iml new file mode 100644 index 0000000000000000000000000000000000000000..f779d857847cb9dbcce74750fecd5360d5f67332 --- /dev/null +++ b/jersey-service/jersey-service.iml @@ -0,0 +1,225 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7"> + <output url="file://$MODULE_DIR$/target/classes" /> + <output-test url="file://$MODULE_DIR$/target/test-classes" /> + <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> + <excludeFolder url="file://$MODULE_DIR$/target" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.9/junit-4.9.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/glassfish/jersey/containers/jersey-container-grizzly2-http/2.17/jersey-container-grizzly2-http-2.17.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/glassfish/hk2/external/javax.inject/2.4.0-b10/javax.inject-2.4.0-b10.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/glassfish/grizzly/grizzly-http-server/2.3.16/grizzly-http-server-2.3.16.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/glassfish/grizzly/grizzly-http/2.3.16/grizzly-http-2.3.16.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/glassfish/grizzly/grizzly-framework/2.3.16/grizzly-framework-2.3.16.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/glassfish/jersey/core/jersey-common/2.17/jersey-common-2.17.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/javax/ws/rs/javax.ws.rs-api/2.0.1/javax.ws.rs-api-2.0.1.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/javax/annotation/javax.annotation-api/1.2/javax.annotation-api-1.2.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/glassfish/jersey/bundles/repackaged/jersey-guava/2.17/jersey-guava-2.17.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/glassfish/hk2/hk2-api/2.4.0-b10/hk2-api-2.4.0-b10.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/glassfish/hk2/hk2-utils/2.4.0-b10/hk2-utils-2.4.0-b10.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/glassfish/hk2/external/aopalliance-repackaged/2.4.0-b10/aopalliance-repackaged-2.4.0-b10.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/glassfish/hk2/hk2-locator/2.4.0-b10/hk2-locator-2.4.0-b10.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/javassist/javassist/3.18.1-GA/javassist-3.18.1-GA.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/glassfish/hk2/osgi-resource-locator/1.0.1/osgi-resource-locator-1.0.1.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/glassfish/jersey/core/jersey-server/2.17/jersey-server-2.17.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/glassfish/jersey/core/jersey-client/2.17/jersey-client-2.17.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/glassfish/jersey/media/jersey-media-jaxb/2.17/jersey-media-jaxb-2.17.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="library" name="Maven: org.glassfish.jersey.containers:jersey-container-grizzly2-http:2.17" level="project" /> + <orderEntry type="library" name="Maven: org.glassfish.hk2.external:javax.inject:2.4.0-b10" level="project" /> + <orderEntry type="library" name="Maven: org.glassfish.grizzly:grizzly-http-server:2.3.16" level="project" /> + <orderEntry type="library" name="Maven: org.glassfish.grizzly:grizzly-http:2.3.16" level="project" /> + <orderEntry type="library" name="Maven: org.glassfish.grizzly:grizzly-framework:2.3.16" level="project" /> + <orderEntry type="library" name="Maven: org.glassfish.jersey.core:jersey-common:2.17" level="project" /> + <orderEntry type="library" name="Maven: javax.annotation:javax.annotation-api:1.2" level="project" /> + <orderEntry type="library" name="Maven: org.glassfish.jersey.bundles.repackaged:jersey-guava:2.17" level="project" /> + <orderEntry type="library" name="Maven: org.glassfish.hk2:hk2-api:2.4.0-b10" level="project" /> + <orderEntry type="library" name="Maven: org.glassfish.hk2:hk2-utils:2.4.0-b10" level="project" /> + <orderEntry type="library" name="Maven: org.glassfish.hk2.external:aopalliance-repackaged:2.4.0-b10" level="project" /> + <orderEntry type="library" name="Maven: org.glassfish.hk2:hk2-locator:2.4.0-b10" level="project" /> + <orderEntry type="library" name="Maven: org.javassist:javassist:3.18.1-GA" level="project" /> + <orderEntry type="library" name="Maven: org.glassfish.hk2:osgi-resource-locator:1.0.1" level="project" /> + <orderEntry type="library" name="Maven: org.glassfish.jersey.core:jersey-server:2.17" level="project" /> + <orderEntry type="library" name="Maven: org.glassfish.jersey.core:jersey-client:2.17" level="project" /> + <orderEntry type="library" name="Maven: org.glassfish.jersey.media:jersey-media-jaxb:2.17" level="project" /> + <orderEntry type="library" name="Maven: javax.validation:validation-api:1.1.0.Final" level="project" /> + <orderEntry type="library" name="Maven: javax.ws.rs:javax.ws.rs-api:2.0.1" level="project" /> + <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.9" level="project" /> + <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" /> + <orderEntry type="library" name="Maven: commons-net:commons-net:2.2" level="project" /> + </component> +</module> \ No newline at end of file diff --git a/jersey-service/pom.xml b/jersey-service/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..b7b8cc9686d83ecfc3e568a0bec9b65eee888b35 --- /dev/null +++ b/jersey-service/pom.xml @@ -0,0 +1,82 @@ +<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/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <groupId>com.example.rest</groupId> + <artifactId>jersey-service</artifactId> + <packaging>jar</packaging> + <version>1.0-SNAPSHOT</version> + <name>jersey-service</name> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.glassfish.jersey</groupId> + <artifactId>jersey-bom</artifactId> + <version>${jersey.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + <dependency> + <groupId>org.glassfish.jersey.containers</groupId> + <artifactId>jersey-container-grizzly2-http</artifactId> + </dependency> + <!-- uncomment this to get JSON support: + <dependency> + <groupId>org.glassfish.jersey.media</groupId> + <artifactId>jersey-media-moxy</artifactId> + </dependency> + --> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.9</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>commons-net</groupId> + <artifactId>commons-net</artifactId> + <version>2.2</version> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.5.1</version> + <inherited>true</inherited> + <configuration> + <source>1.7</source> + <target>1.7</target> + </configuration> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>exec-maven-plugin</artifactId> + <version>1.2.1</version> + <executions> + <execution> + <goals> + <goal>java</goal> + </goals> + </execution> + </executions> + <configuration> + <mainClass>sr.flopbox.Main</mainClass> + </configuration> + </plugin> + </plugins> + </build> + + <properties> + <jersey.version>2.17</jersey.version> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> +</project> diff --git a/jersey-service/src/main/java/sr/flopbox/Client.java b/jersey-service/src/main/java/sr/flopbox/Client.java new file mode 100644 index 0000000000000000000000000000000000000000..5b6dd92fca5551324b134972392f2f61527ce6de --- /dev/null +++ b/jersey-service/src/main/java/sr/flopbox/Client.java @@ -0,0 +1,29 @@ +package sr.flopbox; + +public class Client { + + private String username; + private String password; + + public Client(String username, String password) { + this.username = username; + this.password = password; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + +} diff --git a/jersey-service/src/main/java/sr/flopbox/FtpClient.java b/jersey-service/src/main/java/sr/flopbox/FtpClient.java new file mode 100644 index 0000000000000000000000000000000000000000..9d4ed4c7892a661354cd83b550175fd2a1f9d917 --- /dev/null +++ b/jersey-service/src/main/java/sr/flopbox/FtpClient.java @@ -0,0 +1,40 @@ +package sr.flopbox; + +import org.apache.commons.net.ftp.FTP; +import org.apache.commons.net.ftp.FTPClient; +import org.apache.commons.net.ftp.FTPReply; + +import java.io.IOException; + +public class FtpClient extends FTP { + + private FTPClient client; + private String server; + private int port; + private String username; + private String password; + private int response; + + public FtpClient(String server, int port, String username, String password) { + + this.client = new FTPClient(); + this.server = server; + this.port = port; + this.username = username; + this.password = password; + } + + public void connect() throws IOException { + + this.client.connect(this.server, this.port); + this.response = this.client.getReplyCode(); + + //refus connection + if (!FTPReply.isPositiveCompletion(this.response)) { + this.client.disconnect(); + } + + //accepter la connection + } + +} diff --git a/jersey-service/src/main/java/sr/flopbox/FtpResource.java b/jersey-service/src/main/java/sr/flopbox/FtpResource.java new file mode 100644 index 0000000000000000000000000000000000000000..be7b7f3d959636486a588d379269c15d61182dd8 --- /dev/null +++ b/jersey-service/src/main/java/sr/flopbox/FtpResource.java @@ -0,0 +1,19 @@ +package sr.flopbox; + +import org.apache.commons.net.ftp.FTPClient; + +import javax.ws.rs.*; +import java.util.*; + +@Path("/ftp") +public class FtpResource { + + private static FTPClient ftpClient = new FTPClient(); + private static Map<String, String> ftpMap = new HashMap<>(); + + @POST + @Path("/{name}") + public void newFTP(@PathParam("name") String name, @FormParam("address") String address) { + ftpMap.put(name, address); + } +} diff --git a/jersey-service/src/main/java/sr/flopbox/Main.java b/jersey-service/src/main/java/sr/flopbox/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..b6b6461a6b57fd1ff064ac8c4449f64e17e8d970 --- /dev/null +++ b/jersey-service/src/main/java/sr/flopbox/Main.java @@ -0,0 +1,45 @@ +package sr.flopbox; + +import org.glassfish.grizzly.http.server.HttpServer; +import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; +import org.glassfish.jersey.server.ResourceConfig; + +import java.io.IOException; +import java.net.URI; + +/** + * Main class. + * + */ +public class Main { + // Base URI the Grizzly HTTP server will listen on + public static final String BASE_URI = "http://localhost:8080/myapp/"; + + /** + * Starts Grizzly HTTP server exposing JAX-RS resources defined in this application. + * @return Grizzly HTTP server. + */ + public static HttpServer startServer() { + // create a resource config that scans for JAX-RS resources and providers + // in sr.flopbox package + final ResourceConfig rc = new ResourceConfig().packages("sr.flopbox"); + + // create and start a new instance of grizzly http server + // exposing the Jersey application at BASE_URI + return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc); + } + + /** + * Main method. + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + final HttpServer server = startServer(); + System.out.println(String.format("Jersey app started with WADL available at " + + "%sapplication.wadl\nHit enter to stop it...", BASE_URI)); + System.in.read(); + server.stop(); + } +} + diff --git a/jersey-service/src/main/java/sr/flopbox/MyResource.java b/jersey-service/src/main/java/sr/flopbox/MyResource.java new file mode 100644 index 0000000000000000000000000000000000000000..800d282ddbe459811ac42fa434b49bcba74b8fd3 --- /dev/null +++ b/jersey-service/src/main/java/sr/flopbox/MyResource.java @@ -0,0 +1,25 @@ +package sr.flopbox; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +/** + * Root resource (exposed at "myresource" path) + */ +@Path("myresource") +public class MyResource { + + /** + * Method handling HTTP GET requests. The returned object will be sent + * to the client as "text/plain" media type. + * + * @return String that will be returned as a text/plain response. + */ + @GET + @Produces(MediaType.TEXT_PLAIN) + public String getIt() { + return "Got it!"; + } +} diff --git a/jersey-service/src/test/java/sr/flopbox/MyResourceTest.java b/jersey-service/src/test/java/sr/flopbox/MyResourceTest.java new file mode 100644 index 0000000000000000000000000000000000000000..26c59cacaada88708fe8be8b24295ee04afd2699 --- /dev/null +++ b/jersey-service/src/test/java/sr/flopbox/MyResourceTest.java @@ -0,0 +1,48 @@ +package sr.flopbox; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.WebTarget; + +import org.glassfish.grizzly.http.server.HttpServer; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static org.junit.Assert.assertEquals; + +public class MyResourceTest { + + private HttpServer server; + private WebTarget target; + + @Before + public void setUp() throws Exception { + // start the server + server = Main.startServer(); + // create the client + Client c = ClientBuilder.newClient(); + + // uncomment the following line if you want to enable + // support for JSON in the client (you also have to uncomment + // dependency on jersey-media-json module in pom.xml and Main.startServer()) + // -- + // c.configuration().enable(new org.glassfish.jersey.media.json.JsonJaxbFeature()); + + target = c.target(Main.BASE_URI); + } + + @After + public void tearDown() throws Exception { + server.stop(); + } + + /** + * Test to see that the message "Got it!" is sent in the response. + */ + @Test + public void testGetIt() { + String responseMsg = target.path("myresource").request().get(String.class); + assertEquals("Got it!", responseMsg); + } +} diff --git a/jersey-service/target/classes/sr/flopbox/Main.class b/jersey-service/target/classes/sr/flopbox/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..a3de7d3c6ca7fe5289e8c61567face21988fb8fa Binary files /dev/null and b/jersey-service/target/classes/sr/flopbox/Main.class differ diff --git a/jersey-service/target/classes/sr/flopbox/MyResource.class b/jersey-service/target/classes/sr/flopbox/MyResource.class new file mode 100644 index 0000000000000000000000000000000000000000..3d9e9f05db16dff595cda06e80781a7d966aa09f Binary files /dev/null and b/jersey-service/target/classes/sr/flopbox/MyResource.class differ