类org.apache.commons.httpclient.HttpURL源码实例Demo

下面列出了怎么用org.apache.commons.httpclient.HttpURL的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: incubator-pinot   文件: ChangeTableState.java
@Override
public boolean execute()
    throws Exception {
  if (_controllerHost == null) {
    _controllerHost = NetUtil.getHostAddress();
  }

  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;
}
 
源代码2 项目: swift-k   文件: FileResourceImpl.java
/**
 * Create the davClient and authenticate with the resource. serviceContact
 * should be in the form of a url
 */
public void start() throws IllegalHostException,
        InvalidSecurityContextException, FileResourceException {
    
    ServiceContact serviceContact = getAndCheckServiceContact();
    
    try {
        
        SecurityContext securityContext = getOrCreateSecurityContext("WebDAV", serviceContact);
        
        String contact = getServiceContact().getContact().toString();
        if (!contact.startsWith("http")) {
            contact = "http://" + contact;
        }
        HttpURL hrl = new HttpURL(contact);
        PasswordAuthentication credentials = getCredentialsAsPasswordAuthentication(securityContext);
        
        String username = credentials.getUserName();
        String password = String.valueOf(credentials.getPassword());
        hrl.setUserinfo(username, password);

        davClient = new WebdavResource(hrl);
        setStarted(true);
    }
    catch (URIException ue) {
        throw new IllegalHostException(
                "Error connecting to the WebDAV server at " + serviceContact, ue);
    }
    catch (Exception e) {
        throw new IrrecoverableResourceException(e);
    }
}
 
 类方法
 同包方法