List of usage examples for org.apache.commons.lang3 StringUtils substringAfter
public static String substringAfter(final String str, final String separator)
Gets the substring after the first occurrence of a separator.
From source file:org.kawanfw.commons.client.http.HttpHostPartsExtractor.java
/** * Constructor/*from w ww . j av a 2 s. c o m*/ * @param httpHost A HTTP Host in the format "http://www.site.com:8080" */ public HttpHostPartsExtractor(String httpHost) { if (httpHost == null) { throw new IllegalArgumentException("httpHost can not be null!"); } if (!httpHost.startsWith("http://") && !httpHost.startsWith("https://")) { throw new IllegalArgumentException( "httpHost must start with \"http://\" or \"https://\". passed httpUrl is invalid: " + this.httpHost); } String hostname = StringUtils.substringAfter(httpHost, "://"); if (hostname.contains("/")) { throw new IllegalArgumentException("httpHost can not contain / separator"); } if (hostname.contains(":")) { String portStr = StringUtils.substringAfter(hostname, ":"); if (!StringUtils.isNumeric(portStr)) { throw new IllegalArgumentException("port is not numeric: " + httpHost); } } this.httpHost = httpHost; }
From source file:org.kawanfw.commons.client.http.HttpHostPartsExtractor.java
/** * Returns the host name.// ww w. j a v a2 s . co m * * @return the host name (IP or DNS name) */ public String getHostName() { String hostname = StringUtils.substringAfter(httpHost, "://"); if (hostname.contains(":")) { hostname = StringUtils.substringBefore(hostname, ":"); } return hostname; }
From source file:org.kawanfw.commons.client.http.HttpHostPartsExtractor.java
/** * Returns the port.//w w w . j ava 2s. c om * * @return the host port, or <code>80</code> if not set for http scheme or * or <code>443</code> if not set for https scheme. */ public int getPort() { String hostname = StringUtils.substringAfter(httpHost, "://"); if (hostname.contains(":")) { String portStr = StringUtils.substringAfter(hostname, ":"); int port = Integer.parseInt(portStr); return port; } if (getSchemeName().equals("http")) { return DEFAULT_PORT_HTTP; } else if (getSchemeName().equals("https")) { return DEFAULT_PORT_HTTPS; } else { throw new IllegalArgumentException( "invalid scheme. Must be http or https. value is: " + getSchemeName()); } }
From source file:org.kawanfw.file.api.util.client.RemoteFileUtil.java
/** * Decode the Throwable and rethrow a new RuntimeException or IllegalArgumentException * //from w w w.ja va2 s .c o m * @param throwable the throwable to analyse * @throws IllegalArgumentException if the filter java version is > host java version * @throws RuntimeException the RuntimeException to rethrow */ public static void decodeTrowableForFilterUsage(Throwable throwable) throws IllegalArgumentException, RuntimeException { if (throwable instanceof RemoteException) { Throwable cause = throwable.getCause(); // Say what verson is supported if UnsupportedClassVersionError if (cause != null && cause instanceof UnsupportedClassVersionError) { String message = cause.getMessage(); if (message != null && message.contains(UNSUPPORTED_MAJOR_MINOR_VERSION)) { String classFileVersionNumber = StringUtils.substringAfter(message, UNSUPPORTED_MAJOR_MINOR_VERSION); classFileVersionNumber = classFileVersionNumber.trim(); String classFileVersion = RemoteFileUtil .decodeJavaVersionFromMajorMinor(classFileVersionNumber); String finalMessage = "The filter .class file java version (" + classFileVersion + ") is unsupported on remote host. " + "(" + message + ")"; throw new IllegalArgumentException(finalMessage); } } throw new RuntimeException(cause); } throw new RuntimeException(throwable); }
From source file:org.kawanfw.file.reflection.ClassFileLocatorNew.java
/** * Gets the container of the class, ie the .jar file or the .class file * @return the container of the class, ie the .jar file or the .class file * @throws IOException/*from w ww . j a v a 2 s .c o m*/ */ public File getContainerFile() throws IOException { if (isContainerJar()) { //url : jar:file:/I:/_dev_awake/awake-file-3.0/lib/stringtemplate.jar!/org/antlr/stringtemplate/StringTemplate.class URL url = getUrl(); String urlString = url.toString(); urlString = StringUtils.substringBefore(urlString, "!"); urlString = StringUtils.substringAfter(urlString, "jar:"); File file = null; try { file = new File(new URL(urlString).toURI()); } catch (URISyntaxException e) { throw new IOException(e); } return file; } else { return getDotClassFile(); } }
From source file:org.kawanfw.file.servlet.convert.HttpServletRequestConvertor.java
/** * Decrypt the value// ww w. ja v a 2 s . co m * * @param parameterName * @param value * @return * @throws Exception * @throws IllegalArgumentException */ private String decryptValue(String parameterName, String value) throws Exception, IllegalArgumentException { if (!isRequestEncrypted(parameterName)) { debug("value *not* encrypted: " + value); return value; } value = StringUtils.substringAfter(value, Pbe.KAWANFW_ENCRYPTED); debug(""); debug("value encrypted: " + value); //value = new Pbe().decryptFromHexa(value, // commonsConfigurator.getEncryptionPassword()); value = new Pbe().decryptFromHexa(value, CommonsConfiguratorCall.getEncryptionPassword(commonsConfigurator)); debug("value decrypted: " + value); // Check coherence for known parms and value // Parameter.ACTION, Parameter.TEST_CRYPTO if (parameterName.equals(Parameter.TEST_CRYPTO)) { if (!value.equals(Parameter.TEST_CRYPTO)) { String message = Tag.PRODUCT_USER_CONFIG_FAIL + " Impossible to decrypt correctly the value of the parameter " + parameterName; message += ". Check that password values are the same on client and server side."; throw new IllegalArgumentException(message); } } return value; }
From source file:org.kawanfw.file.servlet.convert.StreamsEncrypted.java
/** * @param stream/* w w w . j ava 2 s.c o m*/ * The ServletFileUpload input stream * @param commonsConfigurator * Used to get the password for encryption */ public static String asString(InputStream stream, CommonsConfigurator commonsConfigurator) throws IOException { String value = Streams.asString(stream); if (isEncrypted(value, commonsConfigurator)) { try { value = StringUtils.substringAfter(value, Pbe.KAWANFW_ENCRYPTED); value = new Pbe().decryptFromHexa(value, CommonsConfiguratorCall.getEncryptionPassword(commonsConfigurator)); return value; } catch (Exception e) { String message = Tag.PRODUCT_USER_CONFIG_FAIL + " Impossible to decrypt the value " + value; message += ". Check that password values are the same on client and server side."; throw new IOException(message, e); } } else { return value; } }
From source file:org.kawanfw.file.servlet.nio.ReturnFileFormatter.java
/** * format the filename of a File returned by the File method * /*w w w . j av a 2 s. c o m*/ * @param fileConfigurator * @param username * @param result * @return */ public static String format(FileConfigurator fileConfigurator, String username, String result) { if (result == null) { return null; } File serverRootFile = fileConfigurator.getServerRoot(); // Direct access to file system if (serverRootFile == null || serverRootFile.toString().equals("/") || serverRootFile.toString().toLowerCase().equals("c:\\")) { result = removeWindowsRoot(result); if (!result.startsWith("/")) { result = "/" + result; } result = result.replace("\\", "/"); return result; } // We have a server root String headerServeroot = fileConfigurator.getServerRoot().toString(); // NO! can happen if parent asked! // if (!result.startsWith(headerServeroot)) { // throw new IllegalArgumentException(Tag.PRODUCT_PRODUCT_FAIL // + " file name should start with " + headerServeroot // + " but does not: " + result); // } // Remove the header result = StringUtils.substringAfter(result, headerServeroot); debug("Before replace: " + result); // Replace all \ by / result = result.replace("\\", "/"); debug("After replace \\ by /: " + result); if (fileConfigurator.useOneRootPerUsername()) { // /username/ if (result.contains("/" + username)) { result = StringUtils.replace(result, "/" + username, ""); } } if (!result.startsWith("/")) { result = "/" + result; } debug("After remove username and / add at head: " + result); return result; }
From source file:org.kawanfw.file.servlet.ServerUserThrowable.java
/** * Return the class where the Exception has been thrown * /*from w w w . j ava 2 s . c o m*/ * @param throwable * the exception thrown * @return the class that throws the Exception */ private static Class<?> extractThrowingClassFromThrowable(Throwable throwable) { try { String statckTrace = ExceptionUtils.getStackTrace(throwable); String className = StringUtils.substringAfter(statckTrace, "at "); className = StringUtils.substringBefore(className, "("); className = StringUtils.substringBeforeLast(className, "."); debug("className: " + ":" + className + ":"); Class<?> theClass = Class.forName(className); return theClass; } catch (ClassNotFoundException e1) { e1.printStackTrace(System.out); return null; } }
From source file:org.kawanfw.file.servlet.ServerUserThrowable.java
/** * Return the class where the Exception has been thrown * //from ww w . ja va 2 s . c o m * @param e * the exception thrown * @return the class that throws the Exception */ private static String extractThrowingMethodNameFromException(Throwable e) { String statckTrace = ExceptionUtils.getStackTrace(e); String className = StringUtils.substringAfter(statckTrace, "at "); className = StringUtils.substringBefore(className, "("); String methodName = StringUtils.substringAfterLast(className, "."); debug("className : " + ":" + className + ":"); debug("methodName: " + ":" + methodName + ":"); return methodName; }