List of usage examples for org.springframework.util Assert state
public static void state(boolean expression, Supplier<String> messageSupplier)
From source file:com.netxforge.oss2.config.VacuumdConfigFactory.java
/** * Return the singleton instance of this factory. * * @return The current factory instance. * @throws java.lang.IllegalStateException * Thrown if the factory has not yet been initialized. *//*www . j a v a 2s. c o m*/ public static synchronized VacuumdConfigFactory getInstance() { Assert.state(m_singleton != null, "The factory has not been initialized"); return m_singleton; }
From source file:com.thoughtworks.go.http.mocks.MockRequestDispatcher.java
@Override public void forward(ServletRequest request, ServletResponse response) { Assert.notNull(request, "Request must not be null"); Assert.notNull(response, "Response must not be null"); Assert.state(!response.isCommitted(), "Cannot perform forward - response is already committed"); getMockHttpServletResponse(response).setForwardedUrl(this.resource); if (logger.isDebugEnabled()) { logger.debug("MockRequestDispatcher: forwarding to [" + this.resource + "]"); }/* ww w. j a v a 2 s . co m*/ }
From source file:com.wavemaker.spinup.web.SpinupController.java
/** * Postback method from the login form. Will either re-direct back to the form (in the case of errors) or redirect * to start the spinup process./*from www. j a va2 s . c om*/ * * @param credentials User credentials * @param bindingResult the binding result from the form * @param request the HTTP request * @param response the HTTP response * @return the response (either a redirect to the form or a redirect to the spinup process) */ @RequestMapping(value = "/login", method = RequestMethod.POST) public ModelAndView processLogin(@Valid LoginCredentialsBean credentials, BindingResult bindingResult, HttpServletRequest request, HttpServletResponse response) { Assert.state(isAjaxRequest(request), "Unable to handle non AJAX post"); // If we have binding errors, re-render the page if (bindingResult.hasErrors()) { return new ModelAndView(); } try { // Login, add the cookie and redirect to start the spinup process this.logger.debug("Starting WaveMaker spinup"); SharedSecret secret = getSecret(request); TransportToken transportToken = this.spinupService.login(secret, credentials); this.logger.debug("Login complete"); String url = performSpinup(credentials, secret, transportToken, response); this.logger.debug("Perform spinup complete"); Cookie cookie = new Cookie(COOKIE_NAME, transportToken.encode()); cookie.setMaxAge(COOKIE_MAX_AGE); cookie.setDomain(this.spinupService.getDomain()); response.addCookie(cookie); response.setHeader("X-Ajax-Redirect", url); response.setStatus(HttpStatus.NO_CONTENT.value()); this.logger.debug("Wavemake spinup complete"); return null; } catch (InvalidLoginCredentialsException e) { // On invalid login redirect with a message in flash scope return new ModelAndView().addObject("message", "Unable to login, please check your credentials"); } }
From source file:com.wavemaker.spinup.web.WavemakerStudioApplicationArchiveFactory.java
private void downloadStudioWar(ServletContext servletContext, boolean replaceExisting) { InputStream reader = null;/*w w w . j a va 2 s.c o m*/ OutputStream out = null; String path = null; int ByteRead = 0; try { String uploadDirName = servletContext.getRealPath(SpinupConstants.STUDIOD_UPLOAD_DIR); File uploadPath = new File(uploadDirName); uploadPath.mkdirs(); File localStudioWar = new File(uploadPath, SpinupConstants.STUDIO_FILE); if (!localStudioWar.exists() || replaceExisting) { try { byte[] buffer = new byte[5242880]; //5mb String customURL = CloudFoundryUtils.getEnvironmentVariable("studio_war_url", ""); if (customURL.isEmpty()) { path = SpinupConstants.STUDIO_URL + SpinupConstants.STUDIO_FILE; } else { path = customURL; } if (this.logger.isInfoEnabled()) { this.logger.info("Downloading studio from: " + path); } URL url = new URL(path); url.openConnection(); reader = url.openStream(); out = new BufferedOutputStream(new FileOutputStream(localStudioWar)); while ((ByteRead = reader.read(buffer)) != -1) { out.write(buffer, 0, ByteRead); } } catch (IOException e) { e.printStackTrace(); throw new IllegalStateException(e); } catch (Exception e) { throw new WMRuntimeException(e); } finally { try { reader.close(); out.close(); } catch (IOException e) { e.printStackTrace(); } } } else { if (this.logger.isInfoEnabled()) { this.logger.info("Using existing studio WAR"); } } this.namingStrategy.getCurrentVersion(this.servletContext); this.studioWarFile = localStudioWar; Assert.state(studioWarFile.exists(), "Studio resource '" + studioWarFile.getPath() + "' does not exist"); if (this.logger.isDebugEnabled()) { this.logger.debug("Studio War is " + studioWarFile.getPath()); } } catch (Exception e) { throw new WMRuntimeException(e); } }
From source file:com.wavemaker.tools.cloudfoundry.spinup.authentication.SharedSecretPropagation.java
/** * Get the shared secret for the currently running application. This method assumes that some other process has * {@link #sendTo(CloudFoundryClient, SharedSecret, CloudApplication) sent} the {@link SharedSecret} to the running * application./*from ww w . j a v a 2 s. c om*/ * * @param required * * @return the shared secret * @throw IllegalStateException if the secret cannot be obtained */ public SharedSecret getForSelf(boolean required) throws IllegalStateException { try { String secret = getEnv(ENV_KEY); if (!StringUtils.hasLength(secret) && !required) { return null; } Assert.state(StringUtils.hasLength(secret), "No shared secret has been propagated"); return SharedSecret.fromBytes(Hex.decodeHex(secret.toCharArray())); } catch (DecoderException e) { throw new IllegalStateException("Unable to decode shared secret key", e); } }
From source file:com.wavemaker.tools.deployment.cloudfoundry.CloudFoundryDeploymentTarget.java
/** * @param deploymentInfo/*from ww w . j a v a 2 s .co m*/ */ private void setupServices(CloudFoundryClient client, DeploymentInfo deploymentInfo) { if (CollectionUtils.isEmpty(deploymentInfo.getDatabases())) { return; } CloudApplication app = client.getApplication(deploymentInfo.getApplicationName()); for (DeploymentDB db : deploymentInfo.getDatabases()) { if (app.getServices().contains(db.getDbName()) && !db.isUpdateSchema()) { // service binding already exists continue; } if (db.isUpdateSchema()) { try { client.deleteService(db.getDbName()); } catch (Exception ex) { } } String dbType = "NONE"; DataModelConfiguration config = this.dataModelManager.getDataModel(db.getDataModelId()); String url = config.readConnectionProperties().getProperty(DataServiceConstants.DB_URL_KEY, ""); if (StringUtils.hasText(url)) { dbType = BaseDataModelSetup.getDBTypeFromURL(url); } boolean serviceToBind = false; try { CloudService service = client.getService(db.getDbName()); if (dbType.equals(MYSQL_SERVICE_VENDOR)) { Assert.state(MYSQL_SERVICE_VENDOR.equals(service.getVendor()), "There is already a service provisioned with the name '" + db.getDbName() + "' but it is not a MySQL service."); } else if (dbType.equals(POSTGRES_SERVICE_VENDOR)) { Assert.state(POSTGRES_SERVICE_VENDOR.equals(service.getVendor()), "There is already a service provisioned with the name '" + db.getDbName() + "' but it is not a PostgreSQL service."); } serviceToBind = true; } catch (CloudFoundryException ex) { if (ex.getStatusCode() != HttpStatus.NOT_FOUND) { throw ex; } if (dbType.equals(MYSQL_SERVICE_VENDOR)) { client.createService(createMySqlService(db)); serviceToBind = true; } else if (dbType.equals(POSTGRES_SERVICE_VENDOR)) { client.createService(createPostgresqlService(db)); serviceToBind = true; } } if (serviceToBind) { client.bindService(deploymentInfo.getApplicationName(), db.getDbName()); } } }
From source file:com.wavemaker.tools.io.virtual.VirtualResourceStore.java
@Override public Resource rename(String name) { Data data = getData();// w w w .ja v a 2 s .c o m Assert.state(data != null, "Unable to rename missing resource " + getPath().getUnjailedPath()); JailedResourcePath destPath = getPath().getParent().get(name); data.setName(name); return getRenamedResource(destPath); }
From source file:com.wavemaker.tools.security.CloudFoundrySecurityFilter.java
private void checkAuthenticationCookie(HttpServletRequest request) throws TransportTokenDigestMismatchException { Cookie[] allCookies = request.getCookies(); Assert.state(allCookies.length < 12, "Way too many auth cookies."); Cookie[] authCookies = new Cookie[allCookies.length]; int num = 0;//from w w w. j a v a2s .com for (Cookie cookie : allCookies) { if (cookie.getName().equals("wavemaker_authentication_token")) { authCookies[num++] = cookie; } } for (Cookie cookie : authCookies) { try { Assert.state(cookie != null, "This is no cookie"); Assert.state(StringUtils.hasLength(cookie.getValue()), "This cookie has no value"); log.debug("Trying = " + cookie.getValue()); SharedSecret sharedSecret = this.propagation.getForSelf(true); sharedSecret.decrypt(TransportToken.decode(cookie.getValue())); return; } catch (TransportTokenDigestMismatchException ttdme) { log.debug("Invalid cookie"); } } log.warn("NO valid cookie - redirecting " + request.getRequestURI() + " to spinup app"); throw (new TransportTokenDigestMismatchException("Unable to find valid secret token")); }
From source file:com.wavemaker.tools.service.ServiceClassGenerator.java
public void run() { Assert.state(this.serviceManager != null, "ServiceManager cannot be null"); for (ServiceDetail serviceDetail : this.serviceDetails) { run(serviceDetail);/* w w w. jav a2 s . co m*/ } }
From source file:de.escalon.hypermedia.spring.AffordanceBuilderFactory.java
private ActionDescriptor createActionDescriptor(Method invokedMethod, Map<String, Object> values, Object[] arguments) {/*from w w w .ja v a2 s.com*/ RequestMethod httpMethod = getHttpMethod(invokedMethod); Type genericReturnType = invokedMethod.getGenericReturnType(); ActionDescriptor actionDescriptor = new ActionDescriptor(invokedMethod.getName(), httpMethod.name()); actionDescriptor.setCardinality(getCardinality(invokedMethod, httpMethod, genericReturnType)); final Action actionAnnotation = AnnotationUtils.getAnnotation(invokedMethod, Action.class); if (actionAnnotation != null) { actionDescriptor.setSemanticActionType(actionAnnotation.value()); } Map<String, ActionInputParameter> requestBodyMap = getActionInputParameters(RequestBody.class, invokedMethod, arguments); Assert.state(requestBodyMap.size() < 2, "found more than one request body on " + invokedMethod.getName()); for (ActionInputParameter value : requestBodyMap.values()) { actionDescriptor.setRequestBody(value); } // the action descriptor needs to know the param type, value and name Map<String, ActionInputParameter> requestParamMap = getActionInputParameters(RequestParam.class, invokedMethod, arguments); for (Map.Entry<String, ActionInputParameter> entry : requestParamMap.entrySet()) { ActionInputParameter value = entry.getValue(); if (value != null) { final String key = entry.getKey(); actionDescriptor.addRequestParam(key, value); if (!value.isRequestBody()) { values.put(key, value.getCallValueFormatted()); } } } Map<String, ActionInputParameter> pathVariableMap = getActionInputParameters(PathVariable.class, invokedMethod, arguments); for (Map.Entry<String, ActionInputParameter> entry : pathVariableMap.entrySet()) { ActionInputParameter actionInputParameter = entry.getValue(); if (actionInputParameter != null) { final String key = entry.getKey(); actionDescriptor.addPathVariable(key, actionInputParameter); if (!actionInputParameter.isRequestBody()) { values.put(key, actionInputParameter.getCallValueFormatted()); } } } Map<String, ActionInputParameter> requestHeadersMap = getActionInputParameters(RequestHeader.class, invokedMethod, arguments); for (Map.Entry<String, ActionInputParameter> entry : pathVariableMap.entrySet()) { ActionInputParameter actionInputParameter = entry.getValue(); if (actionInputParameter != null) { final String key = entry.getKey(); actionDescriptor.addRequestHeader(key, actionInputParameter); if (!actionInputParameter.isRequestBody()) { values.put(key, actionInputParameter.getCallValueFormatted()); } } } return actionDescriptor; }