Commit 06e09331 authored by Gwenael Cattez's avatar Gwenael Cattez
Browse files

Remove jersey dependency, use CXF to do REST request

Add color chooser to add new domain
Set copyright to 2011-2012
parent 22efbfb0
......@@ -73,42 +73,6 @@
<version>${project.version}</version>
</dependency>
<!-- <dependency> -->
<!-- <groupId>com.sun.jersey</groupId> -->
<!-- <artifactId>jersey-bundle</artifactId> -->
<!-- <version>1.13</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.codehaus.jackson</groupId> -->
<!-- <artifactId>jackson-jaxrs</artifactId> -->
<!-- <version>1.9.9</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>com.sun.jersey</groupId> -->
<!-- <artifactId>jersey-server</artifactId> -->
<!-- <version>1.8</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>com.sun.jersey</groupId> -->
<!-- <artifactId>jersey-json</artifactId> -->
<!-- <version>1.8</version> -->
<!-- </dependency> -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.8</version>
</dependency>
<!-- <dependency> -->
<!-- <groupId>com.sun.jersey</groupId> -->
<!-- <artifactId>jersey-server</artifactId> -->
<!-- <version>1.2</version> -->
<!-- </dependency> -->
<!-- OW2 FraSCAti Web Explorer Bootstrap Module. -->
<dependency>
<groupId>org.ow2.frascati</groupId>
......@@ -123,6 +87,13 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.ow2.frascati.examples.test</groupId>
<artifactId>frascati-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<!-- Apache Commons FileUpload. -->
<dependency>
<groupId>commons-fileupload</groupId>
......
......@@ -29,20 +29,13 @@ package org.ow2.frascati.webexplorer.service.upload;
import java.io.IOException;
import javax.ws.rs.core.MultivaluedMap;
import org.eclipse.jetty.http.HttpStatus;
import org.jdom.JDOMException;
import org.json.JSONException;
import org.json.JSONObject;
import org.ow2.frascati.remote.introspection.Deployment;
import org.ow2.frascati.webexplorer.tree.nodes.domain.DomainTreeNode;
import org.ow2.frascati.webexplorer.tree.root.RootTreeNode;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.MultivaluedMapImpl;
/**
*
*/
......@@ -50,75 +43,53 @@ public class UploadServiceImpl implements UploadServiceItf
{
public String getCompositeEntriesFromJar(String domainId,String encodedComposite)
{
System.out.println("domainId : "+domainId);
RootTreeNode root = RootTreeNode.getInstance();
DomainTreeNode domain=root.getDomain(domainId);
if(domain==null)
try
{
RootTreeNode root = RootTreeNode.getInstance();
DomainTreeNode domain=root.getDomain(domainId);
Deployment deployment=domain.getDeploymentClient();
String entries=deployment.getCompositeEntriesFromJar(encodedComposite);
return entries;
}
catch(Exception Exception)
{
return "";
}
String url=domain.getdomainURI();
url+="/deploy/util/getCompositesName";
Client client = Client.create();
WebResource webresource = client.resource(url);
MultivaluedMap<String,String> formData = new MultivaluedMapImpl();
formData.add("jar", encodedComposite);
String entries=webresource.type("application/x-www-form-urlencoded").post(String.class,formData);
return entries;
}
public String deployContribution(String domainId,String encodedContribution) throws JSONException, JDOMException, IOException
{
System.out.println("domainId : "+domainId);
RootTreeNode root = RootTreeNode.getInstance();
DomainTreeNode domain=root.getDomain(domainId);
if(domain==null)
try
{
return "";
RootTreeNode root = RootTreeNode.getInstance();
DomainTreeNode domain=root.getDomain(domainId);
Deployment deployment=domain.getDeploymentClient();
deployment.deployContribution(encodedContribution);
domain.refreshNode();
JSONObject object = domain.toJSON();
return object.toString();
}
Client client = Client.create();
String url=domain.getdomainURI();
url+="/deploy/deploy/contribution";
WebResource webresource = client.resource(url);
MultivaluedMap<String,String> formData = new MultivaluedMapImpl();
formData.add("contribution", encodedContribution);
ClientResponse clientResponse=webresource.type("application/x-www-form-urlencoded").post(ClientResponse.class,formData);
if(clientResponse.getStatus()!=HttpStatus.OK_200)
catch(Exception Exception)
{
return "";
}
domain.refreshNode();
JSONObject object = domain.toJSON();
return object.toString();
}
public String deployComposite(String domainId,String compositeName, String encodedComposite) throws JSONException, JDOMException, IOException
{
RootTreeNode root = RootTreeNode.getInstance();
DomainTreeNode domain=root.getDomain(domainId);
if(domain==null)
try
{
return "";
RootTreeNode root = RootTreeNode.getInstance();
DomainTreeNode domain=root.getDomain(domainId);
Deployment deployment=domain.getDeploymentClient();
deployment.deployComposite(compositeName, encodedComposite);
domain.refreshNode();
JSONObject object = domain.toJSON();
return object.toString();
}
String url=domain.getdomainURI();
url+="/deploy/deploy/composite";
Client client = Client.create();
WebResource webresource = client.resource(url);
MultivaluedMap<String,String> formData = new MultivaluedMapImpl();
formData.add("compositeName", compositeName);
formData.add("jar", encodedComposite);
ClientResponse clientResponse=webresource.type("application/x-www-form-urlencoded").post(ClientResponse.class,formData);
if(clientResponse.getStatus()!=HttpStatus.OK_200)
catch(Exception Exception)
{
return "";
}
domain.refreshNode();
JSONObject object = domain.toJSON();
return object.toString();
}
}
......@@ -31,19 +31,17 @@ import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.jetty.http.HttpStatus;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.json.JSONException;
import org.json.JSONObject;
import org.ow2.frascati.remote.introspection.RemoteScaDomain;
import org.ow2.frascati.webexplorer.tree.nodes.ComponentTreeNode;
import org.ow2.frascati.webexplorer.tree.nodes.PropertyTreeNode;
import org.ow2.frascati.webexplorer.tree.nodes.ReferenceTreeNode;
import org.ow2.frascati.webexplorer.tree.nodes.ServiceTreeNode;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import org.ow2.frascati.webexplorer.tree.nodes.domain.DomainTreeNode;
import org.ow2.frascati.webexplorer.tree.root.RootTreeNode;
/**
*
......@@ -52,7 +50,6 @@ public abstract class AbstractComponentTreeNode extends AbstractIndexableTreeNod
{
private static final String STATUS_STARTED="STARTED";
private static final String STATUS_STOPPED="STOPPED";
private static final String STARTSTOP_PATH="/introspection/component";
protected String status;
......@@ -73,16 +70,18 @@ public abstract class AbstractComponentTreeNode extends AbstractIndexableTreeNod
private boolean startStop(String method)
{
String url=this.getdomainURI();
url+=STARTSTOP_PATH;
url+=this.getFrascatiPath();
url+="/"+method;
System.out.println(url);
Client client = Client.create();
WebResource webresource = client.resource(url);
ClientResponse clientResponse=webresource.post(ClientResponse.class);
if(clientResponse.getStatus()!=HttpStatus.OK_200) return false;
return true;
try
{
RootTreeNode root = RootTreeNode.getInstance();
DomainTreeNode domain=root.getDomainByURI(this.getdomainURI());
RemoteScaDomain introspection=domain.getIntrospectionClient();
introspection.invokeMethod(this.getFrascatiPath(), null);
return true;
}
catch(Exception exception)
{
return false;
}
}
public boolean start()
......
......@@ -33,18 +33,16 @@ import java.util.List;
import javax.ws.rs.core.MultivaluedMap;
import org.eclipse.jetty.http.HttpStatus;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.json.JSONException;
import org.json.JSONObject;
import org.ow2.frascati.remote.introspection.RemoteScaDomain;
import org.ow2.frascati.webexplorer.tree.nodes.InterfaceTreeNode;
import org.ow2.frascati.webexplorer.tree.nodes.binding.BindingTreeNode;
import org.ow2.frascati.webexplorer.tree.nodes.domain.DomainTreeNode;
import org.ow2.frascati.webexplorer.tree.root.RootTreeNode;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.MultivaluedMapImpl;
/**
*
......@@ -115,35 +113,39 @@ public abstract class AbstractServiceReferenceTreeNode extends AbstractIndexable
{
System.out.println("add binding"+params);
if(params==null) return false;
String url=this.getdomainURI();
url+=BINDING_PATH;
url+=this.getFrascatiPath();
System.out.println(url);
Client client = Client.create();
WebResource webresource = client.resource(url);
ClientResponse clientResponse=webresource.type("application/x-www-form-urlencoded").post(ClientResponse.class,params);
if(clientResponse.getStatus()!=HttpStatus.OK_200) return false;
return true;
try
{
RootTreeNode root = RootTreeNode.getInstance();
DomainTreeNode domain=root.getDomainByURI(this.getdomainURI());
RemoteScaDomain introspection=domain.getIntrospectionClient();
introspection.addBinding(this.getFrascatiPath(), params);
return true;
}
catch(Exception exception)
{
return false;
}
}
// cd C:\Users\Gwenael\Documents\workspace\frascati\demo\fire-emergency\turnstile
// start mvn -Prun,web
/**
* @param position
* @return
*/
public Boolean removeBinding(int position)
{
String url=this.getdomainURI();
url+=BINDING_PATH;
url+=this.getFrascatiPath();
Client client = Client.create();
WebResource webresource = client.resource(url);
webresource.queryParam("position",String.valueOf(position));
System.out.println(url+" "+String.valueOf(position));
ClientResponse clientResponse=webresource.type("application/x-www-form-urlencoded").delete(ClientResponse.class);
System.out.println(clientResponse.getEntity(String.class));
if(clientResponse.getStatus()!=HttpStatus.OK_200) return false;
return true;
System.out.println("Remove binding of "+this.getFrascatiPath()+" at position : "+String.valueOf(position));
try
{
RootTreeNode root = RootTreeNode.getInstance();
DomainTreeNode domain=root.getDomainByURI(this.getdomainURI());
RemoteScaDomain introspection=domain.getIntrospectionClient();
introspection.removeBinding(this.getFrascatiPath(), position);
return true;
}
catch(Exception exception)
{
return false;
}
}
/**
......@@ -154,19 +156,17 @@ public abstract class AbstractServiceReferenceTreeNode extends AbstractIndexable
*/
public Boolean setBindingAttribute(int position, String attribute, String newValue)
{
System.out.println("set binding "+String.valueOf(position)+" "+attribute+" "+newValue);
String url=this.getdomainURI();
url+=BINDING_PATH;
url+=this.getFrascatiPath();
System.out.println(url);
Client client = Client.create();
WebResource webresource = client.resource(url);
MultivaluedMap<String,String> formData = new MultivaluedMapImpl();
formData.add("position",String.valueOf(position));
formData.add("attribute",attribute);
formData.add("newValue",newValue);
ClientResponse clientResponse=webresource.type("application/x-www-form-urlencoded").put(ClientResponse.class,formData);
if(clientResponse.getStatus()!=HttpStatus.OK_200) return false;
return true;
try
{
RootTreeNode root = RootTreeNode.getInstance();
DomainTreeNode domain=root.getDomainByURI(this.getdomainURI());
RemoteScaDomain introspection=domain.getIntrospectionClient();
introspection.setBindingAttribute(this.getFrascatiPath(), position, attribute, newValue);
return true;
}
catch(Exception exception)
{
return false;
}
}
}
......@@ -33,19 +33,16 @@ import java.util.List;
import javax.ws.rs.core.MultivaluedMap;
import org.eclipse.jetty.http.HttpStatus;
import org.apache.cxf.jaxrs.impl.MetadataMap;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.json.JSONException;
import org.json.JSONObject;
import org.ow2.frascati.webexplorer.tree.AbstractNode;
import org.ow2.frascati.remote.introspection.RemoteScaDomain;
import org.ow2.frascati.webexplorer.tree.asbstractnodes.AbstractServiceReferenceTreeNode;
import org.ow2.frascati.webexplorer.tree.asbstractnodes.AbstractTreeNode;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.ow2.frascati.webexplorer.tree.nodes.domain.DomainTreeNode;
import org.ow2.frascati.webexplorer.tree.root.RootTreeNode;
/**
*
......@@ -54,7 +51,6 @@ public class MethodTreeNode extends AbstractTreeNode
{
public final static String METHOD_TYPE="method";
public final static String METHOD_IMG="icone_m.png";
public final static String INVOKE_PATH="/introspection/port";
private String signature;
private String value;
......@@ -94,19 +90,20 @@ public class MethodTreeNode extends AbstractTreeNode
public String invoke(AbstractServiceReferenceTreeNode abstractServiceReferenceTreeNode, MultivaluedMap<String, String> params)
{
if(params==null) params=new MultivaluedMapImpl();
if(params==null) params=new MetadataMap<String, String>();
params.add("methodName",this.value);
String url=this.getdomainURI();
url+=INVOKE_PATH;
AbstractNode parent=this.parentNode;
url+=abstractServiceReferenceTreeNode.getFrascatiPath();
System.out.println(url);
Client client = Client.create();
WebResource webresource = client.resource(url);
ClientResponse clientResponse=webresource.type("application/x-www-form-urlencoded").post(ClientResponse.class,params);
if(clientResponse.getStatus()!=HttpStatus.OK_200) return "";
String response=clientResponse.getEntity(String.class);
return response;
try
{
RootTreeNode root = RootTreeNode.getInstance();
DomainTreeNode domain=root.getDomainByURI(this.getdomainURI());
RemoteScaDomain introspection=domain.getIntrospectionClient();
String result=introspection.invokeMethod(abstractServiceReferenceTreeNode.getFrascatiPath(), params);
return result;
}
catch(Exception exception)
{
return "";
}
}
private String formatParameterType(String type)
......
......@@ -29,18 +29,13 @@ package org.ow2.frascati.webexplorer.tree.nodes;
import java.io.IOException;
import javax.ws.rs.core.MultivaluedMap;
import org.eclipse.jetty.http.HttpStatus;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.ow2.frascati.remote.introspection.RemoteScaDomain;
import org.ow2.frascati.webexplorer.tree.asbstractnodes.AbstractIndexableTreeNode;
import org.ow2.frascati.webexplorer.tree.asbstractnodes.AbstractTreeNode;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.ow2.frascati.webexplorer.tree.nodes.domain.DomainTreeNode;
import org.ow2.frascati.webexplorer.tree.root.RootTreeNode;
/**
*
......@@ -76,17 +71,21 @@ public class PropertyTreeNode extends AbstractIndexableTreeNode
public boolean setPropertyValue(String newValue)
{
String url=this.getdomainURI();
url+=PROPERTY_PATH;
url+=this.getFrascatiPath();
System.out.println(url+"?value="+newValue);
Client client = Client.create();
WebResource webresource = client.resource(url);
MultivaluedMap<String,String> formData = new MultivaluedMapImpl();
formData.add("value",newValue);
ClientResponse clientResponse=webresource.type("application/x-www-form-urlencoded").post(ClientResponse.class,formData);
if(clientResponse.getStatus()!=HttpStatus.OK_200) return false;
return true;
try
{
RootTreeNode root = RootTreeNode.getInstance();
DomainTreeNode domain=root.getDomainByURI(this.getdomainURI());
RemoteScaDomain introspection=domain.getIntrospectionClient();
String parentId= this.parentId;
AbstractTreeNode parentNode=root.getNode(parentId);
boolean result=introspection.setProperty(parentNode.getFrascatiPath(),this.getId(), newValue);
return result;
}
catch(Exception exception)
{
return false;
}
}
public String getValue()
......
......@@ -30,8 +30,11 @@ package org.ow2.frascati.webexplorer.tree.nodes.domain;
import java.io.IOException;
import java.util.List;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.ow2.frascati.remote.introspection.Deployment;
import org.ow2.frascati.remote.introspection.RemoteScaDomain;
import org.ow2.frascati.webexplorer.tree.asbstractnodes.AbstractTreeNode;
import org.ow2.frascati.webexplorer.tree.nodes.CompositeTreeNode;
import org.ow2.frascati.webexplorer.tree.root.RootTreeNode;
......@@ -46,6 +49,9 @@ public class DomainTreeNode extends AbstractTreeNode
public final static String DOMAIN_IMG="domain.png";
public final static String DOMAIN_PATH="/introspection/components";
private Deployment deployment;
private RemoteScaDomain introspection;
private String domainName;
private String color;
......@@ -54,9 +60,10 @@ public class DomainTreeNode extends AbstractTreeNode
super(parentNode, text, DOMAIN_IMG, DOMAIN_TYPE,domainURI);
this.domainName=text;
this.color=color;
this.deployment=JAXRSClientFactory.create(domainURI+"/deploy", Deployment.class);
this.introspection=JAXRSClientFactory.create(domainURI+"/introspection", RemoteScaDomain.class);
}
/* (non-Javadoc)
* @see org.ow2.frascati.demo.webexplorer.tree.TreeNode#getPath()
*/
......@@ -100,4 +107,16 @@ public class DomainTreeNode extends AbstractTreeNode
{
return color;
}
public Deployment getDeploymentClient()
{
return deployment;
}
public RemoteScaDomain getIntrospectionClient()
{
return introspection;
}
}
......@@ -99,6 +99,7 @@ public class RootTreeNode implements AbstractNode
for(DomainTreeNode tmpDomain : domainList)
{
tmpDomainId=tmpDomain.getId();
System.out.println("root "+tmpDomain.getId());
if(tmpDomainId.equals(domainId))
{
return tmpDomain;
......@@ -107,6 +108,20 @@ public class RootTreeNode implements AbstractNode
return null;
}
public DomainTreeNode getDomainByURI(String domainURI)
{
String tmpDomainURI;
for(DomainTreeNode tmpDomain : domainList)
{
tmpDomainURI=tmpDomain.getdomainURI();
if(tmpDomainURI.equals(domainURI))
{
return tmpDomain;
}
}