× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



When I want to see the raw text of a web service I direct my SOAP web
service to a Servlet that dumps the entire input stream to the console (or
text file).

That has worked well for me.

The other method I have used is create a small application that allows you
to have an input and output window for calling a web service.  It is bare
bones but it gets the job done.  Load the below code into a file called
GetURL.java and give it a try. Note I used WDSc's GUI capabilities to create
this GUI app.

HTH,
Aaron Bartell



/*
 * GetURL.java
 *
 * Created on April 8, 2003, 10:17 PM
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

/** 
 *
 * @author  ALBartell
 */
public class GetURL extends javax.swing.JFrame {

    /** Creates new form TestJFrame */
    public GetURL() {
        initComponents();
        // Default URLs that are used a lot. This is where you could put
your Servlet that dumps the incoming HTTP request to the console.
        ddURL.add("http://99.99.99.99:8090/cgi-bin/a1";);
        ddURL.add("http://99.99.99.99:8090/cgi-bin/a2";);
        ddURL.add("http://99.99.99.99:8090/cgi-bin/a3";);
        ddURL.add("http://99.99.99.99:8090/cgi-bin/a4";);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() { //GEN-BEGIN:initComponents
        panel1 = new java.awt.Panel();
        taRequest = new java.awt.TextArea();
        labURL = new java.awt.Label();
        buttonSubmit = new javax.swing.JButton();
        taResult = new java.awt.TextArea();
        label1 = new java.awt.Label();
        label2 = new java.awt.Label();
        butClearResults = new javax.swing.JButton();
        ddURL = new java.awt.Choice();

        getContentPane().setLayout(null);

        setTitle("CSO Application Tester");
        setBackground(new java.awt.Color(204, 204, 204));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        panel1.setLayout(null);

        taRequest.setText("");
        panel1.add(taRequest);
        taRequest.setBounds(12, 91, 760, 300);

        labURL.setText("URL:");
        panel1.add(labURL);
        labURL.setBounds(10, 10, 32, 21);

        buttonSubmit.setText("Get It");
        buttonSubmit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSubmitActionPerformed(evt);
            }
        });

        panel1.add(buttonSubmit);
        buttonSubmit.setBounds(10, 647, 70, 27);

        panel1.add(taResult);
        taResult.setBounds(13, 409, 760, 220);

        label1.setText("Content");
        panel1.add(label1);
        label1.setBounds(11, 76, 50, 12);

        label2.setText("Result");
        panel1.add(label2);
        label2.setBounds(14, 397, 40, 12);

        butClearResults.setToolTipText("Clear Result Text Area");
        butClearResults.setFont(new java.awt.Font("Dialog", 0, 12));
        butClearResults.setText("Clear Results");
        butClearResults.addActionListener(new
java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                butClearResultsActionPerformed(evt);
            }
        });

        panel1.add(butClearResults);
        butClearResults.setBounds(89, 648, 110, 27);

        panel1.add(ddURL);
        ddURL.setBounds(50, 10, 570, 21);

        getContentPane().add(panel1);
        setBounds(0, 0, 792, 722);
        panel1.add(getTfURL(), null);
        panel1.add(getCbSOAP(), null);
        panel1.add(getJLabel(), null);
        this.setContentPane(panel1);
        ddURL.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent e) {
                tfURL.setText(ddURL.getSelectedItem());
            }
        });
        panel1.addPropertyChangeListener(new
java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent e) {
                if ((e.getPropertyName().equals("enabled"))) {
                }
            }
        });
    } //GEN-END:initComponents

    private void butClearResultsActionPerformed(java.awt.event.ActionEvent
evt) {
        //GEN-FIRST:event_butClearResultsActionPerformed
        taResult.setText("");
    } //GEN-LAST:event_butClearResultsActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {
//GEN-FIRST:event_formWindowOpened
        // Add your handling code here:
    } //GEN-LAST:event_formWindowOpened

    private void buttonSubmitActionPerformed(java.awt.event.ActionEvent evt)
{
        //GEN-FIRST:event_buttonSubmitActionPerformed

        try {
            URL url = new URL(tfURL.getText());

            HttpURLConnection connection = (HttpURLConnection)
url.openConnection();

            connection.setDoOutput(true);
            connection.setDoInput(true);
            connection.setUseCaches(false);
            connection.setRequestMethod("POST");
            if (cbSOAP.isSelected())
                connection.setRequestProperty("SOAPAction", SOAP_ACTION);

            if (!taRequest.equals(" ") && !taRequest.equals(null) &&
!taRequest.equals("")) {
                OutputStream outStream = connection.getOutputStream();
                outStream.write(taRequest.getText().getBytes());
                outStream.close();
                System.out.println(connection.getHeaderFields().toString());
                System.out.println(connection.getContentType());
                //System.out.println(taRequest.getText());
            }

            taResult.append(readURLConnection(connection));

        } catch (Exception e) {
            e.printStackTrace(System.out);
        }
    } //GEN-LAST:event_buttonSubmitActionPerformed

    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {
//GEN-FIRST:event_exitForm
        System.exit(0);
    } //GEN-LAST:event_exitForm

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        new GetURL().show();

    }

    private static String readURLConnection(URLConnection uc) throws
Exception {
        StringBuffer buffer = new StringBuffer();
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new
InputStreamReader(uc.getInputStream()));
            //String line = null;
            int letter = 0;
            while ((letter = reader.read()) != -1)
                buffer.append((char) letter);
        } catch (Exception e) {
            System.out.println("Cannot read from URL" + e.toString());
            throw e;
        } finally {
            try {
                reader.close();
            } catch (IOException io) {
                System.out.println("Error closing URLReader!");
                throw io;
            }
        }
        return buffer.toString();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton butClearResults;
    private java.awt.Label label2;
    private java.awt.TextArea taRequest;
    private java.awt.Label label1;
    private java.awt.Panel panel1; //
    private java.awt.Label labURL;
    private javax.swing.JButton buttonSubmit;
    private java.awt.TextArea taResult;
    private java.awt.Choice ddURL;
    // End of variables declaration//GEN-END:variables

    private javax.swing.JTextField tfURL = null;
    private final static String SOAP_ACTION =
"http://www.axonom.com/webservices/SubmitOrder";;
    private javax.swing.JCheckBox cbSOAP = null;
    private javax.swing.JLabel jLabel = null;
    /**
     * This method initializes tfURL
     * 
     * @return javax.swing.JTextField
     */
    private javax.swing.JTextField getTfURL() {
        if (tfURL == null) {
            tfURL = new javax.swing.JTextField();
            tfURL.setBounds(53, 45, 452, 19);
        }
        return tfURL;
    }
    /**
     * This method initializes cbSOAP
     * 
     * @return javax.swing.JCheckBox
     */
    private javax.swing.JCheckBox getCbSOAP() {
        if (cbSOAP == null) {
            cbSOAP = new javax.swing.JCheckBox();
            cbSOAP.setBounds(559, 48, 21, 21);
        }
        return cbSOAP;
    }
    /**
     * This method initializes jLabel
     * 
     * @return javax.swing.JLabel
     */
    private javax.swing.JLabel getJLabel() {
        if (jLabel == null) {
            jLabel = new javax.swing.JLabel();
            jLabel.setBounds(522, 52, 36, 14);
            jLabel.setText("SOAP");
        }
        return jLabel;
    }
} //  @jve:visual-info  decl-index=0 visual-constraint="10,10"


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.