Refine search
/** * Constructor specifying a URI. * It is responsibility of the caller to ensure that URI elements * (path & query parameters) are properly encoded (URL safe). * * @param uri either an absolute or relative URI. The URI is expected * to be URL-encoded * * @throws IllegalArgumentException when URI is invalid * @throws IllegalStateException when protocol of the absolute URI is not recognised */ public HttpMethodBase(String uri) throws IllegalArgumentException, IllegalStateException { try { // create a URI and allow for null/empty uri values if (uri == null || uri.equals("")) { uri = "/"; } String charset = getParams().getUriCharset(); setURI(new URI(uri, true, charset)); } catch (URIException e) { throw new IllegalArgumentException("Invalid uri '" + uri + "': " + e.getMessage() ); } }
@Override public void readObjectData(Kryo kryo, ByteBuffer buffer) { try { parseUriReference(StringSerializer.get(buffer), true); } catch (URIException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
throw new URIException("URI-Reference required"); if (validate(firstDelimiter, delims)) { if (length >= 2) { char[] lastDelimiter = { tmp.charAt(length - 1) }; if (validate(lastDelimiter, delims)) { tmp = tmp.substring(1, length - 1); length = length - 2; int at = indexFirstOf(tmp, isStartedFromPath ? "/?#" : ":/?#", from); if (at == -1) { at = 0; _scheme = target; } else { throw new URIException("incorrect scheme"); _query = tmp.substring(at + 1, next).toCharArray(); if (!validate(_query, uric)) { throw new URIException("Invalid query");
@Override public URI getUri() throws URISyntaxException { try { return new URI(postMethod.getURI().toString()); } catch (URIException ex) { throw new URISyntaxException("", ex.getMessage()); } }
private String normalize(String uri) throws URISyntaxException { try { URI normalized = new URI(uri, DefaultHTTPClient.isUrlEncoded(uri)); normalized.normalize(); return normalized.toString(); } catch (URIException e) { LOG.warn("Invalid uri: {}", uri); LOG.error("Can not convert URL", e); throw new URISyntaxException(uri, e.getMessage()); } }
protected void resetClientForRedirect() throws XmlRpcException { //get the location header to find out where to redirect to Header locationHeader = method.getResponseHeader("location"); if (locationHeader == null) { throw new XmlRpcException("Invalid redirect: Missing location header"); } String location = locationHeader.getValue(); URI redirectUri = null; URI currentUri = null; try { currentUri = method.getURI(); String charset = currentUri.getProtocolCharset(); redirectUri = new URI(location, true, charset); method.setURI(redirectUri); } catch (URIException ex) { throw new XmlRpcException(ex.getMessage(), ex); } //And finally invalidate the actual authentication scheme method.getHostAuthState().invalidate(); }
@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); } }
/** * Log a URIException from deep inside other components to the crawl's * shared log. * * @param e URIException encountered * @param u CrawlURI where problem occurred * @param l String which could not be interpreted as URI without exception */ public void logUriError(URIException e, UURI u, CharSequence l) { Object[] array = {u, l}; uriErrors.log(Level.INFO, e.getMessage(), array); }
@Override public HttpMessage handleShortcut(HttpMessage msg) throws ApiException { try { if (msg.getRequestHeader().getURI().getPath().startsWith("/" + OTHER_PROXY_PAC)) { return this.handleApiOther(msg, OTHER_PROXY_PAC, null); } else if (msg.getRequestHeader().getURI().getPath().startsWith("/" + OTHER_SET_PROXY)) { JSONObject params = new JSONObject(); params.put(PARAM_PROXY_DETAILS, msg.getRequestBody().toString()); return this.handleApiOther(msg, OTHER_SET_PROXY, params); } else if (msg.getRequestHeader().getURI().getPath().startsWith("/" + OTHER_SCRIPT_JS)) { return this.handleApiOther(msg, OTHER_SCRIPT_JS, null); } } catch (URIException e) { logger.error(e.getMessage(), e); throw new ApiException(ApiException.Type.INTERNAL_ERROR); } throw new ApiException (ApiException.Type.URL_NOT_FOUND, msg.getRequestHeader().getURI().toString()); }
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); } }
throw new URIException(URIException.PARSING, "scheme required"); if (validate(s, URI.scheme)) { throw new URIException(URIException.PARSING, "incorrect scheme"); _opaque = encode(schemeSpecificPart, allowed_opaque_part, getProtocolCharset());
/** * Set the raw-escaped query. * * @param escapedQuery the raw-escaped query * @throws URIException escaped query not valid */ public void setRawQuery(char[] escapedQuery) throws URIException { if (escapedQuery == null || escapedQuery.length == 0) { _query = escapedQuery; setURI(); return; } // remove the fragment identifier escapedQuery = removeFragmentIdentifier(escapedQuery); if (!validate(escapedQuery, query)) { throw new URIException(URIException.ESCAPING, "escaped query not valid"); } _query = escapedQuery; setURI(); }
history.setRequestURL(HttpUtilities.getURL(httpMethodProxyRequest.getURI().toString())); history.setRequestParams(httpMethodProxyRequest.getQueryString() == null ? "" : httpMethodProxyRequest.getQueryString()); e.printStackTrace();
public URI getURI() { try { return URI.create(this.httpMethod.getURI().getEscapedURI()); } catch (URIException ex) { throw new IllegalStateException("Could not get HttpMethod URI: " + ex.getMessage(), ex); } }
/** * Verify the valid class use for construction. * * @throws URIException the wrong scheme use */ protected void checkValid() throws URIException { // could be explicit protocol or undefined. if (!(equals(_scheme, DEFAULT_SCHEME) || _scheme == null)) { throw new URIException(URIException.PARSING, "wrong class use"); } }
/** * Return if this request header is a image request basing on the path * suffix. */ @Override public boolean isImage() { if (getURI() == null) { return false; } try { // ZAP: prevents a NullPointerException when no path exists final String path = getURI().getPath(); if (path != null) { return (patternImage.matcher(path).find()); } } catch (URIException e) { log.error(e.getMessage(), e); } return false; }
throw new URIException(URIException.PARSING, "base URI required"); this._opaque = relative._opaque; this._fragment = relative._fragment; this.setURI(); return; this._query = base._query; } else { this._path = resolvePath(base._path, relative._path); this._fragment = relative._fragment; this.setURI();
protected static String getServerKey(CrawlURI uri) { try { return CrawlServer.getServerKey(uri.getUURI()); } catch (URIException e) { logger.log(Level.SEVERE, e.toString() + ": " + uri, e); return null; } } }