Package net.sprd.tutorials.common.http

Examples of net.sprd.tutorials.common.http.HttpCallCommandFactory


    public static void main(String[] args)
            throws Exception {
        HttpUrlConnectionFactory urlConnectionFactory =
                new HttpUrlConnectionFactory(API_KEY, SECRET, null);
        HttpCallCommandFactory commandFactory =
                new HttpCallCommandFactory(urlConnectionFactory);

        // create design data using xml
        HttpCallCommand createCommand =
                commandFactory.createFileHttpCallCommand(UPLOAD_URL, HttpMethod.POST, null, new File(UPLOAD_XML), null);
        createCommand.setApiKeyProtected(true);
        createCommand.execute();
        if (createCommand.getStatus() >= 400) {
            throw new Exception("Could not create design xml!");
        }
        log.info("XML location is: " + createCommand.getUrl());

        // get created design xml
        HttpCallCommand getCommand =
                commandFactory.createPlainHttpCallCommand(createCommand.getLocation(), HttpMethod.GET, null);
        getCommand.execute();
        if (createCommand.getStatus() >= 400) {
            throw new Exception("Could not retrieve design xml from " + createCommand.getLocation() + "!");
        }
        String message = (String) getCommand.getOutput();

        // determine upload location
        String searchString = "resource xlink:href=\"";
        int index = message.indexOf(searchString);
        String uploadUrl = message.substring(index + searchString.length(),
                message.indexOf("\"", index + searchString.length() + 1));
        log.info("Upload location is: " + uploadUrl);

        // upload image
        HttpCallCommand uploadCommand =
                commandFactory.createFileHttpCallCommand(uploadUrl, HttpMethod.PUT, null, new File(UPLOAD_IMAGE), null);
        uploadCommand.setApiKeyProtected(true);
        uploadCommand.execute();
        if (uploadCommand.getStatus() >= 400) {
            log.error(uploadCommand.getErrorMessage());
            throw new Exception("Status above 400 expected but status was " + uploadCommand.getStatus() + "!");
View Full Code Here


    public static void main(String[] args)
            throws Exception {
        HttpUrlConnectionFactory urlConnectionFactory =
                new HttpUrlConnectionFactory(API_KEY, SECRET, null);
        HttpCallCommandFactory commandFactory =
                new HttpCallCommandFactory(urlConnectionFactory);

        // create design data using xml
        HttpCallCommand createDesignCommand =
                commandFactory.createPlainHttpCallCommand(UPLOAD_URL, HttpMethod.POST, null);
        createDesignCommand.setInput(getXMLData(UPLOAD_XML));
        createDesignCommand.setApiKeyProtected(true);
        createDesignCommand.execute();
        if (createDesignCommand.getStatus() >= 400) {
            throw new Exception("Could not create design xml!");
        }
        log.info("XML location is: " + createDesignCommand.getUrl());

        // get created design xml
        HttpCallCommand getDesignCommand =
                commandFactory.createPlainHttpCallCommand(createDesignCommand.getLocation(), HttpMethod.GET, null);
        getDesignCommand.execute();
        if (createDesignCommand.getStatus() >= 400) {
            throw new Exception("Could not retrieve design xml from " + createDesignCommand.getLocation() + "!");
        }
        String message = (String) getDesignCommand.getOutput();

        // determine upload location
        String searchString = "resource xlink:href=\"";
        int index = message.indexOf(searchString);
        String uploadUrl = message.substring(index + searchString.length(),
                message.indexOf("\"", index + searchString.length() + 1));
        log.info("Upload location is: " + uploadUrl);

        // upload image
        HttpCallCommand uploadDesignCommand =
                commandFactory.createFileHttpCallCommand(uploadUrl, HttpMethod.PUT, null, new File(UPLOAD_IMAGE), null);
        uploadDesignCommand.setApiKeyProtected(true);
        uploadDesignCommand.execute();
        if (uploadDesignCommand.getStatus() >= 400) {
            log.error(uploadDesignCommand.getErrorMessage());
            throw new Exception("Status above 400 expected but status was " + uploadDesignCommand.getStatus() + "!");
        }

        // create product data using xml
        HttpCallCommand createProductCommand =
                commandFactory.createPlainHttpCallCommand(CREATION_URL, HttpMethod.POST, null);
        String productData = getXMLData(PRODUCT_XML);
        // use id from fetched design xml here -> my solution is only a hack
        productData = productData.replace("THE_DESIGN_ID", "u" + uploadUrl.substring(uploadUrl.lastIndexOf('/') + 1));
        createProductCommand.setInput(productData);
        createProductCommand.setApiKeyProtected(true);
View Full Code Here

TOP

Related Classes of net.sprd.tutorials.common.http.HttpCallCommandFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.