org.apache.commons.httpclient.HttpURL Java Examples

The following examples show how to use org.apache.commons.httpclient.HttpURL. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChangeTableState.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #2
Source File: FileResourceImpl.java    From swift-k with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}