Source Code Cross Referenced for AbstractWsdlRequestDesktopPanel.java in  » Web-Services » soapui-1.7.5 » com » eviware » soapui » impl » wsdl » panels » request » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Services » soapui 1.7.5 » com.eviware.soapui.impl.wsdl.panels.request 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         *  soapUI, copyright (C) 2004-2007 eviware.com 
0003:         *
0004:         *  soapUI is free software; you can redistribute it and/or modify it under the 
0005:         *  terms of version 2.1 of the GNU Lesser General Public License as published by 
0006:         *  the Free Software Foundation.
0007:         *
0008:         *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
0009:         *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
0010:         *  See the GNU Lesser General Public License for more details at gnu.org.
0011:         */
0012:
0013:        package com.eviware.soapui.impl.wsdl.panels.request;
0014:
0015:        import java.awt.BorderLayout;
0016:        import java.awt.Component;
0017:        import java.awt.Dimension;
0018:        import java.awt.event.ActionEvent;
0019:        import java.awt.event.FocusAdapter;
0020:        import java.awt.event.FocusEvent;
0021:        import java.awt.event.FocusListener;
0022:        import java.awt.event.ItemEvent;
0023:        import java.awt.event.ItemListener;
0024:        import java.beans.PropertyChangeEvent;
0025:        import java.beans.PropertyChangeListener;
0026:        import java.security.cert.Certificate;
0027:
0028:        import javax.swing.AbstractAction;
0029:        import javax.swing.Action;
0030:        import javax.swing.BorderFactory;
0031:        import javax.swing.Box;
0032:        import javax.swing.JButton;
0033:        import javax.swing.JComboBox;
0034:        import javax.swing.JComponent;
0035:        import javax.swing.JEditorPane;
0036:        import javax.swing.JPanel;
0037:        import javax.swing.JPopupMenu;
0038:        import javax.swing.JScrollPane;
0039:        import javax.swing.JSeparator;
0040:        import javax.swing.JSplitPane;
0041:        import javax.swing.JTabbedPane;
0042:        import javax.swing.JTable;
0043:        import javax.swing.JToggleButton;
0044:        import javax.swing.JToolBar;
0045:        import javax.swing.SwingUtilities;
0046:        import javax.swing.event.ChangeEvent;
0047:        import javax.swing.event.ChangeListener;
0048:        import javax.swing.event.TableModelEvent;
0049:        import javax.swing.event.TableModelListener;
0050:        import javax.swing.text.html.HTMLEditorKit;
0051:
0052:        import org.apache.log4j.Logger;
0053:
0054:        import com.eviware.soapui.SoapUI;
0055:        import com.eviware.soapui.impl.wsdl.WsdlRequest;
0056:        import com.eviware.soapui.impl.wsdl.WsdlSubmitContext;
0057:        import com.eviware.soapui.impl.wsdl.actions.request.AddRequestToMockServiceAction;
0058:        import com.eviware.soapui.impl.wsdl.actions.request.CloneRequestAction;
0059:        import com.eviware.soapui.impl.wsdl.actions.request.CreateEmptyRequestAction;
0060:        import com.eviware.soapui.impl.wsdl.actions.request.RecreateRequestAction;
0061:        import com.eviware.soapui.impl.wsdl.actions.support.ShowOnlineHelpAction;
0062:        import com.eviware.soapui.impl.wsdl.panels.attachments.AttachmentPanel;
0063:        import com.eviware.soapui.impl.wsdl.panels.request.actions.WSIValidateRequestAction;
0064:        import com.eviware.soapui.impl.wsdl.panels.request.components.RequestMessageXmlEditor;
0065:        import com.eviware.soapui.impl.wsdl.panels.request.components.RequestXmlDocument;
0066:        import com.eviware.soapui.impl.wsdl.panels.request.components.ResponseMessageXmlEditor;
0067:        import com.eviware.soapui.impl.wsdl.panels.request.components.ResponseXmlDocument;
0068:        import com.eviware.soapui.impl.wsdl.panels.request.components.SoapMessageXmlEditor;
0069:        import com.eviware.soapui.impl.wsdl.panels.request.components.editor.XmlDocument;
0070:        import com.eviware.soapui.impl.wsdl.panels.request.components.editor.views.source.XmlSourceEditorView;
0071:        import com.eviware.soapui.impl.wsdl.panels.support.EndpointsComboBoxModel;
0072:        import com.eviware.soapui.impl.wsdl.submit.transports.http.SSLInfo;
0073:        import com.eviware.soapui.impl.wsdl.submit.transports.http.WsdlResponse;
0074:        import com.eviware.soapui.impl.wsdl.support.HelpUrls;
0075:        import com.eviware.soapui.model.ModelItem;
0076:        import com.eviware.soapui.model.iface.Submit;
0077:        import com.eviware.soapui.model.iface.SubmitContext;
0078:        import com.eviware.soapui.model.iface.SubmitListener;
0079:        import com.eviware.soapui.model.iface.Request.SubmitException;
0080:        import com.eviware.soapui.model.iface.Submit.Status;
0081:        import com.eviware.soapui.settings.UISettings;
0082:        import com.eviware.soapui.support.UISupport;
0083:        import com.eviware.soapui.support.action.swing.SwingActionDelegate;
0084:        import com.eviware.soapui.support.actions.ChangeSplitPaneOrientationAction;
0085:        import com.eviware.soapui.support.components.JEditorStatusBarWithProgress;
0086:        import com.eviware.soapui.support.components.JXToolBar;
0087:        import com.eviware.soapui.support.swing.SoapUISplitPaneUI;
0088:        import com.eviware.soapui.support.types.StringToStringMap;
0089:        import com.eviware.soapui.support.xml.JXEditTextArea;
0090:        import com.eviware.soapui.ui.support.ModelItemDesktopPanel;
0091:
0092:        /**
0093:         * Abstract DesktopPanel for WsdlRequests
0094:         * 
0095:         * @author Ole.Matzura
0096:         */
0097:
0098:        public class AbstractWsdlRequestDesktopPanel<T extends ModelItem, T2 extends WsdlRequest>
0099:                extends ModelItemDesktopPanel<T> {
0100:            private final static Logger log = Logger
0101:                    .getLogger(AbstractWsdlRequestDesktopPanel.class);
0102:
0103:            private JComboBox endpointCombo;
0104:            private JButton submitButton;
0105:            private JButton cancelButton;
0106:            private EndpointsComboBoxModel endpointsModel;
0107:            private JEditorStatusBarWithProgress statusBar;
0108:            private JButton splitButton;
0109:            private Submit submit;
0110:            private JButton recreateButton;
0111:            private JButton cloneButton;
0112:            private JButton createEmptyButton;
0113:            private InternalSubmitListener internalSubmitListener;
0114:            private JSplitPane requestSplitPane;
0115:            private MoveFocusAction moveFocusAction;
0116:            private ClosePanelAction closePanelAction = new ClosePanelAction();
0117:            private T2 request;
0118:
0119:            private SoapMessageXmlEditor requestEditor;
0120:            private SoapMessageXmlEditor responseEditor;
0121:
0122:            //public WSIValidateRequestAction wsiValidateAction;
0123:
0124:            private JTabbedPane requestTabs;
0125:            private JPanel requestTabPanel;
0126:            private JToggleButton tabsButton;
0127:
0128:            public boolean responseHasFocus;
0129:
0130:            private JTabbedPane requestEditorTabs;
0131:            private JTabbedPane responseEditorTabs;
0132:
0133:            private JPanel requestEditorTabPanel;
0134:            private JPanel responseEditorTabPanel;
0135:            private AttachmentPropertyChangeListener attachmentsPropertyChangeListener = new AttachmentPropertyChangeListener();
0136:            private StringToStringMapTableModel requestHeadersModel;
0137:            private JTable requestHeadersTable;
0138:            private StringToStringMapTableModel responseHeadersModel;
0139:
0140:            private JEditorPane sslInfoPane;
0141:            private JButton addToMockServiceButton;
0142:            //private JButton addAsMockResponseStepButton;
0143:
0144:            //	private DefaultActionList formEditorActions;
0145:
0146:            private AbstractAction wsiValidateAction;
0147:
0148:            private AttachmentPanel requestAttachmentPanel;
0149:            private AttachmentPanel responseAttachmentPanel;
0150:
0151:            public AbstractWsdlRequestDesktopPanel(T modelItem) {
0152:                super (modelItem);
0153:            }
0154:
0155:            protected void init(T2 request) {
0156:                this .request = request;
0157:
0158:                this .endpointsModel = new EndpointsComboBoxModel(request);
0159:                internalSubmitListener = createSubmitListener();
0160:
0161:                request.addSubmitListener(internalSubmitListener);
0162:
0163:                add(buildContent(), BorderLayout.CENTER);
0164:                add(buildToolbar(), BorderLayout.NORTH);
0165:                add(buildStatusLabel(), BorderLayout.SOUTH);
0166:
0167:                setPreferredSize(new Dimension(600, 500));
0168:
0169:                request
0170:                        .addPropertyChangeListener(attachmentsPropertyChangeListener);
0171:
0172:                addFocusListener(new FocusAdapter() {
0173:
0174:                    @Override
0175:                    public void focusGained(FocusEvent e) {
0176:                        if (requestTabs.getSelectedIndex() == 1
0177:                                || responseHasFocus)
0178:                            responseEditor.requestFocusInWindow();
0179:                        else
0180:                            requestEditor.requestFocusInWindow();
0181:                    }
0182:                });
0183:            }
0184:
0185:            protected InternalSubmitListener createSubmitListener() {
0186:                return new InternalSubmitListener();
0187:            }
0188:
0189:            public final T2 getRequest() {
0190:                return request;
0191:            }
0192:
0193:            public final SoapMessageXmlEditor getRequestEditor() {
0194:                return requestEditor;
0195:            }
0196:
0197:            public final SoapMessageXmlEditor getResponseEditor() {
0198:                return responseEditor;
0199:            }
0200:
0201:            public Submit getSubmit() {
0202:                return submit;
0203:            }
0204:
0205:            protected JComponent buildStatusLabel() {
0206:                statusBar = new JEditorStatusBarWithProgress();
0207:                statusBar
0208:                        .setBorder(BorderFactory.createEmptyBorder(1, 0, 0, 0));
0209:
0210:                return statusBar;
0211:            }
0212:
0213:            public JEditorStatusBarWithProgress getStatusBar() {
0214:                return statusBar;
0215:            }
0216:
0217:            @SuppressWarnings("unchecked")
0218:            protected JComponent buildContent() {
0219:                requestSplitPane = UISupport.createHorizontalSplit();
0220:                requestSplitPane.setResizeWeight(0.5);
0221:                requestSplitPane.setBorder(null);
0222:
0223:                submitButton = createActionButton(new SubmitAction(), true);
0224:                cancelButton = createActionButton(new CancelAction(), false);
0225:                splitButton = createActionButton(
0226:                        new ChangeSplitPaneOrientationAction(requestSplitPane),
0227:                        true);
0228:
0229:                tabsButton = new JToggleButton(new ChangeToTabsAction());
0230:                tabsButton.setPreferredSize(UISupport.TOOLBAR_BUTTON_DIMENSION);
0231:
0232:                recreateButton = createActionButton(new RecreateRequestAction(
0233:                        request), true);
0234:                addToMockServiceButton = createActionButton(SwingActionDelegate
0235:                        .createDelegate(
0236:                                AddRequestToMockServiceAction.SOAPUI_ACTION_ID,
0237:                                request, null, "/addToMockService.gif"), true);
0238:
0239:                cloneButton = createActionButton(SwingActionDelegate
0240:                        .createDelegate(CloneRequestAction.SOAPUI_ACTION_ID,
0241:                                request, null, "/clone_request.gif"), true);
0242:
0243:                createEmptyButton = createActionButton(
0244:                        new CreateEmptyRequestAction(request), true);
0245:
0246:                submitButton.setEnabled(request.getEndpoint() != null
0247:                        && request.getEndpoint().trim().length() > 0);
0248:                wsiValidateAction = SwingActionDelegate.createDelegate(
0249:                        new WSIValidateRequestAction(), request, "alt W");
0250:                wsiValidateAction.setEnabled(request.getResponse() != null);
0251:
0252:                moveFocusAction = new MoveFocusAction();
0253:
0254:                requestEditor = buildRequestEditor();
0255:                responseEditor = buildResponseEditor();
0256:
0257:                requestEditorTabs = new JTabbedPane(JTabbedPane.BOTTOM);
0258:                requestEditorTabs
0259:                        .setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
0260:                requestEditorTabs.addTab("SOAP Request", requestEditor);
0261:                requestAttachmentPanel = new AttachmentPanel(request, true);
0262:                requestEditorTabs.addTab("Request Attachments ("
0263:                        + request.getAttachmentCount() + ")",
0264:                        requestAttachmentPanel);
0265:                requestEditorTabs.addTab("HTTP Headers ("
0266:                        + request.getRequestHeaders().size() + ")",
0267:                        createRequestHttpHeadersPanel());
0268:                requestEditorTabs.addChangeListener(new ChangeListener() {
0269:
0270:                    public void stateChanged(ChangeEvent e) {
0271:                        SwingUtilities.invokeLater(new Runnable() {
0272:
0273:                            public void run() {
0274:                                int ix = requestEditorTabs.getSelectedIndex();
0275:                                if (ix == 0)
0276:                                    requestEditor.requestFocus();
0277:                            }
0278:                        });
0279:
0280:                    }
0281:                });
0282:
0283:                responseEditorTabs = new JTabbedPane(JTabbedPane.BOTTOM);
0284:                responseEditorTabs
0285:                        .setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
0286:                responseEditorTabs.addTab("SOAP Response", responseEditor);
0287:                responseAttachmentPanel = new AttachmentPanel(request, false);
0288:                responseEditorTabs.addTab("Response Attachments ("
0289:                        + (request.getResponse() == null ? 0 : request
0290:                                .getResponse().getAttachments().length) + ")",
0291:                        responseAttachmentPanel);
0292:                responseEditorTabs.addTab("HTTP Headers",
0293:                        createResponseHttpHeadersPanel());
0294:                String sslInfoTabTitle = "SSL Info";
0295:                if (request.getResponse() != null
0296:                        && ((WsdlResponse) request.getResponse()).getSSLInfo() != null)
0297:                    sslInfoTabTitle += " ("
0298:                            + ((WsdlResponse) request.getResponse())
0299:                                    .getSSLInfo().getPeerCertificates().length
0300:                            + " certs)";
0301:                else
0302:                    sslInfoTabTitle += " (-)";
0303:
0304:                responseEditorTabs
0305:                        .addTab(sslInfoTabTitle, createSSLInfoPanel());
0306:                responseEditorTabs.addChangeListener(new ChangeListener() {
0307:
0308:                    public void stateChanged(ChangeEvent e) {
0309:                        SwingUtilities.invokeLater(new Runnable() {
0310:
0311:                            public void run() {
0312:                                int ix = responseEditorTabs.getSelectedIndex();
0313:                                if (ix == 0)
0314:                                    responseEditor.requestFocus();
0315:                            }
0316:                        });
0317:
0318:                    }
0319:                });
0320:
0321:                requestTabs = new JTabbedPane();
0322:                requestTabs.addChangeListener(new ChangeListener() {
0323:
0324:                    public void stateChanged(ChangeEvent e) {
0325:                        SwingUtilities.invokeLater(new Runnable() {
0326:
0327:                            public void run() {
0328:                                int ix = requestTabs.getSelectedIndex();
0329:                                if (ix == 0
0330:                                        && requestEditorTabs.getSelectedIndex() == 0)
0331:                                    requestEditor.requestFocus();
0332:                                else if (ix == 1
0333:                                        && responseEditorTabs
0334:                                                .getSelectedIndex() == 0)
0335:                                    responseEditor.requestFocus();
0336:                            }
0337:                        });
0338:                    }
0339:                });
0340:
0341:                requestTabPanel = UISupport.createTabPanel(requestTabs, true);
0342:
0343:                requestEditorTabPanel = UISupport.createTabPanel(
0344:                        requestEditorTabs, false);
0345:                responseEditorTabPanel = UISupport.createTabPanel(
0346:                        responseEditorTabs, false);
0347:
0348:                if (request.getSettings().getBoolean(
0349:                        UISettings.START_WITH_REQUEST_TABS)) {
0350:                    requestTabs.addTab("Request", requestEditorTabPanel);
0351:                    requestTabs.addTab("Response", responseEditorTabPanel);
0352:                    splitButton.setEnabled(false);
0353:                    tabsButton.setSelected(true);
0354:
0355:                    return requestTabPanel;
0356:                } else {
0357:                    requestSplitPane.setTopComponent(requestEditorTabPanel);
0358:                    requestSplitPane.setBottomComponent(responseEditorTabPanel);
0359:                    requestSplitPane.setDividerLocation(0.5);
0360:                    return requestSplitPane;
0361:                }
0362:            }
0363:
0364:            private Component createSSLInfoPanel() {
0365:                JPanel panel = new JPanel(new BorderLayout());
0366:
0367:                sslInfoPane = new JEditorPane();
0368:                sslInfoPane.setEditorKit(new HTMLEditorKit());
0369:                panel.add(new JScrollPane(sslInfoPane));
0370:
0371:                return panel;
0372:            }
0373:
0374:            private void updateSSLInfo(SSLInfo sslInfo) {
0375:                String sslInfoTabTitle = "SSL Info";
0376:
0377:                if (sslInfo == null) {
0378:                    sslInfoPane
0379:                            .setText("<html><body>Not an SSL connection</body></html>");
0380:                    sslInfoTabTitle += " (-)";
0381:                } else {
0382:                    StringBuffer buf = new StringBuffer(
0383:                            "<html><body><table cellpadding=1 cellspacing=1 border=0>");
0384:
0385:                    buf
0386:                            .append(
0387:                                    "<tr><td><b>CipherSuite:</b></td><td align=left valign=top>")
0388:                            .append(sslInfo.getCipherSuite().toString())
0389:                            .append("</td></tr>");
0390:
0391:                    if (sslInfo.getLocalPrincipal() != null)
0392:                        buf
0393:                                .append(
0394:                                        "<tr><td><b>LocalPrincipal:</b></td><td align=left valign=top>")
0395:                                .append(sslInfo.getLocalPrincipal().getName())
0396:                                .append("</td></tr>");
0397:
0398:                    Certificate[] localCertificates = sslInfo
0399:                            .getLocalCertificates();
0400:
0401:                    if (localCertificates != null) {
0402:                        buf
0403:                                .append("</table><table cellpadding=0 cellspacing=0 border=0>");
0404:
0405:                        int cnt = 1;
0406:                        for (Certificate cert : localCertificates) {
0407:                            buf.append("<tr><td><b>Local Certificate ").append(
0408:                                    cnt++).append(":</b><pre><font size=-1>")
0409:                                    .append(cert.toString()).append(
0410:                                            "</font></pre></td></tr>");
0411:
0412:                        }
0413:
0414:                        buf
0415:                                .append("</table><table cellpadding=1 cellspacing=1 border=0>");
0416:                    }
0417:
0418:                    if (sslInfo.getPeerPrincipal() != null)
0419:                        buf
0420:                                .append(
0421:                                        "<tr><td><b>PeerPrincipal:</b></td><td align=left valign=top>")
0422:                                .append(sslInfo.getPeerPrincipal().toString())
0423:                                .append("</td></tr>");
0424:
0425:                    Certificate[] peerCertificates = sslInfo
0426:                            .getPeerCertificates();
0427:                    if (peerCertificates != null) {
0428:                        buf
0429:                                .append("</table><table cellpadding=0 cellspacing=0 border=0>");
0430:
0431:                        int cnt = 1;
0432:                        for (Certificate cert : peerCertificates) {
0433:                            buf
0434:                                    .append(
0435:                                            "<tr><td colspan=2><b>Peer Certificate ")
0436:                                    .append(cnt++).append(
0437:                                            ":</b><pre><font size=-1>").append(
0438:                                            cert.toString()).append(
0439:                                            "</font></pre></td></tr>");
0440:                        }
0441:
0442:                        buf
0443:                                .append("</table><table cellpadding=0 cellspacing=0 border=0>");
0444:                    }
0445:
0446:                    buf.append("</table></body></html>");
0447:                    sslInfoPane.setText(buf.toString());
0448:
0449:                    sslInfoTabTitle += " ("
0450:                            + sslInfo.getPeerCertificates().length + " certs)";
0451:                }
0452:
0453:                responseEditorTabs.setTitleAt(3, sslInfoTabTitle);
0454:            }
0455:
0456:            private Component createResponseHttpHeadersPanel() {
0457:                responseHeadersModel = new StringToStringMapTableModel(request
0458:                        .getResponse() == null ? new StringToStringMap()
0459:                        : request.getResponse().getResponseHeaders(), "Header",
0460:                        "Value", false);
0461:
0462:                responseHeadersModel
0463:                        .addTableModelListener(new TableModelListener() {
0464:                            public void tableChanged(TableModelEvent arg0) {
0465:                                responseEditorTabs.setTitleAt(2,
0466:                                        "HTTP Headers ("
0467:                                                + responseHeadersModel
0468:                                                        .getRowCount() + ")");
0469:                            }
0470:                        });
0471:
0472:                JTable responseHeadersTable = new JTable(responseHeadersModel);
0473:                return new JScrollPane(responseHeadersTable);
0474:            }
0475:
0476:            private Component createRequestHttpHeadersPanel() {
0477:                requestHeadersModel = new StringToStringMapTableModel(request
0478:                        .getRequestHeaders(), "Header", "Value", true);
0479:                requestHeadersModel
0480:                        .addTableModelListener(new TableModelListener() {
0481:                            public void tableChanged(TableModelEvent arg0) {
0482:                                getRequest().setRequestHeaders(
0483:                                        requestHeadersModel.getData());
0484:                                requestEditorTabs.setTitleAt(2,
0485:                                        "HTTP Headers ("
0486:                                                + requestHeadersModel
0487:                                                        .getRowCount() + ")");
0488:                            }
0489:                        });
0490:
0491:                requestHeadersTable = new JTable(requestHeadersModel);
0492:                JPanel panel = new JPanel(new BorderLayout());
0493:
0494:                panel.add(new JScrollPane(requestHeadersTable),
0495:                        BorderLayout.CENTER);
0496:
0497:                JXToolBar builder = UISupport.createToolbar();
0498:                builder.addFixed(new JButton(new AbstractAction("Add") {
0499:
0500:                    public void actionPerformed(ActionEvent arg0) {
0501:                        Object header = UISupport.prompt(
0502:                                "Specify name of header to add",
0503:                                "Add HTTP Header", "");
0504:                        if (header != null) {
0505:                            requestHeadersModel.add(header.toString(), "");
0506:                        }
0507:                    }
0508:                }));
0509:                builder.addRelatedGap();
0510:                builder.addFixed(new JButton(new AbstractAction("Remove") {
0511:
0512:                    public void actionPerformed(ActionEvent arg0) {
0513:                        int row = requestHeadersTable.getSelectedRow();
0514:                        if (row != -1
0515:                                && UISupport.confirm("Delete selected header?",
0516:                                        "Remove Header")) {
0517:                            requestHeadersModel.remove(row);
0518:                        }
0519:                    }
0520:                }));
0521:
0522:                //		builder.setBorder( BorderFactory.createEmptyBorder( 3, 3, 3, 3 ) );
0523:                builder.addGlue();
0524:                builder.addFixed(UISupport
0525:                        .createToolbarButton(new ShowOnlineHelpAction(
0526:                                HelpUrls.HEADERS_HELP_URL)));
0527:
0528:                panel.add(builder, BorderLayout.SOUTH);
0529:
0530:                return panel;
0531:            }
0532:
0533:            protected SoapMessageXmlEditor buildResponseEditor() {
0534:                return new WsdlResponseMessageEditor(new ResponseXmlDocument(
0535:                        request));
0536:            }
0537:
0538:            protected SoapMessageXmlEditor buildRequestEditor() {
0539:                return new WsdlRequestMessageEditor(new RequestXmlDocument(
0540:                        request));
0541:            }
0542:
0543:            protected JComponent buildToolbar() {
0544:                endpointCombo = new JComboBox(endpointsModel);
0545:                endpointCombo.setToolTipText(endpointsModel.getSelectedItem()
0546:                        .toString());
0547:
0548:                endpointCombo.addItemListener(new ItemListener() {
0549:                    public void itemStateChanged(ItemEvent e) {
0550:                        Object item = endpointCombo.getSelectedItem();
0551:                        if (item == null) {
0552:                            endpointCombo
0553:                                    .setToolTipText("- no endpoint set for request -");
0554:                        } else {
0555:                            String selectedItem = item.toString();
0556:                            endpointCombo.setToolTipText(selectedItem);
0557:                        }
0558:
0559:                        submitButton.setEnabled(submit == null
0560:                                && request.getEndpoint() != null
0561:                                && request.getEndpoint().trim().length() > 0);
0562:                    }
0563:                });
0564:
0565:                JXToolBar toolbar = UISupport.createToolbar();
0566:
0567:                toolbar.add(submitButton);
0568:                insertButtons(toolbar);
0569:
0570:                toolbar.add(addToMockServiceButton);
0571:                //		toolbar.add( addAsMockResponseStepButton);
0572:
0573:                toolbar.add(recreateButton);
0574:                toolbar.add(createEmptyButton);
0575:                toolbar.add(cloneButton);
0576:                toolbar.add(cancelButton);
0577:                toolbar.addSeparator();
0578:                toolbar.add(endpointCombo);
0579:
0580:                toolbar.add(Box.createHorizontalGlue());
0581:                toolbar.add(tabsButton);
0582:                toolbar.add(splitButton);
0583:                toolbar.add(UISupport
0584:                        .createToolbarButton(new ShowOnlineHelpAction(
0585:                                getHelpUrl())));
0586:
0587:                return toolbar;
0588:            }
0589:
0590:            protected String getHelpUrl() {
0591:                return HelpUrls.REQUESTEDITOR_HELP_URL;
0592:            }
0593:
0594:            protected void insertButtons(JToolBar toolbar) {
0595:            }
0596:
0597:            public void setEnabled(boolean enabled) {
0598:                endpointCombo.setEnabled(enabled);
0599:                requestEditor.setEditable(enabled);
0600:                responseEditor.setEditable(enabled);
0601:
0602:                submitButton.setEnabled(enabled
0603:                        && request.getEndpoint() != null
0604:                        && request.getEndpoint().trim().length() > 0);
0605:                recreateButton.setEnabled(enabled);
0606:                createEmptyButton.setEnabled(enabled);
0607:                cloneButton.setEnabled(enabled);
0608:
0609:                statusBar.setIndeterminate(!enabled);
0610:            }
0611:
0612:            private final class AttachmentPropertyChangeListener implements 
0613:                    PropertyChangeListener {
0614:                public void propertyChange(PropertyChangeEvent evt) {
0615:                    if (evt.getPropertyName().equals(
0616:                            WsdlRequest.ATTACHMENTS_PROPERTY)) {
0617:                        requestEditorTabs.setTitleAt(1, "Request Attachments ("
0618:                                + request.getAttachmentCount() + ")");
0619:                    } else if (evt.getPropertyName().equals(
0620:                            WsdlRequest.RESPONSE_PROPERTY)) {
0621:                        responseEditorTabs
0622:                                .setTitleAt(
0623:                                        1,
0624:                                        "Response Attachments ("
0625:                                                + (request.getResponse() == null ? 0
0626:                                                        : request
0627:                                                                .getResponse()
0628:                                                                .getAttachments().length)
0629:                                                + ")");
0630:                    } else if (evt.getPropertyName().equals(
0631:                            WsdlRequest.REQUEST_HEADERS_PROPERTY)) {
0632:                        requestHeadersModel.setData((StringToStringMap) evt
0633:                                .getNewValue());
0634:                    }
0635:                }
0636:            }
0637:
0638:            public class WsdlRequestMessageEditor extends
0639:                    RequestMessageXmlEditor<WsdlRequest> {
0640:                private InputAreaFocusListener inputAreaFocusListener;
0641:                private JXEditTextArea inputArea;
0642:
0643:                public WsdlRequestMessageEditor(XmlDocument document) {
0644:                    super (document, request);
0645:
0646:                    XmlSourceEditorView editor = getSourceEditor();
0647:                    inputArea = editor.getInputArea();
0648:                    inputArea.getInputHandler().addKeyBinding("A+ENTER",
0649:                            submitButton.getAction());
0650:                    inputArea.getInputHandler().addKeyBinding("A+X",
0651:                            cancelButton.getAction());
0652:                    inputArea.getInputHandler().addKeyBinding("AC+TAB",
0653:                            moveFocusAction);
0654:                    inputArea.getInputHandler().addKeyBinding("F5",
0655:                            recreateButton.getAction());
0656:                    inputArea.getInputHandler().addKeyBinding("C+F4",
0657:                            closePanelAction);
0658:
0659:                    inputAreaFocusListener = new InputAreaFocusListener();
0660:                    inputArea.addFocusListener(inputAreaFocusListener);
0661:                }
0662:
0663:                @Override
0664:                public void release() {
0665:                    super .release();
0666:                    inputArea.removeFocusListener(inputAreaFocusListener);
0667:                }
0668:            }
0669:
0670:            public class WsdlResponseMessageEditor extends
0671:                    ResponseMessageXmlEditor<WsdlRequest> {
0672:                private JXEditTextArea inputArea;
0673:                private ResultAreaFocusListener resultAreaFocusListener;
0674:
0675:                public WsdlResponseMessageEditor(XmlDocument document) {
0676:                    super (document, request);
0677:
0678:                    XmlSourceEditorView editor = getSourceEditor();
0679:
0680:                    inputArea = editor.getInputArea();
0681:                    resultAreaFocusListener = new ResultAreaFocusListener();
0682:                    inputArea.addFocusListener(resultAreaFocusListener);
0683:
0684:                    inputArea.getInputHandler().addKeyBinding("A+ENTER",
0685:                            submitButton.getAction());
0686:                    inputArea.getInputHandler().addKeyBinding("A+X",
0687:                            cancelButton.getAction());
0688:                    inputArea.getInputHandler().addKeyBinding("AC+TAB",
0689:                            moveFocusAction);
0690:                    inputArea.getInputHandler().addKeyBinding("C+F4",
0691:                            closePanelAction);
0692:
0693:                    JPopupMenu inputPopup = editor.getEditorPopup();
0694:                    inputPopup.insert(new JSeparator(), 2);
0695:                    inputPopup.insert(wsiValidateAction, 3);
0696:                }
0697:
0698:                @Override
0699:                public void release() {
0700:                    super .release();
0701:
0702:                    inputArea.removeFocusListener(resultAreaFocusListener);
0703:                }
0704:            }
0705:
0706:            protected final class InputAreaFocusListener implements 
0707:                    FocusListener {
0708:                public void focusGained(FocusEvent e) {
0709:                    responseHasFocus = false;
0710:
0711:                    statusBar.setTarget(requestEditor.getSourceEditor()
0712:                            .getInputArea());
0713:                    if (!splitButton.isEnabled()) {
0714:                        requestTabs.setSelectedIndex(0);
0715:                        return;
0716:                    }
0717:
0718:                    if (getModelItem().getSettings().getBoolean(
0719:                            UISettings.NO_RESIZE_REQUEST_EDITOR))
0720:                        return;
0721:
0722:                    // dont resize if split has been dragged
0723:                    if (((SoapUISplitPaneUI) requestSplitPane.getUI())
0724:                            .hasBeenDragged())
0725:                        return;
0726:
0727:                    int pos = requestSplitPane.getDividerLocation();
0728:                    if (pos >= 600)
0729:                        return;
0730:                    if (requestSplitPane.getMaximumDividerLocation() > 700)
0731:                        requestSplitPane.setDividerLocation(600);
0732:                    else
0733:                        requestSplitPane.setDividerLocation(0.8);
0734:                }
0735:
0736:                public void focusLost(FocusEvent e) {
0737:                }
0738:            }
0739:
0740:            protected final class ResultAreaFocusListener implements 
0741:                    FocusListener {
0742:                public void focusGained(FocusEvent e) {
0743:                    responseHasFocus = true;
0744:
0745:                    statusBar.setTarget(responseEditor.getSourceEditor()
0746:                            .getInputArea());
0747:                    if (!splitButton.isEnabled()) {
0748:                        requestTabs.setSelectedIndex(1);
0749:                        return;
0750:                    }
0751:
0752:                    if (request.getSettings().getBoolean(
0753:                            UISettings.NO_RESIZE_REQUEST_EDITOR))
0754:                        return;
0755:
0756:                    // dont resize if split has been dragged or result is empty
0757:                    if (((SoapUISplitPaneUI) requestSplitPane.getUI())
0758:                            .hasBeenDragged()
0759:                            || request.getResponse() == null)
0760:                        return;
0761:
0762:                    int pos = requestSplitPane.getDividerLocation();
0763:                    int maximumDividerLocation = requestSplitPane
0764:                            .getMaximumDividerLocation();
0765:                    if (pos + 600 < maximumDividerLocation)
0766:                        return;
0767:
0768:                    if (maximumDividerLocation > 700)
0769:                        requestSplitPane
0770:                                .setDividerLocation(maximumDividerLocation - 600);
0771:                    else
0772:                        requestSplitPane.setDividerLocation(0.2);
0773:                }
0774:
0775:                public void focusLost(FocusEvent e) {
0776:                }
0777:            }
0778:
0779:            public class SubmitAction extends AbstractAction {
0780:                public SubmitAction() {
0781:                    putValue(Action.SMALL_ICON, UISupport
0782:                            .createImageIcon("/submit_request.gif"));
0783:                    putValue(Action.SHORT_DESCRIPTION,
0784:                            "Submit request to specified endpoint URL");
0785:                    putValue(Action.ACCELERATOR_KEY, UISupport
0786:                            .getKeyStroke("alt ENTER"));
0787:                }
0788:
0789:                public void actionPerformed(ActionEvent e) {
0790:                    if (submit != null
0791:                            && submit.getStatus() == Submit.Status.RUNNING) {
0792:                        if (UISupport.confirm("Cancel current request?",
0793:                                "Submit Request")) {
0794:                            submit.cancel();
0795:                        } else
0796:                            return;
0797:                    }
0798:
0799:                    try {
0800:                        submit = doSubmit();
0801:                    } catch (SubmitException e1) {
0802:                        SoapUI.logError(e1);
0803:                    }
0804:                }
0805:            }
0806:
0807:            protected Submit doSubmit() throws SubmitException {
0808:                return request.submit(new WsdlSubmitContext(null), true);
0809:            }
0810:
0811:            private class CancelAction extends AbstractAction {
0812:                public CancelAction() {
0813:                    super ();
0814:                    putValue(Action.SMALL_ICON, UISupport
0815:                            .createImageIcon("/cancel_request.gif"));
0816:                    putValue(Action.SHORT_DESCRIPTION, "Aborts ongoing request");
0817:                    putValue(Action.ACCELERATOR_KEY, UISupport
0818:                            .getKeyStroke("alt X"));
0819:                }
0820:
0821:                public void actionPerformed(ActionEvent e) {
0822:                    if (submit == null)
0823:                        return;
0824:
0825:                    cancelButton.setEnabled(false);
0826:                    submit.cancel();
0827:                    setEnabled(true);
0828:                    submit = null;
0829:                }
0830:            }
0831:
0832:            private class ClosePanelAction extends AbstractAction {
0833:                public void actionPerformed(ActionEvent e) {
0834:                    SoapUI.getDesktop().closeDesktopPanel(getModelItem());
0835:                }
0836:            }
0837:
0838:            private class MoveFocusAction extends AbstractAction {
0839:                public void actionPerformed(ActionEvent e) {
0840:                    if (requestEditor.hasFocus()) {
0841:                        responseEditor.requestFocus();
0842:                    } else {
0843:                        requestEditor.requestFocus();
0844:                    }
0845:                }
0846:            }
0847:
0848:            protected class InternalSubmitListener implements  SubmitListener {
0849:                protected InternalSubmitListener() {
0850:                }
0851:
0852:                public boolean beforeSubmit(Submit submit, SubmitContext context) {
0853:                    if (submit.getRequest() != request)
0854:                        return true;
0855:
0856:                    if (getModelItem().getSettings().getBoolean(
0857:                            UISettings.AUTO_VALIDATE_REQUEST)) {
0858:                        boolean result = requestEditor.saveDocument(true);
0859:                        if (!result
0860:                                && getModelItem().getSettings().getBoolean(
0861:                                        UISettings.ABORT_ON_INVALID_REQUEST)) {
0862:                            statusBar
0863:                                    .setInfo("Cancelled request due to invalid content");
0864:                            return false;
0865:                        }
0866:                    } else
0867:                        requestEditor.saveDocument(false);
0868:
0869:                    setEnabled(false);
0870:                    cancelButton
0871:                            .setEnabled(AbstractWsdlRequestDesktopPanel.this .submit != null);
0872:                    wsiValidateAction.setEnabled(false);
0873:                    return true;
0874:                }
0875:
0876:                public void afterSubmit(Submit submit, SubmitContext context) {
0877:                    if (submit.getRequest() != request)
0878:                        return;
0879:
0880:                    Status status = submit.getStatus();
0881:                    WsdlResponse response = (WsdlResponse) submit.getResponse();
0882:                    if (status != Status.CANCELED) {
0883:                        request.setResponse(response, context);
0884:                    }
0885:
0886:                    cancelButton.setEnabled(false);
0887:                    wsiValidateAction.setEnabled(request.getResponse() != null);
0888:                    setEnabled(true);
0889:
0890:                    String message = null;
0891:                    String infoMessage = null;
0892:                    String requestName = request.getOperation().getInterface()
0893:                            .getName()
0894:                            + "."
0895:                            + request.getOperation().getName()
0896:                            + ":"
0897:                            + request.getName();
0898:
0899:                    if (status == Status.CANCELED) {
0900:                        message = "CANCELED";
0901:                        infoMessage = "[" + requestName + "] - CANCELED";
0902:                    } else {
0903:                        if (status == Status.ERROR || response == null) {
0904:                            message = "Error getting response; "
0905:                                    + submit.getError();
0906:                            infoMessage = "Error getting response for ["
0907:                                    + requestName + "]; " + submit.getError();
0908:                        } else {
0909:                            message = "response time: "
0910:                                    + response.getTimeTaken() + "ms ("
0911:                                    + response.getContentLength() + " bytes)";
0912:                            infoMessage = "Got response for [" + requestName
0913:                                    + "] in " + response.getTimeTaken()
0914:                                    + "ms (" + response.getContentLength()
0915:                                    + " bytes)";
0916:
0917:                            if (!splitButton.isEnabled())
0918:                                requestTabs.setSelectedIndex(1);
0919:
0920:                            responseEditor.requestFocus();
0921:                        }
0922:
0923:                        responseHeadersModel
0924:                                .setData(submit.getResponse() == null ? null
0925:                                        : submit.getResponse()
0926:                                                .getResponseHeaders());
0927:
0928:                        updateSSLInfo(response == null ? null : response
0929:                                .getSSLInfo());
0930:                        wsiValidateAction.setEnabled(true);
0931:                    }
0932:
0933:                    logMessages(message, infoMessage);
0934:
0935:                    if (getModelItem().getSettings().getBoolean(
0936:                            UISettings.AUTO_VALIDATE_RESPONSE))
0937:                        responseEditor.getSourceEditor().validate();
0938:
0939:                    AbstractWsdlRequestDesktopPanel.this .submit = null;
0940:                }
0941:
0942:                protected void logMessages(String message, String infoMessage) {
0943:                    log.info(infoMessage);
0944:                    statusBar.setInfo(message);
0945:                }
0946:            }
0947:
0948:            public boolean onClose(boolean canCancel) {
0949:                if (canCancel) {
0950:                    if (submit != null
0951:                            && submit.getStatus() == Submit.Status.RUNNING) {
0952:                        Boolean retVal = UISupport.confirmOrCancel(
0953:                                "Cancel request before closing?",
0954:                                "Closing window");
0955:                        if (retVal == null)
0956:                            return false;
0957:
0958:                        if (retVal.booleanValue()
0959:                                && submit.getStatus() == Submit.Status.RUNNING)
0960:                            submit.cancel();
0961:                    }
0962:                } else if (submit != null
0963:                        && submit.getStatus() == Submit.Status.RUNNING) {
0964:                    submit.cancel();
0965:                }
0966:
0967:                request.removeSubmitListener(internalSubmitListener);
0968:                request
0969:                        .removePropertyChangeListener(attachmentsPropertyChangeListener);
0970:                endpointsModel.release();
0971:
0972:                requestEditor.saveDocument(false);
0973:                requestEditor.release();
0974:                responseEditor.release();
0975:
0976:                requestAttachmentPanel.release();
0977:                responseAttachmentPanel.release();
0978:
0979:                responseEditor.getParent().remove(responseEditor);
0980:                responseEditorTabs.removeAll();
0981:                requestEditor.getParent().remove(requestEditor);
0982:                requestEditorTabs.removeAll();
0983:                requestSplitPane.removeAll();
0984:                sslInfoPane.getParent().remove(sslInfoPane);
0985:
0986:                return super .release();
0987:            }
0988:
0989:            public boolean dependsOn(ModelItem modelItem) {
0990:                return modelItem == request
0991:                        || modelItem == request.getOperation()
0992:                        || modelItem == request.getOperation().getInterface()
0993:                        || modelItem == request.getOperation().getInterface()
0994:                                .getProject();
0995:            }
0996:
0997:            public String getDescription() {
0998:                return "Request: [" + request.getName() + "] - "
0999:                        + request.getOperation().getInterface().getName() + "#"
1000:                        + request.getOperation().getName();
1001:            }
1002:
1003:            private final class ChangeToTabsAction extends AbstractAction {
1004:                public ChangeToTabsAction() {
1005:                    putValue(Action.SMALL_ICON, UISupport
1006:                            .createImageIcon("/toggle_tabs.gif"));
1007:                    putValue(Action.SHORT_DESCRIPTION,
1008:                            "Toggles to tab-based layout");
1009:                }
1010:
1011:                public void actionPerformed(ActionEvent e) {
1012:                    if (splitButton.isEnabled()) {
1013:                        splitButton.setEnabled(false);
1014:                        removeContent(requestSplitPane);
1015:                        setContent(requestTabPanel);
1016:                        requestTabs.addTab("Request", requestEditorTabPanel);
1017:                        requestTabs.addTab("Response", responseEditorTabPanel);
1018:
1019:                        if (responseHasFocus) {
1020:                            requestTabs.setSelectedIndex(1);
1021:                            requestEditorTabs.requestFocus();
1022:                        } else {
1023:                            responseEditorTabs.requestFocus();
1024:                        }
1025:                    } else {
1026:                        int selectedIndex = requestTabs.getSelectedIndex();
1027:
1028:                        splitButton.setEnabled(true);
1029:                        removeContent(requestTabPanel);
1030:                        setContent(requestSplitPane);
1031:                        requestSplitPane.setTopComponent(requestEditorTabPanel);
1032:                        requestSplitPane
1033:                                .setBottomComponent(responseEditorTabPanel);
1034:                        requestSplitPane.setDividerLocation(0.5);
1035:
1036:                        if (selectedIndex == 0)
1037:                            requestEditor.requestFocus();
1038:                        else
1039:                            responseEditor.requestFocus();
1040:                    }
1041:
1042:                    revalidate();
1043:                }
1044:            }
1045:
1046:            public void setContent(JComponent content) {
1047:                add(content, BorderLayout.CENTER);
1048:            }
1049:
1050:            public void removeContent(JComponent content) {
1051:                remove(content);
1052:            }
1053:        }
w__ww___.__j___a__va_2s.co__m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.