Examples of HttpCallCommand


Examples of net.sprd.sampleapps.common.http.HttpCallCommand

        BasketDTO basket = objectFactory.createBasketDTO();
        basket.setToken(UUID.randomUUID().toString());
        /*Reference shopRef = objectFactory.createReference();
        shopRef.setId(shop.getId());
        basket.setShop(shopRef);*/
        HttpCallCommand command = factory.createJaxbHttpCallCommand(shop.getBaskets().getHref(), HttpMethod.POST, null);
        command.setApiKeyProtected(true);
        command.setInput(objectFactory.createBasket(basket));
        command.execute();
        log.info(command.getLocation());
        log.info("" + command.getStatus());
        log.info(command.getErrorMessage());
        if (command.getStatus() != 201)
            throw new IllegalArgumentException("Could not create Basket!");
        log.info("Basket location is: " + command.getLocation());
        return getBasket(command.getLocation().substring(command.getLocation().lastIndexOf("/") + 1));
    }
View Full Code Here

Examples of net.sprd.sampleapps.common.http.HttpCallCommand

        log.info("Basket location is: " + command.getLocation());
        return getBasket(command.getLocation().substring(command.getLocation().lastIndexOf("/") + 1));
    }

    public BasketDTO getBasket(String basketId) {
        HttpCallCommand command = factory.createJaxbHttpCallCommand(shop.getBaskets().getHref() + "/" + basketId, HttpMethod.GET, null);
        command.setApiKeyProtected(true);
        command.execute();
        if (command.getStatus() != 200)
            throw new IllegalArgumentException("Could not retrieve basket!");

        return (BasketDTO) ((JAXBElement) command.getOutput()).getValue();
    }
View Full Code Here

Examples of net.sprd.sampleapps.common.http.HttpCallCommand

        return (BasketDTO) ((JAXBElement) command.getOutput()).getValue();
    }

    public void updateBasket(BasketDTO basket) {
        HttpCallCommand command = factory.createJaxbHttpCallCommand(shop.getBaskets().getHref() + "/" + basket.getId(), HttpMethod.PUT, null);
        command.setApiKeyProtected(true);
        command.setInput(objectFactory.createBasket(basket));
        command.execute();
        if (command.getStatus() != 200)
            throw new IllegalArgumentException("Could not create Basket!");
    }
View Full Code Here

Examples of net.sprd.sampleapps.common.http.HttpCallCommand

        if (command.getStatus() != 200)
            throw new IllegalArgumentException("Could not create Basket!");
    }

    public String getBasketCheckoutUrl(String id) {
        HttpCallCommand command =
                factory.createJaxbHttpCallCommand(shop.getBaskets().getHref() + "/" + id + "/checkout", HttpMethod.GET, null);
        command.setApiKeyProtected(true);
        command.execute();
        if (command.getStatus() != 200)
            throw new IllegalArgumentException("Could not retrieve checkout reference!");

        Reference reference = (Reference) ((JAXBElement) command.getOutput()).getValue();
        return reference.getHref();
    }
View Full Code Here

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

                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

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

                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);
        createProductCommand.execute();
        if (createProductCommand.getStatus() >= 400) {
            throw new Exception("Could not create product xml!");
        }
        log.info("XML location is: " + createProductCommand.getLocation());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.