diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component
index e424036..4413d77 100644
--- a/.settings/org.eclipse.wst.common.component
+++ b/.settings/org.eclipse.wst.common.component
@@ -11,9 +11,6 @@
uses
-
- uses
-
diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml
index c82abf3..71d64dd 100644
--- a/.settings/org.eclipse.wst.common.project.facet.core.xml
+++ b/.settings/org.eclipse.wst.common.project.facet.core.xml
@@ -3,5 +3,5 @@
-
+
diff --git a/gcube/extra-resources/WEB-INF/sun-jaxws.xml b/gcube/extra-resources/WEB-INF/sun-jaxws.xml
deleted file mode 100644
index 87d03c5..0000000
--- a/gcube/extra-resources/WEB-INF/sun-jaxws.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/gcube/extra-resources/WEB-INF/web.xml b/gcube/extra-resources/WEB-INF/web.xml
index 9566646..9fd650f 100644
--- a/gcube/extra-resources/WEB-INF/web.xml
+++ b/gcube/extra-resources/WEB-INF/web.xml
@@ -1,43 +1,12 @@
-
-
-
- com.sun.xml.ws.transport.http.servlet.WSServletContextListener
-
-
-
+
- whnmanager
- com.sun.xml.ws.transport.http.servlet.WSServlet
+ org.gcube.resourcemanagement.whnmanager.WHNManager
+
-
-
- whnmanager
- /gcube/vremanagement/ws/whnmanager
+ org.gcube.resourcemanagement.whnmanager.WHNManager
+ /*
-
-
+
diff --git a/pom.xml b/pom.xml
index bfc81c5..97ea121 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,70 +30,54 @@
-
- org.slf4j
- slf4j-api
-
+
org.gcube.core
common-smartgears
-
- javax.servlet
- javax.servlet-api
- 4.0.1
- provided
-
-
-
- javax.ws.rs
- javax.ws.rs-api
-
-
org.gcube.core
common-smartgears-app
+
+
- org.gcube.common
- gxHTTP
+ javax.ws.rs
+ javax.ws.rs-api
+
+
+ org.glassfish.jersey.containers
+ jersey-container-servlet
- org.jboss.weld.servlet
- weld-servlet-core
- 2.0.4.Final
-
-
- jboss-el-api_3.0_spec
- org.jboss.spec.javax.el
-
-
+ javax.servlet
+ javax.servlet-api
+ 3.0.1
+
+
+
+
+ org.glassfish.jersey.media
+ jersey-media-json-jackson
+
+
+
+ org.slf4j
+ slf4j-api
- jboss-el-api_3.0_spec
- org.jboss.spec.javax.el
- 1.0.0.Alpha1
- provided
-
-
-
- org.jboss.weld
- weld-core
- 2.0.4.Final
-
-
- junit
- junit
- 4.11
- test
-
-
- org.gcube.resourcemanagement
- whnmanager-api
- [2.0.2-SNAPSHOT, 3.0.0-SNAPSHOT)
+ org.glassfish.jersey.test-framework
+ jersey-test-framework-core
+ test
+
+
+
+ org.glassfish.jersey.test-framework.providers
+ jersey-test-framework-provider-grizzly2
+ test
diff --git a/src/main/java/org/gcube/vremanagement/whnmanager/jaxws/ws/WhnManagerImpl.java b/src/main/java/org/gcube/vremanagement/whnmanager/ContextManager.java
similarity index 75%
rename from src/main/java/org/gcube/vremanagement/whnmanager/jaxws/ws/WhnManagerImpl.java
rename to src/main/java/org/gcube/vremanagement/whnmanager/ContextManager.java
index f3cad93..b25816c 100644
--- a/src/main/java/org/gcube/vremanagement/whnmanager/jaxws/ws/WhnManagerImpl.java
+++ b/src/main/java/org/gcube/vremanagement/whnmanager/ContextManager.java
@@ -1,42 +1,42 @@
-package org.gcube.vremanagement.whnmanager.jaxws.ws;
+package org.gcube.vremanagement.whnmanager;
import java.net.HttpURLConnection;
import java.util.Map.Entry;
+import java.util.Set;
-import javax.jws.WebService;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.gcube.common.gxhttp.request.GXHTTPStringRequest;
import org.gcube.common.gxhttp.util.ContentUtils;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.common.security.secrets.Secret;
-import org.gcube.resourcemanagement.whnmanager.api.WhnManager;
-import org.gcube.resourcemanagement.whnmanager.api.exception.GCUBEUnrecoverableException;
import org.gcube.smartgears.ContextProvider;
import org.gcube.smartgears.context.application.ApplicationContext;
import org.gcube.smartgears.managers.ContextEvents;
import org.gcube.smartgears.security.SimpleCredentials;
import org.gcube.smartgears.security.defaults.DefaultAuthorizationProvider;
+import org.gcube.smartgears.utils.InnerMethodName;
import org.gcube.vremanagement.whnmanager.utils.ValidationUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-//import org.gcube.common.calls.jaxws.Constants;
-@WebService(portName = "WhnManagerIOPort",
-serviceName = WhnManager.SERVICE_NAME,
-targetNamespace = WhnManager.TNS,
-endpointInterface = "org.gcube.resourcemanagement.whnmanager.api.WhnManager" )
-//@Singleton
-public class WhnManagerImpl implements WhnManager{
-
-
- private static Logger logger=LoggerFactory.getLogger(WhnManagerImpl.class);
-
- /**
- * Add a scope to the ghn profile and publish it on IS
- */
- @Override
- public boolean addToContext(String context) throws GCUBEUnrecoverableException{
+@Path("/contexts")
+public class ContextManager {
+
+ private static Logger logger=LoggerFactory.getLogger(ContextManager.class);
+
+ @PUT
+ @Path("")
+ public Response add(@FormParam("context") String context){
+ InnerMethodName.instance.set("addContext");
Secret secret = SecretManagerProvider.instance.get();
logger.trace("WHNManager: addToContext method invokation with parameters context :{} and caller: {} curentContext: {}",context, secret.getOwner().getId(), secret.getContext() );
ValidationUtils.valid("context", context);
@@ -66,21 +66,21 @@ public class WhnManagerImpl implements WhnManager{
appContext.container().events().fire(context, ContextEvents.ADD_CONTEXT_TO_CONTAINER);
} catch (Exception e) {
logger.error("error adding context {}", context, e);
- return false;
+ return Response.serverError().build();
}
}else{
logger.error("context is null");
- return false;
+ return Response.status(Status.BAD_REQUEST).build();
}
- return true;
+ return Response.ok().build();
}
-
- /**
- * Remove a scope from ghn profile and publish the new profile on IS
- */
- @Override
- public boolean removeFromContext(String context) throws GCUBEUnrecoverableException {
+
+
+ @DELETE
+ @Path("")
+ public Response remove(@FormParam("context") String context){
+ InnerMethodName.instance.set("removeContext");
Secret secret = SecretManagerProvider.instance.get();
logger.trace("WHNManager: removeFromContext method invokation with parameters context :{} and caller: {} curentContext: {}",context, secret.getOwner().getId(), secret.getContext());
ValidationUtils.valid("context", context);
@@ -111,16 +111,25 @@ public class WhnManagerImpl implements WhnManager{
appContext.container().events().fire(context, ContextEvents.REMOVE_CONTEXT_FROM_CONTAINER);
} catch (Exception e) {
logger.error("error removing context {}", context, e);
- return false;
+ return Response.serverError().build();
}
}else{
logger.error("context is null");
- return false;
+ return Response.status(Status.BAD_REQUEST).build();
}
- return true;
+ return Response.ok().build();
}
-
-
+
+ @GET
+ @Path("")
+ @Produces(MediaType.APPLICATION_JSON)
+ public String[] get(){
+ InnerMethodName.instance.set("addContext");
+ ApplicationContext appContext = ContextProvider.get();
+ Set contexts = appContext.authorizationProvider().getContexts();
+ return contexts.stream().toArray(String[]::new);
+ }
+
}
diff --git a/src/main/java/org/gcube/vremanagement/whnmanager/WHNManager.java b/src/main/java/org/gcube/vremanagement/whnmanager/WHNManager.java
new file mode 100644
index 0000000..d509491
--- /dev/null
+++ b/src/main/java/org/gcube/vremanagement/whnmanager/WHNManager.java
@@ -0,0 +1,22 @@
+package org.gcube.vremanagement.whnmanager;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Application;
+
+@Path("/")
+public class WHNManager extends Application{
+
+
+ @Override
+ public Set> getClasses() {
+ final Set> classes = new HashSet>();
+ classes.add(ContextManager.class);
+ return classes;
+ }
+
+
+
+}
diff --git a/src/test/java/org/gcube/resourcemanagement/whnmanager/ContextManagerIntegrationTest.java b/src/test/java/org/gcube/resourcemanagement/whnmanager/ContextManagerIntegrationTest.java
new file mode 100644
index 0000000..f0b72d6
--- /dev/null
+++ b/src/test/java/org/gcube/resourcemanagement/whnmanager/ContextManagerIntegrationTest.java
@@ -0,0 +1,134 @@
+package org.gcube.resourcemanagement.whnmanager;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Collections;
+import java.util.Set;
+
+import javax.servlet.ServletContext;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import org.gcube.common.events.Hub;
+import org.gcube.common.security.credentials.Credentials;
+import org.gcube.common.security.secrets.Secret;
+import org.gcube.smartgears.ContextProvider;
+import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
+import org.gcube.smartgears.context.Properties;
+import org.gcube.smartgears.context.application.ApplicationContext;
+import org.gcube.smartgears.context.container.ContainerContext;
+import org.gcube.smartgears.lifecycle.application.ApplicationLifecycle;
+import org.gcube.smartgears.persistence.PersistenceWriter;
+import org.gcube.smartgears.security.AuthorizationProvider;
+import org.gcube.vremanagement.whnmanager.ContextManager;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.JerseyTest;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class ContextManagerIntegrationTest extends JerseyTest {
+
+ @Override
+ protected Application configure() {
+ return new ResourceConfig(ContextManager.class);
+ }
+
+ @BeforeClass
+ public static void init() {
+ ContextProvider.set(new ApplicationContext() {
+
+ @Override
+ public Properties properties() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public PersistenceWriter persistence() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String name() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public ApplicationLifecycle lifecycle() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String id() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Hub events() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public ContainerContext container() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public ApplicationConfiguration configuration() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public AuthorizationProvider authorizationProvider() {
+ return new AuthorizationProvider() {
+
+ @Override
+ public Set getContexts() {
+ return Collections.singleton("/test/context");
+ }
+
+ @Override
+ public Secret getSecretForContext(String context) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Credentials getCredentials() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+ }
+
+ @Override
+ public ServletContext application() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ });
+ }
+
+ @Test
+ public void gettingContexts() {
+ Response response = target("/contexts").request()
+ .get();
+
+ assertEquals("Http Response should be 200: ", Status.OK.getStatusCode(), response.getStatus());
+ assertEquals("Http Content-Type should be: ", MediaType.APPLICATION_JSON, response.getHeaderString(HttpHeaders.CONTENT_TYPE));
+
+ String[] content = response.readEntity(String[].class);
+ assertArrayEquals(content, new String[]{"/test/context"});
+ }
+}
diff --git a/src/test/resources/dataio.war b/src/test/resources/dataio.war
deleted file mode 100644
index a14bf8c..0000000
Binary files a/src/test/resources/dataio.war and /dev/null differ
diff --git a/src/test/resources/log4j.properties b/src/test/resources/log4j.properties
deleted file mode 100644
index f1ebf00..0000000
--- a/src/test/resources/log4j.properties
+++ /dev/null
@@ -1,9 +0,0 @@
-log4j.rootCategory = WARN,ROOT
-
-log4j.appender.ROOT=org.apache.log4j.ConsoleAppender
-log4j.appender.ROOT.layout=org.apache.log4j.PatternLayout
-log4j.appender.ROOT.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p %c{2} [%t,%M:%L] %m%n
-
-log4j.category.org.gcube = TRACE,ROOT
-log4j.additivity.org.gcube=false
-
diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml
new file mode 100644
index 0000000..e854089
--- /dev/null
+++ b/src/test/resources/logback-test.xml
@@ -0,0 +1,13 @@
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n
+
+
+
+
+
+
+
+
+
\ No newline at end of file