Example usage for org.apache.commons.httpclient HttpClient HttpClient

List of usage examples for org.apache.commons.httpclient HttpClient HttpClient

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpClient HttpClient.

Prototype

public HttpClient() 

Source Link

Usage

From source file:ar.com.zauber.commons.web.proxy.HttpClientRequestProxyTest.java

/** test */
public final void testContentTypeCharset() {
    HttpClientRequestProxy p = new HttpClientRequestProxy(new URLRequestMapper() {
        public final URLResult getProxiedURLFromRequest(final HttpServletRequest request) {
            return null;
        }//from   w  w w.  j av a  2 s .  c  o  m
    }, new HttpClient());

    HttpMethod m = new GetMethod() {
        /** @see HttpMethodBase#getResponseHeader(String) */
        @Override
        public Header getResponseHeader(final String headerName) {
            return new Header(headerName, "text/html ; charset =  utf-8");
        }
    };
    assertEquals("text/html ; charset =  utf-8", p.getContentType(m));
}

From source file:com.ebay.jetstream.application.dataflows.VisualDataFlow.java

private URL getYumlPic(String yumlData) {
    try {/*from  w  w w. j av a  2  s .co  m*/
        if (!graphYuml.containsKey(yumlData)) {
            HttpClient httpclient = new HttpClient();
            PostMethod post = new PostMethod(yumlActivityUrl);
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            post.addParameter(new NameValuePair("dsl_text", yumlData));
            httpclient.executeMethod(post);
            URL url = new URL(yumlUrl + post.getResponseBodyAsString());
            graphYuml.put(yumlData, url);
            return url;
        } else {
            return graphYuml.get(yumlData);
        }
    } catch (Exception e) {
        logger.error(" Exception while rendering pipeline ", e);
        return null;
    }
}

From source file:com.qubole.rubix.hadoop1.Hadoop1ClusterManager.java

@Override
public void initialize(Configuration conf) {
    super.initialize(conf);
    nnPort = conf.getInt(nnPortConf, nnPort);

    nodesSupplier = Suppliers.memoizeWithExpiration(new Supplier<List<String>>() {
        @Override/*from   ww  w  . j a v a 2 s  .  c o  m*/
        public List<String> get() {
            if (!isMaster) {
                // First time all nodes start assuming themselves as master and down the line figure out their role
                // Next time onwards, only master will be fetching the list of nodes
                return ImmutableList.of();
            }

            HttpClient httpclient = new HttpClient();
            HttpMethod method = new GetMethod(
                    "http://localhost:" + nnPort + "/dfsnodelist.jsp?whatNodes=LIVE&status=NORMAL");
            int sc;
            try {
                sc = httpclient.executeMethod(method);
            } catch (IOException e) {
                // not reachable => worker
                sc = -1;
            }

            if (sc != 200) {
                LOG.debug("Could not reach dfsnodelist.jsp, setting worker role");
                isMaster = false;
                return ImmutableList.of();
            }

            LOG.debug("Reached dfsnodelist.jsp, setting master role");
            isMaster = true;
            String html;
            try {
                byte[] buf = method.getResponseBody();
                html = new String(buf);
            } catch (IOException e) {
                throw Throwables.propagate(e);
            }

            List<String> nodes = extractNodes(html);
            return nodes;
        }
    }, 10, TimeUnit.SECONDS);
    nodesSupplier.get();
}

From source file:com.linkedin.pinot.common.utils.webhdfs.WebHdfsV1Client.java

public WebHdfsV1Client(String host, int port, String protocol, boolean overwrite, int permission) {
    _host = host;/*from  w  w  w.j  a  v  a2  s  . com*/
    _port = port;
    _protocol = protocol;
    _overwrite = overwrite;
    _permission = permission;
    _httpClient = new HttpClient();
}

From source file:com.lp.client.frame.component.phone.HttpPhoneDialer.java

public HttpPhoneDialer() {
    client = new HttpClient();
}

From source file:es.carebear.rightmanagement.client.RestClient.java

public User logInTest(String username, String password) throws IOException {

    HttpClient client = new HttpClient();

    PostMethod method = new PostMethod(getServiceBaseURI() + "/client/users/login/" + username);

    method.addParameter("password", password);

    System.out.println(method.getPath());

    int responseCode = client.executeMethod(method);

    String response = responseToString(method.getResponseBodyAsStream());

    System.out.println(response);

    return XMLHelper.fromXML(response, User.class);
}

From source file:com.linkedin.pinot.tools.admin.command.ChangeTableState.java

