[wise-commits] wise SVN: r525 - webgui/trunk/src/main/java/org/jboss/wise/gui.

wise-commits at lists.jboss.org wise-commits at lists.jboss.org
Tue Feb 19 10:10:22 EST 2013


Author: alessio.soldano at jboss.com
Date: 2013-02-19 10:10:22 -0500 (Tue, 19 Feb 2013)
New Revision: 525

Added:
   webgui/trunk/src/main/java/org/jboss/wise/gui/ClientHelper.java
Modified:
   webgui/trunk/src/main/java/org/jboss/wise/gui/ClientConversationBean.java
Log:
Minor refactoring


Modified: webgui/trunk/src/main/java/org/jboss/wise/gui/ClientConversationBean.java
===================================================================
--- webgui/trunk/src/main/java/org/jboss/wise/gui/ClientConversationBean.java	2013-02-19 14:11:37 UTC (rev 524)
+++ webgui/trunk/src/main/java/org/jboss/wise/gui/ClientConversationBean.java	2013-02-19 15:10:22 UTC (rev 525)
@@ -19,39 +19,25 @@
 import java.io.ByteArrayOutputStream;
 import java.io.PrintStream;
 import java.io.Serializable;
-import java.lang.reflect.Type;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
 import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.StringTokenizer;
 
 import javax.annotation.PostConstruct;
 import javax.enterprise.context.Conversation;
 import javax.enterprise.context.ConversationScoped;
 import javax.inject.Inject;
 import javax.inject.Named;
-import javax.jws.soap.SOAPBinding;
 
 import org.jboss.logging.Logger;
 import org.jboss.wise.core.client.InvocationResult;
 import org.jboss.wise.core.client.WSDynamicClient;
-import org.jboss.wise.core.client.WSEndpoint;
 import org.jboss.wise.core.client.WSMethod;
-import org.jboss.wise.core.client.WSService;
-import org.jboss.wise.core.client.WebParameter;
 import org.jboss.wise.core.client.builder.WSDynamicClientBuilder;
 import org.jboss.wise.core.client.impl.reflection.builder.ReflectionBasedWSDynamicClientBuilder;
 import org.jboss.wise.core.exception.InvocationException;
-import org.jboss.wise.core.exception.WiseRuntimeException;
 import org.jboss.wise.core.utils.JBossLoggingOutputStream;
 import org.jboss.wise.gui.treeElement.GroupWiseTreeElement;
 import org.jboss.wise.gui.treeElement.LazyLoadWiseTreeElement;
 import org.jboss.wise.gui.treeElement.WiseTreeElement;
-import org.jboss.wise.gui.treeElement.WiseTreeElementBuilder;
 import org.richfaces.component.UITree;
 import org.richfaces.event.ItemChangeEvent;
 import org.richfaces.model.TreeNodeImpl;
