[wise-commits] wise SVN: r541 - in webgui/trunk/src/main: webapp and 1 other directory.

wise-commits at lists.jboss.org wise-commits at lists.jboss.org
Wed Mar 20 10:40:22 EDT 2013


Author: alessio.soldano at jboss.com
Date: 2013-03-20 10:40:22 -0400 (Wed, 20 Mar 2013)
New Revision: 541

Added:
   webgui/trunk/src/main/java/org/jboss/wise/gui/ResponseLogHandler.java
Modified:
   webgui/trunk/src/main/java/org/jboss/wise/gui/ClientConversationBean.java
   webgui/trunk/src/main/webapp/index.xhtml
Log:
[WISE-198] Adding soap response view panel


Modified: webgui/trunk/src/main/java/org/jboss/wise/gui/ClientConversationBean.java
===================================================================
--- webgui/trunk/src/main/java/org/jboss/wise/gui/ClientConversationBean.java	2013-03-20 11:56:40 UTC (rev 540)
+++ webgui/trunk/src/main/java/org/jboss/wise/gui/ClientConversationBean.java	2013-03-20 14:40:22 UTC (rev 541)
@@ -70,6 +70,7 @@
     private String error;
     private UITree inTree;
     private String requestPreview;
+    private String responseMessage;
     private String requestActiveTab;
 
     @PostConstruct
