Commit 0b8754ed authored by Gwenael Cattez's avatar Gwenael Cattez
Browse files

Manage Web Exception

parent e98596ef
......@@ -17,6 +17,9 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Authors: Christophe Demarey
*
* Contributor(s): Gwenael Cattez
*
*/
package org.ow2.frascati.remote.introspection;
......
......@@ -20,7 +20,7 @@
*
* Author: Christophe Demarey
*
* Contributor(s): Philippe Merle
* Contributor(s): Philippe Merle, Gwenael Cattez
*
*/
package org.ow2.frascati.remote.introspection;
......
......@@ -26,21 +26,11 @@
package org.ow2.frascati.webexplorer.service;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.UriInfo;
import org.jdom.JDOMException;
import org.json.JSONException;
import org.json.JSONObject;
import org.osoa.sca.annotations.EagerInit;
import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Scope;
import org.ow2.frascati.binding.factory.AbstractBindingFactoryProcessor;
import org.ow2.frascati.remote.introspection.exception.MyWebApplicationException;
import org.ow2.frascati.webexplorer.tree.AbstractNode;
import org.ow2.frascati.webexplorer.tree.asbstractnodes.AbstractComponentTreeNode;
import org.ow2.frascati.webexplorer.tree.asbstractnodes.AbstractServiceReferenceTreeNode;
......@@ -61,226 +51,164 @@ import org.ow2.frascati.webexplorer.tree.utils.TreeUtils;
@Scope("COMPOSITE")
public class WebExplorerImpl implements WebExplorerItf
{
public String getTree() throws JSONException, JDOMException, IOException
public String getTree()
{
RootTreeNode root = RootTreeNode.getInstance();
JSONObject object = root.toJSON();
return object.toString();
}
public String getDomain(String domainId) throws JSONException
public String getDomain(String domainId)
{
RootTreeNode root = RootTreeNode.getInstance();
DomainTreeNode domain=root.getDomain(domainId);
if(domain==null)
{
return "";
}
JSONObject domainObject=domain.toJSON();
DomainTreeNode domain = root.getDomain(domainId);
JSONObject domainObject = domain.toJSON();
return domainObject.toString();
}
public String addDomain(String name, String domainURI, String color) throws JDOMException, IOException, JSONException
public String addDomain(String name, String domainURI, String color)
{
RootTreeNode root = RootTreeNode.getInstance();
DomainTreeNode domain = new DomainTreeNode(root,name,domainURI,color);
DomainTreeNode domain = new DomainTreeNode(root, name, domainURI, color);
root.addDomain(domain);
JSONObject object = domain.toJSON();
return object.toString();
}
public String removeDomain(String domainId) throws JSONException
public String removeDomain(String domainId)
{
RootTreeNode root = RootTreeNode.getInstance();
boolean isRemoved=root.removeDomain(domainId);
if(!isRemoved)
{
return "";
}
root.removeDomain(domainId);
JSONObject object = root.toJSON();
return object.toString();
}
/* (non-Javadoc)
* @see org.ow2.frascati.demo.webexplorer.service.WebExplorer#refreshTreeNode(java.lang.String)
*/
public String refreshTreeNode(String treeId) throws JDOMException, IOException, JSONException
public String refreshTreeNode(String treeId)
{
RootTreeNode root = RootTreeNode.getInstance();
AbstractNode node=root.getNode(treeId);
if(node!=null)
{
node=node.refreshNode();
JSONObject object = node.toJSON();
return object.toString();
}
return "";
AbstractNode node = root.getNode(treeId);
node = node.refreshNode();
JSONObject object = node.toJSON();
return object.toString();
}
/* (non-Javadoc)
* @see org.ow2.frascati.demo.webexplorer.service.WebExplorer#startComponent(java.lang.String)
*/
public String startComponent(String treeId) throws JDOMException, IOException, JSONException
public String startComponent(String treeId)
{
RootTreeNode root = RootTreeNode.getInstance();
AbstractTreeNode node=root.getNode(treeId);
if(node.getType()==ComponentTreeNode.COMPONENT_TYPE || node.getType()==CompositeTreeNode.COMPOSITE_TYPE)
AbstractTreeNode node = root.getNode(treeId);
if (node.getType() == ComponentTreeNode.COMPONENT_TYPE || node.getType() == CompositeTreeNode.COMPOSITE_TYPE)
{
AbstractComponentTreeNode abstractComponentTreeNode=(AbstractComponentTreeNode) node;
AbstractComponentTreeNode abstractComponentTreeNode = (AbstractComponentTreeNode) node;
abstractComponentTreeNode.start();
AbstractNode abstractNode=abstractComponentTreeNode.refreshNode();
JSONObject object=abstractNode.toJSON();
AbstractNode abstractNode = abstractComponentTreeNode.refreshNode();
JSONObject object = abstractNode.toJSON();
return object.toString();
}
return "";
throw new MyWebApplicationException("startComponent method can't be apply on a " + node.getType() + " node");
}
/* (non-Javadoc)
* @see org.ow2.frascati.demo.webexplorer.service.WebExplorer#stopComponent(java.lang.String)
*/
public String stopComponent(String treeId) throws JDOMException, IOException, JSONException
public String stopComponent(String treeId)
{
RootTreeNode root = RootTreeNode.getInstance();
AbstractTreeNode node=root.getNode(treeId);
if(node.getType()==ComponentTreeNode.COMPONENT_TYPE || node.getType()==CompositeTreeNode.COMPOSITE_TYPE)
AbstractTreeNode node = root.getNode(treeId);
if (node.getType() == ComponentTreeNode.COMPONENT_TYPE || node.getType() == CompositeTreeNode.COMPOSITE_TYPE)
{
AbstractComponentTreeNode abstractComponentTreeNode=(AbstractComponentTreeNode) node;
boolean isStopped=abstractComponentTreeNode.stop();
if(isStopped)
{
AbstractNode abstractNode=abstractComponentTreeNode.refreshNode();
JSONObject object=abstractNode.toJSON();
return object.toString();
}
AbstractComponentTreeNode abstractComponentTreeNode = (AbstractComponentTreeNode) node;
abstractComponentTreeNode.stop();
AbstractNode abstractNode = abstractComponentTreeNode.refreshNode();
JSONObject object = abstractNode.toJSON();
return object.toString();
}
return "";
throw new MyWebApplicationException("stopComponent method can't be invoke on a " + node.getType() + " node");
}
/* (non-Javadoc)
* @see org.ow2.frascati.demo.webexplorer.service.WebExplorer#invokeMethod(java.lang.String, javax.ws.rs.core.MultivaluedMap)
*/
public String invokeMethod(MultivaluedMap<String, String> params)
{
System.out.println("invokeMethod");
String treeId=params.getFirst("treeId");
if(treeId==null)
String treeId = params.getFirst("treeId");
if (treeId == null)
{
return "no treeId";
throw new MyWebApplicationException("treeId params is compulsory");
}
RootTreeNode root = RootTreeNode.getInstance();
AbstractTreeNode node=root.getNode(treeId);
if(node.getType()!=MethodTreeNode.METHOD_TYPE)
AbstractTreeNode node = root.getNode(treeId);
if (node.getType() != MethodTreeNode.METHOD_TYPE)
{
return "not a method";
throw new MyWebApplicationException("invokeMethod method can't be apply on a " + node.getType() + " node");
}
MethodTreeNode methodTreeNode=(MethodTreeNode) node;
String nodeId=TreeUtils.getParentId(methodTreeNode.getId());
node=root.getNode(nodeId);
nodeId=TreeUtils.getParentId(node.getId());
node=root.getNode(nodeId);
if(node.getType()!=ServiceTreeNode.SERVICE_TYPE && node.getType()!=ReferenceTreeNode.REFERENCE_TYPE)
{
return "not a method";
}
AbstractServiceReferenceTreeNode abstractServiceReferenceTreeNode=(AbstractServiceReferenceTreeNode) node;
return methodTreeNode.invoke(abstractServiceReferenceTreeNode,params);
MethodTreeNode methodTreeNode = (MethodTreeNode) node;
String nodeId = TreeUtils.getParentId(methodTreeNode.getId());
node = root.getNode(nodeId);
nodeId = TreeUtils.getParentId(node.getId());
node = root.getNode(nodeId);
AbstractServiceReferenceTreeNode abstractServiceReferenceTreeNode = (AbstractServiceReferenceTreeNode) node;
return methodTreeNode.invoke(abstractServiceReferenceTreeNode, params);
}
/* (non-Javadoc)
* @see org.ow2.frascati.demo.webexplorer.service.WebExplorer#setProperty(java.lang.String, java.lang.String)
*/
public String setProperty(String treeId, String value)
{
System.out.println(treeId+" "+value);
System.out.println("setProperty");
RootTreeNode root = RootTreeNode.getInstance();
AbstractTreeNode node=root.getNode(treeId);
if(node.getType()!=PropertyTreeNode.PROPERTY_TYPE)
AbstractTreeNode node = root.getNode(treeId);
if (node.getType() != PropertyTreeNode.PROPERTY_TYPE)
{
return "";
throw new MyWebApplicationException("setProperty method can't be apply on a " + node.getType() + " node");
}
PropertyTreeNode propertyTreeNode=(PropertyTreeNode) node;
Boolean isSet=propertyTreeNode.setPropertyValue(value);
PropertyTreeNode propertyTreeNode = (PropertyTreeNode) node;
Boolean isSet = propertyTreeNode.setPropertyValue(value);
return isSet.toString();
}
/* (non-Javadoc)
* @see org.ow2.frascati.demo.webexplorer.service.WebExplorer#addBinding(java.lang.String, javax.ws.rs.core.MultivaluedMap)
*/
public String addBinding(MultivaluedMap<String, String> params) throws JDOMException, IOException, JSONException
public String addBinding(MultivaluedMap<String, String> params)
{
System.out.println("add binding");
String treeId=params.getFirst("treeId");
if(treeId==null)
String treeId = params.getFirst("treeId");
if (treeId == null)
{
return "";
throw new MyWebApplicationException("treeId params is compulsory");
}
System.out.println("treeId "+treeId);
RootTreeNode root = RootTreeNode.getInstance();
AbstractTreeNode node=root.getNode(treeId);
if(node.getType()!=ServiceTreeNode.SERVICE_TYPE && node.getType()!=ReferenceTreeNode.REFERENCE_TYPE)
AbstractTreeNode node = root.getNode(treeId);
if (node.getType() != ServiceTreeNode.SERVICE_TYPE && node.getType() != ReferenceTreeNode.REFERENCE_TYPE)
{
return "";
throw new MyWebApplicationException("addBinding method can't be apply on a " + node.getType() + " node");
}
System.out.println("type "+node.getType());
AbstractServiceReferenceTreeNode abstractServiceReferenceTreeNode=(AbstractServiceReferenceTreeNode) node;
Boolean isAdded=abstractServiceReferenceTreeNode.addBinding(params);
System.out.println("isAdded "+isAdded);
if(isAdded)
{
AbstractNode refreshedNode=abstractServiceReferenceTreeNode.refreshNode();
JSONObject object = refreshedNode.toJSON();
return object.toString();
}
return "";
AbstractServiceReferenceTreeNode abstractServiceReferenceTreeNode = (AbstractServiceReferenceTreeNode) node;
abstractServiceReferenceTreeNode.addBinding(params);
AbstractNode refreshedNode = abstractServiceReferenceTreeNode.refreshNode();
JSONObject object = refreshedNode.toJSON();
return object.toString();
}
/* (non-Javadoc)
* @see org.ow2.frascati.demo.webexplorer.service.WebExplorer#removeBinding(java.lang.String, int)
*/
public String removeBinding(String treeId, int position) throws JDOMException, IOException, JSONException
public String removeBinding(String treeId, int position)
{
RootTreeNode root = RootTreeNode.getInstance();
AbstractTreeNode node=root.getNode(treeId);
if(node.getType()!=ServiceTreeNode.SERVICE_TYPE && node.getType()!=ReferenceTreeNode.REFERENCE_TYPE)
AbstractTreeNode node = root.getNode(treeId);
if (node.getType() != ServiceTreeNode.SERVICE_TYPE && node.getType() != ReferenceTreeNode.REFERENCE_TYPE)
{
return "";
throw new MyWebApplicationException("removeBinding method can't be apply on a " + node.getType() + " node");
}
AbstractServiceReferenceTreeNode abstractServiceReferenceTreeNode=(AbstractServiceReferenceTreeNode) node;
Boolean isRemoved=abstractServiceReferenceTreeNode.removeBinding(position);
if(isRemoved)
{
AbstractNode refreshedNode=abstractServiceReferenceTreeNode.refreshNode();
JSONObject object = refreshedNode.toJSON();
return object.toString();
}
return isRemoved.toString();
AbstractServiceReferenceTreeNode abstractServiceReferenceTreeNode = (AbstractServiceReferenceTreeNode) node;
abstractServiceReferenceTreeNode.removeBinding(position);
AbstractNode refreshedNode = abstractServiceReferenceTreeNode.refreshNode();
JSONObject object = refreshedNode.toJSON();
return object.toString();
}
/* (non-Javadoc)
* @see org.ow2.frascati.demo.webexplorer.service.WebExplorer#setBindingAttribute(java.lang.String, int, java.lang.String, java.lang.String)
*/
public String setBindingAttribute(String treeId, int position, String attribute, String newValue) throws JDOMException, IOException, JSONException
public String setBindingAttribute(String treeId, int position, String attribute, String newValue)
{
RootTreeNode root = RootTreeNode.getInstance();
AbstractTreeNode node=root.getNode(treeId);
if(node.getType()!=ServiceTreeNode.SERVICE_TYPE && node.getType()!=ReferenceTreeNode.REFERENCE_TYPE)
{
return "";
}
AbstractServiceReferenceTreeNode abstractServiceReferenceTreeNode=(AbstractServiceReferenceTreeNode) node;
Boolean isSet=abstractServiceReferenceTreeNode.setBindingAttribute(position,attribute, newValue);
if(isSet)
AbstractTreeNode node = root.getNode(treeId);
if (node.getType() != ServiceTreeNode.SERVICE_TYPE && node.getType() != ReferenceTreeNode.REFERENCE_TYPE)
{
AbstractNode refreshedNode=abstractServiceReferenceTreeNode.refreshNode();
JSONObject object = refreshedNode.toJSON();
return object.toString();
throw new MyWebApplicationException("setBindingAttribute method can't be apply on a " + node.getType() + " node");
}
return isSet.toString();
AbstractServiceReferenceTreeNode abstractServiceReferenceTreeNode = (AbstractServiceReferenceTreeNode) node;
Boolean isSet = abstractServiceReferenceTreeNode.setBindingAttribute(position, attribute, newValue);
AbstractNode refreshedNode = abstractServiceReferenceTreeNode.refreshNode();
JSONObject object = refreshedNode.toJSON();
return object.toString();
}
}
......@@ -27,8 +27,6 @@
package org.ow2.frascati.webexplorer.service;
import java.io.IOException;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
......@@ -39,8 +37,6 @@ import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MultivaluedMap;
import org.jdom.JDOMException;
import org.json.JSONException;
import org.osoa.sca.annotations.Service;
/**
......@@ -52,37 +48,37 @@ public interface WebExplorerItf
@GET
@Path("/tree")
@Produces("application/json")
public String getTree() throws JSONException, JDOMException, IOException;
public String getTree();
@GET
@Path("/domain")
@Produces("application/json")
public String getDomain(@FormParam("id") String domainId) throws JSONException;
public String getDomain(@FormParam("id") String domainId);
@POST
@Path("/domain")
@Produces("application/json")
public String addDomain(@FormParam("name") String name, @FormParam("domainURI") String domainURI, @FormParam("color") String hexaColor) throws JDOMException, IOException, JSONException;
public String addDomain(@FormParam("name") String name, @FormParam("domainURI") String domainURI, @FormParam("color") String hexaColor);
@DELETE
@Path("/domain")
@Produces("application/json")
public String removeDomain(@FormParam("id") String domainId) throws JSONException;
public String removeDomain(@FormParam("id") String domainId);
@GET
@Path("/node")
@Produces("application/json")
public String refreshTreeNode(@FormParam("treeId") String treeId) throws JDOMException, IOException, JSONException;
public String refreshTreeNode(@FormParam("treeId") String treeId);
@POST
@Path("/component/start")
@Produces("application/json")
public String startComponent(@FormParam("treeId") String treeId) throws JDOMException, IOException, JSONException;
public String startComponent(@FormParam("treeId") String treeId) ;
@POST
@Path("/component/stop")
@Produces("application/json")
public String stopComponent(@FormParam("treeId") String treeId) throws JDOMException, IOException, JSONException;
public String stopComponent(@FormParam("treeId") String treeId) ;
@POST
@Path("/port")
......@@ -99,15 +95,15 @@ public interface WebExplorerItf
@Path("/binding")
@Consumes("application/x-www-form-urlencoded")
@Produces("application/json")
public String addBinding(MultivaluedMap<String, String> params) throws JDOMException, IOException, JSONException;
public String addBinding(MultivaluedMap<String, String> params) ;
@DELETE
@Path("/binding")
@Produces("application/json")
public String removeBinding(@FormParam("treeId") String treeId, @FormParam("position") int position) throws JDOMException, IOException, JSONException;
public String removeBinding(@FormParam("treeId") String treeId, @FormParam("position") int position);
@PUT
@Path("/binding")
@Produces("application/json")
public String setBindingAttribute(@FormParam("treeId") String treeId,@FormParam("position") int position,@FormParam("attribute") String attribute,@FormParam("newValue") String newValue) throws JDOMException, IOException, JSONException;
public String setBindingAttribute(@FormParam("treeId") String treeId,@FormParam("position") int position,@FormParam("attribute") String attribute,@FormParam("newValue") String newValue) ;
}
......@@ -33,6 +33,7 @@ import org.jdom.JDOMException;
import org.json.JSONException;
import org.json.JSONObject;
import org.ow2.frascati.remote.introspection.Deployment;
import org.ow2.frascati.remote.introspection.exception.MyWebApplicationException;
import org.ow2.frascati.webexplorer.tree.asbstractnodes.AbstractTreeNode;
import org.ow2.frascati.webexplorer.tree.nodes.ComponentTreeNode;
import org.ow2.frascati.webexplorer.tree.nodes.CompositeTreeNode;
......@@ -60,10 +61,8 @@ public class UploadServiceImpl implements UploadServiceItf
}
}
public String deployContribution(String domainId,String encodedContribution) throws JSONException, JDOMException, IOException
public String deployContribution(String domainId,String encodedContribution)
{
try
{
RootTreeNode root = RootTreeNode.getInstance();
DomainTreeNode domain=root.getDomain(domainId);
Deployment deployment=domain.getdeploymentClient();
......@@ -71,17 +70,10 @@ public class UploadServiceImpl implements UploadServiceItf
domain.refreshNode();
JSONObject object = domain.toJSON();
return object.toString();
}
catch(Exception Exception)
{
return "";
}
}
public String deployComposite(String domainId,String compositeName, String encodedComposite) throws JSONException, JDOMException, IOException
public String deployComposite(String domainId,String compositeName, String encodedComposite)
{
try
{
RootTreeNode root = RootTreeNode.getInstance();
DomainTreeNode domain=root.getDomain(domainId);
Deployment deployment=domain.getdeploymentClient();
......@@ -89,22 +81,15 @@ public class UploadServiceImpl implements UploadServiceItf
domain.refreshNode();
JSONObject object = domain.toJSON();
return object.toString();
}
catch(Exception Exception)
{
return "";
}
}
public String undeployComposite(String treeId) throws JDOMException, IOException, JSONException
public String undeployComposite(String treeId)
{
RootTreeNode root = RootTreeNode.getInstance();
AbstractTreeNode node=root.getNode(treeId);
if(node.getType()==ComponentTreeNode.COMPONENT_TYPE || node.getType()==CompositeTreeNode.COMPOSITE_TYPE)
{
try
{
String domainURI=node.getDomainURI();
DomainTreeNode domain=root.getDomainByURI(domainURI);
Deployment deployment=domain.getdeploymentClient();
......@@ -113,12 +98,7 @@ public class UploadServiceImpl implements UploadServiceItf
domain.refreshNode();
JSONObject object = domain.toJSON();
return object.toString();
}
catch(Exception exception)
{
return "";
}
}
return "";
throw new MyWebApplicationException("undeployComposite method can't be apply on a " + node.getType() + " node");
}
}
......@@ -27,16 +27,12 @@
package org.ow2.frascati.webexplorer.service.upload;
import java.io.IOException;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.jdom.JDOMException;
import org.json.JSONException;
import org.osoa.sca.annotations.Service;