@@ -60,7 +46,7 @@
 @ConversationScoped
 public class ClientConversationBean implements Serializable {
 
-    private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = -3778997821476776895L;
     
     private static final int CONVERSATION_TIMEOUT = 15 * 60 * 1000; //15 mins instead of default 30 mins
     private static CleanupTask<WSDynamicClient> cleanupTask = new CleanupTask<WSDynamicClient>(true);
@@ -113,7 +99,7 @@
 	}
 	if (client != null) {
 	    try {
-		services = convertServicesToGui(client.processServices());
+		services = ClientHelper.convertServicesToGui(client.processServices());
 	    } catch (Exception e) {
 		error = "Could not parse WSDL from specified URL. Please check logs for further information.";
 		logException(e);
@@ -125,14 +111,10 @@
 	if (currentOperation == null) return;
 	outputTree = null;
 	error = null;
-	StringTokenizer st = new StringTokenizer(currentOperation, ";");
-	String serviceName = st.nextToken();
-	String portName = st.nextToken();
-	String operationName = st.nextToken();
 	try {
-	    inputTree = convertOperationParametersToGui(client.getWSMethod(serviceName, portName, operationName), client);
+	    inputTree = ClientHelper.convertOperationParametersToGui(ClientHelper.getWSMethod(currentOperation, client), client);
 	} catch (Exception e) {
-	    error = toErrorMessage(e);
+	    error = ClientHelper.toErrorMessage(e);
 	    logException(e);
 	}
     }
@@ -140,52 +122,34 @@
     public void performInvocation() {
 	outputTree = null;
 	error = null;
-	StringTokenizer st = new StringTokenizer(currentOperation, ";");
-	String serviceName = st.nextToken();
-	String portName = st.nextToken();
-	String operationName = st.nextToken();
 	try {
-	    WSMethod wsMethod = client.getWSMethod(serviceName, portName, operationName);
-	    Map<String, Object> params = new HashMap<String, Object>();
-	    for (Iterator<Object> it = inputTree.getChildrenKeysIterator(); it.hasNext(); ) {
-		WiseTreeElement wte = (WiseTreeElement)inputTree.getChild(it.next());
-		params.put(wte.getName(), wte.isNil() ? null : wte.toObject());
-	    }
+	    WSMethod wsMethod = ClientHelper.getWSMethod(currentOperation, client);
 	    InvocationResult result = null;
 	    try {
-		result = wsMethod.invoke(params);
+		result = wsMethod.invoke(ClientHelper.processGUIParameters(inputTree));
 	    } catch (InvocationException e) {
 		logException(e);
 		error = "Unexpected fault / error received from target endpoint";
 	    }
 	    if (result != null) {
-		outputTree = convertOperationResultToGui(result, client);
+		outputTree = ClientHelper.convertOperationResultToGui(result, client);
 		error = null;
 	    }
 	} catch (Exception e) {
-	    error = toErrorMessage(e);
+	    error = ClientHelper.toErrorMessage(e);
 	    logException(e);
 	}
     }
     
     public void generateRequestPreview() {
 	requestPreview = null;
-	StringTokenizer st = new StringTokenizer(currentOperation, ";");
-	String serviceName = st.nextToken();
-	String portName = st.nextToken();
-	String operationName = st.nextToken();
 	try {
-	    WSMethod wsMethod = client.getWSMethod(serviceName, portName, operationName);
-	    Map<String, Object> params = new HashMap<String, Object>();
-	    for (Iterator<Object> it = inputTree.getChildrenKeysIterator(); it.hasNext(); ) {
-		WiseTreeElement wte = (WiseTreeElement)inputTree.getChild(it.next());
-		params.put(wte.getName(), wte.isNil() ? null : wte.toObject());
-	    }
+	    WSMethod wsMethod = ClientHelper.getWSMethod(currentOperation, client);
 	    ByteArrayOutputStream os = new ByteArrayOutputStream();
-	    wsMethod.writeRequestPreview(params, os);
+	    wsMethod.writeRequestPreview(ClientHelper.processGUIParameters(inputTree), os);
 	    requestPreview = os.toString("UTF-8");
 	} catch (Exception e) {
-	    requestPreview = toErrorMessage(e);
+	    requestPreview = ClientHelper.toErrorMessage(e);
 	    logException(e);
 	}
     }
@@ -202,7 +166,7 @@
 	try {
 	    el.resolveReference();
 	} catch (Exception e) {
-	    error = toErrorMessage(e);
+	    error = ClientHelper.toErrorMessage(e);
 	    logException(e);
 	}
     }
@@ -211,86 +175,6 @@
 	el.setNotNil(true);
     }
     
