当前位置: 首页>>代码示例>>Java>>正文


Java HttpStatus.SC_OK属性代码示例

本文整理汇总了Java中org.apache.commons.httpclient.HttpStatus.SC_OK属性的典型用法代码示例。如果您正苦于以下问题:Java HttpStatus.SC_OK属性的具体用法?Java HttpStatus.SC_OK怎么用?Java HttpStatus.SC_OK使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.apache.commons.httpclient.HttpStatus的用法示例。


在下文中一共展示了HttpStatus.SC_OK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getData

public List<DataPoint> getData ( final String item, final String type, final Date from, final Date to, final Integer number ) throws Exception
{
    final HttpClient client = new HttpClient ();
    final HttpMethod method = new GetMethod ( this.baseUrl + "/" + URLEncoder.encode ( item, "UTF-8" ) + "/" + URLEncoder.encode ( type, "UTF-8" ) + "?from=" + URLEncoder.encode ( Utils.isoDateFormat.format ( from ), "UTF-8" ) + "&to=" + URLEncoder.encode ( Utils.isoDateFormat.format ( to ), "UTF-8" ) + "&no=" + number );
    client.getParams ().setSoTimeout ( (int)this.timeout );
    try
    {
        final int status = client.executeMethod ( method );
        if ( status != HttpStatus.SC_OK )
        {
            throw new RuntimeException ( "Method failed with error " + status + " " + method.getStatusLine () );
        }
        return Utils.fromJson ( method.getResponseBodyAsString () );
    }
    finally
    {
        method.releaseConnection ();
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:HdHttpClient.java

示例2: getUrlContent

/**
 * Retrieves the content under the given URL with username and passwort
 * authentication.
 * 
 * @param url
 *            the URL to read
 * @param username
 * @param password
 * @return the read content.
 * @throws IOException
 *             if an I/O exception occurs.
 */
private static byte[] getUrlContent(URL url, String username,
        String password) throws IOException {
    final HttpClient client = new HttpClient();

    // Set credentials:
    client.getParams().setAuthenticationPreemptive(true);
    final Credentials credentials = new UsernamePasswordCredentials(
            username, password);
    client.getState()
            .setCredentials(
                    new AuthScope(url.getHost(), url.getPort(),
                            AuthScope.ANY_REALM), credentials);

    // Retrieve content:
    final GetMethod method = new GetMethod(url.toString());
    final int status = client.executeMethod(method);
    if (status != HttpStatus.SC_OK) {
        throw new IOException("Error " + status + " while retrieving "
                + url);
    }
    return method.getResponseBody();
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:34,代码来源:BasicAuthLoader.java

示例3: doPut

public String doPut(String url, String charset, String jsonObj) {
    String resStr = null;
    HttpClient htpClient = new HttpClient();
    PutMethod putMethod = new PutMethod(url);
    putMethod.getParams().setParameter(
            HttpMethodParams.HTTP_CONTENT_CHARSET, charset);
    try {
        putMethod.setRequestEntity(new StringRequestEntity(jsonObj,
                "application/json", charset));
        int statusCode = htpClient.executeMethod(putMethod);
        if (statusCode != HttpStatus.SC_OK) {
            log.error("Method failed: " + putMethod.getStatusLine());
            return null;
        }
        byte[] responseBody = putMethod.getResponseBody();
        resStr = new String(responseBody, charset);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        putMethod.releaseConnection();
    }
    return resStr;
}
 
开发者ID:BriData,项目名称:DBus,代码行数:23,代码来源:HttpRequest.java

示例4: SecureHttpMethodResponse

public SecureHttpMethodResponse(HttpMethod method, HostConfiguration hostConfig, 
        EncryptionUtils encryptionUtils) throws AuthenticationException, IOException
{
    super(method);
    this.hostConfig = hostConfig;
    this.encryptionUtils = encryptionUtils;

    if(method.getStatusCode() == HttpStatus.SC_OK)
    {
        this.decryptedBody = encryptionUtils.decryptResponseBody(method);
        // authenticate the response
        if(!authenticate())
        {
            throw new AuthenticationException(method);
        }
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:17,代码来源:HttpClientFactory.java

示例5: downloadPacContent

private String downloadPacContent(String url) throws IOException {
	if (url == null) {
		Engine.logProxyManager.debug("(PacManager) Invalid PAC script URL: null");
		throw new IOException("Invalid PAC script URL: null");
	}

	HttpClient client = new HttpClient();
	HttpMethod method = new GetMethod(url);

	int statusCode = client.executeMethod(method);

	if (statusCode != HttpStatus.SC_OK) {
		throw new IOException("(PacManager) Method failed: " + method.getStatusLine());
	}
	
	return IOUtils.toString(method.getResponseBodyAsStream(), "UTF-8");
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:17,代码来源:PacManager.java

示例6: send

/** {@inheritDoc} */
public void send(String endpoint, SOAPMessageContext messageContext) throws SOAPException, SecurityException {
    PostMethod post = null;
    try {
        post = createPostMethod(endpoint, (HttpSOAPRequestParameters) messageContext.getSOAPRequestParameters(),
                (Envelope) messageContext.getOutboundMessage());

        int result = httpClient.executeMethod(post);
        log.debug("Received HTTP status code of {} when POSTing SOAP message to {}", result, endpoint);

        if (result == HttpStatus.SC_OK) {
            processSuccessfulResponse(post, messageContext);
        } else if (result == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
            processFaultResponse(post, messageContext);
        } else {
            throw new SOAPClientException("Received " + result + " HTTP response status code from HTTP request to "
                    + endpoint);
        }
    } catch (IOException e) {
        throw new SOAPClientException("Unable to send request to " + endpoint, e);
    } finally {
        if (post != null) {
            post.releaseConnection();
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:HttpSOAPClient.java

示例7: exists

/** {@inheritDoc} */
public boolean exists() throws ResourceException {
    HeadMethod headMethod = new HeadMethod(resourceUrl);
    headMethod.addRequestHeader("Connection", "close");

    try {
        httpClient.executeMethod(headMethod);
        if (headMethod.getStatusCode() != HttpStatus.SC_OK) {
            return false;
        }

        return true;
    } catch (IOException e) {
        throw new ResourceException("Unable to contact resource URL: " + resourceUrl, e);
    } finally {
        headMethod.releaseConnection();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:HttpResource.java

示例8: getResource

/**
 * Gets remote resource.
 * 
 * @return the remove resource
 * 
 * @throws ResourceException thrown if the resource could not be fetched
 */
protected GetMethod getResource() throws ResourceException {
    GetMethod getMethod = new GetMethod(resourceUrl);
    getMethod.addRequestHeader("Connection", "close");

    try {
        httpClient.executeMethod(getMethod);
        if (getMethod.getStatusCode() != HttpStatus.SC_OK) {
            throw new ResourceException("Unable to retrieve resource URL " + resourceUrl
                    + ", received HTTP status code " + getMethod.getStatusCode());
        }
        return getMethod;
    } catch (IOException e) {
        throw new ResourceException("Unable to contact resource URL: " + resourceUrl, e);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:HttpResource.java

示例9: doTestConnection

public FormValidation doTestConnection(
        @QueryParameter("mirrorGateAPIUrl") final String mirrorGateAPIUrl,
        @QueryParameter("mirrorgateCredentialsId") final String credentialsId)
        throws Descriptor.FormException {
    MirrorGateService testMirrorGateService = getMirrorGateService();
    if (testMirrorGateService != null) {
        MirrorGateResponse response
                = testMirrorGateService.testConnection();
        return response.getResponseCode() == HttpStatus.SC_OK
                ? FormValidation.ok("Success")
                : FormValidation.error("Failure<"
                        + response.getResponseCode() + ">");
    } else {
        return FormValidation.error("Failure");
    }
}
 
开发者ID:BBVA,项目名称:mirrorgate-jenkins-builds-collector,代码行数:16,代码来源:MirrorGatePublisher.java

示例10: main

public static void main(String[] args) throws Exception {
  if (args.length != 1)  {
      System.out.println("Usage: ChunkEncodedPost <file>");
      System.out.println("<file> - full path to a file to be posted");
      System.exit(1);
  }
  HttpClient client = new HttpClient();

  PostMethod httppost = new PostMethod("http://localhost:8080/httpclienttest/body");

  File file = new File(args[0]);
  httppost.setRequestEntity(new InputStreamRequestEntity(
      new FileInputStream(file), file.length()));

  try {
      client.executeMethod(httppost);

      if (httppost.getStatusCode() == HttpStatus.SC_OK) {
          System.out.println(httppost.getResponseBodyAsString());
      } else {
        System.out.println("Unexpected failure: " + httppost.getStatusLine().toString());
      }
  } finally {
      httppost.releaseConnection();
  }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:26,代码来源:UnbufferedPost.java

示例11: downloadToFile

@Override
public File downloadToFile(String key) throws Exception {
  String ip = ips[rand.nextInt(ips.length)];
  String url = String.format(urlPattern, ip, key);
  LOG.debug("Download url:" + url);
  try {
    GetMethod get = new GetMethod(url);
    int code = client.executeMethod(get);
    if (code != HttpStatus.SC_OK) {
      throw new IOException("Failed to download file from url " + url);
    }
    File file = SourceUtil.getRandomFile();
    OutputStream outputStream = new FileOutputStream(file);
    IOUtils.copy(get.getResponseBodyAsStream(), outputStream);
    outputStream.flush();
    outputStream.close();
    return file;
  } catch (Exception e) {
    throw new IOException("Failed to download file from url " + url, e);
  }
}
 
开发者ID:XiaoMi,项目名称:galaxy-fds-migration-tool,代码行数:21,代码来源:HTTPSource.java

示例12: getCurrentGeoLocation

@Override
public GeoLocation getCurrentGeoLocation() throws Exception {
    HttpClient httpClient = component.getHttpClient();
    GetMethod getMethod = new GetMethod("http://freegeoip.io/json/");
    try {
        int statusCode = httpClient.executeMethod(getMethod);
        if (statusCode != HttpStatus.SC_OK) {
            throw new IllegalStateException("Got the unexpected http-status '" + getMethod.getStatusLine() + "' for the geolocation");
        }
        String geoLocation = component.getCamelContext().getTypeConverter().mandatoryConvertTo(String.class, getMethod.getResponseBodyAsStream());
        if (isEmpty(geoLocation)) {
            throw new IllegalStateException("Got the unexpected value '" + geoLocation + "' for the geolocation");
        }

        ObjectMapper mapper = new ObjectMapper();
        JsonNode node = mapper.readValue(geoLocation, JsonNode.class);
        JsonNode latitudeNode = notNull(node.get("latitude"), "latitude");
        JsonNode longitudeNode = notNull(node.get("longitude"), "longitude");

        return new GeoLocation(longitudeNode.asText(), latitudeNode.asText());
    } finally {
        getMethod.releaseConnection();
    }

}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:FreeGeoIpGeoLocationProvider.java

示例13: get

public void  get() throws UnsupportedEncodingException {
    HttpClient client = new HttpClient();
    String APIKEY = "4b441cb500f431adc6cc0cb650b4a5d0";
    String INFO =new URLCodec().encode("who are you","utf-8");
    String requesturl = "http://www.tuling123.com/openapi/api?key=" + APIKEY + "&info=" + INFO;
    GetMethod getMethod = new GetMethod(requesturl);
    try {
        int stat = client.executeMethod(getMethod);
        if (stat != HttpStatus.SC_OK)
           log.error("get失败!");
        byte[] responseBody = getMethod.getResponseBody();
        String content=new String(responseBody ,"utf-8");
        log.info(content);
    }catch (Exception e){
       log.error(""+e.getLocalizedMessage());
    }finally {
        getMethod.releaseConnection();
    }
}
 
开发者ID:ggj2010,项目名称:javabase,代码行数:19,代码来源:OldHttpClientApi.java

示例14: save

public static void save(String record) {
HttpClient client = new HttpClient();
 	PostMethod post = new PostMethod(url); 
 	post.addParameter("action", "save");
 	post.addParameter("record", record);
 	try{
  	int status = client.executeMethod(post);
  	if (status == HttpStatus.SC_OK){	  	
  		String response = post.getResponseBodyAsString();
  		System.out.println(response);
  	}else{
  		System.out.println(status);
  	}
 	}catch(Exception ex){
 		ex.printStackTrace();
 	}
 }
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:17,代码来源:Test.java

示例15: interactive

public static String interactive(String url, String queryString) throws Exception {
		String response = null;
		HttpClient client = new HttpClient();
		HttpMethod method = new GetMethod(url);
		try {
			// if (StringUtils.isNotBlank(queryString))
			if (queryString != null && !queryString.equals(""))
				method.setQueryString(URIUtil.encodeQuery(queryString,"GBK"));
			client.executeMethod(method);
			if (method.getStatusCode() == HttpStatus.SC_OK) {
//				response = method.getResponseBodyAsString();
				InputStream input = method.getResponseBodyAsStream();
				response = Ryt.readStream(input);
				response=transCharCode(response);//对响应xml转码
			}
		} catch (Exception e) {
			logger.error(e.getMessage());
			throw new Exception("请求银行接口异常!");
		} finally {
			method.releaseConnection();
		}
		throwRequestException(response);
		return response;
	}
 
开发者ID:wufeisoft,项目名称:ryf_mms2,代码行数:24,代码来源:BOCOMSettleCore.java


注:本文中的org.apache.commons.httpclient.HttpStatus.SC_OK属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。