List of usage examples for org.apache.commons.httpclient HttpStatus SC_MOVED_TEMPORARILY
int SC_MOVED_TEMPORARILY
To view the source code for org.apache.commons.httpclient HttpStatus SC_MOVED_TEMPORARILY.
Click Source Link
From source file:com.bluexml.side.framework.alfresco.webscriptExtension.SiteScriptExtension.java
/** * Method to delete a site/*from ww w .j ava 2s . co m*/ * The site is deleted through an http post call using a json structure as done by Share. * The json structure is of the form: * { * "shortName" : "mytestsite100", * }, * * @param baseUrl the base url * @param alfrescoUsername the alfresco user login to use to send request * @param alfrescoUsername the alfresco password to use to send request * @param siteShortname the mandatory site short name * * @return nodeRef of the site; null if the site successed to be deleted; in the javascript, use site.getSite(siteShortname) to get the site. */ public NodeRef deleteSite(String baseUrl, String alfrescoUsername, String alfrescoPwd, String siteShortname) { if (logger.isDebugEnabled()) { logger.debug("Delete site - sitheShortname =" + siteShortname); logger.debug(" - baseUrl =" + baseUrl + " - alfrescoUsername=" + alfrescoUsername + " - alfrescoPwd=" + alfrescoPwd); } NodeRef nodeRef = null; if (siteShortname != null) { SiteInfo siteInfo = siteService.getSite(siteShortname); if (siteInfo == null) { if (baseUrl == null) baseUrl = BASE_URL; // Create Apache HTTP Client to use for both calls: login and create-site HttpClient httpClient = new HttpClient(); // Login to Share to get a JSESSIONID setup in HTTP Client String loginData = "username=" + alfrescoUsername + "&password=" + alfrescoPwd; makePostCall(httpClient, baseUrl + LOGIN_URL, loginData, CONTENT_TYPE_FORM, "Login to Alfresco Share", HttpStatus.SC_MOVED_TEMPORARILY, alfrescoUsername); // create body request using site parameters JSONObject json = new JSONObject(); try { json.put("shortName", siteShortname); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } // send create-site request makePostCall(httpClient, baseUrl + DELETE_SITE_URL, json.toString(), CONTENT_TYPE_JSON, "Delete site with name: " + siteShortname, HttpStatus.SC_OK, alfrescoUsername); siteInfo = siteService.getSite(siteShortname); if (siteInfo != null) { // Site already exists, cannot create it, continue with next one nodeRef = siteInfo.getNodeRef(); logger.warn("Site (" + siteShortname + ") has not been deleted !!! - Check log."); } } else { // Site does not exists, cannot delete it, continue with next one logger.warn("Site (" + siteShortname + ") does not exist, cannot delete it"); } } else { // Site shortname is mandatory logger.warn("Site shortName parameter is mandatory, cannot delete site without shortName"); } return nodeRef; }
From source file:com.github.maven.plugin.client.impl.GithubClientImpl.java
/** * Removes the given download from the repository download section. * * @param repositoryUrl The repository url. * @param artifactName The download name. *///w w w .j av a 2 s .c o m private void delete(String repositoryUrl, String artifactName) { final Map<String, Integer> downloads = retrieveDownloadsInfos(repositoryUrl); if (!downloads.containsKey(artifactName)) { throw new GithubArtifactNotFoundException( "The download " + artifactName + " cannot be found in " + repositoryUrl); } final String downloadUrl = String.format("%s/%d", toRepositoryDownloadUrl(repositoryUrl), downloads.get(artifactName)); PostMethod githubDelete = new PostMethod(downloadUrl); githubDelete.setRequestBody(new NameValuePair[] { new NameValuePair("_method", "delete"), new NameValuePair("login", login), new NameValuePair("token", token) }); try { int response = httpClient.executeMethod(githubDelete); if (response != HttpStatus.SC_MOVED_TEMPORARILY) { throw new GithubException("Unexpected error " + HttpStatus.getStatusText(response)); } } catch (IOException e) { throw new GithubException(e); } githubDelete.releaseConnection(); }
From source file:com.cerema.cloud2.lib.common.OwnCloudClient.java
public RedirectionPath followRedirection(HttpMethod method) throws IOException { int redirectionsCount = 0; int status = method.getStatusCode(); RedirectionPath result = new RedirectionPath(status, MAX_REDIRECTIONS_COUNT); while (redirectionsCount < MAX_REDIRECTIONS_COUNT && (status == HttpStatus.SC_MOVED_PERMANENTLY || status == HttpStatus.SC_MOVED_TEMPORARILY || status == HttpStatus.SC_TEMPORARY_REDIRECT)) { Header location = method.getResponseHeader("Location"); if (location == null) { location = method.getResponseHeader("location"); }// w w w . j av a 2 s . com if (location != null) { Log_OC.d(TAG + " #" + mInstanceNumber, "Location to redirect: " + location.getValue()); String locationStr = location.getValue(); result.addLocation(locationStr); // Release the connection to avoid reach the max number of connections per host // due to it will be set a different url exhaustResponse(method.getResponseBodyAsStream()); method.releaseConnection(); method.setURI(new URI(locationStr, true)); Header destination = method.getRequestHeader("Destination"); if (destination == null) { destination = method.getRequestHeader("destination"); } if (destination != null) { int suffixIndex = locationStr.lastIndexOf( (mCredentials instanceof OwnCloudBearerCredentials) ? AccountUtils.ODAV_PATH : AccountUtils.WEBDAV_PATH_4_0); String redirectionBase = locationStr.substring(0, suffixIndex); String destinationStr = destination.getValue(); String destinationPath = destinationStr.substring(mBaseUri.toString().length()); String redirectedDestination = redirectionBase + destinationPath; destination.setValue(redirectedDestination); method.setRequestHeader(destination); } status = super.executeMethod(method); result.addStatus(status); redirectionsCount++; } else { Log_OC.d(TAG + " #" + mInstanceNumber, "No location to redirect!"); status = HttpStatus.SC_NOT_FOUND; } } return result; }
From source file:davmail.http.DavGatewayHttpClientFacade.java
/** * Check if status is a redirect (various 30x values). * * @param status Http status//www . j ava 2s .c o m * @return true if status is a redirect */ public static boolean isRedirect(int status) { return status == HttpStatus.SC_MOVED_PERMANENTLY || status == HttpStatus.SC_MOVED_TEMPORARILY || status == HttpStatus.SC_SEE_OTHER || status == HttpStatus.SC_TEMPORARY_REDIRECT; }
From source file:com.foglyn.fogbugz.FogBugzClient.java
/** * Will throw exception if FogBugz wants to use different repository *///from ww w .java2s . c om private void checkUseDifferentRepositoryProblem(FogBugzHttpException e, String usedURL) throws FogBugzException { if (e.getHttpCode() != HttpStatus.SC_MOVED_TEMPORARILY) { return; } String location = e.getResponseHeaders().get("location"); if (location == null) { return; } String orig = usedURL.toLowerCase(); String received = location.toLowerCase(); String locationForUser = Utils.replaceSuffix(location, "api.asp", "", "api.php", ""); // if requested location is same as supplied, but with HTTPS insteada of HTTP, we send simplified error to user if (orig.startsWith("http:") && received.startsWith("https:") && orig.substring("http:".length()).equals(received.substring("https:".length()))) { throw new FogBugzException("This server requires HTTPS protocol (i.e., " + locationForUser + ")"); } throw new FogBugzException("Please use '" + locationForUser + "' as server repository"); }
From source file:JiraWebSession.java
private HostConfiguration login(HttpClient httpClient, IProgressMonitor monitor) throws JiraException { RedirectTracker tracker = new RedirectTracker(); final String restLogin = "/rest/gadget/1.0/login"; //$NON-NLS-1$ // JIRA 4.x has additional endpoint for login that tells if CAPTCHA limit was hit final String loginAction = "/secure/Dashboard.jspa"; //$NON-NLS-1$; boolean jira4x = true; for (int i = 0; i <= MAX_REDIRECTS; i++) { AuthenticationCredentials credentials = location.getCredentials(AuthenticationType.REPOSITORY); if (credentials == null) { // TODO prompt user? credentials = new AuthenticationCredentials("", ""); //$NON-NLS-1$ //$NON-NLS-2$ }// w ww .j a v a 2s. c om String url = baseUrl + (jira4x ? restLogin : loginAction); PostMethod login = new PostMethod(url); login.setFollowRedirects(false); login.setRequestHeader("Content-Type", getContentType()); //$NON-NLS-1$ login.addParameter("os_username", credentials.getUserName()); //$NON-NLS-1$ login.addParameter("os_password", credentials.getPassword()); //$NON-NLS-1$ login.addParameter("os_destination", "/success"); //$NON-NLS-1$ //$NON-NLS-2$ tracker.addUrl(url); try { HostConfiguration hostConfiguration = WebUtil.createHostConfiguration(httpClient, location, monitor); int statusCode = WebUtil.execute(httpClient, hostConfiguration, login, monitor); if (statusCode == HttpStatus.SC_NOT_FOUND) { jira4x = false; continue; } if (needsReauthentication(httpClient, login, monitor)) { continue; } else if (statusCode != HttpStatus.SC_MOVED_TEMPORARILY && statusCode != HttpStatus.SC_MOVED_PERMANENTLY) { throw new JiraServiceUnavailableException("Unexpected status code during login: " + statusCode); //$NON-NLS-1$ } tracker.addRedirect(url, login, statusCode); this.characterEncoding = login.getResponseCharSet(); Header locationHeader = login.getResponseHeader("location"); //$NON-NLS-1$ if (locationHeader == null) { throw new JiraServiceUnavailableException("Invalid redirect, missing location"); //$NON-NLS-1$ } url = locationHeader.getValue(); tracker.checkForCircle(url); if (!insecureRedirect && isSecure() && url.startsWith("http://")) { //$NON-NLS-1$ tracker.log("Redirect to insecure location during login to repository: " + client.getBaseUrl()); //$NON-NLS-1$ insecureRedirect = true; } if (url.endsWith("/success")) { //$NON-NLS-1$ String newBaseUrl = url.substring(0, url.lastIndexOf("/success")); //$NON-NLS-1$ if (baseUrl.equals(newBaseUrl) || !client.getLocalConfiguration().getFollowRedirects()) { // success addAuthenticationCookie(httpClient, login); return hostConfiguration; } else { // need to login to make sure HttpClient picks up the session cookie baseUrl = newBaseUrl; } } } catch (IOException e) { throw new JiraServiceUnavailableException(e); } finally { login.releaseConnection(); } } tracker.log( "Exceeded maximum number of allowed redirects during login to repository: " + client.getBaseUrl()); //$NON-NLS-1$ throw new JiraServiceUnavailableException("Exceeded maximum number of allowed redirects during login"); //$NON-NLS-1$ }
From source file:com.tacitknowledge.maven.plugin.crx.CRXPackageInstallerPlugin.java
/** * @param cookies/* w w w . java2 s .c o m*/ * get a session using the same existing previously requested * response cookies. * @throws MojoExecutionException * if any error occurred during this process. */ @SuppressWarnings("deprecation") private void getSession(final Cookie[] cookies) throws MojoExecutionException { PostMethod loginPost = new PostMethod(crxPath + "/login.jsp"); loginPost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true); try { getLog().info("login to " + loginPost.getPath()); loginPost.setParameter("Workspace", workspace); loginPost.setParameter("UserId", login); loginPost.setParameter("Password", password); HttpClient client = new HttpClient(); client.getState().setCookiePolicy(CookiePolicy.COMPATIBILITY); client.getState().addCookies(cookies); client.getHttpConnectionManager().getParams().setConnectionTimeout(CONNECTION_DEFAULT_TIMEOUT); int status = client.executeMethod(loginPost); // log the status getLog().info( "Response status: " + status + ", statusText: " + HttpStatus.getStatusText(status) + "\r\n"); if (status == HttpStatus.SC_MOVED_TEMPORARILY) { getLog().info("Login successful"); } else { logResponseDetails(loginPost); throw new MojoExecutionException("Login failed, response=" + HttpStatus.getStatusText(status)); } } catch (Exception ex) { getLog().error("ERROR: " + ex.getClass().getName() + " " + ex.getMessage()); throw new MojoExecutionException(ex.getMessage()); } finally { loginPost.releaseConnection(); } }
From source file:com.google.collide.server.fe.WebFE.java
private void sendRedirect(HttpServerRequest req, String url) { req.response.putHeader("Location", url); sendStatusCode(req, HttpStatus.SC_MOVED_TEMPORARILY); }
From source file:com.tacitknowledge.maven.plugin.crx.CRXPackageInstallerPlugin.java
/** * @param cookies//from ww w. j av a2s.c o m * the previous requests cookies to keep in the same session. * @throws MojoExecutionException * if any error occurs during this process. */ @SuppressWarnings("deprecation") private void uploadPackage(final Cookie[] cookies) throws MojoExecutionException { PostMethod filePost = new PostMethod(crxPath + "/packmgr/list.jsp"); filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true); try { getLog().info("Uploading " + jarfile + " to " + filePost.getPath()); File jarFile = new File(jarfile); Part[] parts = { new FilePart("file", jarFile) }; filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams())); HttpClient client = new HttpClient(); client.getState().setCookiePolicy(CookiePolicy.COMPATIBILITY); client.getState().addCookies(cookies); client.getHttpConnectionManager().getParams().setConnectionTimeout(CONNECTION_DEFAULT_TIMEOUT); int status = client.executeMethod(filePost); // log the status getLog().info( "Response status: " + status + ", statusText: " + HttpStatus.getStatusText(status) + "\r\n"); if (status == HttpStatus.SC_MOVED_TEMPORARILY) { getLog().info("Upload complete"); } else { logResponseDetails(filePost); throw new MojoExecutionException( "Package upload failed, response=" + HttpStatus.getStatusText(status)); } } catch (Exception ex) { getLog().error("ERROR: " + ex.getClass().getName() + " " + ex.getMessage()); throw new MojoExecutionException(ex.getMessage()); } finally { filePost.releaseConnection(); } }
From source file:com.dtolabs.client.utils.HttpClientChannel.java
private HttpMethod checkFollowRedirect(final HttpMethod method, final int res) throws IOException, HttpClientException { if ((res == HttpStatus.SC_MOVED_TEMPORARILY) || (res == HttpStatus.SC_MOVED_PERMANENTLY) || (res == HttpStatus.SC_SEE_OTHER) || (res == HttpStatus.SC_TEMPORARY_REDIRECT)) { final Header locHeader = method.getResponseHeader("Location"); if (locHeader == null) { throw new HttpClientException("Redirect with no Location header, request URL: " + method.getURI()); }/*from w w w . j a va 2 s .co m*/ final String location = locHeader.getValue(); logger.debug("Follow redirect: " + res + ": " + location); method.releaseConnection(); final GetMethod followMethod = new GetMethod(location); followMethod.setFollowRedirects(true); resultCode = httpc.executeMethod(followMethod); reasonCode = followMethod.getStatusText(); logger.debug("Result: " + resultCode); return followMethod; } return method; }