List of usage examples for org.apache.commons.httpclient RedirectException getMessage
public String getMessage()
From source file:at.spardat.xma.boot.transport.HTTPTransport.java
private Object callRedirectAware(XMA_URI resource, RedirectCallback callback) throws CommunicationException { Set<URL> redirectLoopPreventionSet = new HashSet<URL>(); URL url = resource.getHTTP_URI(); String initialResourceHostApp = resource.getHostApp(); do {/* w w w.j ava 2s. com*/ XMA_URI redirectedResource = getRedirection(resource); if (redirectedResource != null) { url = redirectedResource.getHTTP_URI(); log_.log(LogLevel.FINE, "Using redirect cache: " + resource + " -> " + redirectedResource); } redirectLoopPreventionSet.add(url); try { return callback.call(url); } catch (RedirectException re) { log_.log(LogLevel.WARNING, re.getMessage()); try { url = new URL(re.getLocation()); String resourceHostApp = resource.getHostApp(); resource = new XMA_URI(url); String newHostApp = resource.getHostApp(); if (!resourceHostApp.equals(newHostApp)) { redirectCache.put(resourceHostApp, newHostApp); // be aware of multiple redirects redirectCache.put(initialResourceHostApp, newHostApp); log_.log(LogLevel.FINE, "Adding redirect cache: " + resourceHostApp + " -> " + newHostApp); } } catch (MalformedURLException e) { throw new ServerException("Illegal HTTP redirect location: " + re.getLocation(), re, re.getReturnCode()); } } } while (!redirectLoopPreventionSet.contains(url) && redirectLoopPreventionSet.size() < 5); throw new ServerException("HTTP redirect loop detected at " + url); }
From source file:org.eclipse.mylyn.internal.bugzilla.core.BugzillaClient.java
public boolean getSearchHits(IRepositoryQuery query, TaskDataCollector collector, TaskAttributeMapper mapper, IProgressMonitor monitor) throws IOException, CoreException { HttpMethodBase postMethod = null;// w w w. ja va 2 s. c om try { authenticate(new SubProgressMonitor(monitor, 1)); String queryUrl = query.getUrl(); int start = queryUrl.indexOf('?'); List<NameValuePair> pairs = new ArrayList<NameValuePair>(); if (start != -1) { queryUrl = queryUrl.substring(start + 1); String[] result = queryUrl.split("&"); //$NON-NLS-1$ if (result.length > 0) { for (String string : result) { String[] nameValue = string.split("="); //$NON-NLS-1$ if (nameValue.length == 1) { pairs.add(new NameValuePair(nameValue[0].trim(), "")); //$NON-NLS-1$ } else if (nameValue.length == 2 && nameValue[0] != null && nameValue[1] != null) { //Hack around bugzilla's change of attribute name for comment search field bug#289155 if (nameValue[0].startsWith("long_desc")) { //$NON-NLS-1$ pairs.add(new NameValuePair(nameValue[0].replace("long_desc", "longdesc"), //$NON-NLS-1$ //$NON-NLS-2$ URLDecoder.decode(nameValue[1].trim(), getCharacterEncoding()))); } pairs.add(new NameValuePair(nameValue[0].trim(), URLDecoder.decode(nameValue[1].trim(), getCharacterEncoding()))); } } } } NameValuePair ctypePair = new NameValuePair("ctype", "rdf"); //$NON-NLS-1$ //$NON-NLS-2$ // Test that we don't specify content type twice. if (!pairs.contains(ctypePair)) { pairs.add(ctypePair); } try { postMethod = postFormData(IBugzillaConstants.URL_BUGLIST, pairs.toArray(new NameValuePair[pairs.size()]), monitor); } catch (RedirectException r) { // Handle one redirect (Bugzilla 3.4 provides a redirect upon query submission via post) postMethod = getConnectGzip(r.getMessage(), monitor, null); } if (postMethod != null && postMethod.getResponseHeader("Content-Type") != null) { //$NON-NLS-1$ Header responseTypeHeader = postMethod.getResponseHeader("Content-Type"); //$NON-NLS-1$ for (String type : VALID_CONFIG_CONTENT_TYPES) { if (responseTypeHeader.getValue().toLowerCase(Locale.ENGLISH).contains(type)) { InputStream stream = getResponseStream(postMethod, monitor); try { RepositoryQueryResultsFactory queryFactory = getQueryResultsFactory(stream); int count = queryFactory.performQuery(repositoryUrl.toString(), collector, mapper, TaskDataCollector.MAX_HITS); return count > 0; } finally { stream.close(); } } } } // because html is not a valid config content type it is save to get the response here throw new CoreException(parseHtmlError(getResponseStream(postMethod, monitor))); } finally { if (postMethod != null) { WebUtil.releaseConnection(postMethod, monitor); } } }