Package org.ofbiz.base.util

Examples of org.ofbiz.base.util.HttpClient


        if (Debug.verboseOn()) {
            Debug.logVerbose("DHL Connect URL : " + conStr, module);
            Debug.logVerbose("DHL XML String : " + xmlString, module);
        }

        HttpClient http = new HttpClient(conStr);
        http.setTimeout(timeout * 1000);
        String response = null;
        try {
            response = http.post(xmlString);
        } catch (HttpClientException e) {
            Debug.logError(e, "Problem connecting with DHL server", module);
            throw new DhlConnectException("URL Connection problem", e);
        }

View Full Code Here


            timeout = Integer.parseInt(timeOutStr);
        } catch (NumberFormatException e) {
            Debug.logError(e, "Unable to set timeout to " + timeOutStr + " using default " + timeout);
        }

        HttpClient http = new HttpClient(conUrl);
        http.setTimeout(timeout * 1000);
        http.setParameter("API", requestType);
        http.setParameter("XML", xmlString);

        String responseString = null;
        try {
            responseString = http.get();
        } catch (HttpClientException e) {
            throw new UspsRequestException("Problem connecting with USPS server", e);
        }

        Debug.logInfo("USPS response: " + responseString, module);
View Full Code Here

        if (Debug.verboseOn()) {
            Debug.logVerbose("Fedex Connect URL : " + url, module);
            Debug.logVerbose("Fedex XML String : " + xmlString, module);
        }

        HttpClient http = new HttpClient(url);
        http.setTimeout(timeout * 1000);
        String response = null;
        try {
            response = http.post(xmlString);
        } catch (HttpClientException e) {
            Debug.logError(e, "Problem connecting to Fedex server", module);
            throw new FedexConnectException("URL Connection problem", e);
        }

View Full Code Here

            } catch (Exception e) {
                Debug.logError(e, "Error saving message to file [" + saveToFilename + "]: " + e.toString(), module);
                return ServiceUtil.returnError(UtilProperties.getMessage(resource, "OagisErrorSavingMessage", UtilMisc.toMap("saveToFilename", saveToFilename, "errorString", e.toString()), locale));
            }
        } else if (UtilValidate.isNotEmpty(sendToUrl)) {
            HttpClient http = new HttpClient(sendToUrl);

            // test parameters
            http.setHostVerificationLevel(SSLUtil.HOSTCERT_NO_CHECK);
            http.setAllowUntrusted(true);
            http.setDebug(true);

            // needed XML post parameters
            if (UtilValidate.isNotEmpty(certAlias)) {
                http.setClientCertificateAlias(certAlias);
            }
            if (UtilValidate.isNotEmpty(basicAuthUsername)) {
                http.setBasicAuthInfo(basicAuthUsername, basicAuthPassword);
            }
            http.setContentType("text/xml");
            http.setKeepAlive(true);

            try {
                http.post(outText);
            } catch (Exception e) {
                Debug.logError(e, "Error posting message to server with URL [" + sendToUrl + "]: " + e.toString(), module);
                return ServiceUtil.returnError(UtilProperties.getMessage(resource, "OagisErrorPostingMessage", UtilMisc.toMap("sendToUrl", sendToUrl, "errorString", e.toString()), locale));
            }
        } else {
View Full Code Here

                if (script == null) {
                    URL scriptUrl = UtilURL.fromResource(location, cl);

                    if (scriptUrl != null) {
                        try {
                            HttpClient http = new HttpClient(scriptUrl);
                            script = http.get();
                        } catch (HttpClientException e) {
                            throw new GenericServiceException("Cannot read script from resource", e);
                        }
                    } else {
                        throw new GenericServiceException("Cannot read script, resource [" + location + "] not found");
View Full Code Here

        Map<String, Object> parameters = FastMap.newInstance();
        parameters.put("serviceName", modelService.invoke);
        if (xmlContext != null)
            parameters.put("serviceContext", xmlContext);
       
        HttpClient http = new HttpClient(this.getLocation(modelService), parameters);
        String postResult = null;       
        try {
            postResult = http.post();
        } catch (HttpClientException e) {
            throw new GenericServiceException("Problems invoking HTTP request", e);
        }
       
        Map<String, Object> result = null;
View Full Code Here

        if (Debug.verboseOn()) {
            Debug.logVerbose("DHL Connect URL : " + conStr, module);
            Debug.logVerbose("DHL XML String : " + xmlString, module);
        }

        HttpClient http = new HttpClient(conStr);
        http.setTimeout(timeout * 1000);
        String response = null;
        try {
            response = http.post(xmlString);
        } catch (HttpClientException e) {
            Debug.logError(e, "Problem connecting with DHL server", module);
            throw new DhlConnectException("URL Connection problem", e);
        }

View Full Code Here

        if (Debug.verboseOn()) {
            Debug.logVerbose("Fedex Connect URL : " + url, module);
            Debug.logVerbose("Fedex XML String : " + xmlString, module);
        }

        HttpClient http = new HttpClient(url);
        http.setTimeout(timeout * 1000);
        String response = null;
        try {
            response = http.post(xmlString);
        } catch ( HttpClientException e) {
            Debug.logError(e, "Problem connecting to Fedex server", module);
            throw new FedexConnectException("URL Connection problem", e);
        }

View Full Code Here

        if (mode == MODE_IN) {
            String stream = this.toString() + "..\r\n";
            Debug.log("Sending - \n" + stream, module);
            String urlString = "http://" + host + ":" + port;
            HttpClient http = new HttpClient(urlString);
            http.setDebug(true);

            /*
            SocketFactory sf = null;
            if (ssl) {
                sf = SSLSocketFactory.getDefault();
            } else {
                sf = SocketFactory.getDefault();
            }
            Socket sock = sf.createSocket(host, port);

            // get the streams
            BufferedReader br = new BufferedReader(new InputStreamReader(sock.getInputStream()));
            PrintStream ps = new PrintStream(sock.getOutputStream());

            // send the request
            ps.print(this.toString());
            ps.flush();

            // the output map
            LinkedMap docMap = new LinkedMap();
            String line;

            // read the response
            while ((line = br.readLine()) != null) {
                Debug.log(line, module);
                if (!line.trim().equals(".")) {
                    String[] lineSplit = line.trim().split(" ");
                    if (lineSplit != null && lineSplit.length == 2) {
                        docMap.put(lineSplit[0], lineSplit[1]);
                    } else {
                        Debug.logWarning("Line split error - " + line, module);
                    }
                } else {
                    break;
                }
            }
            Debug.log("Reading finished.", module);

            // send session finished signal
            ps.print("..\r\n");
            ps.flush();

            // close the streams
            ps.close();
            br.close();
            */

            LinkedMap docMap = new LinkedMap();           
            String resp = null;
            try {
                resp = http.post(stream);
            } catch (HttpClientException e) {
                Debug.logError(e, module);
                throw new IOException(e.getMessage());
            }

View Full Code Here

        return "success";
    }

    public static String httpClientTest(HttpServletRequest request, HttpServletResponse response) {
        try {
            HttpClient http = new HttpClient("http://ofbiz.apache.org/cgi-bin/http_test.pl");

            http.setHeader("Cookie", "name=value,value=name");
            http.setHeader("User-Agent", "Mozilla/4.0");
            http.setParameter("testId", "testing");
            Debug.log(http.post(), module);
        } catch (Exception e) {
            Debug.log(e, "HttpClientException Caught.", module);
        }
        return "success";
    }
View Full Code Here

TOP

Related Classes of org.ofbiz.base.util.HttpClient

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.