Author: bfitzpat
Date: 2010-07-07 16:34:18 -0400 (Wed, 07 Jul 2010)
New Revision: 23289
Modified:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUI.properties
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUIMessages.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/JAXRSTester.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/JAXWSTester2.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/JAXRSWSTestView.java
Log:
[JBIDE-6589] Delivering fixes to allow canceling a web service invocation
Modified:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUI.properties
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUI.properties 2010-07-07
19:52:56 UTC (rev 23288)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUI.properties 2010-07-07
20:34:18 UTC (rev 23289)
@@ -92,6 +92,7 @@
JAXRSWSTestView_Invoking_WS_Status=Invoking web service...
JAXRSWSTestView_JAXRS_Success_Status=Successful JAX-RS Web Service Execution
JAXRSWSTestView_JAXWS_Success_Status=Successful JAX-WS Web Service Execution
+JAXRSWSTestView_Message_Service_Invocation_Cancelled=Service invocation cancelled by
user.
JAXRSWSTestView_Open_Monitor_Button=Open Monitor
JAXRSWSTestView_Open_Response_Tag_Contents_in_XML_Editor=Open &Response tag contents
in XML Editor
JAXRSWSTestView_Open_Result_in_XML_Editor=&Open in XML Editor
Modified:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUIMessages.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUIMessages.java 2010-07-07
19:52:56 UTC (rev 23288)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUIMessages.java 2010-07-07
20:34:18 UTC (rev 23289)
@@ -123,6 +123,7 @@
public static String JAXRSWSTestView_Invoking_WS_Status;
public static String JAXRSWSTestView_JAXRS_Success_Status;
public static String JAXRSWSTestView_JAXWS_Success_Status;
+ public static String JAXRSWSTestView_Message_Service_Invocation_Cancelled;
public static String JAXRSWSTestView_Open_Monitor_Button;
public static String JAXRSWSTestView_Open_Response_Tag_Contents_in_XML_Editor;
public static String JAXRSWSTestView_Open_Result_in_XML_Editor;
Modified:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/JAXRSTester.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/JAXRSTester.java 2010-07-07
19:52:56 UTC (rev 23288)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/JAXRSTester.java 2010-07-07
20:34:18 UTC (rev 23289)
@@ -212,9 +212,19 @@
requestHeaders = httpurlc.getRequestProperties();
+ // Check if task has been interrupted
+ if (Thread.interrupted()) {
+ throw new InterruptedException();
+ }
+
// CONNECT!
httpurlc.connect();
+ // Check if task has been interrupted
+ if (Thread.interrupted()) {
+ throw new InterruptedException();
+ }
+
// If we are doing a POST and we have some request body to pass along, do it
if (requestBody != null && (
methodType.equalsIgnoreCase("POST") //$NON-NLS-1$
|| methodType.equalsIgnoreCase("PUT"))) { //$NON-NLS-1$
@@ -225,10 +235,19 @@
out.close();
}
+ // Check if task has been interrupted
+ if (Thread.interrupted()) {
+ throw new InterruptedException();
+ }
+
// retrieve result and put string results into the response
InputStream is = null;
try {
is = httpurlc.getInputStream();
+ // Check if task has been interrupted
+ if (Thread.interrupted()) {
+ throw new InterruptedException();
+ }
BufferedReader br = new BufferedReader(new InputStreamReader(is,
"UTF-8"));//$NON-NLS-1$
StringBuilder sb = new StringBuilder();
String line;
@@ -238,6 +257,10 @@
}
br.close();
resultBody = sb.toString();
+ // Check if task has been interrupted
+ if (Thread.interrupted()) {
+ throw new InterruptedException();
+ }
} catch (IOException ie) {
try {
is = httpurlc.getErrorStream();
Modified:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/JAXWSTester2.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/JAXWSTester2.java 2010-07-07
19:52:56 UTC (rev 23288)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/JAXWSTester2.java 2010-07-07
20:34:18 UTC (rev 23289)
@@ -14,6 +14,7 @@
import java.io.ByteArrayOutputStream;
import java.net.URL;
import java.util.Map;
+import java.util.concurrent.ExecutionException;
import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
@@ -21,11 +22,14 @@
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Dispatch;
+import javax.xml.ws.Response;
import javax.xml.ws.Service;
import javax.xml.ws.Service.Mode;
import javax.xml.ws.handler.MessageContext;
import org.apache.axis.message.SOAPEnvelope;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.jboss.tools.ws.ui.messages.JBossWSUIMessages;
/**
* Test a JAX-WS web service using the JAX-WS API
@@ -79,7 +83,7 @@
* @throws Exception
*/
@SuppressWarnings("unchecked")
- public void doTest( String endpointurl, String actionurl, String ns,
+ public void doTest( IProgressMonitor monitor, String endpointurl, String actionurl,
String ns,
String serviceName, String messageName, String body ) throws Exception {
this.resultBody = EMPTY_STRING;
@@ -96,18 +100,55 @@
SOAPMessage m = mf.createMessage( null, new ByteArrayInputStream(body.getBytes()));
m.saveChanges();
- SOAPMessage o = d.invoke(m);
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- o.writeTo(baos);
- this.resultBody = baos.toString();
- this.resultSOAPBody = o.getSOAPBody();
-
- if (d.getResponseContext() != null) {
- Object responseHeaders =
d.getResponseContext().get(MessageContext.HTTP_RESPONSE_HEADERS);
- if ( responseHeaders != null && responseHeaders instanceof Map) {
- this.resultHeaders = (Map<String, String>) responseHeaders;
+ Response<SOAPMessage> response = d.invokeAsync(m);
+ while (!response.isDone()){
+ //go off and do some work
+ if (monitor != null) {
+ if (monitor.isCanceled()) {
+ response.cancel(true);
+ }
}
}
+
+ try {
+ if (!response.isCancelled()) {
+ //get the actual result
+ SOAPMessage o = (javax.xml.soap.SOAPMessage)response.get();
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ o.writeTo(baos);
+ this.resultBody = baos.toString();
+ this.resultSOAPBody = o.getSOAPBody();
+
+ if (d.getResponseContext() != null) {
+ Object responseHeaders =
d.getResponseContext().get(MessageContext.HTTP_RESPONSE_HEADERS);
+ if ( responseHeaders != null && responseHeaders instanceof Map) {
+ this.resultHeaders = (Map<String, String>) responseHeaders;
+ }
+ }
+ } else {
+ throw new
InterruptedException(JBossWSUIMessages.JAXRSWSTestView_Message_Service_Invocation_Cancelled);
+ }
+ } catch (ExecutionException ex){
+ //get the actual cause
+ Throwable cause = ex.getCause();
+ throw new Exception(cause);
+ } catch (InterruptedException ie){
+ //note interruptions
+ throw ie;
+ }
+// SOAPMessage o = d.invoke(m);
+//
+// ByteArrayOutputStream baos = new ByteArrayOutputStream();
+// o.writeTo(baos);
+// this.resultBody = baos.toString();
+// this.resultSOAPBody = o.getSOAPBody();
+//
+// if (d.getResponseContext() != null) {
+// Object responseHeaders =
d.getResponseContext().get(MessageContext.HTTP_RESPONSE_HEADERS);
+// if ( responseHeaders != null && responseHeaders instanceof Map) {
+// this.resultHeaders = (Map<String, String>) responseHeaders;
+// }
+// }
}
}
Modified:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/JAXRSWSTestView.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/JAXRSWSTestView.java 2010-07-07
19:52:56 UTC (rev 23288)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/JAXRSWSTestView.java 2010-07-07
20:34:18 UTC (rev 23289)
@@ -816,12 +816,15 @@
public void sleeping(IJobChangeEvent event) {};
public void scheduled(IJobChangeEvent event) {};
public void running(IJobChangeEvent event) {};
- public void done(IJobChangeEvent event) {
+ public void done(final IJobChangeEvent event) {
if (event.getResult() instanceof WSTestStatus) {
final WSTestStatus status = (WSTestStatus) event.getResult();
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
public void run() {
- resultsText.setText(status.getResultsText());
+ if (status.getResultsText() != null)
+ resultsText.setText(status.getResultsText());
+ else if (status.getMessage() != null)
+ resultsText.setText(status.getMessage());
resultHeadersList.removeAll();
String[] headers =
DelimitedStringList.parseString(status.getHeadersList(),
RESULT_HEADER_DELIMITER);
@@ -855,7 +858,21 @@
// JAXWSTester tester = new JAXWSTester();
// tester.doTest(url, action, body);
JAXWSTester2 tester = new JAXWSTester2();
- tester.doTest(url, action, serviceNSMessage[0], serviceNSMessage[1],
serviceNSMessage[2], body);
+ while (!monitor.isCanceled()) {
+ try {
+ // call the service
+ tester.doTest(monitor, url, action, serviceNSMessage[0], serviceNSMessage[1],
serviceNSMessage[2], body);
+ } catch (InterruptedException ie) {
+ monitor.setCanceled(true);
+ }
+ }
+ if (monitor.isCanceled()) {
+ WSTestStatus status = new WSTestStatus(IStatus.WARNING,
+ JBossWSUIPlugin.PLUGIN_ID,
+ JBossWSUIMessages.JAXRSWSTestView_Message_Service_Invocation_Cancelled);
+ return status;
+ }
+// tester.doTest(url, action, serviceNSMessage[0], serviceNSMessage[1],
serviceNSMessage[2], body);
monitor.worked(70);
String result = tester.getResultBody();
envelope = tester.getResultSOAP();