-    private static TreeNodeImpl convertOperationParametersToGui(WSMethod wsMethod, WSDynamicClient client) {
-	WiseTreeElementBuilder builder = new WiseTreeElementBuilder(client, true);
-	TreeNodeImpl rootElement = new TreeNodeImpl();
-	Collection<? extends WebParameter> parameters = wsMethod.getWebParams().values();
-	SOAPBinding soapBindingAnn = wsMethod.getEndpoint().getUnderlyingObjectClass().getAnnotation(SOAPBinding.class);
-	boolean rpcLit = false;
-	if (soapBindingAnn != null) {
-	    SOAPBinding.Style style = soapBindingAnn.style();
-	    rpcLit = style != null && SOAPBinding.Style.RPC.equals(style);
-	}
-	for (WebParameter parameter : parameters) {
-	    WiseTreeElement wte = builder.buildTreeFromType(parameter.getType(), parameter.getName(), null, !rpcLit);
-	    rootElement.addChild(wte.getId(), wte);
-	}
-	return rootElement;
-    }
-    
-    private static TreeNodeImpl convertOperationResultToGui(InvocationResult result,  WSDynamicClient client) {
-	WiseTreeElementBuilder builder = new WiseTreeElementBuilder(client, false);
-	TreeNodeImpl rootElement = new TreeNodeImpl();
-	Map<String, Type> resTypes = new HashMap<String, Type>();
-	for (Entry<String, Object> res : result.getResult().entrySet()) {
-	    String key = res.getKey();
-	    if (key.startsWith(WSMethod.TYPE_PREFIX)) {
-		resTypes.put(key, (Type)res.getValue());
-	    }
-	}
-	for (Entry<String, Object> res : result.getResult().entrySet()) {
-	    final String key = res.getKey();
-	    if (!key.startsWith(WSMethod.TYPE_PREFIX)) {
-		Type type = resTypes.get(WSMethod.TYPE_PREFIX + key);
-		if (type != void.class && type != Void.class) {
-		    WiseTreeElement wte = builder.buildTreeFromType(type, key, res.getValue(), true);
-		    rootElement.addChild(wte.getId(), wte);
-		}
-	    }
-	}
-	return rootElement;
-    }
-    
-    private static List<Service> convertServicesToGui(Map<String, WSService> servicesMap) {
-	List<Service> services = new LinkedList<Service>();
-	for (Entry<String, WSService> serviceEntry : servicesMap.entrySet()) {
-	    Service service = new Service();
-	    services.add(service);
-	    service.setName(serviceEntry.getKey());
-	    List<Port> ports = new LinkedList<Port>();
-	    service.setPorts(ports);
-	    for (Entry<String, WSEndpoint> endpointEntry : serviceEntry.getValue().processEndpoints().entrySet()) {
-		Port port = new Port();
-		port.setName(endpointEntry.getKey());
-		ports.add(port);
-		List<Operation> operations = new LinkedList<Operation>();
-		port.setOperations(operations);
-		for (Entry<String, WSMethod> methodEntry : endpointEntry.getValue().getWSMethods().entrySet()) {
-		    Operation operation = new Operation();
-		    operation.setName(methodEntry.getKey());
-		    StringBuilder sb = new StringBuilder();
-		    sb.append(methodEntry.getKey());
-		    sb.append("(");
-		    Iterator<? extends WebParameter> paramIt = methodEntry.getValue().getWebParams().values().iterator();
-		    while (paramIt.hasNext()) {
-			WebParameter param = paramIt.next();
-			Type type = param.getType();
-			sb.append(type instanceof Class<?> ? ((Class<?>)type).getSimpleName() : type.toString());
-			sb.append(" ");
-			sb.append(param.getName());
-			if (paramIt.hasNext()) {
-			    sb.append(", ");
-			}
-		    }
-		    sb.append(")");
-		    operation.setFullName(sb.toString());
-		    operations.add(operation);
-		}
-	    }
-	}
-	return services;
-    }
-    
     public void updateCurrentOperation(ItemChangeEvent event){
 	  setCurrentOperation(event.getNewItemName());
 	}
@@ -392,21 +276,6 @@
         this.requestPreview = requestPreview;
     }
 
-    private static String toErrorMessage(Exception e) {
-	StringBuilder sb = new StringBuilder();
-	if (e instanceof WiseRuntimeException) {
-	    sb.append(e.getMessage());
-	} else {
-	    sb.append(e.toString());
-	}
-	if (e.getCause() != null) {
-	    sb.append(", caused by ");
-	    sb.append(e.getCause());
-	}
-	sb.append(". Please check logs for further information.");
-	return sb.toString();
-    }
-    
     private static void logException(Exception e) {
 	logger.error("", e);
     }