@@ -114,6 +115,7 @@
     public void parseOperationParameters() {
 	if (currentOperation == null) return;
 	outputTree = null;
+	responseMessage = null;
 	error = null;
 	try {
 	    inputTree = ClientHelper.convertOperationParametersToGui(ClientHelper.getWSMethod(currentOperation, client), client);
@@ -126,9 +128,11 @@
     public void performInvocation() {
 	outputTree = null;
 	error = null;
+	responseMessage = null;
 	try {
 	    WSMethod wsMethod = ClientHelper.getWSMethod(currentOperation, client);
 	    InvocationResult result = null;
+	    ByteArrayOutputStream os = new ByteArrayOutputStream();
 	    try {
 		Map<String, Object> params = ClientHelper.processGUIParameters(inputTree);
 		ClientHelper.addOUTParameters(params, wsMethod, client);
@@ -136,10 +140,16 @@
 		endpoint.setTargetUrl(invocationUrl);
 		endpoint.setPassword(invocationPwd);
 		endpoint.setUsername(invocationUser);
+		endpoint.addHandler(new ResponseLogHandler(os));
 		result = wsMethod.invoke(params);
 	    } catch (InvocationException e) {
 		logException(e);
 		error = "Unexpected fault / error received from target endpoint";
+	    } finally {
+		responseMessage = os.toString("UTF-8");
+		if (responseMessage.trim().length() == 0) {
+		    responseMessage = null;
+		}
 	    }
 	    if (result != null) {
 		outputTree = ClientHelper.convertOperationResultToGui(result, client);
@@ -194,6 +204,10 @@
 	}
     }
     
+    public boolean isResponseAvailable() {
+	return outputTree != null || responseMessage != null;
+    }
+    
     private void cleanup() {
 	if (client != null) {
 	    cleanupTask.removeRef(client);
@@ -209,6 +223,7 @@
 	}
 	inputTree = null;
 	error = null;
+	responseMessage = null;
 	invocationUrl = null;
     }
     
@@ -344,6 +359,14 @@
         this.requestActiveTab = requestActiveTab;
     }
 
+    public String getResponseMessage() {
+        return responseMessage;
+    }
+
+    public void setResponseMessage(String responseMessage) {
+        this.responseMessage = responseMessage;
+    }
+
     private static void logException(Exception e) {
 	logger.error("", e);
     }

Added: webgui/trunk/src/main/java/org/jboss/wise/gui/ResponseLogHandler.java
===================================================================
--- webgui/trunk/src/main/java/org/jboss/wise/gui/ResponseLogHandler.java	                        (rev 0)
+++ webgui/trunk/src/main/java/org/jboss/wise/gui/ResponseLogHandler.java	2013-03-20 14:40:22 UTC (rev 541)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.wise.gui;
+
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.soap.SOAPHandler;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+
+/**
+ * Logs the client inbound response message
+ * 
+ * @author alessio.soldano at jboss.com
+ */
+public class ResponseLogHandler implements SOAPHandler<SOAPMessageContext> {
+
+    private final OutputStream outputStream;
+
+    public ResponseLogHandler(OutputStream outStream) {
+	this.outputStream = outStream;
+    }
+
+    public Set<QName> getHeaders() {
+	return new HashSet<QName>(); // empty set
+    }
+
+    public boolean handleMessage(SOAPMessageContext smc) {
+	doLog(smc);
+	return true;
+    }
+
+    public boolean handleFault(SOAPMessageContext smc) {
+	doLog(smc);
+	return true;
+    }
+
+    // nothing to clean up
+    public void close(MessageContext messageContext) {
+    }
+
+    private void doLog(SOAPMessageContext smc) {
+	if (!(Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) {
+	    try {
+		TransformerFactory tff = TransformerFactory.newInstance();
+		Transformer tf = tff.newTransformer();
+		tf.setOutputProperty(OutputKeys.INDENT, "yes");
+		tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
+		
+		Source sc = smc.getMessage().getSOAPPart().getContent();
+		
+		StreamResult result = new StreamResult(outputStream);
+		tf.transform(sc, result);
+		
+	    } catch (Exception e) {
+		PrintWriter ps = new PrintWriter(outputStream);
+		ps.println("Exception getting response message log: ");
+		e.printStackTrace(ps);
+	    }
+	}
+    }
+
+}

Modified: webgui/trunk/src/main/webapp/index.xhtml
===================================================================
--- webgui/trunk/src/main/webapp/index.xhtml	2013-03-20 11:56:40 UTC (rev 540)
+++ webgui/trunk/src/main/webapp/index.xhtml	2013-03-20 14:40:22 UTC (rev 541)
@@ -216,7 +216,7 @@
             <br />
             <a4j:outputPanel id="resultPanel" ajaxRendered="true">
             
-            <rich:panel header="Response" rendered="#{not empty clientConversationBean.outputTree}">
+            <rich:panel header="Response" rendered="#{clientConversationBean.responseAvailable}">
                 <h:form id="resForm">
                     <rich:tree id="richResTree" var="node" value="#{clientConversationBean.outputTree}" nodeType="#{node.kind}" switchType="ajax">
 				        <rich:treeNode type="simple">
@@ -259,6 +259,20 @@
         					<h:outputText value="#{node.type} : #{node.name} = ***NIL***" rendered="#{node.nil}" />
         				</rich:treeNode>
 		        	</rich:tree>
+		        	<br/>
+		        	<a4j:commandButton value="View message" render="popupView"
+                       id="viewMessageButton" oncomplete="#{rich:component('popupView')}.show();">
+                    </a4j:commandButton>
+                    <rich:popupPanel id="popupView" modal="true" resizeable="true" onmaskclick="#{rich:component('popupView')}.hide()" minWidth="550" minHeight="450">
+                        <f:facet name="header">
+                            <h:outputText value="SOAP response message" />
+                        </f:facet>
+                        <f:facet name="controls">
+                            <h:outputLink value="#" onclick="#{rich:component('popupView')}.hide(); return false;">X</h:outputLink>
+                        </f:facet>
+                        <p>Below is the captured SOAP response message:</p>
+                        <div align="center"><h:inputTextarea value="#{clientConversationBean.responseMessage}" cols="80" rows="20" readonly="true" styleClass="preformatted"/></div>
+                    </rich:popupPanel>
                 </h:form>
             </rich:panel>
             <rich:panel header="Error" rendered="#{not empty clientConversationBean.error}">



More information about the wise-commits mailing list