List of usage examples for com.google.gwt.http.client Response SC_PRECONDITION_FAILED
int SC_PRECONDITION_FAILED
To view the source code for com.google.gwt.http.client Response SC_PRECONDITION_FAILED.
Click Source Link
From source file:com.google.appinventor.client.Ode.java
License:Open Source License
/** * Main entry point for Ode. Setting up the UI and the web service * connections.// ww w. j ava 2 s .c o m */ @Override public void onModuleLoad() { Tracking.trackPageview(); // Handler for any otherwise unhandled exceptions GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() { @Override public void onUncaughtException(Throwable e) { OdeLog.xlog(e); if (AppInventorFeatures.sendBugReports()) { if (Window.confirm(MESSAGES.internalErrorReportBug())) { Window.open(BugReport.getBugReportLink(e), "_blank", ""); } } else { // Display a confirm dialog with error msg and if 'ok' open the debugging view if (Window.confirm(MESSAGES.internalErrorClickOkDebuggingView())) { Ode.getInstance().switchToDebuggingView(); } } } }); // Define bridge methods to Javascript JsonpConnection.defineBridgeMethod(); // Initialize global Ode instance instance = this; // Let's see if we were started with a repo= parameter which points to a template templatePath = Window.Location.getParameter("repo"); if (templatePath != null) { OdeLog.wlog("Got a template path of " + templatePath); templateLoadingFlag = true; } // Let's see if we were started with a galleryId= parameter which points to a template galleryId = Window.Location.getParameter("galleryId"); if (galleryId != null) { OdeLog.wlog("Got a galleryId of " + galleryId); galleryIdLoadingFlag = true; } // Get user information. OdeAsyncCallback<Config> callback = new OdeAsyncCallback<Config>( // failure message MESSAGES.serverUnavailable()) { @Override public void onSuccess(Config result) { config = result; user = result.getUser(); isReadOnly = user.isReadOnly(); // If user hasn't accepted terms of service, ask them to. if (!user.getUserTosAccepted() && !isReadOnly) { // We expect that the redirect to the TOS page should be handled // by the onFailure method below. The server should return a // "forbidden" error if the TOS wasn't accepted. ErrorReporter.reportError(MESSAGES.serverUnavailable()); return; } splashConfig = result.getSplashConfig(); if (result.getRendezvousServer() != null) { setRendezvousServer(result.getRendezvousServer()); } else { setRendezvousServer(YaVersion.RENDEZVOUS_SERVER); } userSettings = new UserSettings(user); // Gallery settings gallerySettings = new GallerySettings(); //gallerySettings.loadGallerySettings(); loadGallerySettings(); // Initialize project and editor managers // The project manager loads the user's projects asynchronously projectManager = new ProjectManager(); projectManager.addProjectManagerEventListener(new ProjectManagerEventAdapter() { @Override public void onProjectsLoaded() { projectManager.removeProjectManagerEventListener(this); // This handles any built-in templates stored in /war // Retrieve template data stored in war/templates folder and // and save it for later use in TemplateUploadWizard OdeAsyncCallback<String> templateCallback = new OdeAsyncCallback<String>( // failure message MESSAGES.createProjectError()) { @Override public void onSuccess(String json) { // Save the templateData TemplateUploadWizard.initializeBuiltInTemplates(json); // Here we call userSettings.loadSettings, but the settings are actually loaded // asynchronously, so this loadSettings call will return before they are loaded. // After the user settings have been loaded, openPreviousProject will be called. // We have to call this after the builtin templates have been loaded otherwise // we will get a NPF. userSettings.loadSettings(); } }; Ode.getInstance().getProjectService().retrieveTemplateData( TemplateUploadWizard.TEMPLATES_ROOT_DIRECTORY, templateCallback); } }); editorManager = new EditorManager(); // Initialize UI initializeUi(); topPanel.showUserEmail(user.getUserEmail()); } @Override public void onFailure(Throwable caught) { if (caught instanceof StatusCodeException) { StatusCodeException e = (StatusCodeException) caught; int statusCode = e.getStatusCode(); switch (statusCode) { case Response.SC_UNAUTHORIZED: // unauthorized => not on whitelist // getEncodedResponse() gives us the message that we wrote in // OdeAuthFilter.writeWhitelistErrorMessage(). Window.alert(e.getEncodedResponse()); return; case Response.SC_FORBIDDEN: // forbidden => need tos accept Window.open("/" + ServerLayout.YA_TOS_FORM, "_self", null); return; case Response.SC_PRECONDITION_FAILED: String locale = Window.Location.getParameter("locale"); if (locale == null || locale.equals("")) { Window.Location.replace("/login/"); } else { Window.Location.replace("/login/?locale=" + locale); } return; // likely not reached } } super.onFailure(caught); } }; // The call below begins an asynchronous read of the user's settings // When the settings are finished reading, various settings parsers // will be called on the returned JSON object. They will call various // other functions in this module, including openPreviousProject (the // previous project ID is stored in the settings) as well as the splash // screen displaying functions below. // // TODO(user): ODE makes too many RPC requests at startup time. Currently // we do 3 RPCs + 1 per project + 1 per open file. We should bundle some of // those with each other or with the initial HTML transfer. // // This call also stores our sessionId in the backend. This will be checked // when we go to save a file and if different file saving will be disabled // Newer sessions invalidate older sessions. userInfoService.getSystemConfig(sessionId, callback); History.addValueChangeHandler(new ValueChangeHandler<String>() { @Override public void onValueChange(ValueChangeEvent<String> event) { openProject(event.getValue()); } }); // load project based on current url // TODO(sharon): Seems like a possible race condition here if the onValueChange // handler defined above gets called before the getSystemConfig call sets // userSettings. // The following line causes problems with GWT debugging, and commenting // it out doesn't seem to break things. //History.fireCurrentHistoryState(); }
From source file:com.google.appinventor.client.OdeAsyncCallback.java
License:Open Source License
@Override public void onFailure(Throwable caught) { if (caught instanceof IncompatibleRemoteServiceException) { ErrorReporter.reportError(/*w w w.ja va 2 s. com*/ "App Inventor has just been upgraded, you will need to press the reload button in your browser window"); return; } if (caught instanceof InvalidSessionException) { Ode.getInstance().invalidSessionDialog(); return; } if (caught instanceof ChecksumedFileException) { Ode.getInstance().corruptionDialog(); return; } if (caught instanceof BlocksTruncatedException) { OdeLog.log("Caught BlocksTruncatedException"); ErrorReporter.reportError("Caught BlocksTruncatedException"); return; } // SC_PRECONDITION_FAILED if our session has expired or login cookie // has become invalid if ((caught instanceof StatusCodeException) && ((StatusCodeException) caught).getStatusCode() == Response.SC_PRECONDITION_FAILED) { Ode.getInstance().sessionDead(); return; } String errorMessage = (failureMessage == null) ? caught.getMessage() : failureMessage; ErrorReporter.reportError(errorMessage); OdeLog.elog("Got exception: " + caught.getMessage()); Throwable cause = caught.getCause(); if (cause != null) { OdeLog.elog("Caused by: " + cause.getMessage()); } }
From source file:org.sigmah.server.file.util.MultipartRequest.java
License:Open Source License
public void parse(MultipartRequestCallback callback) throws IOException, FileUploadException, StatusServletException { if (!ServletFileUpload.isMultipartContent(request)) { LOGGER.error("Request content is not multipart."); throw new StatusServletException(Response.SC_PRECONDITION_FAILED); }//from w ww . jav a 2s .c om final FileItemIterator iterator = new ServletFileUpload(new DiskFileItemFactory()).getItemIterator(request); while (iterator.hasNext()) { // Gets the first HTTP request element. final FileItemStream item = iterator.next(); if (item.isFormField()) { final String value = Streams.asString(item.openStream(), "UTF-8"); properties.put(item.getFieldName(), value); } else if (callback != null) { callback.onInputStream(item.openStream(), item.getFieldName(), item.getContentType()); } } }
From source file:org.sigmah.shared.file.DirectTransfertManager.java
License:Open Source License
@Override public void upload(final FormPanel formPanel, final ProgressListener progressListener) { final ServletUrlBuilder urlBuilder = new ServletUrlBuilder(authenticationProvider, pageManager, ServletConstants.Servlet.FILE, ServletConstants.ServletMethod.UPLOAD); formPanel.setAction(urlBuilder.toString()); formPanel.setEncoding(FormPanel.Encoding.MULTIPART); formPanel.setMethod(FormPanel.Method.POST); formPanel.addListener(Events.Submit, new Listener<FormEvent>() { @Override/*w ww .j av a2s. c o m*/ public void handleEvent(FormEvent formEvent) { formPanel.removeListener(Events.Submit, this); final String result = formEvent.getResultHtml(); switch (ServletConstants.getErrorCode(result)) { case Response.SC_OK: progressListener.onLoad(result); break; case Response.SC_NO_CONTENT: progressListener.onFailure(Cause.EMPTY_FILE); break; case Response.SC_REQUEST_ENTITY_TOO_LARGE: progressListener.onFailure(Cause.FILE_TOO_LARGE); break; case Response.SC_PRECONDITION_FAILED: progressListener.onFailure(Cause.BAD_REQUEST); break; default: progressListener.onFailure(Cause.SERVER_ERROR); break; } } }); formPanel.submit(); }