Author: bfitzpat
Date: 2010-05-05 17:19:30 -0400 (Wed, 05 May 2010)
New Revision: 21927
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/icons/obj16/ws_tester.gif
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/WSTestUtils.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/DelimitedStringList.java
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/JAXRSWSTestView.java
Modified:
trunk/ws/plugins/org.jboss.tools.ws.ui/META-INF/MANIFEST.MF
trunk/ws/plugins/org.jboss.tools.ws.ui/plugin.properties
trunk/ws/plugins/org.jboss.tools.ws.ui/plugin.xml
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
Log:
OPEN - issue JBIDE-6253: Need a web service tester (JAX-WS and JAX-RS) in the tooling
https://jira.jboss.org/jira/browse/JBIDE-6253
Modified: trunk/ws/plugins/org.jboss.tools.ws.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.ui/META-INF/MANIFEST.MF 2010-05-05 21:13:29 UTC
(rev 21926)
+++ trunk/ws/plugins/org.jboss.tools.ws.ui/META-INF/MANIFEST.MF 2010-05-05 21:19:30 UTC
(rev 21927)
@@ -18,7 +18,11 @@
org.eclipse.wst.common.frameworks,
org.eclipse.wst.common.emfworkbench.integration,
org.jboss.tools.common.ui,
- org.eclipse.core.filesystem
+ org.eclipse.core.filesystem,
+ com.ibm.icu,
+ org.apache.axis,
+ javax.xml.soap,
+ javax.xml.rpc
Bundle-ActivationPolicy: lazy
Export-Package: org.jboss.tools.ws.ui,
org.jboss.tools.ws.ui.messages,
Added: trunk/ws/plugins/org.jboss.tools.ws.ui/icons/obj16/ws_tester.gif
===================================================================
(Binary files differ)
Property changes on: trunk/ws/plugins/org.jboss.tools.ws.ui/icons/obj16/ws_tester.gif
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:mime-type
+ application/octet-stream
Modified: trunk/ws/plugins/org.jboss.tools.ws.ui/plugin.properties
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.ui/plugin.properties 2010-05-05 21:13:29 UTC (rev
21926)
+++ trunk/ws/plugins/org.jboss.tools.ws.ui/plugin.properties 2010-05-05 21:19:30 UTC (rev
21927)
@@ -3,4 +3,6 @@
JBOSSWS_GENERATEACTION_LABEL=Create a Sample Web Service
PLUGIN_NAME=JBoss WebServices Tools
PLUGIN_PROVIDER=JBoss by Red Hat
-JBOSSWS_WIZARD_DESC=Create a sample web service
\ No newline at end of file
+JBOSSWS_WIZARD_DESC=Create a sample web service
+test.view.category.name = JBoss Tools Web Services
+test.view.name = Web Service Tester
\ No newline at end of file
Modified: trunk/ws/plugins/org.jboss.tools.ws.ui/plugin.xml
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.ui/plugin.xml 2010-05-05 21:13:29 UTC (rev 21926)
+++ trunk/ws/plugins/org.jboss.tools.ws.ui/plugin.xml 2010-05-05 21:19:30 UTC (rev 21927)
@@ -38,4 +38,18 @@
</description>
</wizard>
</extension>
+ <extension
+ point="org.eclipse.ui.views">
+ <category
+ id="org.jboss.tools.ws.ui.tester"
+ name="%test.view.category.name">
+ </category>
+ <view
+ category="org.jboss.tools.ws.ui.tester"
+ class="org.jboss.tools.ws.ui.views.JAXRSWSTestView"
+ icon="icons/obj16/ws_tester.gif"
+ id="org.jboss.tools.ws.ui.tester.views.TestWSView"
+ name="%test.view.name">
+ </view>
+ </extension>
</plugin>
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-05-05
21:13:29 UTC (rev 21926)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUI.properties 2010-05-05
21:19:30 UTC (rev 21927)
@@ -62,4 +62,19 @@
Error_JBossWS_GenerateWizard_PackageExists=Package already exists
Error_JBossWS_GenerateWizard_PackageNotShown=Package already exists. Note: Views might
filter empty parent packages
Error_JBossWS_GenerateWizard_PackageExistsDifferentCase=Package already exists with a
different case
-Error_JBossWS_GenerateWizard_NoSrcInProject=The project misses JAVA Source folders
\ No newline at end of file
+Error_JBossWS_GenerateWizard_NoSrcInProject=The project misses JAVA Source folders
+
+JBossWS_DelimitedStringList_EditValue_Dialog_Title=Edit Value
+JBossWS_DelimitedStringList_EditValue_Dialog_Message=Specify the updated value below.
+
+JAXRSWSTestView_Action_URL_Label=Action URL:
+JAXRSWSTestView_HTTP_Method_Label=HTTP Method:
+JAXRSWSTestView_Invoke_Label=Invoke
+JAXRSWSTestView_Request_Body_Label=Request Body
+JAXRSWSTestView_Request_Header_Label=Request Header
+JAXRSWSTestView_Request_Parameters_Label=Request Parameters
+JAXRSWSTestView_Results_Body_Label=Results Body
+JAXRSWSTestView_Results_Header_Label=Results Header
+JAXRSWSTestView_Service_URL_Label=Service URL:
+JAXRSWSTestView_Set_Sample_Data_Label=Set Sample Data
+JAXRSWSTestView_Web_Service_Type_Label=Web Service Type:
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-05-05
21:13:29 UTC (rev 21926)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/messages/JBossWSUIMessages.java 2010-05-05
21:19:30 UTC (rev 21927)
@@ -88,6 +88,20 @@
public static String Error_JBossWS_GenerateWizard_PackageExistsDifferentCase;
public static String Error_JBossWS_GenerateWizard_NoSrcInProject;
+ public static String JBossWS_DelimitedStringList_EditValue_Dialog_Title;
+ public static String JBossWS_DelimitedStringList_EditValue_Dialog_Message;
+ public static String JAXRSWSTestView_Action_URL_Label;
+ public static String JAXRSWSTestView_HTTP_Method_Label;
+ public static String JAXRSWSTestView_Invoke_Label;
+ public static String JAXRSWSTestView_Request_Body_Label;
+ public static String JAXRSWSTestView_Request_Header_Label;
+ public static String JAXRSWSTestView_Request_Parameters_Label;
+ public static String JAXRSWSTestView_Results_Body_Label;
+ public static String JAXRSWSTestView_Results_Header_Label;
+ public static String JAXRSWSTestView_Service_URL_Label;
+ public static String JAXRSWSTestView_Set_Sample_Data_Label;
+ public static String JAXRSWSTestView_Web_Service_Type_Label;
+
static {
NLS.initializeMessages(BUNDLE_NAME, JBossWSUIMessages.class);
}
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/WSTestUtils.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/WSTestUtils.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/WSTestUtils.java 2010-05-05
21:19:30 UTC (rev 21927)
@@ -0,0 +1,186 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.ui.utils;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.net.HttpURLConnection;
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.axis.Message;
+import org.apache.axis.client.Call;
+import org.apache.axis.client.Service;
+import org.apache.axis.message.SOAPEnvelope;
+
+/**
+ * Static utility methods for testing JAX-RS and JAX-WS web services
+ * @author bfitzpat
+ *
+ */
+public class WSTestUtils {
+
+ private static Map<?, ?> resultHeaders = null;
+ private static String EMPTY_STRING = ""; //$NON-NLS-1$
+
+ public static Map<?, ?> getResultHeaders() {
+ return WSTestUtils.resultHeaders;
+ }
+
+ /*
+ * Start building the web query. Append parameters to URL
+ */
+ private static String buildWebQuery(Map<String, String> parameters) throws
Exception {
+ if (!parameters.isEmpty()) {
+ StringBuilder sb = new StringBuilder();
+ for (Map.Entry<String, String> entry : parameters.entrySet()) {
+ String key = URLEncoder.encode(entry.getKey(), "UTF-8");
//$NON-NLS-1$
+ String value = URLEncoder.encode(entry.getValue(), "UTF-8");
//$NON-NLS-1$
+
sb.append(key).append("=").append(value).append("&");
//$NON-NLS-1$ //$NON-NLS-2$
+ }
+ return sb.toString().substring(0, sb.length() - 1);
+ }
+ return EMPTY_STRING;
+ }
+
+ // static simple call, pass in url, parms, and headers
+ public static String callRestfulWebService(String address, Map<String, String>
parameters, Map<String, String> headers) throws Exception {
+ return callRestfulWebService(address, parameters, headers, "GET", null,
null, 0); //$NON-NLS-1$
+ }
+
+ // static call - provide url, parms, headers, the method type, and request body
+ public static String callRestfulWebService(String address, Map<String, String>
parameters, Map<String, String> headers, String methodType, String requestBody)
throws Exception {
+ return callRestfulWebService(address, parameters, headers, methodType,
requestBody, null, 0);
+ }
+
+ // static call - provide url, parms, headers, the method type, request body, proxy
string, and port # as string
+ public static String callRestfulWebService(String address, Map<String, String>
parameters, Map<String, String> headers, String methodType, String requestBody,
String proxy, String port) throws Exception {
+ return callRestfulWebService(address, parameters, headers, methodType,
requestBody, proxy, Integer.parseInt(port));
+ }
+
+ // static call - provide url, parms, headers, the method type, request body, proxy
string, port #
+ public static String callRestfulWebService(String address, Map<String, String>
parameters, Map<String, String> headers, String methodType, String requestBody,
String proxy, int port) throws Exception {
+
+ // handle the proxy
+ Proxy proxyObject = null;
+ if (proxy != null && proxy.length() > 0 && port > 0) {
+ InetSocketAddress proxyAddress = new InetSocketAddress(proxy, port);
+ proxyObject = new Proxy(Proxy.Type.HTTP, proxyAddress);
+ }
+
+ // clear the returned results
+ String response = EMPTY_STRING;
+
+ // get the parms string
+ String query = buildWebQuery(parameters);
+
+ // build the complete URL
+ URL url = null;
+ if (query != null) {
+ // add parms to the url if we have some
+ url = new URL(address + query);
+ } else {
+ url = new URL(address);
+ }
+
+ // make connection
+ HttpURLConnection httpurlc = null;
+ if (proxyObject == null) {
+ httpurlc = (HttpURLConnection) url.openConnection();
+ } else {
+ // if have proxy, pass it along
+ httpurlc = (HttpURLConnection) url.openConnection(proxyObject);
+ }
+
+ // since we are expecting output back, set to true
+ httpurlc.setDoOutput(true);
+
+ // not sure what this does - may be used for authentication?
+ httpurlc.setAllowUserInteraction(false);
+
+ // set whether this is a GET or POST
+ httpurlc.setRequestMethod(methodType);
+
+ // if we are sending/receiving XML, make sure the connection knows
+ if (headers != null && !headers.isEmpty()) {
+ Iterator<?> iter = headers.entrySet().iterator();
+ while (iter.hasNext()) {
+ Entry<?, ?> entry = (Entry<?, ?>)iter.next();
+ if (entry.getKey() != null && entry.getKey() instanceof String)
+ httpurlc.addRequestProperty((String) entry.getKey(), (String)
entry.getValue());
+ }
+ }
+
+ // CONNECT!
+ httpurlc.connect();
+
+ // 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$
+ OutputStreamWriter out = new OutputStreamWriter(httpurlc.getOutputStream());
+ out.write(requestBody);
+ out.close();
+ }
+
+ // retrieve result and put string results into the response
+ InputStream is = (InputStream) httpurlc.getInputStream();
+ BufferedReader br = new BufferedReader(new InputStreamReader(is,
"UTF-8"));//$NON-NLS-1$
+ StringBuilder sb = new StringBuilder();
+ String line;
+ while ((line = br.readLine()) != null) {
+ sb.append(line);
+ sb.append("\n");//$NON-NLS-1$
+ }
+ br.close();
+ response = sb.toString();
+
+ WSTestUtils.resultHeaders = httpurlc.getHeaderFields();
+
+ // disconnect explicitly (may not be necessary)
+ httpurlc.disconnect();
+
+ return response;
+ }
+
+ /*
+ * Invokes the WS and returns a result
+ */
+ public static String invokeWS( String endpointurl, String actionurl, String body )
throws Exception {
+
+ /*
+ * the endpoint & action urls + the soap in are what we
+ * need to invoke the WS
+ */
+ String endpoint = endpointurl;
+ String action = actionurl;
+ String soapIn = body;
+
+ /* Use AXIS to call the WS */
+ String document = soapIn;
+ Service service = new Service();
+ Call call= (Call) service.createCall();
+ call.setTargetEndpointAddress( new java.net.URL(endpoint) );
+ call.setOperationStyle( org.apache.axis.constants.Style.MESSAGE );
+ if ( action != null ) {
+ call.setProperty(Call.SOAPACTION_USE_PROPERTY,Boolean.TRUE);
+ call.setProperty(Call.SOAPACTION_URI_PROPERTY,action);
+ }
+ SOAPEnvelope envelope = call.invoke( new Message(document) );
+ return
envelope.getBody().toString().replaceAll("><",">\n<");//$NON-NLS-1$
//$NON-NLS-2$
+ }
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/utils/WSTestUtils.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/DelimitedStringList.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/DelimitedStringList.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/DelimitedStringList.java 2010-05-05
21:19:30 UTC (rev 21927)
@@ -0,0 +1,567 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sybase, Inc./Eclipse - DTP - initial API and implementation
+ * Red Hat, Inc. - added Edit button
+ ******************************************************************************/
+package org.jboss.tools.ws.ui.views;
+
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+import org.eclipse.core.runtime.ListenerList;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Text;
+import org.jboss.tools.ws.ui.messages.JBossWSUIMessages;
+
+import com.ibm.icu.util.StringTokenizer;
+
+/**
+ * Composite that provides a method of managing a delimited list of strings.
+ *
+ * @author brianf
+ */
+public class DelimitedStringList extends Composite {
+
+ // delimiter used
+ private static final String DELIMITER = ",";//$NON-NLS-1$
+
+ // ui elements
+ private Button mAddButton;
+ private Button mClearAllButton;
+ private Button mRemoveButton;
+ private Button mDownButton;
+ private Button mUpButton;
+ private Button mEditButton;
+ private List mPropsList;
+ private Text mAddText;
+ private Text mHiddenText;
+ private boolean isReadOnly = false;
+
+ // current delimiter
+ private String mDelimiter = DELIMITER;
+
+ // Warning
+ private String mWarning = null;
+
+ // change listeners
+ private ListenerList changeListeners;
+
+ private class AddTextModifyListener implements ModifyListener {
+
+ private DelimitedStringList parent;
+
+ public AddTextModifyListener(DelimitedStringList parent) {
+ this.parent = parent;
+ }
+
+ public void modifyText(ModifyEvent e) {
+ updatePropertyButtons();
+ fireChangedEvent(parent);
+ }
+ }
+
+ /**
+ * Constructor
+ *
+ * @param parent
+ * @param style
+ */
+ public DelimitedStringList(Composite parent, int style) {
+ this(parent, style, false);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param parent
+ * @param style
+ */
+ public DelimitedStringList(Composite parent, int style, boolean isReadOnly) {
+ super(parent, style);
+ this.isReadOnly = isReadOnly;
+ this.changeListeners = new ListenerList();
+
+ int additionalStyles = SWT.NONE;
+ if (isReadOnly){
+ additionalStyles = SWT.READ_ONLY;
+ }
+
+ final GridLayout gridLayout = new GridLayout();
+ gridLayout.marginWidth = 0;
+ gridLayout.marginHeight = 0;
+ gridLayout.numColumns = 2;
+ setLayout(gridLayout);
+ {
+ this.mAddText = new Text(this, SWT.BORDER | additionalStyles);
+ this.mAddText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ this.mAddText.addModifyListener(new AddTextModifyListener(this));
+ }
+ {
+ this.mAddButton = new Button(this, SWT.NONE);
+ this.mAddButton.setLayoutData(new GridData(
+ GridData.HORIZONTAL_ALIGN_FILL));
+ this.mAddButton.setText("Add");//$NON-NLS-1$
+ this.mAddButton.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent e) {
+ addStringToList();
+ fireChangedEvent(e.getSource());
+ }
+ });
+
+ this.mAddButton.setEnabled(false);
+ }
+ {
+ final Composite mSpacerComposite = new Composite(this, SWT.NONE);
+ final GridData gridData = new GridData();
+ gridData.heightHint = 10;
+ gridData.horizontalSpan = 2;
+ mSpacerComposite.setLayoutData(gridData);
+ mSpacerComposite.setLayout(new GridLayout());
+ }
+ {
+ this.mPropsList = new List(this, SWT.BORDER);
+ final GridData gridData = new GridData(
+ GridData.HORIZONTAL_ALIGN_FILL
+ | GridData.VERTICAL_ALIGN_FILL);
+ gridData.verticalSpan = 5;
+ this.mPropsList.setLayoutData(gridData);
+ this.mPropsList.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent e) {
+ updatePropertyButtons();
+ }
+ });
+ }
+ {
+ this.mUpButton = new Button(this, SWT.NONE);
+ this.mUpButton.setLayoutData(new GridData(
+ GridData.HORIZONTAL_ALIGN_FILL));
+ this.mUpButton.setText("Up");//$NON-NLS-1$
+ this.mUpButton.setEnabled(false);
+ this.mUpButton.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent e) {
+ moveUpInList();
+ }
+ });
+ }
+ {
+ this.mDownButton = new Button(this, SWT.NONE);
+ this.mDownButton.setLayoutData(new GridData(
+ GridData.HORIZONTAL_ALIGN_FILL));
+ this.mDownButton.setText("Down");//$NON-NLS-1$
+ this.mDownButton.setEnabled(false);
+ this.mDownButton.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent e) {
+ moveDownInList();
+ }
+ });
+ }
+ {
+ this.mEditButton = new Button(this, SWT.NONE);
+ this.mEditButton.setLayoutData(new GridData(
+ GridData.HORIZONTAL_ALIGN_FILL));
+ this.mEditButton.setText("Edit");//$NON-NLS-1$
+ this.mEditButton.setEnabled(false);
+ this.mEditButton.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent e) {
+ editInList();
+ }
+ });
+ }
+ {
+ this.mRemoveButton = new Button(this, SWT.NONE);
+ this.mRemoveButton.setLayoutData(new GridData(
+ GridData.HORIZONTAL_ALIGN_FILL));
+ this.mRemoveButton.setText("Remove");//$NON-NLS-1$
+ this.mRemoveButton.setEnabled(false);
+ this.mRemoveButton.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent e) {
+ removeFromList();
+ }
+ });
+ }
+ {
+ this.mClearAllButton = new Button(this, SWT.NONE);
+ this.mClearAllButton.setEnabled(false);
+ this.mClearAllButton.setLayoutData(new GridData(
+ GridData.HORIZONTAL_ALIGN_FILL));
+ this.mClearAllButton.setText("Clear All");//$NON-NLS-1$
+ this.mClearAllButton.addSelectionListener(new SelectionAdapter() {
+
+ public void widgetSelected(SelectionEvent e) {
+ DelimitedStringList.this.mPropsList.removeAll();
+ DelimitedStringList.this.mHiddenText.setText(DelimitedStringList.this.getSelection().trim());
+ updatePropertyButtons();
+ }
+ });
+ }
+ {
+ this.mHiddenText = new Text(this, SWT.BORDER);
+ final GridData gridData = new GridData();
+ gridData.horizontalSpan = 2;
+ this.mHiddenText.setLayoutData(gridData);
+ this.mHiddenText.setVisible(false);
+ }
+ updatePropertyButtons();
+ }
+
+ /**
+ * Add a listener to receive notifications when the property list is
+ * modified.
+ *
+ * @param listener
+ */
+ public void addModifyListener(ModifyListener listener) {
+ this.mHiddenText.addModifyListener(listener);
+ }
+
+ public void removeModifyListener(ModifyListener listener) {
+ this.mHiddenText.removeModifyListener(listener);
+ }
+
+ public void dispose() {
+ super.dispose();
+ }
+
+ protected void checkSubclass() {
+ // empty
+ }
+
+ /**
+ * Add a new string to the list
+ */
+ private void addStringToList() {
+ if (this.mAddText.getText().length() > 0) {
+ this.mPropsList.add(this.mAddText.getText().trim());
+ if (!isReadOnly){
+ this.mClearAllButton.setEnabled(true);
+ }
+ String selected = getSelection();
+ this.mHiddenText.setText(selected.trim());
+ this.mAddText.setSelection(0, this.mAddText.getText().length());
+ this.mAddText.setFocus();
+ }
+ }
+
+ private void editInList() {
+ if (this.mPropsList.getSelectionCount() == 1) {
+ int index = this.mPropsList.getSelectionIndex();
+ String toEdit = this.mPropsList.getItem(index);
+
+ InputDialog editDialog = new InputDialog(getShell(),
+ JBossWSUIMessages.JBossWS_DelimitedStringList_EditValue_Dialog_Title,
+ JBossWSUIMessages.JBossWS_DelimitedStringList_EditValue_Dialog_Message,
+ toEdit, null);
+ int rtn_code = editDialog.open();
+ if (rtn_code == Window.OK) {
+ this.mPropsList.remove(index);
+ this.mPropsList.add(editDialog.getValue(), index);
+ }
+ }
+
+ this.mPropsList.setFocus();
+
+ updatePropertyButtons();
+ }
+
+ /**
+ * Remove a string from the list
+ */
+ private void removeFromList() {
+ if (this.mPropsList.getSelectionCount() == 1) {
+ int index = this.mPropsList.getSelectionIndex();
+ this.mPropsList.remove(index);
+ String selected = getSelection();
+ this.mHiddenText.setText(selected.trim());
+
+ try {
+ if (this.mPropsList.getItem(index) != null) {
+ this.mPropsList.select(index);
+ }
+ }
+ catch (IllegalArgumentException e) {
+ // do nothing
+ }
+ }
+
+ this.mPropsList.setFocus();
+
+ updatePropertyButtons();
+ }
+
+ /**
+ * Move a string up in the list
+ */
+ private void moveUpInList() {
+ if (this.mPropsList.getSelectionCount() == 1) {
+ int selection = this.mPropsList.getSelectionIndex();
+ int destination = -1;
+ if (selection > 0) {
+ destination = selection - 1;
+ String value_a = this.mPropsList.getItem(destination);
+ String value_b = this.mPropsList.getItem(selection);
+
+ String[] items = this.mPropsList.getItems();
+ this.mPropsList.removeAll();
+
+ int counter = 0;
+ while (counter < items.length) {
+ if (counter == destination) {
+ this.mPropsList.add(value_b);
+ this.mPropsList.add(value_a);
+ counter = counter + 2;
+ }
+ else {
+ this.mPropsList.add(items[counter]);
+ counter++;
+ }
+ }
+
+ String selected = getSelection();
+ this.mHiddenText.setText(selected.trim());
+ this.mPropsList.setSelection(destination);
+ }
+ }
+ this.mPropsList.setFocus();
+ updatePropertyButtons();
+ }
+
+ /**
+ * Move a string down in the list
+ */
+ private void moveDownInList() {
+ if (this.mPropsList.getSelectionCount() == 1) {
+ int selection = this.mPropsList.getSelectionIndex();
+ int destination = -1;
+ if (selection < this.mPropsList.getItemCount() - 1) {
+
+ destination = selection + 1;
+
+ String value_a = this.mPropsList.getItem(destination);
+ String value_b = this.mPropsList.getItem(selection);
+
+ String[] items = this.mPropsList.getItems();
+ this.mPropsList.removeAll();
+
+ int counter = 0;
+ while (counter < items.length) {
+ if (counter == selection) {
+ this.mPropsList.add(value_a);
+ this.mPropsList.add(value_b);
+ }
+ else if (counter == destination) {
+ // empty
+ }
+ else {
+ this.mPropsList.add(items[counter]);
+ }
+ counter++;
+ }
+
+ String selected = getSelection();
+ this.mHiddenText.setText(selected.trim());
+ this.mPropsList.setSelection(destination);
+
+ }
+ }
+ this.mPropsList.setFocus();
+ updatePropertyButtons();
+ }
+
+ /**
+ * Return the current selection
+ */
+ public String getSelection() {
+ String selectString = ""; //$NON-NLS-1$
+ for (int i = 0; i < this.mPropsList.getItems().length; i++) {
+ String testitem = this.mPropsList.getItem(i).trim();
+ selectString = selectString + testitem;
+ if (i < this.mPropsList.getItems().length - 1) {
+ selectString = selectString + this.mDelimiter;
+ }
+ }
+ return selectString;
+ }
+
+ /**
+ * Update button state based on what's selected
+ */
+ public void updatePropertyButtons() {
+ if (!isReadOnly){
+ this.mDownButton.setEnabled(false);
+ this.mUpButton.setEnabled(false);
+ this.mRemoveButton.setEnabled(false);
+ this.mEditButton.setEnabled(false);
+ this.mClearAllButton.setEnabled(false);
+
+ if (this.mPropsList.getItemCount() > 0) {
+
+ this.mClearAllButton.setEnabled(true);
+
+ if(this.mPropsList.getSelectionCount() == 1){
+ int selection = this.mPropsList.getSelectionIndex();
+
+ this.mRemoveButton.setEnabled(true);
+ this.mEditButton.setEnabled(true);
+
+ if (selection - 1 >= 0)
+ this.mUpButton.setEnabled(true);
+
+ if (selection + 1 < this.mPropsList.getItemCount())
+ this.mDownButton.setEnabled(true);
+ }
+ }
+
+ String value = ""; //$NON-NLS-1$
+ value = this.mAddText.getText();
+ boolean flag = value != null && value.trim().length() > 0;
+ boolean valid = validateText(value);
+ this.mAddButton.setEnabled(flag && valid);
+ }
+ }
+
+ private boolean validateText(String text) {
+ if (text != null && text.trim().length() > 0 &&
text.indexOf(",") > -1) { //$NON-NLS-1$
+ this.mWarning = "There are no commas delimiting the name and value for this
key/value pair."; //$NON-NLS-1$
+ return false;
+ }
+ this.mWarning = null;
+ return true;
+ }
+
+ /**
+ * Set focus to the add text box
+ */
+ public boolean setFocus() {
+ if (this.mAddText != null)
+ return this.mAddText.setFocus();
+ return false;
+ }
+
+ /**
+ * Set the initial delimited list
+ *
+ * @param str_list
+ */
+ public void setSelection(String str_list) {
+ String[] str_array = parseString(str_list);
+ this.mPropsList.setItems(str_array);
+ updatePropertyButtons();
+ }
+
+ /**
+ * Parse the list
+ *
+ * @param str_list
+ * @return
+ */
+ private String[] parseString(String str_list) {
+ StringTokenizer tk = new StringTokenizer(str_list, this.mDelimiter);
+ String[] pieces = new String[tk.countTokens()];
+ int index = 0;
+ while (tk.hasMoreTokens())
+ pieces[index++] = tk.nextToken();
+ return pieces;
+ }
+
+ public static String[] parseString(String str_list, String delimiter) {
+ StringTokenizer tk = new StringTokenizer(str_list, delimiter);
+ String[] pieces = new String[tk.countTokens()];
+ int index = 0;
+ while (tk.hasMoreTokens())
+ pieces[index++] = tk.nextToken();
+ return pieces;
+ }
+
+ /**
+ * Change the delimiter
+ *
+ * @param delimiter
+ */
+ public void setDelimiter(String delimiter) {
+ this.mDelimiter = delimiter;
+ }
+
+ /**
+ * Return the delimiter
+ *
+ * @return
+ */
+ public String getDelimiter() {
+ return this.mDelimiter;
+ }
+
+ public String getWarning() {
+ return this.mWarning;
+ }
+
+ /**
+ * If we changed, fire a changed event.
+ *
+ * @param source
+ */
+ private void fireChangedEvent(Object source) {
+ ChangeEvent e = new ChangeEvent(source);
+ // inform any listeners of the resize event
+ Object[] listeners = this.changeListeners.getListeners();
+ for (int i = 0; i < listeners.length; ++i) {
+ ((ChangeListener) listeners[i]).stateChanged(e);
+ }
+ }
+
+ /**
+ * Add a change listener
+ *
+ * @param listener
+ */
+ public void addChangeListener(ChangeListener listener) {
+ this.changeListeners.add(listener);
+ }
+
+ /**
+ * Remove a change listener.
+ *
+ * @param listener
+ */
+ public void removeChangeListener(ChangeListener listener) {
+ this.changeListeners.remove(listener);
+ }
+
+ @Override
+ public void setEnabled(boolean enabled) {
+ super.setEnabled(enabled);
+ mAddButton.setEnabled(enabled);
+ mAddText.setEnabled(enabled);
+ mClearAllButton.setEnabled(enabled);
+ mDownButton.setEnabled(enabled);
+ mEditButton.setEnabled(enabled);
+ mPropsList.setEnabled(enabled);
+ mRemoveButton.setEnabled(enabled);
+ mUpButton.setEnabled(enabled);
+ if (enabled)
+ updatePropertyButtons();
+ }
+
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/DelimitedStringList.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
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
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/JAXRSWSTestView.java 2010-05-05
21:19:30 UTC (rev 21927)
@@ -0,0 +1,400 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.ui.views;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map.Entry;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.TabItem;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.part.ViewPart;
+import org.jboss.tools.ws.ui.messages.JBossWSUIMessages;
+import org.jboss.tools.ws.ui.utils.WSTestUtils;
+
+public class JAXRSWSTestView extends ViewPart {
+
+ private static final String DELETE = "DELETE";//$NON-NLS-1$
+ private static final String PUT = "PUT";//$NON-NLS-1$
+ private static final String POST = "POST";//$NON-NLS-1$
+ private static final String GET = "GET";//$NON-NLS-1$
+ private static final String JAX_WS = "JAX-WS"; //$NON-NLS-1$
+ private static final String JAX_RS = "JAX-RS"; //$NON-NLS-1$
+ private static final String EMPTY_STRING = ""; //$NON-NLS-1$
+
+ /**
+ * The ID of the view as specified by the extension.
+ */
+ public static final String ID =
"org.jboss.tools.ws.ui.tester.views.TestWSView";//$NON-NLS-1$
+
+ /* UI controls */
+ private Button testButton = null;
+ private Text actionText;
+ private Text resultsText;
+ private Combo urlCombo;
+ private DelimitedStringList dlsList;
+ private Combo methodCombo;
+ private Combo wsTypeCombo;
+ private Text bodyText;
+ private TabFolder tabGroup;
+ private TabItem bodyTab;
+ private TabItem headerTab;
+ private List resultHeadersList;
+ private TabItem resultHeadersTab;
+ private TabItem resultTab;
+ private TabFolder resultTabGroup;
+
+ private TabItem parmsTab;
+
+ private DelimitedStringList parmsList;
+
+ /**
+ * The constructor.
+ */
+ public JAXRSWSTestView() {
+ }
+
+ /**
+ * This is a callback that will allow us
+ * to create the viewer and initialize it.
+ */
+ public void createPartControl(Composite parent) {
+
+ Composite innerComposite = new Composite (parent, SWT.NONE);
+ innerComposite.setLayout(new GridLayout(2, false));
+
+ Label typeLabel = new Label(innerComposite, SWT.NONE);
+ typeLabel.setText(JBossWSUIMessages.JAXRSWSTestView_Web_Service_Type_Label);
+ typeLabel.setLayoutData(new GridData());
+
+ wsTypeCombo = new Combo(innerComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
+ wsTypeCombo.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
+ wsTypeCombo.add(JAX_WS);
+ wsTypeCombo.add(JAX_RS);
+ wsTypeCombo.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+ public void widgetSelected(SelectionEvent e) {
+ setControlsForWSType(wsTypeCombo.getText());
+ }
+ });
+
+ Label methodLabel = new Label(innerComposite, SWT.NONE);
+ methodLabel.setText(JBossWSUIMessages.JAXRSWSTestView_HTTP_Method_Label);
+ methodLabel.setLayoutData(new GridData());
+
+ methodCombo = new Combo(innerComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
+ methodCombo.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
+ methodCombo.add(GET);
+ methodCombo.add(POST);
+ methodCombo.add(PUT);
+ methodCombo.add(DELETE);
+ methodCombo.setText(GET);
+
+ Label urlLabel = new Label(innerComposite, SWT.NONE);
+ urlLabel.setText(JBossWSUIMessages.JAXRSWSTestView_Service_URL_Label);
+ urlLabel.setLayoutData(new GridData());
+
+// urlText = new Text(innerComposite, SWT.BORDER);
+// urlText.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
+
+ urlCombo = new Combo(innerComposite, SWT.BORDER | SWT.DROP_DOWN);
+ urlCombo.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
+
+ Label actionLabel = new Label(innerComposite, SWT.NONE);
+ actionLabel.setText(JBossWSUIMessages.JAXRSWSTestView_Action_URL_Label);
+ actionLabel.setLayoutData(new GridData());
+
+ actionText = new Text(innerComposite, SWT.BORDER);
+ actionText.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
+
+ tabGroup = new TabFolder(innerComposite, SWT.BORDER);
+
+ bodyTab = new TabItem(tabGroup, SWT.NONE, 0);
+ bodyTab.setText(JBossWSUIMessages.JAXRSWSTestView_Request_Body_Label);
+
+ parmsTab = new TabItem(tabGroup, SWT.NONE, 1);
+ parmsTab.setText(JBossWSUIMessages.JAXRSWSTestView_Request_Parameters_Label);
+
+ parmsList = new DelimitedStringList(tabGroup, SWT.None);
+ parmsTab.setControl(parmsList);
+ GridData parmsListGD = new GridData(SWT.FILL, SWT.FILL, true, true);
+ parmsListGD.horizontalSpan = 2;
+ parmsList.setLayoutData(parmsListGD);
+
+ headerTab = new TabItem(tabGroup, SWT.NONE, 2);
+ bodyText = new Text(tabGroup, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
+ GridData btGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ bodyText.setLayoutData(btGridData);
+ bodyTab.setControl(bodyText);
+
+ headerTab.setText(JBossWSUIMessages.JAXRSWSTestView_Request_Header_Label);
+ GridData hgGridData = new GridData(SWT.FILL, SWT.NONE, true, false);
+ hgGridData.horizontalSpan = 2;
+ tabGroup.setLayoutData(hgGridData);
+
+ dlsList = new DelimitedStringList(tabGroup, SWT.None);
+ headerTab.setControl(dlsList);
+ GridData dlsListGD = new GridData(SWT.FILL, SWT.FILL, true, true);
+ dlsListGD.horizontalSpan = 2;
+ dlsList.setLayoutData(dlsListGD);
+
+// Button sampleButton = new Button(innerComposite, SWT.PUSH);
+// sampleButton.setText(JBossWSUIMessages.JAXRSWSTestView_Set_Sample_Data_Label);
+// sampleButton.setLayoutData(new GridData());
+//
+// sampleButton.addSelectionListener(new SelectionListener() {
+// public void widgetSelected(SelectionEvent e) {
+// setupSample();
+// }
+// public void widgetDefaultSelected(SelectionEvent e) {
+// widgetSelected(e);
+// }
+// });
+
+ GridData buttonGD = new GridData(SWT.BEGINNING, SWT.NONE, false, false);
+ testButton = new Button (innerComposite, SWT.PUSH);
+ testButton.setText(JBossWSUIMessages.JAXRSWSTestView_Invoke_Label);
+ testButton.setLayoutData(buttonGD);
+
+ testButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ handleTest();
+ }
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+ });
+
+ resultTabGroup = new TabFolder(innerComposite, SWT.BORDER);
+ GridData rtGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ rtGridData.horizontalSpan = 2;
+ resultTabGroup.setLayoutData(rtGridData);
+
+ resultTab = new TabItem(resultTabGroup, SWT.NONE, 0);
+ resultTab.setText(JBossWSUIMessages.JAXRSWSTestView_Results_Body_Label);
+ resultsText = new Text(resultTabGroup, SWT.BORDER | SWT.V_SCROLL | SWT.WRAP |
SWT.READ_ONLY );
+ resultsText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ resultTab.setControl(resultsText);
+
+ resultHeadersTab = new TabItem(resultTabGroup, SWT.NONE, 1);
+ resultHeadersTab.setText(JBossWSUIMessages.JAXRSWSTestView_Results_Header_Label);
+ resultHeadersList = new List(resultTabGroup, SWT.V_SCROLL);
+ resultHeadersTab.setControl(resultHeadersList);
+ GridData rdlsListGD = new GridData(SWT.FILL, SWT.FILL, true, true);
+ rdlsListGD.horizontalSpan = 2;
+ resultHeadersList.setLayoutData(dlsListGD);
+
+ wsTypeCombo.setText(JAX_WS);
+ setControlsForWSType(wsTypeCombo.getText());
+ }
+
+ private void setControlsForWSType ( String wsType ) {
+ if (wsType.equalsIgnoreCase(JAX_WS)) {
+ actionText.setEnabled(true);
+ bodyText.setEnabled(true);
+ methodCombo.setEnabled(false);
+ parmsList.setEnabled(false);
+ dlsList.setEnabled(false);
+ parmsTab.getControl().setEnabled(false);
+ headerTab.getControl().setEnabled(false);
+ }
+ else if (wsType.equalsIgnoreCase(JAX_RS)) {
+ actionText.setEnabled(false);
+ bodyText.setEnabled(true);
+ methodCombo.setEnabled(true);
+ parmsList.setEnabled(true);
+ dlsList.setEnabled(true);
+ parmsTab.getControl().setEnabled(true);
+ headerTab.getControl().setEnabled(true);
+ }
+ }
+
+ /*
+ * Sets up the controls to call a public sample RESTful WS that does
+ * a postal code lookup.
+ */
+ private void setupSample() {
+ // go to
http://www.geonames.org/export/web-services.html for example
+ //http://ws.geonames.org/postalCodeSearch?postalcode=9011&maxRows=10
+ if (wsTypeCombo.getText().equalsIgnoreCase(JAX_RS)) {
+
urlCombo.setText("http://ws.geonames.org/postalCodeSearch?"); //$NON-NLS-1$
+ parmsList.setSelection("postalcode=80920,maxRows=10"); //$NON-NLS-1$
+ dlsList.setSelection("content-type=application/xml"); //$NON-NLS-1$
+ methodCombo.setText(GET);
+ tabGroup.setSelection(parmsTab);
+ bodyText.setText(EMPTY_STRING);
+ }
+ else if (wsTypeCombo.getText().equalsIgnoreCase(JAX_WS)) {
+ String soapIn = "<?xml version=\"1.0\" standalone=\"yes\"
?>" + //$NON-NLS-1$
+ "<soap:Envelope
xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " + //$NON-NLS-1$
+ "xmlns:ns=\"http://xmlme.com/WebServices\">" + //$NON-NLS-1$
+ "<soap:Body>" + //$NON-NLS-1$
+ "<ns:GetSpeech>" + //$NON-NLS-1$
+ "<ns:Request>slings and arrows</ns:Request>"+ //$NON-NLS-1$
+ "</ns:GetSpeech>"+ //$NON-NLS-1$
+ "</soap:Body>" + //$NON-NLS-1$
+ "</soap:Envelope>"; //$NON-NLS-1$
+
+
urlCombo.setText("http://www.xmlme.com/WSShakespeare.asmx"); //$NON-NLS-1$
+
actionText.setText("http://xmlme.com/WebServices/GetSpeech"); //$NON-NLS-1$
+ bodyText.setText(soapIn);
+ parmsList.setSelection(EMPTY_STRING);
+ dlsList.setSelection(EMPTY_STRING);
+ tabGroup.setSelection(bodyTab);
+ }
+ }
+
+ private void handleTest() {
+ if (urlCombo.getItemCount() > 0) {
+ java.util.List<String> aList = Arrays.asList(urlCombo.getItems());
+ if (!aList.contains(urlCombo.getText())) {
+ urlCombo.add(urlCombo.getText());
+ }
+ } else {
+ urlCombo.add(urlCombo.getText());
+ }
+
+ if (wsTypeCombo.getText().equalsIgnoreCase(JAX_RS)) {
+ handleRSTest();
+ }
+ else if (wsTypeCombo.getText().equalsIgnoreCase(JAX_WS)) {
+ handleWSTest();
+ }
+ }
+
+ /*
+ * Actually call the WS and displays the result
+ */
+ private void handleWSTest() {
+ try {
+ String result = WSTestUtils.invokeWS(urlCombo.getText(), actionText.getText(),
bodyText.getText());
+ resultsText.setText(result);
+
+ resultHeadersList.removeAll();
+ if (WSTestUtils.getResultHeaders() != null) {
+ Iterator<?> iter = WSTestUtils.getResultHeaders().entrySet().iterator();
+ while (iter.hasNext()) {
+ String text = EMPTY_STRING;
+ Entry<?, ?> entry = (Entry<?, ?>) iter.next();
+ if (entry.getKey() == null)
+ text = entry.getValue().toString();
+ else
+ text = text + entry.toString();
+ resultHeadersList.add(text);
+ }
+ }
+ } catch (Exception e) {
+ resultsText.setText(e.toString());
+ e.printStackTrace();
+ }
+ }
+
+ /*
+ * Actually call the RESTful WS to test it
+ */
+ private void handleRSTest() {
+
+ // Get the service URL
+ String address = urlCombo.getText();
+
+ // Is this a GET or POST activity?
+ String method = methodCombo.getText();
+
+ // What's the Request body text?
+ String body = bodyText.getText();
+
+ // if no actual text in the request body, set to null
+ if (body.trim().length() == 0) body = null;
+
+ // Process parameters for web service call
+ HashMap<String, String> parameters = new HashMap<String, String>();
+ if (!parmsList.isDisposed() && parmsList.getSelection() != null &&
parmsList.getSelection().length() > 0) {
+ String[] parsedList = DelimitedStringList.parseString(parmsList.getSelection() ,
","); //$NON-NLS-1$
+ if (parsedList != null && parsedList.length > 0) {
+ for (int i = 0; i < parsedList.length; i++) {
+ String nameValuePair = parsedList[i];
+ String[] nameAndValue = DelimitedStringList.parseString(nameValuePair,
"="); //$NON-NLS-1$
+ if (nameAndValue != null && nameAndValue.length == 2) {
+ parameters.put(nameAndValue[0], nameAndValue[1]);
+ }
+ }
+ }
+ }
+
+ // Process headers for web service call
+ HashMap<String, String> headers = new HashMap<String, String>();
+ if (!dlsList.isDisposed() && dlsList.getSelection() != null &&
dlsList.getSelection().length() > 0) {
+ String[] parsedList = DelimitedStringList.parseString(dlsList.getSelection() ,
","); //$NON-NLS-1$
+ if (parsedList != null && parsedList.length > 0) {
+ for (int i = 0; i < parsedList.length; i++) {
+ String nameValuePair = parsedList[i];
+ String[] nameAndValue = DelimitedStringList.parseString(nameValuePair,
"="); //$NON-NLS-1$
+ if (nameAndValue != null && nameAndValue.length == 2) {
+ headers.put(nameAndValue[0], nameAndValue[1]);
+ }
+ }
+ }
+ }
+
+ // now actually call it
+ try {
+ // clear the results text
+ resultsText.setText(EMPTY_STRING);
+
+ // call the service
+ String result =
+ WSTestUtils.callRestfulWebService(address, parameters, headers, method, body);
+
+ // put the results in the result text field
+ resultsText.setText(result);
+
+ resultHeadersList.removeAll();
+ Iterator<?> iter = WSTestUtils.getResultHeaders().entrySet().iterator();
+ while (iter.hasNext()) {
+ String text = EMPTY_STRING;
+ Entry<?, ?> entry = (Entry<?, ?>) iter.next();
+ if (entry.getKey() == null)
+ text = entry.getValue().toString();
+ else
+ text = text + entry.toString();
+ resultHeadersList.add(text);
+ }
+
+ } catch (Exception e) {
+
+ // if we hit an error, put it in the results text
+ resultsText.setText(e.toString());
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Passing the focus request to the control.
+ */
+ public void setFocus() {
+ // set initial focus to the URL text combo
+ urlCombo.setFocus();
+ }
+}
\ No newline at end of file
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.ui/src/org/jboss/tools/ws/ui/views/JAXRSWSTestView.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain