package org.ksoap2.samples.quotes;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

import org.ksoap2.*;
import org.ksoap2.serialization.*;
import org.ksoap2.transport.*;

public class StockQuoteDemo extends MIDlet implements CommandListener {

    Form mainForm = new Form("StockQuotes");
    TextField symbolField = new TextField("Symbol", "IBM", 5, TextField.ANY);
    StringItem resultItem = new StringItem("", "");
    Command getCommand = new Command("Get", Command.SCREEN, 1);

    public StockQuoteDemo() {
        mainForm.append(symbolField);
        mainForm.append(resultItem);
        mainForm.addCommand(getCommand);
        mainForm.setCommandListener(this);
    }

    public void startApp() {
        Display.getDisplay(this).setCurrent(mainForm);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable d) {
        try {
            // build request string
            String symbol = symbolField.getString();

            SoapObject rpc =
                new SoapObject("urn:xmethods-delayed-quotes", "getQuote");

            rpc.addProperty("symbol", symbol);

            SoapSerializationEnvelope envelope =
                new SoapSerializationEnvelope(SoapEnvelope.VER10);

            envelope.bodyOut = rpc;

            resultItem.setLabel(symbol);

            HttpTransport ht = new HttpTransport("http://services.xmethods.net/soap");
             ht.debug = true;
             
             try {
                ht.call("urn:xmethods-delayed-quotes#getQuote", envelope);
             }
             catch (Exception e) {
                e.printStackTrace();
                System.err.println (ht.requestDump);  
                System.err.println (ht.responseDump);  
             }

            resultItem.setText("" + envelope.getResult());

        }
        catch (Exception e) {
            e.printStackTrace();
            resultItem.setLabel("Error:");
            resultItem.setText(e.toString());
        }
    }

    /** for me4se */

    public static void main(String[] argv) {
        new StockQuoteDemo().startApp();
    }
}

@@ -28,16 +28,17 @@
 quotes;%0A
+%0A
 import j

access to some statics changed to a static way (to make Eclipse happy)