protected static String createUrl(List<NameValuePair> pairs) throws URIException{ HttpMethod method = new GetMethod("http://example.org"); method.setQueryString(pairs.toArray(new NameValuePair[]{})); return method.getURI().getEscapedURI(); }
logger.debug("About to execute '{}'", method.getURI()); } catch (URIException e) { logger.debug("{}", e.getMessage());
hostconfig = defaulthostconfig; URI uri = method.getURI(); if (hostconfig == defaulthostconfig || uri.isAbsoluteURI()) {
uri = http.getURI().toString(); } catch (URIException uriex) { throw new EsHadoopTransportException("Invalid target URI " + request, uriex);
public String getRequestUrl() { try { return httpMethod.getURI().toString(); } catch (URIException ex) { throw new IllegalStateException(ex); } }
/** * @param method * @return the http status code of the execution * @throws IOException * @throws HttpException */ private int executeMethod(HttpMethod method) throws IOException, HttpException { String host = method.getURI().getHost(); if (host != null && nonProxyHosts.contains(host.toLowerCase())) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine( "Bypassing proxy config due to nonProxyHosts for " + method.getURI().toString()); } return client.executeMethod(hostConfigNoProxy, method); } return client.executeMethod(method); }
private void warn(final String msg, final Throwable t) { try { m_log.warn(msg + this.m_httpMethod.getURI(), t); } catch (final URIException e) { } }
/** * Return the request URI */ public String getUri() { try { return method.getURI().toString(); } catch (URIException e) { } return null; // shouldn't happen }
private static String createUrl(String url, List<NameValuePair> pairs) throws URIException { HttpMethod method = new GetMethod(url); NameValuePair[] nameValuePairs = pairs.toArray(new NameValuePair[pairs.size()]); method.setQueryString(nameValuePairs); return method.getURI().getEscapedURI(); } }
protected HttpMethod formLogin(HttpClient httpClient, HttpMethod initmethod, String userName, String password) throws IOException { LOGGER.debug("Form based authentication detected"); HttpMethod logonMethod = buildLogonMethod(httpClient, initmethod); if (logonMethod == null) { LOGGER.debug("Authentication form not found at " + initmethod.getURI() + ", trying default url"); logonMethod = new PostMethod("/owa/auth/owaauth.dll"); } logonMethod = postLogonMethod(httpClient, logonMethod, password); return logonMethod; }
@Override protected HttpMethod formLogin(HttpClient httpClient, HttpMethod initmethod, String userName, String password) throws IOException { LOGGER.debug("Form based authentication detected"); HttpMethod logonMethod = buildLogonMethod(httpClient, initmethod); if (logonMethod == null) { LOGGER.debug("Authentication form not found at " + initmethod.getURI() + ", will try direct EWS access"); } else { logonMethod = postLogonMethod(httpClient, logonMethod, password); } return logonMethod; }
/** * Returns the response address.<br> * Corresponds to the IP address of the responding server. * * @return The response address. */ @Override public String getServerAddress() { try { return getHttpMethod().getURI().getHost(); } catch (URIException e) { return null; } }
public HttpUrl createHttpsGatewayUrl(String gatewayUrl) throws MalformedURLException, URIException { HttpMethod method = new GetMethod(gatewayUrl); method.setQueryString("ssl=true"); String url = method.getURI().getEscapedURI(); return new HttpUrl(url); } }
private static int executeMethod(HttpClient httpClient, HttpMethod currentMethod) throws IOException { httpClient.executeMethod(currentMethod); int status = currentMethod.getStatusCode(); if ((status == HttpStatus.SC_UNAUTHORIZED || status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) && acceptsNTLMOnly(currentMethod) && !hasNTLMorNegotiate(httpClient)) { LOGGER.debug("Received " + status + " unauthorized at " + currentMethod.getURI() + ", retrying with NTLM"); resetMethod(currentMethod); addNTLM(httpClient); status = httpClient.executeMethod(currentMethod); } return status; }
@SneakyThrows public static void prepareRPC(HttpMethod httpMethod) { val context = threadLocal.get(); if (context == null) return; val method = httpMethod.getName(); trace("RPC", method + " " + httpMethod.getURI()); httpMethod.setRequestHeader(BLACKCAT_TRACEID, context.getTraceId()); val linkId = context.getParentLinkId() + String.format(".%06d", context.getSubLinkId()); httpMethod.setRequestHeader(BLACKCAT_LINKID, linkId); }
/** * Treats the response as JSON string and performs a databinding. */ public <T> T bind(Class<T> type, BeesClient root) throws IOException { if (getCode() >= 300) throw new IOException("Failed to " + method.getName() + " : " + method.getURI() + " : code=" + getCode() + " response=" + getContent()); if (type != null && getContent() != null) { T ret = BeesClient.MAPPER.readValue(getContent(), type); if (ret instanceof CBObject) {// TODO: nested objects? ((CBObject) ret).root = root; } return ret; } return null; }
@Override public void addAuthentication(HttpMethod forMethod, HttpClient forClient) { try { forMethod.addRequestHeader("Authorization", "token " + accessToken); String url = forMethod.getURI().toString(); String separator = url.contains("?") ? "&" : "?"; url += separator + "access_token=" + getAccessToken(); forMethod.setURI(new URI(url, true)); } catch (URIException e) { throw new SourceControlException("Failed to decode/encode given URI. " + e.getMessage(), e); } }
protected void fixClientHost(HttpMethod method) { try { // update client host, workaround for Exchange 2003 mailbox with an Exchange 2007 frontend URI currentUri = method.getURI(); if (currentUri != null && currentUri.getHost() != null && currentUri.getScheme() != null) { httpClient.getHostConfiguration().setHost(currentUri.getHost(), currentUri.getPort(), currentUri.getScheme()); } } catch (URIException e) { LOGGER.warn("Unable to update http client host:" + e.getMessage(), e); } }
/** * Treats the response as JSON string and performs a databinding. */ public <T> T bind(Class<T> type, BeesClient root) throws IOException { if (getCode() >= 300) throw new IOException("Failed to " + method.getName() + " : " + method.getURI() + " : code=" + getCode() + " response=" + getContent()); if (type != null && getContent() != null) { T ret = BeesClient.MAPPER.readValue(getContent(), type); if (ret instanceof CBObject) {// TODO: nested objects? ((CBObject) ret).root = root; } return ret; } return null; }
@Override public void handleResponse(HttpMethod method) throws IOException, AGHttpException { String mimeType = getResponseMIMEType(method); if (!mimeType.equals(getRequestMIMEType())) { throw new AGHttpException("unexpected response MIME type: " + mimeType); } InputStream response = getInputStream(method); // Note: we ignore charset specified in the response. Reader reader = new InputStreamReader(response, StandardCharsets.UTF_8); try { RDFParser parser = Rio.createParser(format, vf); parser.setPreserveBNodeIDs(true); parser.setRDFHandler(rdfhandler); parser.parse(reader, method.getURI().getURI()); } catch (RDFParseException | RDFHandlerException e) { throw new AGHttpException(e); } }