commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oglu...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/examples ClientApp.java CookieDemoApp.java CustomHttpConnection.java MultipartFileUploadApp.java PostXML.java TrivialApp.java
Date Thu, 13 Feb 2003 09:14:43 GMT
oglueck     2003/02/13 01:14:43

  Modified:    httpclient/src/examples ClientApp.java CookieDemoApp.java
                        CustomHttpConnection.java
                        MultipartFileUploadApp.java PostXML.java
                        TrivialApp.java
  Log:
  fixed tabbing (no tabs)
  
  Revision  Changes    Path
  1.10      +119 -119  jakarta-commons/httpclient/src/examples/ClientApp.java
  
  Index: ClientApp.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/examples/ClientApp.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ClientApp.java	23 Jan 2003 22:47:42 -0000	1.9
  +++ ClientApp.java	13 Feb 2003 09:14:43 -0000	1.10
  @@ -72,88 +72,88 @@
   import javax.swing.text.html.*;
   
   /**
  - * 
  + *
    * This is a Swing application that demonstrates
    * how to use the Jakarta HttpClient API.
  - * 
  + *
    * @author Sean C. Sullivan
    * @author Ortwin Glück
    */
   public class ClientApp {
   
       public static void main(String[] args) {
  -		HttpClientMainFrame f = new HttpClientMainFrame();
  -		f.setTitle("HttpClient demo application");
  -		f.setSize(700, 500);
  -		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  -		f.setVisible(true);
  -	}
  +        HttpClientMainFrame f = new HttpClientMainFrame();
  +        f.setTitle("HttpClient demo application");
  +        f.setSize(700, 500);
  +        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  +        f.setVisible(true);
  +    }
   
       public static class HttpClientMainFrame extends javax.swing.JFrame {
  -		private HttpClientPanel m_panel;
  +        private HttpClientPanel m_panel;
   
           public HttpClientMainFrame() {
  -			m_panel = new HttpClientPanel();
  -			this.getContentPane().add(m_panel);
  -		}
  -	}
  +            m_panel = new HttpClientPanel();
  +            this.getContentPane().add(m_panel);
  +        }
  +    }
   
       public static class HttpClientPanel extends JPanel {
  -		private static final String strTenSpaces = "          ";
  -		private static final String strFortySpaces =
  -			strTenSpaces + strTenSpaces + strTenSpaces + strTenSpaces;
  -		private static final String strEightySpaces =
  -			strFortySpaces + strFortySpaces;
  +        private static final String strTenSpaces = "          ";
  +        private static final String strFortySpaces =
  +            strTenSpaces + strTenSpaces + strTenSpaces + strTenSpaces;
  +        private static final String strEightySpaces =
  +            strFortySpaces + strFortySpaces;
   
           public HttpClientPanel() {
  -			final JPanel panInput = new JPanel();
  -			panInput.setLayout(new FlowLayout());
  +            final JPanel panInput = new JPanel();
  +            panInput.setLayout(new FlowLayout());
   
  -			final JPanel panDisplay = new JPanel();
  -			panDisplay.setLayout(new BorderLayout());
  +            final JPanel panDisplay = new JPanel();
  +            panDisplay.setLayout(new BorderLayout());
   
               String[] aURLs = {
  -					"http://www.apache.org/",
  -					"http://www.google.com/",
  -					"http://www.opensource.org/",
  -					"http://www.anybrowser.org/",
  -					"http://jakarta.apache.org/",
  +                    "http://www.apache.org/",
  +                    "http://www.google.com/",
  +                    "http://www.opensource.org/",
  +                    "http://www.anybrowser.org/",
  +                    "http://jakarta.apache.org/",
                       "http://www.w3.org/"
               };
   
  -			final JComboBox cmbURL = new JComboBox(aURLs);
  -			cmbURL.setToolTipText("Enter a URL");
  -			cmbURL.setPrototypeDisplayValue(strEightySpaces);
  -			cmbURL.setEditable(true);
  -			cmbURL.setSelectedIndex(0);
  -
  -			final JTextArea taTextResponse = new JTextArea();
  -			taTextResponse.setEditable(false);
  -			taTextResponse.setCaretPosition(0);
  +            final JComboBox cmbURL = new JComboBox(aURLs);
  +            cmbURL.setToolTipText("Enter a URL");
  +            cmbURL.setPrototypeDisplayValue(strEightySpaces);
  +            cmbURL.setEditable(true);
  +            cmbURL.setSelectedIndex(0);
  +
  +            final JTextArea taTextResponse = new JTextArea();
  +            taTextResponse.setEditable(false);
  +            taTextResponse.setCaretPosition(0);
   
  -			final JLabel lblURL = new JLabel("URL:");
  +            final JLabel lblURL = new JLabel("URL:");
   
  -			final JButton btnGET = new JButton("GET");
  +            final JButton btnGET = new JButton("GET");
   
               cmbURL.addActionListener(new ActionListener() {
  -				public void actionPerformed(ActionEvent ae)
  -				{
  -					btnGET.doClick();
  -				}
  -			});
  +                public void actionPerformed(ActionEvent ae)
  +                {
  +                    btnGET.doClick();
  +                }
  +            });
   
               btnGET.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent ae) {
  -					final String strRawURL = (String) cmbURL.getSelectedItem();
  +                    final String strRawURL = (String) cmbURL.getSelectedItem();
                       if (strRawURL.length() > 0) {
  -						final URL u;
  +                        final URL u;
                           try {
  -							u = new URL(strRawURL.trim());
  +                            u = new URL(strRawURL.trim());
                               Thread t = new Thread() {
                                   public void run() {
                                       HttpClient client = new HttpClient(new MultiThreadedHttpConnectionManager());
  -									GetMethod get = new GetMethod();
  -									HeadMethod head = new HeadMethod();
  +                                    GetMethod get = new GetMethod();
  +                                    HeadMethod head = new HeadMethod();
                                       HostConfiguration hc = new HostConfiguration();
                                       try {
                                           hc.setHost(new URI(u));
  @@ -162,89 +162,89 @@
                                       }
                                       client.setHostConfiguration(hc);
                                       client.setConnectionTimeout(30000);
  -									int iGetResultCode;
  -									int iHeadResultCode;
  +                                    int iGetResultCode;
  +                                    int iHeadResultCode;
                                       try {
                                           //to execute two methods in a row without reading
the first method's response
                                           //we *need* the MultiThreadedHttpConnectionManager
as set in the HttpClient's
                                           //constructor.
  -										iGetResultCode = client.executeMethod(get);
  -										iHeadResultCode = client.executeMethod(head);
  -										
  -										final String strGetResponseBody =
  -											get.getResponseBodyAsString();
  +                                        iGetResultCode = client.executeMethod(get);
  +                                        iHeadResultCode = client.executeMethod(head);
  +
  +                                        final String strGetResponseBody =
  +                                            get.getResponseBodyAsString();
                                           get.releaseConnection();
  -											
  -										final String strHeadResponseBody =
  -											head.getResponseBodyAsString();
  +
  +                                        final String strHeadResponseBody =
  +                                            head.getResponseBodyAsString();
                                           head.releaseConnection();
  -											
  +
                                           if (strGetResponseBody != null) {
                                               Runnable r = new Runnable() {
                                                   public void run() {
  -													panDisplay.removeAll();
  -		
  -													taTextResponse.setText(
  -														strGetResponseBody);
  -													taTextResponse.setCaretPosition(0);
  -													taTextResponse.requestFocus();
  -		
  -														JEditorPane htmlPane =
  +                                                    panDisplay.removeAll();
  +
  +                                                    taTextResponse.setText(
  +                                                        strGetResponseBody);
  +                                                    taTextResponse.setCaretPosition(0);
  +                                                    taTextResponse.requestFocus();
  +
  +                                                        JEditorPane htmlPane =
                                                           new JEditorPane("text/html",
                                                               strGetResponseBody);
  -														htmlPane.setEditable(false);
  -			
  -														final JSplitPane splitResponsePane =
  -															new JSplitPane(
  -																JSplitPane.HORIZONTAL_SPLIT,
  -																new JScrollPane(taTextResponse),
  -																new JScrollPane(htmlPane));
  -														splitResponsePane
  -															.setOneTouchExpandable(
  -															false);
  -														panDisplay.add(
  -															splitResponsePane,
  -															BorderLayout.CENTER);
  -			
  -														splitResponsePane
  -															.setDividerLocation(
  -															panDisplay.getWidth() / 2);
  -			
  -														panDisplay.validate();
  -													}
  -											};
  +                                                        htmlPane.setEditable(false);
  +
  +                                                        final JSplitPane splitResponsePane
=
  +                                                            new JSplitPane(
  +                                                                JSplitPane.HORIZONTAL_SPLIT,
  +                                                                new JScrollPane(taTextResponse),
  +                                                                new JScrollPane(htmlPane));
  +                                                        splitResponsePane
  +                                                            .setOneTouchExpandable(
  +                                                            false);
  +                                                        panDisplay.add(
  +                                                            splitResponsePane,
  +                                                            BorderLayout.CENTER);
  +
  +                                                        splitResponsePane
  +                                                            .setDividerLocation(
  +                                                            panDisplay.getWidth() / 2);
  +
  +                                                        panDisplay.validate();
  +                                                    }
  +                                            };
                                               try {
  -												SwingUtilities.invokeAndWait(r);
  +                                                SwingUtilities.invokeAndWait(r);
                                               } catch (InvocationTargetException ex) {
  -												ex.printStackTrace();
  +                                                ex.printStackTrace();
                                               } catch (InterruptedException ex) {
  -												ex.printStackTrace();
  -											}
  -										}
  -									}
  +                                                ex.printStackTrace();
  +                                            }
  +                                        }
  +                                    }
                                       catch (HttpException ex) {
  -										ex.printStackTrace();
  +                                        ex.printStackTrace();
                                       } catch (IOException ex) {
  -										ex.printStackTrace();
  -									}
  -								}
  -							};
  -							t.start();
  +                                        ex.printStackTrace();
  +                                    }
  +                                }
  +                            };
  +                            t.start();
                           } catch (MalformedURLException ignored) {
  -							// ignore
  -						}
  -					}
  -				}
  -			});
  -
  -			panInput.add(lblURL);
  -			panInput.add(cmbURL);
  -			panInput.add(btnGET);
  -
  -			this.setLayout(new BorderLayout());
  -
  -			this.add(panInput, BorderLayout.NORTH);
  -			this.add(panDisplay, BorderLayout.CENTER);
  -		}
  -	}
  +                            // ignore
  +                        }
  +                    }
  +                }
  +            });
  +
  +            panInput.add(lblURL);
  +            panInput.add(cmbURL);
  +            panInput.add(btnGET);
  +
  +            this.setLayout(new BorderLayout());
  +
  +            this.add(panInput, BorderLayout.NORTH);
  +            this.add(panDisplay, BorderLayout.CENTER);
  +        }
  +    }
   }
  
  
  
  1.7       +38 -38    jakarta-commons/httpclient/src/examples/CookieDemoApp.java
  
  Index: CookieDemoApp.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/examples/CookieDemoApp.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- CookieDemoApp.java	23 Jan 2003 22:47:42 -0000	1.6
  +++ CookieDemoApp.java	13 Feb 2003 09:14:43 -0000	1.7
  @@ -66,72 +66,72 @@
   import java.net.URL;
   
   /**
  - * 
  + *
    * This is a sample application that demonstrates
  - * how to use the Jakarta HttpClient API. 
  - * 
  - * This application sets an HTTP cookie and 
  + * how to use the Jakarta HttpClient API.
  + *
  + * This application sets an HTTP cookie and
    * updates the cookie's value across multiple
    * HTTP GET requests.
  - * 
  + *
    * @author Sean C. Sullivan
    *
    */
   public class CookieDemoApp {
  -	private static final String COOKIE_NAME = "count";
  +    private static final String COOKIE_NAME = "count";
   
       /**
  -     *  
  +     *
        * Usage:
        *          java CookieDemoApp http://mywebserver:80/
  -     * 
  +     *
        *  @param args command line arguments
        *                 Argument 0 is a URL to a web server
  -     *                
  -     * 
  +     *
  +     *
        */
       public static void main(String[] args) throws Exception {
           if (args.length != 1) {
               System.err.println("Usage: java CookieDemoApp <url>");
               System.err.println("<url> The url of a webpage");
  -			System.exit(1);
  -		}
  -		
  -		String strURL = args[0];
  -		
  -		URL u = new URL(strURL);
  -		
  -		HttpState initialState = new HttpState();
  -
  -		Cookie ck = new Cookie(".foobar.com",
  -				COOKIE_NAME,
  -				"0");
  +            System.exit(1);
  +        }
  +
  +        String strURL = args[0];
   
  -		initialState.addCookie(ck);
  +        URL u = new URL(strURL);
  +
  +        HttpState initialState = new HttpState();
  +
  +        Cookie ck = new Cookie(".foobar.com",
  +                COOKIE_NAME,
  +                "0");
  +
  +        initialState.addCookie(ck);
   
           HttpClient client = new HttpClient();
           HostConfiguration hc = new HostConfiguration();
           hc.setHost(new URI(u));
           client.setHostConfiguration(hc);
  -		
  +
           client.setConnectionTimeout(30000);
           client.setState(initialState);
   
           for (int i = 0; i < 10; i++) {
  -			GetMethod get = new GetMethod("/");
  +            GetMethod get = new GetMethod("/");
               int iResultCode = client.executeMethod(get);
               HttpState state = client.getState();
  -			Cookie[] cookies = state.getCookies();
  +            Cookie[] cookies = state.getCookies();
               for (int k = 0; k < cookies.length; k++) {
  -				Cookie currentCookie = cookies[k];
  +                Cookie currentCookie = cookies[k];
                   if (currentCookie.getName().equals(COOKIE_NAME)) {
  -					Integer iCount = new Integer(currentCookie.getValue());
  -					System.out.println("count value is : " + iCount);
  -					int iNewCount = iCount.intValue() + 1;
  -					currentCookie.setValue("" + iNewCount);
  -				}
  -			}
  +                    Integer iCount = new Integer(currentCookie.getValue());
  +                    System.out.println("count value is : " + iCount);
  +                    int iNewCount = iCount.intValue() + 1;
  +                    currentCookie.setValue("" + iNewCount);
  +                }
  +            }
               get.releaseConnection();
  -		}
  -	}
  +        }
  +    }
   }
  
  
  
  1.2       +30 -27    jakarta-commons/httpclient/src/examples/CustomHttpConnection.java
  
  Index: CustomHttpConnection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/examples/CustomHttpConnection.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CustomHttpConnection.java	25 Jan 2003 19:24:40 -0000	1.1
  +++ CustomHttpConnection.java	13 Feb 2003 09:14:43 -0000	1.2
  @@ -1,4 +1,7 @@
   /*
  + * $Header$
  + * $Revision$
  + * $Date$
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
  @@ -63,40 +66,40 @@
   import org.apache.commons.httpclient.HttpMethod;
   import org.apache.commons.httpclient.URI;
   import org.apache.commons.httpclient.UsernamePasswordCredentials;
  -import org.apache.commons.httpclient.protocol.Protocol; 
  +import org.apache.commons.httpclient.protocol.Protocol;
   import org.apache.commons.httpclient.methods.GetMethod;
   import org.apache.commons.httpclient.ConnectMethod;
   
   /**
  - * This example demonstrates how to establishing connection to an HTTP server 
  + * This example demonstrates how to establishing connection to an HTTP server
    * when higher level of control is desired
  - * 
  + *
    * @author Armando Anton
    * @author Oleg Kalnichevski
    */
   
   public class CustomHttpConnection
   {
  -	public static void main(String[] args) throws Exception
  -	{
  +    public static void main(String[] args) throws Exception
  +    {
           if (args.length != 1)
           {
               System.err.println("Usage: java CustomHttpConnection <url>");
               System.err.println("<url> The url of a webpage");
  -			System.exit(1);
  -		}
  -		
  +            System.exit(1);
  +        }
  +
           URI uri = new URI(args[0].toCharArray()); // i like this constructor :)
   
  -		String schema = uri.getScheme();
  -		if ((schema == null) || (schema.equals("")))
  -		{
  -			schema = "http";
  -		}
  -		Protocol protocol = Protocol.getProtocol(schema);
  +        String schema = uri.getScheme();
  +        if ((schema == null) || (schema.equals("")))
  +        {
  +            schema = "http";
  +        }
  +        Protocol protocol = Protocol.getProtocol(schema);
   
           HttpState state = new HttpState();
  -		
  +
           HttpMethod method = new GetMethod(uri.toString());
           String host = uri.getHost();
           int port = uri.getPort();
  @@ -105,13 +108,13 @@
   
           connection.setProxyHost(System.getProperty("http.proxyHost"));
           connection.setProxyPort( Integer.parseInt(System.getProperty("http.proxyPort","80")));
  -        
  +
           if (System.getProperty("http.proxyUserName") != null)
           {
  -        	state.setProxyCredentials(null, 
  -        	  new UsernamePasswordCredentials(
  -        	    System.getProperty("http.proxyUserName"),
  -        	    System.getProperty("http.proxyPassword")));
  +            state.setProxyCredentials(null,
  +              new UsernamePasswordCredentials(
  +                System.getProperty("http.proxyUserName"),
  +                System.getProperty("http.proxyPassword")));
           }
   
           if (connection.isProxied() && connection.isSecure()) {
  @@ -119,11 +122,11 @@
           }
           method.execute(state, connection);
   
  -	    if (method.getStatusCode() == HttpStatus.SC_OK) {
  -	        System.out.println(method.getResponseBodyAsString());
  -	    } else {
  -	    	System.out.println("Unexpected failure: " + method.getStatusLine().toString());
  -	    }
  -	    method.releaseConnection();
  -	}
  +        if (method.getStatusCode() == HttpStatus.SC_OK) {
  +            System.out.println(method.getResponseBodyAsString());
  +        } else {
  +            System.out.println("Unexpected failure: " + method.getStatusLine().toString());
  +        }
  +        method.releaseConnection();
  +    }
   }
  
  
  
  1.4       +101 -101  jakarta-commons/httpclient/src/examples/MultipartFileUploadApp.java
  
  Index: MultipartFileUploadApp.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/examples/MultipartFileUploadApp.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MultipartFileUploadApp.java	23 Jan 2003 22:47:42 -0000	1.3
  +++ MultipartFileUploadApp.java	13 Feb 2003 09:14:43 -0000	1.4
  @@ -72,147 +72,147 @@
   import javax.swing.text.html.*;
   
   /**
  - * 
  + *
    * This is a Swing application that demonstrates
    * how to use the Jakarta HttpClient multipart POST method
    * for uploading files
  - * 
  + *
    * @author Sean C. Sullivan
    *
    */
   public class MultipartFileUploadApp {
   
       public static void main(String[] args) {
  -		MultipartFileUploadMainFrame f = new MultipartFileUploadMainFrame();
  -		f.setTitle("HTTP multipart file upload application");
  -		f.setSize(700, 500);
  -		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  -		f.setVisible(true);
  -	}
  +        MultipartFileUploadMainFrame f = new MultipartFileUploadMainFrame();
  +        f.setTitle("HTTP multipart file upload application");
  +        f.setSize(700, 500);
  +        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  +        f.setVisible(true);
  +    }
   
       public static class MultipartFileUploadMainFrame extends javax.swing.JFrame {
  -		private MultipartFileUploadPanel m_panel;
  +        private MultipartFileUploadPanel m_panel;
   
           public MultipartFileUploadMainFrame() {
  -			m_panel = new MultipartFileUploadPanel();
  -			this.getContentPane().add(m_panel);
  -		}
  -	}
  +            m_panel = new MultipartFileUploadPanel();
  +            this.getContentPane().add(m_panel);
  +        }
  +    }
   
       public static class MultipartFileUploadPanel extends JPanel {
  -		private static final String strTenSpaces = "          ";
  -		private static final String strFortySpaces =
  -			strTenSpaces + strTenSpaces + strTenSpaces + strTenSpaces;
  -		private static final String strEightySpaces =
  -			strFortySpaces + strFortySpaces;
  +        private static final String strTenSpaces = "          ";
  +        private static final String strFortySpaces =
  +            strTenSpaces + strTenSpaces + strTenSpaces + strTenSpaces;
  +        private static final String strEightySpaces =
  +            strFortySpaces + strFortySpaces;
  +
  +        private File targetFile = null;
   
  -		private File targetFile = null;
  -		
           public MultipartFileUploadPanel() {
  -			final JPanel panInput = new JPanel();
  -			
  +            final JPanel panInput = new JPanel();
  +
               String[] aURLs = {
  -					"http://localhost:8080/foo/bar"
  -				};
  +                    "http://localhost:8080/foo/bar"
  +                };
   
  -			final JComboBox cmbURL = new JComboBox(aURLs);
  -			cmbURL.setToolTipText("Enter a URL");
  -			cmbURL.setPrototypeDisplayValue(strEightySpaces);
  -			cmbURL.setEditable(true);
  -			cmbURL.setSelectedIndex(0);
  +            final JComboBox cmbURL = new JComboBox(aURLs);
  +            cmbURL.setToolTipText("Enter a URL");
  +            cmbURL.setPrototypeDisplayValue(strEightySpaces);
  +            cmbURL.setEditable(true);
  +            cmbURL.setSelectedIndex(0);
   
  -			final JLabel lblTargetFile = new JLabel();
  -			lblTargetFile.setText("");
  +            final JLabel lblTargetFile = new JLabel();
  +            lblTargetFile.setText("");
   
  -			final JButton btnDoUpload = new JButton("Upload");
  -			btnDoUpload.setEnabled(false);
  +            final JButton btnDoUpload = new JButton("Upload");
  +            btnDoUpload.setEnabled(false);
   
  -			final JButton btnSelectFile = new JButton("Select a file...");
  +            final JButton btnSelectFile = new JButton("Select a file...");
               btnSelectFile.addActionListener(new ActionListener() {
                       public void actionPerformed(final ActionEvent evt) {
  -						final JFileChooser chooser = new JFileChooser();
  -						chooser.setFileHidingEnabled(false);
  -						chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
  -						chooser.setMultiSelectionEnabled(false);
  -						chooser.setDialogType(JFileChooser.OPEN_DIALOG);
  -						chooser.setDialogTitle("Choose a file...");
  +                        final JFileChooser chooser = new JFileChooser();
  +                        chooser.setFileHidingEnabled(false);
  +                        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
  +                        chooser.setMultiSelectionEnabled(false);
  +                        chooser.setDialogType(JFileChooser.OPEN_DIALOG);
  +                        chooser.setDialogTitle("Choose a file...");
                           if (chooser.showOpenDialog(MultipartFileUploadPanel.this) == JFileChooser.APPROVE_OPTION)
{
  -							targetFile = chooser.getSelectedFile();
  -							lblTargetFile.setText("Selected file:  " + targetFile.toString());
  -							btnDoUpload.setEnabled(true);
  -						}
  -					}
  -				});
  -			
  -			final JTextArea taTextResponse = new JTextArea();
  -			taTextResponse.setEditable(false);
  -			taTextResponse.setCaretPosition(0);
  +                            targetFile = chooser.getSelectedFile();
  +                            lblTargetFile.setText("Selected file:  " + targetFile.toString());
  +                            btnDoUpload.setEnabled(true);
  +                        }
  +                    }
  +                });
  +
  +            final JTextArea taTextResponse = new JTextArea();
  +            taTextResponse.setEditable(false);
  +            taTextResponse.setCaretPosition(0);
   
  -			final JLabel lblURL = new JLabel("URL:");
  +            final JLabel lblURL = new JLabel("URL:");
   
   
               btnDoUpload.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent ae) {
  -					URL targetURL = null;
  +                    URL targetURL = null;
   
                       try {
  -						targetURL = new URL(cmbURL.getSelectedItem().toString());
  +                        targetURL = new URL(cmbURL.getSelectedItem().toString());
                       } catch (MalformedURLException ex) {
  -						// todo - code here
  -						ex.printStackTrace();
  -					}
  +                        // todo - code here
  +                        ex.printStackTrace();
  +                    }
  +
   
  -										
  -					MultipartPostMethod filePost = new MultipartPostMethod();
  +                    MultipartPostMethod filePost = new MultipartPostMethod();
                       if (targetURL.getPath() == null) {
  -						filePost.setPath("/");
  +                        filePost.setPath("/");
                       } else {
  -						filePost.setPath(targetURL.getPath());
  -					}
  -					
  +                        filePost.setPath(targetURL.getPath());
  +                    }
  +
                       try {
  -						filePost.addParameter(
  -								targetFile.getName(),
  -								targetFile);
  -						HttpClient client = new HttpClient();
  +                        filePost.addParameter(
  +                                targetFile.getName(),
  +                                targetFile);
  +                        HttpClient client = new HttpClient();
                           HostConfiguration hc = new HostConfiguration();
                           hc.setHost(new URI(targetURL));
                           client.setHostConfiguration(hc);
  -						client.executeMethod(filePost);
  +                        client.executeMethod(filePost);
                           filePost.releaseConnection();
                       } catch (FileNotFoundException ex) {
  -						// todo - put real code here
  -						ex.printStackTrace();
  +                        // todo - put real code here
  +                        ex.printStackTrace();
                       } catch (HttpException ex) {
  -						// todo - put real code here
  -						ex.printStackTrace();
  +                        // todo - put real code here
  +                        ex.printStackTrace();
                       } catch (java.io.IOException ex) {
  -						// todo - put real code here
  -						ex.printStackTrace();
  -					}
  -					
  -				}
  -			});
  -
  -			JPanel panURLInput = new JPanel();
  -			panURLInput.setLayout(new FlowLayout());
  -			panURLInput.add(lblURL);
  -			panURLInput.add(cmbURL);
  -			
  -			JPanel panFile = new JPanel();
  -			panFile.setLayout(new FlowLayout());
  -			panFile.add(lblTargetFile);
  -			panFile.add(btnSelectFile);
  -			
  -			panInput.setLayout(new GridLayout(3, 1));
  -
  -			panInput.add(panURLInput);
  -			panInput.add(panFile);
  -			panInput.add(btnDoUpload);
  -			
  -			this.setLayout(new BorderLayout());
  -
  -			this.add(panInput, BorderLayout.CENTER);
  -		}
  -	}
  +                        // todo - put real code here
  +                        ex.printStackTrace();
  +                    }
  +
  +                }
  +            });
  +
  +            JPanel panURLInput = new JPanel();
  +            panURLInput.setLayout(new FlowLayout());
  +            panURLInput.add(lblURL);
  +            panURLInput.add(cmbURL);
  +
  +            JPanel panFile = new JPanel();
  +            panFile.setLayout(new FlowLayout());
  +            panFile.add(lblTargetFile);
  +            panFile.add(btnSelectFile);
  +
  +            panInput.setLayout(new GridLayout(3, 1));
  +
  +            panInput.add(panURLInput);
  +            panInput.add(panFile);
  +            panInput.add(btnDoUpload);
  +
  +            this.setLayout(new BorderLayout());
  +
  +            this.add(panInput, BorderLayout.CENTER);
  +        }
  +    }
   }
  
  
  
  1.7       +39 -39    jakarta-commons/httpclient/src/examples/PostXML.java
  
  Index: PostXML.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/examples/PostXML.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- PostXML.java	23 Jan 2003 22:47:42 -0000	1.6
  +++ PostXML.java	13 Feb 2003 09:14:43 -0000	1.7
  @@ -66,27 +66,27 @@
   import java.net.URL;
   
   /**
  - * 
  + *
    * This is a sample application that demonstrates
  - * how to use the Jakarta HttpClient API. 
  - * 
  - * This application sends an XML document 
  + * how to use the Jakarta HttpClient API.
  + *
  + * This application sends an XML document
    * to a remote web server using HTTP POST
  - * 
  + *
    * @author Sean C. Sullivan
    * @author Ortwin Glück
    */
   public class PostXML {
   
       /**
  -     *  
  +     *
        * Usage:
        *          java PostXML http://mywebserver:80/ c:\foo.xml
  -     * 
  +     *
        *  @param args command line arguments
        *                 Argument 0 is a URL to a web server
        *                 Argument 1 is a local filename
  -     * 
  +     *
        */
       public static void main(String[] args) throws Exception {
           if (args.length != 2) {
  @@ -96,41 +96,41 @@
               System.out.println("<url> - the URL to post the file to");
               System.out.println("<filename> - file to post to the URL");
               System.out.println();
  -			System.exit(1);
  -		}
  -		
  -		String strURL = args[0];
  -		
  -		URL u = new URL(strURL);
  -		
  -		String strXMLFilename = args[1];
  -
  -		InputStream input = null;
  -		
  -		input = new FileInputStream(strXMLFilename);
  +            System.exit(1);
  +        }
   
  -		PostMethod post = new PostMethod();
  +        String strURL = args[0];
  +
  +        URL u = new URL(strURL);
  +
  +        String strXMLFilename = args[1];
  +
  +        InputStream input = null;
  +
  +        input = new FileInputStream(strXMLFilename);
  +
  +        PostMethod post = new PostMethod();
  +
  +        post.setRequestBody(input);
   
  -		post.setRequestBody(input);
  -		
           if ((u.getPath() == null) || (u.getPath().length() == 0)) {
  -			post.setPath("/");
  -		}
  +            post.setPath("/");
  +        }
           else {
  -			post.setPath(u.getPath());
  -		}
  -		post.setRequestHeader("Content-type", "text/xml");
  -				
  -		HttpClient hc = new HttpClient();
  +            post.setPath(u.getPath());
  +        }
  +        post.setRequestHeader("Content-type", "text/xml");
  +
  +        HttpClient hc = new HttpClient();
           HostConfiguration cfg = new HostConfiguration();
           cfg.setHost(new URI(u));
  -		
  -		int iResultCode = hc.executeMethod(post);
  -		
  -		System.out.println("iResultCode = " + iResultCode);
   
  -		System.out.println("Server response:" + post.getResponseBodyAsString() );
  +        int iResultCode = hc.executeMethod(post);
  +
  +        System.out.println("iResultCode = " + iResultCode);
  +
  +        System.out.println("Server response:" + post.getResponseBodyAsString() );
   
           post.releaseConnection();
  -	}
  +    }
   }
  
  
  
  1.9       +5 -5      jakarta-commons/httpclient/src/examples/TrivialApp.java
  
  Index: TrivialApp.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/httpclient/src/examples/TrivialApp.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TrivialApp.java	1 Feb 2003 18:46:11 -0000	1.8
  +++ TrivialApp.java	13 Feb 2003 09:14:43 -0000	1.9
  @@ -77,10 +77,10 @@
   import org.apache.commons.httpclient.methods.GetMethod;
   
   /**
  - * 
  + *
    * This is a simple text mode application that demonstrates
    * how to use the Jakarta HttpClient API.
  - * 
  + *
    * @author <a href="mailto:jsdever@apache.org">Jeff Dever</a>
    * @author Ortwin Glück
    */
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message