Example usage for org.apache.commons.httpclient HttpStatus SC_NOT_IMPLEMENTED

List of usage examples for org.apache.commons.httpclient HttpStatus SC_NOT_IMPLEMENTED

Introduction

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

Prototype

int SC_NOT_IMPLEMENTED

To view the source code for org.apache.commons.httpclient HttpStatus SC_NOT_IMPLEMENTED.

Click Source Link

Document

<tt>501 Not Implemented</tt> (HTTP/1.0 - RFC 1945)

Usage

From source file:com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult.java

public void notImplemented(Localizable message) {
    this.message = message;
    httpCode = HttpStatus.SC_NOT_IMPLEMENTED;
}

From source file:cn.newtouch.util.HttpClientUtil.java

/**
 * ?url??get/*from w w  w  . ja  v  a 2 s  .c  om*/
 * 
 * @param url
 */
public static String reqUrl(String url) {
    HttpClient client = new HttpClient();
    GetMethod method = new GetMethod(url);
    try {
        int returnCode = client.executeMethod(method);
        if (returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {
            System.err.println("The Post method is not implemented by this URI");
        } else {
            return method.getResponseBodyAsString();

        }
    } catch (Exception e) {
        System.err.println(e);
    }
    return null;
}

From source file:com.nfl.dm.clubsites.cms.articles.categorization.OpenCalaisRESTPost.java

private Map<String, ArrayList<String>> doRequest(String input, PostMethod method) {
    ArrayList<String> person = new ArrayList<String>();
    ArrayList<String> organization = new ArrayList<String>();
    Map<String, ArrayList<String>> output = new HashMap<String, ArrayList<String>>();
    try {/*w  w w  .  j  a v a  2 s . c o m*/
        int returnCode = client.executeMethod(method);
        if (returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {
            System.err.println("The Post method is not implemented by this URI");
            // still consume the response body
            method.getResponseBodyAsString();
        } else if (returnCode == HttpStatus.SC_OK) {
            System.out.println("Post succeeded: " + input);
            JSONObject json = (JSONObject) JSONSerializer.toJSON(method.getResponseBodyAsString());
            Iterator<?> keys = json.keys();
            while (keys.hasNext()) {
                String key = (String) keys.next();
                if (json.get(key) instanceof JSONObject && !key.equals("doc")) {
                    JSONObject jsonElement = (JSONObject) json.get(key);
                    if (jsonElement.get("_typeGroup").equals("entities")) {
                        if (jsonElement.get("_type").equals("Person")) {
                            person.add(jsonElement.get("name").toString());
                        } else if (jsonElement.get("_type").equals("Organization")) {
                            organization.add(jsonElement.get("name").toString());
                        }
                    }
                }
            }
            output.put("person", person);
            output.put("organization", organization);
        } else {
            System.err.println("Post failed: " + input);
            System.err.println("Got code: " + returnCode);
            System.err.println("response: " + method.getResponseBodyAsString());
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        method.releaseConnection();
    }
    return output;
}

From source file:cn.newtouch.util.HttpClientUtil.java

/**
 * ?url??post/*  ww  w .  j  a  v a 2  s. co  m*/
 * 
 * @param url
 * @param paramsStr
 *            ?
 * @param method
 * @return String ?
 */
public static String post(String url, String paramsStr, String method) {

    HttpClient client = new HttpClient();
    HttpMethod httpMethod = new PostMethod(url);
    httpMethod.setQueryString(paramsStr);
    try {
        int returnCode = client.executeMethod(httpMethod);
        if (returnCode == HttpStatus.SC_OK) {
            return httpMethod.getResponseBodyAsString();
        } else if (returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {
            System.err.println("The Post method is not implemented by this URI");
        }
    } catch (Exception e) {
        System.err.println(e);
    } finally {
        httpMethod.releaseConnection();
    }
    return null;
}

From source file:com.ikanow.infinit.e.harvest.enrichment.legacy.HttpClientPost.java

private void doRequest(File file, PostMethod method) {
    try {//ww w . j a v a 2s  .co m
        int returnCode = client.executeMethod(method);
        if (returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {
            System.err.println("The Post method is not implemented by this URI");
            // still consume the response body
            method.getResponseBodyAsString();
        } else if (returnCode == HttpStatus.SC_OK) {
            System.out.println("File post succeeded: " + file);
            saveResponse(file, method);
        } else {
            System.err.println("File post failed: " + file);
            System.err.println("Got code: " + returnCode);
            System.err.println("response: " + method.getResponseBodyAsString());
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        method.releaseConnection();
    }
}

From source file:com.alta189.cyborg.commit.ShortUrlService.java

public static String shorten(String url, String keyword) {
    switch (service) {
    case BIT_LY://from   w  ww  .ja va 2  s  .  co m
        HttpClient httpclient = new HttpClient();
        HttpMethod method = new GetMethod("http://api.bit.ly/shorten");
        method.setQueryString(
                new NameValuePair[] { new NameValuePair("longUrl", url), new NameValuePair("version", "2.0.1"),
                        new NameValuePair("login", user), new NameValuePair("apiKey", apiKey),
                        new NameValuePair("format", "xml"), new NameValuePair("history", "1") });
        try {
            httpclient.executeMethod(method);
            String responseXml = method.getResponseBodyAsString();
            String retVal = null;
            if (responseXml != null) {
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                DocumentBuilder db = dbf.newDocumentBuilder();
                StringReader st = new StringReader(responseXml);
                Document d = db.parse(new InputSource(st));
                NodeList nl = d.getElementsByTagName("shortUrl");
                if (nl != null) {
                    Node n = nl.item(0);
                    retVal = n.getTextContent();
                }
            }

            return retVal;
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (SAXException e) {
            e.printStackTrace();
        }
        return null;
    case SPOUT_IN:
        HttpClient client = new HttpClient();
        String result = null;
        client.getParams().setParameter("http.useragent", "Test Client");

        BufferedReader br = null;
        PostMethod pMethod = new PostMethod("http://spout.in/yourls-api.php");
        pMethod.addParameter("signature", apiKey);
        pMethod.addParameter("action", "shorturl");
        pMethod.addParameter("format", "simple");
        pMethod.addParameter("url", url);
        if (keyword != null) {
            pMethod.addParameter("keyword", keyword);
        }

        try {
            int returnCode = client.executeMethod(pMethod);

            if (returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {
                System.err.println("The Post method is not implemented by this URI");
                pMethod.getResponseBodyAsString();
            } else {
                br = new BufferedReader(new InputStreamReader(pMethod.getResponseBodyAsStream()));
                String readLine;
                if (((readLine = br.readLine()) != null)) {
                    result = readLine;
                }
            }
        } catch (Exception e) {
            System.err.println(e);
        } finally {
            pMethod.releaseConnection();
            if (br != null) {
                try {
                    br.close();
                } catch (Exception fe) {
                    fe.printStackTrace();
                }
            }
        }
        return result;
    }
    return null;
}

From source file:com.hw13c.HttpClientPost.java

private void doRequest(File file, PostMethod method) {
    try {//from ww w . ja  va  2s  .  c om
        int returnCode = client.executeMethod(method);
        if (returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {
            System.err.println("The Post method is not implemented by this URI");
            // still consume the response body
            method.getResponseBodyAsString();
        } else if (returnCode == HttpStatus.SC_OK) {
            System.out.println("File post succeeded: " + file);
            //   System.out.println(method.getResponseBodyAsString());

            saveResponse(file, method);
        } else {
            System.err.println("File post failed: " + file);
            System.err.println("Got code: " + returnCode);
            System.err.println("response: " + method.getResponseBodyAsString());
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        method.releaseConnection();
    }
}

From source file:models.Calais.java

private JSONObject doRequest(PostMethod method) throws IOException, ParseException {
    int returnCode = client.executeMethod(method);
    JSONObject result = null;//from   ww w  .ja va2  s . c o m
    if (returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {
        System.err.println("The Post method is not implemented by this URI");
        // still consume the response body
        method.getResponseBodyAsString();
    } else if (returnCode == HttpStatus.SC_OK) {
        System.out.println("Post succeeded.");
        result = saveResponse(method);
    } else {
        System.err.println("Post failed.");
        System.err.println("Got code: " + returnCode);
        System.err.println("response: " + method.getResponseBodyAsString());
    }
    method.releaseConnection();
    return result;
}

From source file:com.cognifide.calais.OpenCalaisService.java

@SuppressWarnings("deprecation")
private String doCalaisRequest(String textBody) throws IOException {
    HttpClient client = new HttpClient();
    client.getParams().setParameter("http.useragent", "Calais Rest Client");

    PostMethod method = createPostMethod();
    method.setRequestEntity(new StringRequestEntity(textBody));

    try {//from  w w  w.j  a v a 2s  .co m
        int returnCode = client.executeMethod(method);
        if (returnCode == HttpStatus.SC_OK) {
            return getResponse(method);
        } else if (returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {
            log("The Post method is not implemented by this URI");
        } else {
            log("Got code: " + returnCode);
            log("response: " + method.getResponseBodyAsString());
        }
    } finally {
        method.releaseConnection();
    }

    return null;
}

From source file:com.gm.machine.util.CommonUtils.java

/**
 * //from   w  w w  .ja  v a  2s  .c  o m
 * ????
 * 
 * @since 2013-1-12
 * @author qingang
 * @param url
 *            ?????
 * @param remark
 *            
 * @param path
 *            ??
 * @param encoding
 *            ??
 * @throws Exception
 */
public static void createHtmlPage(String url, String remark, String path, String encoding) throws Exception {
    HttpClient client = new HttpClient();
    HttpMethod httpMethod = new PostMethod(url);

    try {
        int returnCode = client.executeMethod(httpMethod);
        if (returnCode == HttpStatus.SC_OK) {
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(httpMethod.getResponseBodyAsStream(), "ISO-8859-1"));
            String tmp = null;
            StringBuffer htmlRet = new StringBuffer();
            while ((tmp = reader.readLine()) != null) {
                htmlRet.append(tmp + "\n");
            }
            writeHtml(path,
                    Global.HMTLPAGE_CHARSET + new String(htmlRet.toString().getBytes("ISO-8859-1"), encoding),
                    encoding);
            System.out.println("??=====================??" + remark + "===" + url
                    + "===??:" + path + "===?" + getCurrentDate("yyyy-MM-dd HH:mm")
                    + "=======================");
        } else if (returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {
            System.err.println("The Post method is not implemented by this URI");
        }
    } catch (Exception e) {
        System.err.println(e);
        System.out.println("?=====================??" + remark + "===" + url
                + "===??:" + path + "===?" + getCurrentDate("yyyy-MM-dd HH:mm")
                + "=======================");
        e.printStackTrace();
        throw e;
    } finally {
        httpMethod.releaseConnection();
    }

}