diff --git a/pom.xml b/pom.xml index e8bfae8..6622f1f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,10 +6,10 @@ com.inteligr8.alfresco acs-public-rest-client - 2.0.1 + 2.0.1-jersey Alfresco Content Services ReST API Client for Java - An ACS Client library for building REST API clients that support either the CXF and Jersey frameworks + An ACS Client library for building Jersey-based REST API clients https://bitbucket.org/inteligr8/acs-public-rest-client @@ -43,17 +43,18 @@ 8 lines,vars,source - acs62 + acs7 5.7.2 5.2.14.RELEASE + 2.35 com.inteligr8 common-rest-client - 2.0.1 + 2.0.1-jersey com.inteligr8.alfresco @@ -85,10 +86,49 @@ 2.17.2 test + + + + org.glassfish.jersey.inject + jersey-hk2 + ${jersey.version} + test + + + org.glassfish.jersey.media + jersey-media-json-jackson + ${jersey.version} + test + + + org.codehaus.mojo + build-helper-maven-plugin + 3.2.0 + + + add-jaxrs-src + add-source + + + src/main/jersey + + + + + add-test-src + add-test-source + + + src/test/jersey + + + + + maven-surefire-plugin 3.0.0-M5 diff --git a/src/main/jersey/com/inteligr8/alfresco/acs/AcsClientJerseyConfiguration.java b/src/main/jersey/com/inteligr8/alfresco/acs/AcsClientJerseyConfiguration.java new file mode 100644 index 0000000..578636c --- /dev/null +++ b/src/main/jersey/com/inteligr8/alfresco/acs/AcsClientJerseyConfiguration.java @@ -0,0 +1,46 @@ +/* + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ +package com.inteligr8.alfresco.acs; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import com.inteligr8.rs.ClientJerseyConfiguration; + +/** + * This class provides a POJO & Spring-based implementation of the + * ClientJerseyConfiguration interface. You can use it outside of the Spring + * context, but you will need the spring-context and spring-beans libraries in + * your non-Spring application. + * + * @author brian@inteligr8.com + */ +@Configuration +@ComponentScan +public class AcsClientJerseyConfiguration extends AcsClientConfiguration implements ClientJerseyConfiguration { + + @Value("${content.service.jersey.putBodyRequired:true}") + private boolean putBodyRequired; + + public boolean isPutBodyRequired() { + return this.putBodyRequired; + } + + public void setPutBodyRequired(boolean putBodyRequired) { + this.putBodyRequired = putBodyRequired; + } + +} diff --git a/src/main/jersey/com/inteligr8/alfresco/acs/AcsClientJerseyImpl.java b/src/main/jersey/com/inteligr8/alfresco/acs/AcsClientJerseyImpl.java new file mode 100644 index 0000000..1a6a215 --- /dev/null +++ b/src/main/jersey/com/inteligr8/alfresco/acs/AcsClientJerseyImpl.java @@ -0,0 +1,43 @@ +/* + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ +package com.inteligr8.alfresco.acs; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +import com.inteligr8.rs.ClientJerseyImpl; + +/** + * This class provides a POJO & Spring-based implementation of the Jersey + * client configured for APS. You can use it outside of the Spring context, + * but you will need the spring-context and spring-beans libraries in your + * non-Spring application. + * + * @author brian@inteligr8.com + */ +@Component("acs.client.jersey") +@Lazy +public class AcsClientJerseyImpl extends ClientJerseyImpl { + + /** + * This constructor is for Spring and POJO use + */ + @Autowired + public AcsClientJerseyImpl(AcsClientJerseyConfiguration config) { + super(config); + } + +} diff --git a/src/main/jersey/com/inteligr8/alfresco/acs/AcsPublicRestApiJerseyImpl.java b/src/main/jersey/com/inteligr8/alfresco/acs/AcsPublicRestApiJerseyImpl.java new file mode 100644 index 0000000..33048db --- /dev/null +++ b/src/main/jersey/com/inteligr8/alfresco/acs/AcsPublicRestApiJerseyImpl.java @@ -0,0 +1,39 @@ +/* + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ +package com.inteligr8.alfresco.acs; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +/** + * This class provides the Jersey client to the JAX-RS API for the ACS Public + * ReST API. + * + * @author brian@inteligr8.com + */ +@Component("acs.api.jersey") +@Lazy +public class AcsPublicRestApiJerseyImpl extends AcsPublicRestApiImpl implements AcsPublicRestJerseyApi { + + /** + * This constructor is for Spring or POJO use + */ + @Autowired + public AcsPublicRestApiJerseyImpl(AcsClientJerseyImpl client) { + super(client); + } + +} diff --git a/src/test/jersey/META-INF/services/javax.ws.rs.client.ClientBuilder b/src/test/jersey/META-INF/services/javax.ws.rs.client.ClientBuilder new file mode 100644 index 0000000..48b9fa5 --- /dev/null +++ b/src/test/jersey/META-INF/services/javax.ws.rs.client.ClientBuilder @@ -0,0 +1 @@ +org.glassfish.jersey.client.JerseyClientBuilder \ No newline at end of file diff --git a/src/test/jersey/com/inteligr8/alfresco/acs/ConnectionJerseyClientIT.java b/src/test/jersey/com/inteligr8/alfresco/acs/ConnectionJerseyClientIT.java new file mode 100644 index 0000000..5b71830 --- /dev/null +++ b/src/test/jersey/com/inteligr8/alfresco/acs/ConnectionJerseyClientIT.java @@ -0,0 +1,42 @@ +/* + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ +package com.inteligr8.alfresco.acs; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import com.inteligr8.rs.ClientConfiguration; + +@TestPropertySource(locations = {"/local.properties"}) +@SpringJUnitConfig(classes = {AcsClientJerseyConfiguration.class, AcsPublicRestApiJerseyImpl.class, AcsClientJerseyImpl.class}) +public class ConnectionJerseyClientIT extends ConnectionClientIT { + + @Autowired + @Qualifier("acs.api.jersey") + private AcsPublicRestApiImpl api; + + @Override + public AcsPublicRestApi getApi() { + return this.api; + } + + @Override + public ClientConfiguration getConfiguration() { + return this.api.getClient().getConfig(); + } + +} diff --git a/src/test/jersey/com/inteligr8/alfresco/acs/JerseyUploadIT.java b/src/test/jersey/com/inteligr8/alfresco/acs/JerseyUploadIT.java new file mode 100644 index 0000000..40d9794 --- /dev/null +++ b/src/test/jersey/com/inteligr8/alfresco/acs/JerseyUploadIT.java @@ -0,0 +1,72 @@ +/* + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ +package com.inteligr8.alfresco.acs; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.text.ParseException; +import java.util.Collections; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIf; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; + +import com.inteligr8.alfresco.acs.model.Node; +import com.inteligr8.alfresco.acs.model.NodeBodyCreate; +import com.inteligr8.alfresco.acs.model.NodeBodyCreateMultipartJersey; +import com.inteligr8.rs.ClientConfiguration; + +@TestPropertySource(locations = {"/local.properties"}) +@SpringJUnitConfig(classes = {AcsClientJerseyConfiguration.class, AcsPublicRestApiJerseyImpl.class, AcsClientJerseyImpl.class}) +public class JerseyUploadIT extends UploadIT { + + @Autowired + @Qualifier("acs.api.jersey") + private AcsPublicRestApiJerseyImpl api; + + @Override + public AcsPublicRestApi getApi() { + return this.api; + } + + @Override + public ClientConfiguration getConfiguration() { + return this.api.getClient().getConfig(); + } + + @Test + @EnabledIf("hostExists") + public void uploadFile() throws IOException, ParseException { + String folderNodeId = this.getSharedFolder(); + + NodeBodyCreate nodeBody = new NodeBodyCreate().nodeType("trx:transferReport").name("test-name1.txt") + .properties(Collections.singletonMap("cm:author", "Brian")); + + ByteArrayInputStream istream = new ByteArrayInputStream("This is a test".getBytes()); + NodeBodyCreateMultipartJersey body = NodeBodyCreateMultipartJersey.from(nodeBody, "test-name2.txt", istream, true, null, null); + + Node newNode = this.api.getNodesExtApi().createNode(folderNodeId, body).getEntry(); + Assertions.assertNotNull(newNode); + Assertions.assertNotNull(newNode.getId()); + Assertions.assertEquals(folderNodeId, newNode.getParentId()); + Assertions.assertEquals(nodeBody.getNodeType(), newNode.getNodeType()); + Assertions.assertTrue(newNode.getName().startsWith("test-name1")); + } + +}