List of usage examples for java.net URISyntaxException getMessage
public String getMessage()
From source file:org.dasein.cloud.tier3.APIHandler.java
private void get(@Nonnull APIResponse apiResponse, @Nullable String paginationId, final int page, final @Nonnull String resource, final @Nullable String id, final @Nullable NameValuePair... parameters) throws InternalException, CloudException { if (logger.isTraceEnabled()) { logger.trace("ENTER - " + APIHandler.class.getName() + ".get(" + paginationId + "," + page + "," + resource + "," + id + "," + Arrays.toString(parameters) + ")"); }/* ww w. ja v a 2 s . co m*/ try { NameValuePair[] params; if (parameters != null && paginationId != null) { if (parameters.length < 1) { params = new NameValuePair[] { new BasicNameValuePair("requestPaginationId", paginationId), new BasicNameValuePair("requestPage", String.valueOf(page)) }; } else { params = new NameValuePair[parameters.length + 2]; int i = 0; for (; i < parameters.length; i++) { params[i] = parameters[i]; } params[i++] = new BasicNameValuePair("requestPaginationId", paginationId); params[i] = new BasicNameValuePair("requestPage", String.valueOf(page)); } } else { params = parameters; } String target = getEndpoint(resource, id, params); if (wire.isDebugEnabled()) { wire.debug(""); wire.debug(">>> [GET (" + (new Date()) + ")] -> " + target + " >--------------------------------------------------------------------------------------"); } try { URI uri; try { uri = new URI(target); } catch (URISyntaxException e) { throw new ConfigurationException(e); } HttpClient client = getClient(uri); try { ProviderContext ctx = provider.getContext(); if (ctx == null) { throw new NoContextException(); } HttpGet get = new HttpGet(target); get.addHeader("Accept", "application/json"); get.addHeader("Content-Type", "application/json"); get.addHeader("Cookie", provider.logon()); if (wire.isDebugEnabled()) { wire.debug(get.getRequestLine().toString()); for (Header header : get.getAllHeaders()) { wire.debug(header.getName() + ": " + header.getValue()); } wire.debug(""); } HttpResponse response; StatusLine status; try { APITrace.trace(provider, "GET " + resource); response = client.execute(get); status = response.getStatusLine(); } catch (IOException e) { logger.error("Failed to execute HTTP request due to a cloud I/O error: " + e.getMessage()); throw new CloudException(e); } if (logger.isDebugEnabled()) { logger.debug("HTTP Status " + status); } Header[] headers = response.getAllHeaders(); if (wire.isDebugEnabled()) { wire.debug(status.toString()); for (Header h : headers) { if (h.getValue() != null) { wire.debug(h.getName() + ": " + h.getValue().trim()); } else { wire.debug(h.getName() + ":"); } } wire.debug(""); } if (status.getStatusCode() == NOT_FOUND) { apiResponse.receive(); return; } if (status.getStatusCode() != OK) { logger.error("Expected OK for GET request, got " + status.getStatusCode()); HttpEntity entity = response.getEntity(); String body; if (entity == null) { throw new Tier3Exception(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(), status.getReasonPhrase()); } try { body = EntityUtils.toString(entity); } catch (IOException e) { throw new Tier3Exception(e); } if (wire.isDebugEnabled()) { wire.debug(body); } wire.debug(""); apiResponse.receive(new Tier3Exception(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(), body)); } else { HttpEntity entity = response.getEntity(); if (entity == null) { throw new CloudException("No entity was returned from an HTTP GET"); } boolean complete; Header h = response.getFirstHeader("x-es-pagination"); final String pid; if (h != null) { pid = h.getValue(); if (pid != null) { Header last = response.getFirstHeader("x-es-last-page"); complete = last != null && last.getValue().equalsIgnoreCase("true"); } else { complete = true; } } else { pid = null; complete = true; } if (entity.getContentType() == null || entity.getContentType().getValue().contains("json")) { String body; try { body = EntityUtils.toString(entity); } catch (IOException e) { throw new Tier3Exception(e); } if (wire.isDebugEnabled()) { wire.debug(body); } wire.debug(""); try { apiResponse.receive(status.getStatusCode(), new JSONObject(body), complete); } catch (JSONException e) { throw new CloudException(e); } } else { try { apiResponse.receive(status.getStatusCode(), entity.getContent()); } catch (IOException e) { throw new CloudException(e); } } if (!complete) { APIResponse r = new APIResponse(); apiResponse.setNext(r); get(r, pid, page + 1, resource, id, parameters); } } } finally { try { client.getConnectionManager().shutdown(); } catch (Throwable ignore) { } } } finally { if (wire.isDebugEnabled()) { wire.debug("<<< [GET (" + (new Date()) + ")] -> " + target + " <--------------------------------------------------------------------------------------"); wire.debug(""); } } } finally { if (logger.isTraceEnabled()) { logger.trace("EXIT - " + APIHandler.class.getName() + ".get()"); } } }
From source file:io.pyd.synchro.SyncJob.java
/** * Download remote file content for node * /* www . j av a 2s. c o m*/ * @param node * @param targetFile * @throws SynchroOperationException * @throws SynchroFileOperationException * @throws InterruptedException */ protected void synchronousDL(Node node, File targetFile) throws SynchroOperationException, SynchroFileOperationException, InterruptedException { URI uri = null; try { uri = AjxpAPI.getInstance().getDownloadUri(node.getPath(true)); } catch (URISyntaxException e) { throw new SynchroOperationException("Wrong URI Syntax: " + e.getMessage(), e); } this.uriContentToFile(uri, targetFile, null); }
From source file:org.dasein.cloud.cloudsigma.CloudSigmaMethod.java
public @Nullable String putString(@Nonnull String resource, @Nonnull String body) throws InternalException, CloudException { if (logger.isTraceEnabled()) { logger.trace("ENTER - " + CloudSigma.class.getName() + ".putString(" + resource + "," + body + ")"); }// w w w .j a v a2 s . c o m try { String target = getEndpoint(resource); if (wire.isDebugEnabled()) { wire.debug(""); wire.debug(">>> [PUT (" + (new Date()) + ")] -> " + target + " >--------------------------------------------------------------------------------------"); } try { URI uri; try { uri = new URI(target); } catch (URISyntaxException e) { throw new CloudSigmaConfigurationException(e); } HttpClient client = getClient(uri); try { ProviderContext ctx = provider.getContext(); if (ctx == null) { throw new NoContextException(); } HttpPut put = new HttpPut(target); String auth; try { String userName = new String(ctx.getAccessPublic(), "utf-8"); String password = new String(ctx.getAccessPrivate(), "utf-8"); auth = new String(Base64.encodeBase64((userName + ":" + password).getBytes())); } catch (UnsupportedEncodingException e) { throw new InternalException(e); } //dmayne 20130218: add new JSON headers put.addHeader("Host", uri.getHost()); put.addHeader("Content-Type", "application/json; charset=utf-8"); put.addHeader("Accept", "application/json"); put.addHeader("Authorization", "Basic " + auth); try { put.setEntity(new StringEntity(body, "utf-8")); } catch (UnsupportedEncodingException e) { logger.error("Unsupported encoding UTF-8: " + e.getMessage()); throw new InternalException(e); } if (wire.isDebugEnabled()) { wire.debug(put.getRequestLine().toString()); for (Header header : put.getAllHeaders()) { wire.debug(header.getName() + ": " + header.getValue()); } wire.debug(""); wire.debug(body); wire.debug(""); } HttpResponse response; StatusLine status; try { response = client.execute(put); status = response.getStatusLine(); } catch (IOException e) { logger.error("Failed to execute HTTP request due to a cloud I/O error: " + e.getMessage()); throw new CloudException(e); } if (logger.isDebugEnabled()) { logger.debug("HTTP Status " + status); } Header[] headers = response.getAllHeaders(); if (wire.isDebugEnabled()) { wire.debug(status.toString()); for (Header h : headers) { if (h.getValue() != null) { wire.debug(h.getName() + ": " + h.getValue().trim()); } else { wire.debug(h.getName() + ":"); } } wire.debug(""); } if (status.getStatusCode() == NOT_FOUND) { return null; } if (status.getStatusCode() != OK && status.getStatusCode() != NO_CONTENT && status.getStatusCode() != CREATED && status.getStatusCode() != ACCEPTED) { logger.error("Expected OK for PUT request, got " + status.getStatusCode()); HttpEntity entity = response.getEntity(); if (entity == null) { throw new CloudSigmaException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(), status.getReasonPhrase()); } try { body = EntityUtils.toString(entity); } catch (IOException e) { throw new CloudSigmaException(e); } if (wire.isDebugEnabled()) { wire.debug(body); } wire.debug(""); throw new CloudSigmaException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(), body); } else { HttpEntity entity = response.getEntity(); if (entity == null) { return ""; } try { body = EntityUtils.toString(entity); } catch (IOException e) { throw new CloudSigmaException(e); } if (wire.isDebugEnabled()) { wire.debug(body); } wire.debug(""); return body; } } finally { try { client.getConnectionManager().shutdown(); } catch (Throwable ignore) { } } } finally { if (wire.isDebugEnabled()) { wire.debug("<<< [PUT (" + (new Date()) + ")] -> " + target + " <--------------------------------------------------------------------------------------"); wire.debug(""); } } } finally { if (logger.isTraceEnabled()) { logger.trace("EXIT - " + CloudSigma.class.getName() + ".putString()"); } } }
From source file:org.dasein.cloud.cloudsigma.CloudSigmaMethod.java
public @Nullable String postString(@Nonnull String resource, @Nonnull String body) throws InternalException, CloudException { if (logger.isTraceEnabled()) { logger.trace("ENTER - " + CloudSigma.class.getName() + ".postString(" + resource + "," + body + ")"); }/*from w ww.j a v a 2s. c o m*/ try { String target = getEndpoint(resource); if (wire.isDebugEnabled()) { wire.debug(""); wire.debug(">>> [POST (" + (new Date()) + ")] -> " + target + " >--------------------------------------------------------------------------------------"); } try { URI uri; try { uri = new URI(target); } catch (URISyntaxException e) { throw new CloudSigmaConfigurationException(e); } HttpClient client = getClient(uri); try { ProviderContext ctx = provider.getContext(); if (ctx == null) { throw new NoContextException(); } HttpPost post = new HttpPost(target); String auth; try { String userName = new String(ctx.getAccessPublic(), "utf-8"); String password = new String(ctx.getAccessPrivate(), "utf-8"); auth = new String(Base64.encodeBase64((userName + ":" + password).getBytes())); } catch (UnsupportedEncodingException e) { throw new InternalException(e); } //dmayne 20130218: add new JSON headers post.addHeader("Host", uri.getHost()); post.addHeader("Content-Type", "application/json; charset=utf-8"); post.addHeader("Accept", "application/json"); post.addHeader("Authorization", "Basic " + auth); try { post.setEntity(new StringEntity(body, "utf-8")); } catch (UnsupportedEncodingException e) { logger.error("Unsupported encoding UTF-8: " + e.getMessage()); throw new InternalException(e); } if (wire.isDebugEnabled()) { wire.debug(post.getRequestLine().toString()); for (Header header : post.getAllHeaders()) { wire.debug(header.getName() + ": " + header.getValue()); } wire.debug(""); wire.debug(body); wire.debug(""); } HttpResponse response; StatusLine status; try { response = client.execute(post); status = response.getStatusLine(); } catch (IOException e) { logger.error("Failed to execute HTTP request due to a cloud I/O error: " + e.getMessage()); throw new CloudException(e); } if (logger.isDebugEnabled()) { logger.debug("HTTP Status " + status); } Header[] headers = response.getAllHeaders(); if (wire.isDebugEnabled()) { wire.debug(status.toString()); for (Header h : headers) { if (h.getValue() != null) { wire.debug(h.getName() + ": " + h.getValue().trim()); } else { wire.debug(h.getName() + ":"); } } wire.debug(""); } if (status.getStatusCode() == NOT_FOUND) { return null; } //dmayne 20130227: creating server returns accepted (202) response if (status.getStatusCode() != OK && status.getStatusCode() != NO_CONTENT && status.getStatusCode() != CREATED && status.getStatusCode() != ACCEPTED) { logger.error("Expected OK for POST request, got " + status.getStatusCode()); HttpEntity entity = response.getEntity(); if (entity == null) { throw new CloudSigmaException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(), status.getReasonPhrase()); } try { body = EntityUtils.toString(entity); } catch (IOException e) { throw new CloudSigmaException(e); } if (wire.isDebugEnabled()) { wire.debug(body); } wire.debug(""); throw new CloudSigmaException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(), body); } else { HttpEntity entity = response.getEntity(); if (entity == null) { return ""; } try { body = EntityUtils.toString(entity); } catch (IOException e) { throw new CloudSigmaException(e); } if (wire.isDebugEnabled()) { wire.debug(body); } wire.debug(""); return body; } } finally { try { client.getConnectionManager().shutdown(); } catch (Throwable ignore) { } } } finally { if (wire.isDebugEnabled()) { wire.debug("<<< [POST (" + (new Date()) + ")] -> " + target + " <--------------------------------------------------------------------------------------"); wire.debug(""); } } } finally { if (logger.isTraceEnabled()) { logger.trace("EXIT - " + CloudSigma.class.getName() + ".postString()"); } } }
From source file:org.dasein.cloud.skeleton.RESTMethod.java
public @Nonnull APIResponse put(@Nonnull String resource, @Nonnull String id, @Nonnull String json) throws InternalException, CloudException { if (logger.isTraceEnabled()) { logger.trace(//w w w.j ava 2s . c o m "ENTER - " + RESTMethod.class.getName() + ".put(" + resource + "," + id + "," + json + ")"); } try { String target = getEndpoint(resource, id, null); if (wire.isDebugEnabled()) { wire.debug(""); wire.debug(">>> [PUT (" + (new Date()) + ")] -> " + target + " >--------------------------------------------------------------------------------------"); } try { URI uri; try { uri = new URI(target); } catch (URISyntaxException e) { throw new ConfigurationException(e); } HttpClient client = getClient(uri); try { ProviderContext ctx = provider.getContext(); if (ctx == null) { throw new NoContextException(); } HttpPut put = new HttpPut(target); long timestamp = System.currentTimeMillis(); String signature = getSignature(ctx.getAccessPublic(), ctx.getAccessPrivate(), "PUT", resource, id, timestamp); try { put.addHeader(ACCESS_KEY_HEADER, new String(ctx.getAccessPublic(), "utf-8")); } catch (UnsupportedEncodingException e) { throw new InternalException(e); } put.addHeader("Accept", "application/json"); put.addHeader(SIGNATURE_HEADER, signature); put.addHeader(VERSION_HEADER, VERSION); put.addHeader("Content-type", "application/json;charset=utf-8"); try { put.setEntity(new StringEntity(json, "utf-8")); } catch (UnsupportedEncodingException e) { logger.error("Unsupported encoding UTF-8: " + e.getMessage()); throw new InternalException(e); } if (wire.isDebugEnabled()) { wire.debug(put.getRequestLine().toString()); for (Header header : put.getAllHeaders()) { wire.debug(header.getName() + ": " + header.getValue()); } wire.debug(""); wire.debug(json); wire.debug(""); } HttpResponse response; StatusLine status; try { APITrace.trace(provider, "PUT " + resource); response = client.execute(put); status = response.getStatusLine(); } catch (IOException e) { logger.error("Failed to execute HTTP request due to a cloud I/O error: " + e.getMessage()); throw new CloudException(e); } if (logger.isDebugEnabled()) { logger.debug("HTTP Status " + status); } Header[] headers = response.getAllHeaders(); if (wire.isDebugEnabled()) { wire.debug(status.toString()); for (Header h : headers) { if (h.getValue() != null) { wire.debug(h.getName() + ": " + h.getValue().trim()); } else { wire.debug(h.getName() + ":"); } } wire.debug(""); } if (status.getStatusCode() == NOT_FOUND || status.getStatusCode() == NO_CONTENT) { APIResponse r = new APIResponse(); r.receive(); return r; } if (status.getStatusCode() != ACCEPTED) { logger.error( "Expected ACCEPTED or CREATED for POST request, got " + status.getStatusCode()); HttpEntity entity = response.getEntity(); if (entity == null) { throw new CloudProviderException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(), status.getReasonPhrase()); } try { json = EntityUtils.toString(entity); } catch (IOException e) { throw new CloudProviderException(e); } if (wire.isDebugEnabled()) { wire.debug(json); } wire.debug(""); throw new CloudProviderException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(), json); } else { HttpEntity entity = response.getEntity(); if (entity == null) { throw new CloudException("No response to the PUT"); } try { json = EntityUtils.toString(entity); } catch (IOException e) { throw new CloudProviderException(e); } if (wire.isDebugEnabled()) { wire.debug(json); } wire.debug(""); APIResponse r = new APIResponse(); try { r.receive(status.getStatusCode(), new JSONObject(json), true); } catch (JSONException e) { throw new CloudException(e); } return r; } } finally { try { client.getConnectionManager().shutdown(); } catch (Throwable ignore) { } } } finally { if (wire.isDebugEnabled()) { wire.debug("<<< [PUT (" + (new Date()) + ")] -> " + target + " <--------------------------------------------------------------------------------------"); wire.debug(""); } } } finally { if (logger.isTraceEnabled()) { logger.trace("EXIT - " + RESTMethod.class.getName() + ".put()"); } } }
From source file:org.dasein.cloud.skeleton.RESTMethod.java
public @Nonnull APIResponse post(@Nonnull String resource, @Nonnull String json) throws InternalException, CloudException { if (logger.isTraceEnabled()) { logger.trace("ENTER - " + RESTMethod.class.getName() + ".post(" + resource + "," + json + ")"); }/* w w w. j a v a 2 s . com*/ try { String target = getEndpoint(resource, null); if (wire.isDebugEnabled()) { wire.debug(""); wire.debug(">>> [POST (" + (new Date()) + ")] -> " + target + " >--------------------------------------------------------------------------------------"); } try { URI uri; try { uri = new URI(target); } catch (URISyntaxException e) { throw new ConfigurationException(e); } HttpClient client = getClient(uri); try { ProviderContext ctx = provider.getContext(); if (ctx == null) { throw new NoContextException(); } HttpPost post = new HttpPost(target); long timestamp = System.currentTimeMillis(); String signature = getSignature(ctx.getAccessPublic(), ctx.getAccessPrivate(), "POST", resource, null, timestamp); try { post.addHeader(ACCESS_KEY_HEADER, new String(ctx.getAccessPublic(), "utf-8")); } catch (UnsupportedEncodingException e) { throw new InternalException(e); } post.addHeader("Accept", "application/json"); post.addHeader(SIGNATURE_HEADER, signature); post.addHeader(VERSION_HEADER, VERSION); post.addHeader("Content-type", "application/json;charset=utf-8"); try { post.setEntity(new StringEntity(json, "utf-8")); } catch (UnsupportedEncodingException e) { logger.error("Unsupported encoding UTF-8: " + e.getMessage()); throw new InternalException(e); } if (wire.isDebugEnabled()) { wire.debug(post.getRequestLine().toString()); for (Header header : post.getAllHeaders()) { wire.debug(header.getName() + ": " + header.getValue()); } wire.debug(""); wire.debug(json); wire.debug(""); } HttpResponse response; StatusLine status; try { APITrace.trace(provider, "POST " + resource); response = client.execute(post); status = response.getStatusLine(); } catch (IOException e) { logger.error("Failed to execute HTTP request due to a cloud I/O error: " + e.getMessage()); throw new CloudException(e); } if (logger.isDebugEnabled()) { logger.debug("HTTP Status " + status); } Header[] headers = response.getAllHeaders(); if (wire.isDebugEnabled()) { wire.debug(status.toString()); for (Header h : headers) { if (h.getValue() != null) { wire.debug(h.getName() + ": " + h.getValue().trim()); } else { wire.debug(h.getName() + ":"); } } wire.debug(""); } if (status.getStatusCode() == NOT_FOUND) { throw new CloudException("No such endpoint: " + target); } if (status.getStatusCode() != ACCEPTED && status.getStatusCode() != CREATED) { logger.error( "Expected ACCEPTED or CREATED for POST request, got " + status.getStatusCode()); HttpEntity entity = response.getEntity(); if (entity == null) { throw new CloudProviderException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(), status.getReasonPhrase()); } try { json = EntityUtils.toString(entity); } catch (IOException e) { throw new CloudProviderException(e); } if (wire.isDebugEnabled()) { wire.debug(json); } wire.debug(""); throw new CloudProviderException(CloudErrorType.GENERAL, status.getStatusCode(), status.getReasonPhrase(), json); } else { HttpEntity entity = response.getEntity(); if (entity == null) { throw new CloudException("No response to the POST"); } try { json = EntityUtils.toString(entity); } catch (IOException e) { throw new CloudProviderException(e); } if (wire.isDebugEnabled()) { wire.debug(json); } wire.debug(""); APIResponse r = new APIResponse(); try { r.receive(status.getStatusCode(), new JSONObject(json), true); } catch (JSONException e) { throw new CloudException(e); } return r; } } finally { try { client.getConnectionManager().shutdown(); } catch (Throwable ignore) { } } } finally { if (wire.isDebugEnabled()) { wire.debug("<<< [POST (" + (new Date()) + ")] -> " + target + " <--------------------------------------------------------------------------------------"); wire.debug(""); } } } finally { if (logger.isTraceEnabled()) { logger.trace("EXIT - " + RESTMethod.class.getName() + ".post()"); } } }
From source file:io.pyd.synchro.SyncJob.java
/** * Update node during synchro/*from w w w .j a v a 2s .c o m*/ * * @param node * @param targetFile * @param remoteNode * @throws SynchroOperationException * @throws SynchroFileOperationException * @throws InterruptedException */ protected void updateNode(Node node, File targetFile, Node remoteNode) throws SynchroOperationException, SynchroFileOperationException, InterruptedException { if (targetFile.exists() && getCoreManager().getRdiffProc() != null && getCoreManager().getRdiffProc().rdiffEnabled()) { // Compute signature File sigFile = tmpFileName(targetFile, "sig"); File delta = tmpFileName(targetFile, "delta"); RdiffProcessor proc = getCoreManager().getRdiffProc(); proc.signature(targetFile, sigFile); // Post it to the server to retrieve delta, logChange(getMessage("job_log_downdelta"), targetFile.getName()); URI uri = null; try { uri = AjxpAPI.getInstance().getFilehashDeltaUri(node); } catch (URISyntaxException e) { throw new SynchroOperationException("URI Syntax error: " + e.getMessage(), e); } this.uriContentToFile(uri, delta, sigFile); sigFile.delete(); // apply patch to a tmp version File patched = new File(targetFile.getParent(), targetFile.getName() + ".patched"); if (delta.length() > 0) { proc.patch(targetFile, delta, patched); } if (!patched.exists()) { this.synchronousDL(node, targetFile); return; } delta.delete(); // check md5 if (remoteNode != null && remoteNode.getPropertyValue("md5") != null && remoteNode.getPropertyValue("md5").equals(SyncJob.computeMD5(patched))) { targetFile.delete(); patched.renameTo(targetFile); } else { // There is a doubt, re-download whole file! patched.delete(); this.synchronousDL(node, targetFile); } } else { this.synchronousDL(node, targetFile); } }
From source file:czd.lib.network.AsyncHttpClient.java
/** * Simple interface method, to enable or disable redirects. If you set manually RedirectHandler * on underlying HttpClient, effects of this method will be canceled. * * @param enableRedirects boolean//from w ww . j av a2s .c om */ public void setEnableRedirects(final boolean enableRedirects) { if (enableRedirects) { httpClient.setRedirectHandler(new DefaultRedirectHandler() { @Override public boolean isRedirectRequested(HttpResponse response, HttpContext context) { if (response == null) { throw new IllegalArgumentException("HTTP response may not be null"); } int statusCode = response.getStatusLine().getStatusCode(); switch (statusCode) { case HttpStatus.SC_MOVED_TEMPORARILY: case HttpStatus.SC_MOVED_PERMANENTLY: case HttpStatus.SC_SEE_OTHER: case HttpStatus.SC_TEMPORARY_REDIRECT: return true; default: return false; } } @Override public URI getLocationURI(HttpResponse response, HttpContext context) throws ProtocolException { if (response == null) { throw new IllegalArgumentException("HTTP response may not be null"); } //get the location header to find out where to redirect to Header locationHeader = response.getFirstHeader("location"); if (locationHeader == null) { // got a redirect response, but no location header throw new ProtocolException("Received redirect response " + response.getStatusLine() + " but no location header"); } //HERE IS THE MODIFIED LINE OF CODE String location = locationHeader.getValue().replaceAll(" ", "%20"); URI uri; try { uri = new URI(location); } catch (URISyntaxException ex) { throw new ProtocolException("Invalid redirect URI: " + location, ex); } HttpParams params = response.getParams(); // rfc2616 demands the location value be a complete URI // Location = "Location" ":" absoluteURI if (!uri.isAbsolute()) { if (params.isParameterTrue(ClientPNames.REJECT_RELATIVE_REDIRECT)) { throw new ProtocolException("Relative redirect location '" + uri + "' not allowed"); } // Adjust location URI HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); if (target == null) { throw new IllegalStateException("Target host not available " + "in the HTTP context"); } HttpRequest request = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); try { URI requestURI = new URI(request.getRequestLine().getUri()); URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, true); uri = URIUtils.resolve(absoluteRequestURI, uri); } catch (URISyntaxException ex) { throw new ProtocolException(ex.getMessage(), ex); } } if (params.isParameterFalse(ClientPNames.ALLOW_CIRCULAR_REDIRECTS)) { RedirectLocations redirectLocations = (RedirectLocations) context .getAttribute("http.protocol.redirect-locations"); if (redirectLocations == null) { redirectLocations = new RedirectLocations(); context.setAttribute("http.protocol.redirect-locations", redirectLocations); } URI redirectURI; if (uri.getFragment() != null) { try { HttpHost target = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); redirectURI = URIUtils.rewriteURI(uri, target, true); } catch (URISyntaxException ex) { throw new ProtocolException(ex.getMessage(), ex); } } else { redirectURI = uri; } if (redirectLocations.contains(redirectURI)) { throw new CircularRedirectException("Circular redirect to '" + redirectURI + "'"); } else { redirectLocations.add(redirectURI); } } return uri; } }); } }