Added: webgui/trunk/src/main/java/org/jboss/wise/gui/ClientHelper.java
===================================================================
--- webgui/trunk/src/main/java/org/jboss/wise/gui/ClientHelper.java	                        (rev 0)
+++ webgui/trunk/src/main/java/org/jboss/wise/gui/ClientHelper.java	2013-02-19 15:10:22 UTC (rev 525)
@@ -0,0 +1,159 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2013, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the 
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed 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.
+ */
+package org.jboss.wise.gui;
+
+import java.io.Serializable;
+import java.lang.reflect.Type;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.Map.Entry;
+
+import javax.jws.soap.SOAPBinding;
+
+import org.jboss.wise.core.client.InvocationResult;
+import org.jboss.wise.core.client.WSDynamicClient;
+import org.jboss.wise.core.client.WSEndpoint;
+import org.jboss.wise.core.client.WSMethod;
+import org.jboss.wise.core.client.WSService;
+import org.jboss.wise.core.client.WebParameter;
+import org.jboss.wise.core.exception.ResourceNotAvailableException;
+import org.jboss.wise.core.exception.WiseRuntimeException;
+import org.jboss.wise.gui.treeElement.WiseTreeElement;
+import org.jboss.wise.gui.treeElement.WiseTreeElementBuilder;
+import org.richfaces.model.TreeNodeImpl;
+
+public class ClientHelper implements Serializable {
+
+    private static final long serialVersionUID = 4838483183941121581L;
+
+    public static WSMethod getWSMethod(String currentOperation, WSDynamicClient client) throws ResourceNotAvailableException {
+	StringTokenizer st = new StringTokenizer(currentOperation, ";");
+	String serviceName = st.nextToken();
+	String portName = st.nextToken();
+	String operationName = st.nextToken();
+	return client.getWSMethod(serviceName, portName, operationName);
+    }
+    
+    public static TreeNodeImpl convertOperationParametersToGui(WSMethod wsMethod, WSDynamicClient client) {
+	WiseTreeElementBuilder builder = new WiseTreeElementBuilder(client, true);
+	TreeNodeImpl rootElement = new TreeNodeImpl();
+	Collection<? extends WebParameter> parameters = wsMethod.getWebParams().values();
+	SOAPBinding soapBindingAnn = wsMethod.getEndpoint().getUnderlyingObjectClass().getAnnotation(SOAPBinding.class);
+	boolean rpcLit = false;
+	if (soapBindingAnn != null) {
+	    SOAPBinding.Style style = soapBindingAnn.style();
+	    rpcLit = style != null && SOAPBinding.Style.RPC.equals(style);
+	}
+	for (WebParameter parameter : parameters) {
+	    WiseTreeElement wte = builder.buildTreeFromType(parameter.getType(), parameter.getName(), null, !rpcLit);
+	    rootElement.addChild(wte.getId(), wte);
+	}
+	return rootElement;
+    }
+    
+    public static TreeNodeImpl convertOperationResultToGui(InvocationResult result,  WSDynamicClient client) {
+	WiseTreeElementBuilder builder = new WiseTreeElementBuilder(client, false);
+	TreeNodeImpl rootElement = new TreeNodeImpl();
+	Map<String, Type> resTypes = new HashMap<String, Type>();
+	for (Entry<String, Object> res : result.getResult().entrySet()) {
+	    String key = res.getKey();
+	    if (key.startsWith(WSMethod.TYPE_PREFIX)) {
+		resTypes.put(key, (Type)res.getValue());
+	    }
+	}
+	for (Entry<String, Object> res : result.getResult().entrySet()) {
+	    final String key = res.getKey();
+	    if (!key.startsWith(WSMethod.TYPE_PREFIX)) {
+		Type type = resTypes.get(WSMethod.TYPE_PREFIX + key);
+		if (type != void.class && type != Void.class) {
+		    WiseTreeElement wte = builder.buildTreeFromType(type, key, res.getValue(), true);
+		    rootElement.addChild(wte.getId(), wte);
+		}
+	    }
+	}
+	return rootElement;
+    }
+    
+    public static List<Service> convertServicesToGui(Map<String, WSService> servicesMap) {
+	List<Service> services = new LinkedList<Service>();
+	for (Entry<String, WSService> serviceEntry : servicesMap.entrySet()) {
+	    Service service = new Service();
+	    services.add(service);
+	    service.setName(serviceEntry.getKey());
+	    List<Port> ports = new LinkedList<Port>();
+	    service.setPorts(ports);
+	    for (Entry<String, WSEndpoint> endpointEntry : serviceEntry.getValue().processEndpoints().entrySet()) {
+		Port port = new Port();
+		port.setName(endpointEntry.getKey());
+		ports.add(port);
+		List<Operation> operations = new LinkedList<Operation>();
+		port.setOperations(operations);
+		for (Entry<String, WSMethod> methodEntry : endpointEntry.getValue().getWSMethods().entrySet()) {
+		    Operation operation = new Operation();
+		    operation.setName(methodEntry.getKey());
+		    StringBuilder sb = new StringBuilder();
+		    sb.append(methodEntry.getKey());
+		    sb.append("(");
+		    Iterator<? extends WebParameter> paramIt = methodEntry.getValue().getWebParams().values().iterator();
+		    while (paramIt.hasNext()) {
+			WebParameter param = paramIt.next();
+			Type type = param.getType();
+			sb.append(type instanceof Class<?> ? ((Class<?>)type).getSimpleName() : type.toString());
+			sb.append(" ");
+			sb.append(param.getName());
+			if (paramIt.hasNext()) {
+			    sb.append(", ");
+			}
+		    }
+		    sb.append(")");
+		    operation.setFullName(sb.toString());
+		    operations.add(operation);
+		}
+	    }
+	}
+	return services;
+    }
+    
+    public static Map<String, Object> processGUIParameters(TreeNodeImpl inputTree) {
+	Map<String, Object> params = new HashMap<String, Object>();
+	for (Iterator<Object> it = inputTree.getChildrenKeysIterator(); it.hasNext();) {
+	    WiseTreeElement wte = (WiseTreeElement) inputTree.getChild(it.next());
+	    params.put(wte.getName(), wte.isNil() ? null : wte.toObject());
+	}
+	return params;
+    }
+
+    public static String toErrorMessage(Exception e) {
+	StringBuilder sb = new StringBuilder();
+	if (e instanceof WiseRuntimeException) {
+	    sb.append(e.getMessage());
+	} else {
+	    sb.append(e.toString());
+	}
+	if (e.getCause() != null) {
+	    sb.append(", caused by ");
+	    sb.append(e.getCause());
+	}
+	sb.append(". Please check logs for further information.");
+	return sb.toString();
+    }
+}



More information about the wise-commits mailing list