@Override
public boolean execute() throws Exception {
    if (_controllerHost == null) {
        _controllerHost = NetUtil.getHostAddress();
    }//from  w  w w  . ja  v a 2s .  com

    String stateValue = _state.toLowerCase();
    if (!stateValue.equals("enable") && !stateValue.equals("disable") && !stateValue.equals("drop")) {
        throw new IllegalArgumentException(
                "Invalid value for state: " + _state + "\n Value must be one of enable|disable|drop");
    }
    HttpClient httpClient = new HttpClient();
    HttpURL url = new HttpURL(_controllerHost, Integer.parseInt(_controllerPort), URI_TABLES_PATH + _tableName);
    url.setQuery("state", stateValue);
    GetMethod httpGet = new GetMethod(url.getEscapedURI());
    int status = httpClient.executeMethod(httpGet);
    if (status != 200) {
        throw new RuntimeException("Failed to change table state, error: " + httpGet.getResponseBodyAsString());
    }
    return true;
}

From source file:com.jmeter.alfresco.utils.HttpUtils.java

/**
 * Gets the login response./*from  w ww.j a  v  a2 s.  c o  m*/
 *
 * @param authURI the path
 * @param username the username
 * @param password the password
 * @return the login response
 * @throws ParseException the parse exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
public Map<String, String> getAuthResponse(final String authURI, final String username, final String password)
        throws ParseException, IOException {

    LOG.debug("Authenticating request..");
    final Map<String, String> responseMap = new ConcurrentHashMap<String, String>();
    GetMethod getRequest = null;
    try {
        final HttpClient httpclient = new HttpClient();
        getRequest = new GetMethod(getAuthURL(authURI, username, password));
        final int statusCode = httpclient.executeMethod(getRequest);
        LOG.debug("Auth Response Status: " + statusCode + "|" + getRequest.getStatusText());

        responseMap.put(Constants.RESP_BODY, getRequest.getResponseBodyAsString());
        responseMap.put(Constants.CONTENT_TYPE,
                getRequest.getResponseHeader(Constants.CONTENT_TYPE_HDR).getValue());
        responseMap.put(Constants.STATUS_CODE, String.valueOf(statusCode));

    } finally {
        if (getRequest != null) {
            getRequest.releaseConnection();
        }
    }
    return responseMap;
}

From source file:apm.common.utils.HttpTookit.java

/**
 * HTTP POST?HTML/*w  w  w  . ja  v a2s  .com*/
 * 
 * @param url
 *            URL?
 * @param params
 *            ?,?null
 * @param charset
 *            
 * @param pretty
 *            ?
 * @return ?HTML
 */
public static String doPost(String url, Map<String, String> params, String charset, boolean pretty) {
    StringBuffer response = new StringBuffer();
    HttpClient client = new HttpClient();
    HttpMethod method = new PostMethod(url);
    // Http Post?
    if (params != null) {
        HttpMethodParams p = new HttpMethodParams();
        for (Map.Entry<String, String> entry : params.entrySet()) {
            p.setParameter(entry.getKey(), entry.getValue());
        }
        method.setParams(p);
    }
    try {
        client.executeMethod(method);
        if (method.getStatusCode() == HttpStatus.SC_OK) {
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(method.getResponseBodyAsStream(), charset));
            String line;
            while ((line = reader.readLine()) != null) {
                if (pretty) {
                    response.append(line).append(System.getProperty("line.separator"));
                } else {
                    response.append(line);
                }
            }
            reader.close();
        }
    } catch (IOException e) {
        log.error("HTTP Post" + url + "??", e);
    } finally {
        method.releaseConnection();
    }
    return response.toString();
}

From source file:net.duckling.ddl.web.controller.UploadImgController.java

@RequestMapping
public void execute(HttpServletRequest request, HttpServletResponse response) throws IOException {
    Site site = VWBContext.findSite(request);
    FileVersion attachItem = new FileVersion();
    response.setContentType("text/xml");
    response.setCharacterEncoding("UTF-8");
    ////www. ja  v a  2 s.  c  o m
    String url = request.getParameter("url");
    HttpClient client = new HttpClient();
    GetMethod getMethod = new GetMethod(url);
    String fakeReferer = getFakeReferer(url);//??
    if (fakeReferer != null) {
        String thisReferer = request.getHeader("Referer");
        if (thisReferer.contains(fakeReferer)) {//????
            response.getWriter().write(getReturnXml(site, 0, "??", attachItem));
            response.flushBuffer();
            return;
        }
        getMethod.setRequestHeader("Referer", fakeReferer);
    }
    client.executeMethod(getMethod);

    //?

    try {
        attachItem = uploadImg(getMethod, request);
    } catch (NoEnoughSpaceException e) {
        JSONObject j = new JSONObject();
        j.put("result", false);
        j.put("message", e.getMessage());
        j.put("error", e.getMessage());
        JsonUtil.writeJSONObject(response, j);
        return;
    }
    //
    response.getWriter().write("");
    response.getWriter().write(getReturnXml(site, 1, "????", attachItem));
    response.flushBuffer();
}