PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/scanhttpinfo/sectools/src/org/bresearch/websec/net/win/ConnectFrame.java

http://websecuritynotebook.googlecode.com/
Java | 132 lines | 58 code | 22 blank | 52 comment | 0 complexity | 817ff956c2bcca7b8bada9518ca22c8b MD5 | raw file
Possible License(s): Apache-2.0
  1. /**
  2. *
  3. * Copyright (c) 2006-2007 Berlin Brown and botnode.com/Berlin Research All Rights Reserved
  4. *
  5. * http://www.opensource.org/licenses/bsd-license.php
  6. * All rights reserved.
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright notice,
  10. * this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. * * Neither the name of the Botnode.com (Berlin Brown) nor
  15. * the names of its contributors may be used to endorse or promote
  16. * products derived from this software without specific prior written permission.
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  21. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  25. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  26. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * Date: 12/15/2009
  30. *
  31. * Home Page: http://botnode.com/
  32. *
  33. * Contact: Berlin Brown <berlin dot brown at gmail.com>
  34. */
  35. package org.bresearch.websec.net.win;
  36. import java.awt.event.ActionEvent;
  37. import java.awt.event.ActionListener;
  38. import javax.swing.BoxLayout;
  39. import javax.swing.JButton;
  40. import javax.swing.JFrame;
  41. import javax.swing.JScrollPane;
  42. import javax.swing.JTextArea;
  43. import javax.swing.JTextField;
  44. import org.bresearch.websec.net.ConnectSettingsBean;
  45. import org.bresearch.websec.net.HttpConnect;
  46. import org.bresearch.websec.net.IHttpConnect;
  47. public class ConnectFrame extends JFrame {
  48. /**
  49. *
  50. */
  51. private static final long serialVersionUID = 535710310815697611L;
  52. private JTextField urlField;
  53. private JTextArea responseArea;
  54. private JButton actionButton;
  55. public ConnectFrame(final JTextField url, final JTextArea response, final JButton actionButton) {
  56. this.urlField = url;
  57. this.responseArea = response;
  58. this.actionButton = actionButton;
  59. }
  60. public void loadFrame() {
  61. final BoxLayout layout = new BoxLayout(getContentPane(), BoxLayout.Y_AXIS);
  62. this.getContentPane().setLayout(layout);
  63. this.add(this.urlField);
  64. // Build a scrollable pane around the text area //
  65. final JScrollPane jScrollPane = new JScrollPane(this.responseArea);
  66. this.add(jScrollPane);
  67. this.add(this.actionButton);
  68. // Add the button handler //
  69. this.actionButton.addActionListener(
  70. new ActionListener() {
  71. public void actionPerformed(final ActionEvent event) {
  72. ConnectFrame.this.handleConnect();
  73. }
  74. } // End of Listener //
  75. );
  76. }
  77. public void handleConnect() {
  78. System.out.println("Executing Connect");
  79. final ConnectSettingsBean settings = new ConnectSettingsBean(this.urlField.getText());
  80. final IHttpConnect connection = new HttpConnect(settings, null);
  81. connection.connect(connection.buildURL());
  82. final StringBuilder buf = new StringBuilder(100);
  83. buf.append(connection.getLastResult().buildHeaderResponse());
  84. buf.append("-------------------\n");
  85. buf.append(connection.getLastResult().getHtmlData());
  86. this.responseArea.setText(buf.toString());
  87. }
  88. /**
  89. * @return the urlField
  90. */
  91. public JTextField getUrlField() {
  92. return urlField;
  93. }
  94. /**
  95. * @return the responseArea
  96. */
  97. public JTextArea getResponseArea() {
  98. return responseArea;
  99. }
  100. /**
  101. * @return the actionButton
  102. */
  103. public JButton getActionButton() {
  104. return actionButton;
  105. }
  106. } // End of the Class //