From f3189bad3e9af8c533a6b2a06e6647eee1a048cb Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 17 Aug 2011 23:53:30 +0000 Subject: [PATCH] [MRM-1490] Expose Archiva services trough rest add modules structure with the very first service : ping :-) git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1158972 13f79535-47bb-0310-9956-ffa450edef68 --- .../archiva-rest/archiva-rest-api/pom.xml | 44 +++++ .../archiva/rest/api/model/Artifact.java | 173 ++++++++++++++++++ .../archiva/rest/api/model/Dependency.java | 172 +++++++++++++++++ .../rest/api/services/PingService.java | 48 +++++ .../archiva-rest-services/pom.xml | 145 +++++++++++++++ .../DefaultPingService.java | 18 ++ .../resources/META-INF/spring-context.xml | 54 ++++++ .../rest/services/PingServiceTest.java | 50 +++++ .../src/test/resources/log4j.xml | 47 +++++ .../archiva-web/archiva-rest/pom.xml | 33 ++++ archiva-modules/archiva-web/pom.xml | 7 +- pom.xml | 74 +++++++- 12 files changed, 860 insertions(+), 5 deletions(-) create mode 100644 archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml create mode 100644 archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/Artifact.java create mode 100644 archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/Dependency.java create mode 100644 archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/PingService.java create mode 100644 archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml create mode 100644 archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org.apache.archiva.rest.services/DefaultPingService.java create mode 100644 archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml create mode 100644 archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/PingServiceTest.java create mode 100644 archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/resources/log4j.xml create mode 100644 archiva-modules/archiva-web/archiva-rest/pom.xml diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml new file mode 100644 index 000000000..55071aa82 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + + archiva-rest + org.apache.archiva + 1.4-SNAPSHOT + + archiva-rest-api + Archiva Web :: REST support :: Api + + + + org.codehaus.redback + redback-authorization-api + + + commons-logging + commons-logging + + + + + javax.ws.rs + jsr311-api + + + + org.apache.cxf + cxf-bundle-jaxrs + + + org.eclipse.jetty + jetty-server + + + commons-logging + commons-logging + + + + + diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/Artifact.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/Artifact.java new file mode 100644 index 000000000..251c5ea8c --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/Artifact.java @@ -0,0 +1,173 @@ +package org.apache.archiva.rest.api.model; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import javax.xml.bind.annotation.XmlRootElement; +import java.io.Serializable; + +@XmlRootElement( name = "artifact" ) +public class Artifact + implements Serializable +{ + private String repositoryId; + + private String groupId; + + private String artifactId; + + private String version; + + private String type; + + //private Date whenGathered; + + public Artifact() + { + + } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + if ( o == null || getClass() != o.getClass() ) + { + return false; + } + + Artifact artifact = (Artifact) o; + + if ( !artifactId.equals( artifact.artifactId ) ) + { + return false; + } + if ( !groupId.equals( artifact.groupId ) ) + { + return false; + } + if ( !repositoryId.equals( artifact.repositoryId ) ) + { + return false; + } + if ( type != null ? !type.equals( artifact.type ) : artifact.type != null ) + { + return false; + } + if ( !version.equals( artifact.version ) ) + { + return false; + } + + return true; + } + + @Override + public int hashCode() + { + int result = repositoryId.hashCode(); + result = 31 * result + groupId.hashCode(); + result = 31 * result + artifactId.hashCode(); + result = 31 * result + version.hashCode(); + result = 31 * result + ( type != null ? type.hashCode() : 0 ); + return result; + } + + @Override + public String toString() + { + return "Artifact{" + "repositoryId='" + repositoryId + '\'' + ", groupId='" + groupId + '\'' + ", artifactId='" + + artifactId + '\'' + ", version='" + version + '\'' + ", type='" + type + '\'' + '}'; + } + + public Artifact( String repositoryId, String groupId, String artifactId, String version, String type ) +// String type, Date whenGathered ) + { + this.repositoryId = repositoryId; + this.groupId = groupId; + this.artifactId = artifactId; + this.version = version; + this.type = type; + //this.whenGathered = whenGathered; + } + + public String getGroupId() + { + return groupId; + } + + public String getArtifactId() + { + return artifactId; + } + + public String getVersion() + { + return version; + } + + public String getType() + { + return type; + } + + public String getRepositoryId() + { + return repositoryId; + } + + /*public Date getWhenGathered() + { + return whenGathered; + }*/ + + public void setGroupId( String groupId ) + { + this.groupId = groupId; + } + + public void setArtifactId( String artifactId ) + { + this.artifactId = artifactId; + } + + public void setVersion( String version ) + { + this.version = version; + } + + public void setType( String type ) + { + this.type = type; + } + + public void setRepositoryId( String repositoryId ) + { + this.repositoryId = repositoryId; + } + + /*@ServiceBeanField( "whenGathered" ) + public void setWhenGathered( Date whenGathered ) + { + this.whenGathered = whenGathered; + }*/ +} diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/Dependency.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/Dependency.java new file mode 100644 index 000000000..0d945ef4e --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/Dependency.java @@ -0,0 +1,172 @@ +package org.apache.archiva.rest.api.model; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import javax.xml.bind.annotation.XmlRootElement; +import java.io.Serializable; + +@XmlRootElement( name = "dependency" ) +public class Dependency + implements Serializable +{ + private String groupId; + + private String artifactId; + + private String version; + + private String classifier; + + private String type; + + private String scope; + + @Override + public String toString() + { + return "Dependency{" + "groupId='" + groupId + '\'' + ", artifactId='" + artifactId + '\'' + ", version='" + + version + '\'' + ", classifier='" + classifier + '\'' + ", type='" + type + '\'' + ", scope='" + scope + + '\'' + '}'; + } + + @Override + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + if ( o == null || getClass() != o.getClass() ) + { + return false; + } + + Dependency that = (Dependency) o; + + if ( !artifactId.equals( that.artifactId ) ) + { + return false; + } + if ( classifier != null ? !classifier.equals( that.classifier ) : that.classifier != null ) + { + return false; + } + if ( !groupId.equals( that.groupId ) ) + { + return false; + } + if ( scope != null ? !scope.equals( that.scope ) : that.scope != null ) + { + return false; + } + if ( type != null ? !type.equals( that.type ) : that.type != null ) + { + return false; + } + if ( !version.equals( that.version ) ) + { + return false; + } + + return true; + } + + @Override + public int hashCode() + { + int result = groupId.hashCode(); + result = 31 * result + artifactId.hashCode(); + result = 31 * result + version.hashCode(); + result = 31 * result + ( classifier != null ? classifier.hashCode() : 0 ); + result = 31 * result + ( type != null ? type.hashCode() : 0 ); + result = 31 * result + ( scope != null ? scope.hashCode() : 0 ); + return result; + } + + public Dependency( String groupId, String artifactId, String version, String classifier, String type, String scope ) + { + this.groupId = groupId; + this.artifactId = artifactId; + this.version = version; + this.classifier = classifier; + this.type = type; + this.scope = scope; + } + + public String getGroupId() + { + return groupId; + } + + public void setGroupId( String groupId ) + { + this.groupId = groupId; + } + + public String getArtifactId() + { + return artifactId; + } + + public void setArtifactId( String artifactId ) + { + this.artifactId = artifactId; + } + + public String getVersion() + { + return version; + } + + public void setVersion( String version ) + { + this.version = version; + } + + public String getClassifier() + { + return classifier; + } + + public void setClassifier( String classifier ) + { + this.classifier = classifier; + } + + public String getType() + { + return type; + } + + public void setType( String type ) + { + this.type = type; + } + + public String getScope() + { + return scope; + } + + public void setScope( String scope ) + { + this.scope = scope; + } +} diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/PingService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/PingService.java new file mode 100644 index 000000000..e03362d67 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/PingService.java @@ -0,0 +1,48 @@ +package org.apache.archiva.rest.api.services; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.codehaus.plexus.redback.authorization.RedbackAuthorization; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +/** + * @author Olivier Lamy + * @since 1.4 + */ +@Path( "/pingService/" ) +public interface PingService +{ + + /** + * + * ping service to monitor Archiva with a nice returned message :-) + * @return Yeah Baby It rocks! + */ + @Path( "addAuthenticationKey" ) + @GET + @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) + @RedbackAuthorization( noRestriction = true ) + String ping( ); + +} diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml new file mode 100644 index 000000000..5ca1d23d2 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml @@ -0,0 +1,145 @@ + + + 4.0.0 + + archiva-rest + org.apache.archiva + 1.4-SNAPSHOT + + archiva-rest-services + 1.4-SNAPSHOT + Archiva Web :: REST support :: Services + + + 7.4.5.v20110725 + + + + + org.codehaus.redback + redback-authorization-api + + + commons-logging + commons-logging + + + + + org.codehaus.redback + redback-authentication-api + + + commons-logging + commons-logging + + + + + org.codehaus.redback + redback-common-integrations + + + commons-logging + commons-logging + + + + + org.apache.archiva + archiva-rest-api + + + org.codehaus.redback + redback-rest-services + + + org.codehaus.redback + redback-rest-api + + + javax.ws.rs + jsr311-api + + + + org.apache.cxf + cxf-bundle-jaxrs + + + org.eclipse.jetty + jetty-server + + + + + org.codehaus.redback + redback-rest-services + tests + test + + + + junit + junit + test + + + org.springframework + spring-test + test + + + + org.springframework + spring-web + test + + + + org.eclipse.jetty + jetty-server + ${jettyVersion} + test + + + org.eclipse.jetty + jetty-plus + ${jettyVersion} + test + + + + org.slf4j + slf4j-log4j12 + test + + + + org.apache.derby + derby + test + + + + org.slf4j + jcl-over-slf4j + test + + + + org.codehaus.redback + redback-authentication-memory + test + ${redback.version} + + + org.codehaus.redback + redback-keys-memory + test + ${redback.version} + + + + diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org.apache.archiva.rest.services/DefaultPingService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org.apache.archiva.rest.services/DefaultPingService.java new file mode 100644 index 000000000..e6d8c2849 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org.apache.archiva.rest.services/DefaultPingService.java @@ -0,0 +1,18 @@ +package org.apache.archiva.rest.services; + +import org.apache.archiva.rest.api.services.PingService; +import org.springframework.stereotype.Service; + +/** + * @author Olivier Lamy + * @since TODO + */ +@Service( "pingService#rest" ) +public class DefaultPingService + implements PingService +{ + public String ping() + { + return "Yeah Baby It rocks!"; + } +} diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml new file mode 100644 index 000000000..053891ef3 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/resources/META-INF/spring-context.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/PingServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/PingServiceTest.java new file mode 100644 index 000000000..73d3b239c --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/PingServiceTest.java @@ -0,0 +1,50 @@ +package org.apache.archiva.rest.services; + +import org.apache.archiva.rest.api.services.PingService; +import org.apache.cxf.jaxrs.client.JAXRSClientFactory; +import org.codehaus.redback.rest.services.AbstractRestServicesTest; +import org.codehaus.redback.rest.services.FakeCreateAdminService; +import org.junit.Before; +import org.junit.Test; + +/** + * @author Olivier Lamy + * @since TODO + */ +public class PingServiceTest + extends AbstractRestServicesTest +{ + + @Before + public void setUp() + throws Exception + { + super.startServer(); + + FakeCreateAdminService fakeCreateAdminService = + JAXRSClientFactory.create( "http://localhost:" + port + "/services/fakeCreateAdminService/", + FakeCreateAdminService.class ); + + Boolean res = fakeCreateAdminService.createAdminIfNeeded(); + assertTrue( res.booleanValue() ); + } + + PingService getPingService() + { + return JAXRSClientFactory.create( "http://localhost:" + port + "/services/archivaServices/", + PingService.class ); + + } + + + @Test + public void ping() + throws Exception + { + // 1000000L + //WebClient.getConfig( userService ).getHttpConduit().getClient().setReceiveTimeout(3000); + + String res = getPingService().ping(); + assertEquals( "Yeah Baby It rocks!", res ); + } +} diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/resources/log4j.xml b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/resources/log4j.xml new file mode 100644 index 000000000..8c55a1c3d --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/resources/log4j.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/archiva-modules/archiva-web/archiva-rest/pom.xml b/archiva-modules/archiva-web/archiva-rest/pom.xml new file mode 100644 index 000000000..74ad4433e --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + org.apache.archiva + archiva-web + 1.4-SNAPSHOT + + archiva-rest + Archiva Web :: REST support + pom + + archiva-rest-api + archiva-rest-services + + \ No newline at end of file diff --git a/archiva-modules/archiva-web/pom.xml b/archiva-modules/archiva-web/pom.xml index c4b17053d..5ec8f7174 100644 --- a/archiva-modules/archiva-web/pom.xml +++ b/archiva-modules/archiva-web/pom.xml @@ -13,9 +13,7 @@ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~ See the License for the specific language governing permissions and ~ limitations under the License. - --> - - + --> 4.0.0 org.apache.archiva @@ -34,6 +32,7 @@ archiva-webdav archiva-rss archiva-xmlrpc + archiva-rest @@ -44,4 +43,4 @@ - + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 340ba9d24..f8be21c8d 100644 --- a/pom.xml +++ b/pom.xml @@ -75,6 +75,7 @@ UTF-8 true 3.0.3 + 2.4.2 @@ -234,6 +235,16 @@ archiva-indexer ${project.version} + + org.apache.archiva + archiva-rest-api + ${project.version} + + + org.apache.archiva + archiva-rest-services + ${project.version} + org.apache.maven.indexer indexer-core @@ -410,6 +421,27 @@ 3.0.1 + + javax.ws.rs + jsr311-api + 1.1.1 + + + org.apache.cxf + cxf-bundle-jaxrs + ${cxfVersion} + + + org.eclipse.jetty + jetty-server + + + commons-logging + commons-logging + + + + com.google.guava @@ -702,6 +734,17 @@ + + org.codehaus.redback + redback-authorization-api + ${redback.version} + + + commons-logging + commons-logging + + + org.codehaus.redback redback-users-memory @@ -831,7 +874,36 @@ ${redback.version} - + + org.codehaus.redback + redback-rest-api + ${redback.version} + + + + org.codehaus.redback + redback-rest-services + ${redback.version} + + + org.codehaus.redback + redback-rest-services + ${redback.version} + tests + + + org.codehaus.redback + redback-authentication-api + ${redback.version} + + + commons-logging + commons-logging + + + + + org.codehaus.redback.components.registry