Sample code for 30+ languages & platforms
Java

REST Auto Reconnect for Multiple Requests (dev.markitondemand.com)

See more REST Examples

Demonstrates how the autoReconnect argument to the Connect method is used.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Rest;
import com.chilkatsoft.chilkat2.Xml;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example requires the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        Rest rest = new Rest();

        // This example demonstrates the usage of the autoReconnect argument to the Connect method.
        // When autoReconnect is on, subsequent REST method calls will automatically re-connect
        // if necessary, using the same information (domain/IP address, port number, and TLS).
        boolean bTls = false;
        int port = 80;
        boolean bAutoReconnect = true;
        rest.connect("dev.markitondemand.com", port, bTls, bAutoReconnect);

        // Get a stock quote:
        rest.addQueryParam("symbol", "AAPL");
        String responseXml;
        try {
            responseXml = rest.fullRequestNoBody("GET", "/MODApis/Api/v2/Quote");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        Xml xml = new Xml();
        xml.loadXml(responseXml);
        System.out.println("AAPL LastPrice: " + xml.getChildContent("LastPrice"));

        // Get another stock quote.  If a new HTTP connection is required,
        // the REST object will automatically connect using the same parameters.
        rest.addQueryParam("symbol", "AMZN");
        try {
            responseXml = rest.fullRequestNoBody("GET", "/MODApis/Api/v2/Quote");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        xml.loadXml(responseXml);
        System.out.println("AMZN LastPrice: " + xml.getChildContent("LastPrice"));
    }
}