public File getDefaultDirectory() { String address = StringUtils.trimToEmpty(this.endpoint); File directory = new File(String.format("bytetcc/%s", address.replaceAll("\\W", "_"))); if (directory.exists() == false) { try { directory.mkdirs(); } catch (SecurityException ex) { logger.error("Error occurred while creating directory {}!", directory.getAbsolutePath(), ex); } } return directory; }
/** * Reads the file, which contains the filelist. This is used for the * command line arguments --filelist/-filelist for both PMD and CPD. * The separator in the filelist is a command and/or newlines. * * @param filelist the file which contains the list of path names * @return a comma-separated list of file paths * @throws IOException if the file couldn't be read */ public static String readFilelist(File filelist) throws IOException { String filePaths = FileUtils.readFileToString(filelist); filePaths = StringUtils.trimToEmpty(filePaths); filePaths = filePaths.replaceAll("\\r?\\n", ","); filePaths = filePaths.replaceAll(",+", ","); return filePaths; } }
@Override public String toString() { return StringUtils.trimToEmpty(name); } }
/** * Helper method to build a comma separated string from a list. * Blank strings are filtered out * * @param lines A list of strings * @return Comma separated String from given list */ protected static String buildCommaSeparatedString( List<String> lines ) { if ( lines == null || lines.size() == 0 ) { return null; } List<String> strings = new ArrayList<String>( lines.size() ); for ( String str : lines ) { // filter out blank strings if ( StringUtils.isNotBlank( str ) ) { strings.add( StringUtils.trimToEmpty( str ) ); } } return StringUtils.join( strings, "," ); }
@Test public void testTrimToEmpty() { assertEquals(FOO, StringUtils.trimToEmpty(FOO + " ")); assertEquals(FOO, StringUtils.trimToEmpty(" " + FOO + " ")); assertEquals(FOO, StringUtils.trimToEmpty(" " + FOO)); assertEquals(FOO, StringUtils.trimToEmpty(FOO + "")); assertEquals("", StringUtils.trimToEmpty(" \t\r\n\b ")); assertEquals("", StringUtils.trimToEmpty(StringUtilsTest.TRIMMABLE)); assertEquals(StringUtilsTest.NON_TRIMMABLE, StringUtils.trimToEmpty(StringUtilsTest.NON_TRIMMABLE)); assertEquals("", StringUtils.trimToEmpty("")); assertEquals("", StringUtils.trimToEmpty(null)); }
private Object createDataSourceWrapperIfNecessary(Object bean, String beanName) { if (DataSource.class.isInstance(bean) == false) { return bean; } else if (LocalXADataSource.class.isInstance(bean)) { return bean; } String value = StringUtils.trimToEmpty(this.environment.getProperty(CONSTANT_AUTO_CONFIG)); if (StringUtils.isNotBlank(value) && Boolean.valueOf(value) == false) { return bean; } DataSource delegate = (DataSource) bean; LocalXADataSource dataSource = new LocalXADataSource(); dataSource.setDataSource(delegate); dataSource.setBeanName(beanName); dataSource.setTransactionManager(this.transactionManager); return dataSource; }
Matcher m = regexAttributesToSend.matcher(""); for (Map.Entry<String, String> entry : attributes.entrySet()) { String headerKey = trimToEmpty(entry.getKey()); String headerVal = trimToEmpty(entry.getValue()); requestBuilder = requestBuilder.addHeader(headerKey, headerVal);
@Override public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) { if (descriptor.isDynamic()) { final Set<String> newDynamicPropertyNames = new HashSet<>(dynamicPropertyNames); if (newValue == null) { newDynamicPropertyNames.remove(descriptor.getName()); } else if (oldValue == null) { // new property newDynamicPropertyNames.add(descriptor.getName()); } this.dynamicPropertyNames = Collections.unmodifiableSet(newDynamicPropertyNames); } else { // compile the attributes-to-send filter pattern if (PROP_ATTRIBUTES_TO_SEND.getName().equalsIgnoreCase(descriptor.getName())) { if (newValue == null || newValue.isEmpty()) { regexAttributesToSend = null; } else { final String trimmedValue = StringUtils.trimToEmpty(newValue); regexAttributesToSend = Pattern.compile(trimmedValue); } } } }
@Override public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) { if (descriptor.isDynamic()) { final Set<String> newDynamicPropertyNames = new HashSet<>(dynamicPropertyNames); if (newValue == null) { newDynamicPropertyNames.remove(descriptor.getName()); } else if (oldValue == null) { // new property newDynamicPropertyNames.add(descriptor.getName()); } this.dynamicPropertyNames = Collections.unmodifiableSet(newDynamicPropertyNames); } else { // compile the attributes-to-send filter pattern if (PROP_ATTRIBUTES_TO_SEND.getName().equalsIgnoreCase(descriptor.getName())) { if (newValue == null || newValue.isEmpty()) { regexAttributesToSend = null; } else { final String trimmedValue = StringUtils.trimToEmpty(newValue); regexAttributesToSend = Pattern.compile(trimmedValue); } } } }
private void initializeRemoteParticipantIfNecessary(final String system) throws RpcException { RemoteCoordinatorRegistry participantRegistry = RemoteCoordinatorRegistry.getInstance(); final String application = StringUtils.trimToEmpty(system).intern(); RemoteCoordinator remoteParticipant = participantRegistry.getParticipant(application); if (remoteParticipant == null) { synchronized (application) { RemoteCoordinator participant = participantRegistry.getParticipant(application); if (participant == null) { this.processInitRemoteParticipantIfNecessary(application); } } // end-synchronized (target) } // end-if (remoteParticipant == null) }
private void initializeRemoteParticipantIfNecessary(final String system) throws RpcException { RemoteCoordinatorRegistry participantRegistry = RemoteCoordinatorRegistry.getInstance(); final String application = StringUtils.trimToEmpty(system).intern(); RemoteCoordinator remoteParticipant = participantRegistry.getParticipant(application); if (remoteParticipant == null) { synchronized (application) { RemoteCoordinator participant = participantRegistry.getParticipant(application); if (participant == null) { this.processInitRemoteParticipantIfNecessary(application); } } // end-synchronized (target) } // end-if (remoteParticipant == null) }
protected GenericApiGatewayRequest configureRequest(final ProcessContext context, final ProcessSession session, final String resourcePath, final FlowFile requestFlowFile) { String method = trimToEmpty( context.getProperty(PROP_METHOD).evaluateAttributeExpressions(requestFlowFile) .getValue()).toUpperCase(); HttpMethodName methodName = HttpMethodName.fromValue(method); return configureRequest(context, session, resourcePath,requestFlowFile, methodName); }
private void setAuthenticator(OkHttpClient.Builder okHttpClientBuilder, ProcessContext context) { final String authUser = trimToEmpty(context.getProperty(PROP_BASIC_AUTH_USERNAME).getValue()); // If the username/password properties are set then check if digest auth is being used if (!authUser.isEmpty() && "true".equalsIgnoreCase(context.getProperty(PROP_DIGEST_AUTH).getValue())) { final String authPass = trimToEmpty(context.getProperty(PROP_BASIC_AUTH_PASSWORD).getValue()); /* * OkHttp doesn't have built-in Digest Auth Support. A ticket for adding it is here[1] but they authors decided instead to rely on a 3rd party lib. * * [1] https://github.com/square/okhttp/issues/205#issuecomment-154047052 */ final Map<String, CachingAuthenticator> authCache = new ConcurrentHashMap<>(); com.burgstaller.okhttp.digest.Credentials credentials = new com.burgstaller.okhttp.digest.Credentials(authUser, authPass); final DigestAuthenticator digestAuthenticator = new DigestAuthenticator(credentials); okHttpClientBuilder.interceptors().add(new AuthenticationCacheInterceptor(authCache)); okHttpClientBuilder.authenticator(new CachingAuthenticatorDecorator(digestAuthenticator, authCache)); } }
private void initalizeEndpointOverride(final ProcessContext context, final AmazonS3Client s3) { // if ENDPOINT_OVERRIDE is set, use PathStyleAccess if(StringUtils.trimToEmpty(context.getProperty(ENDPOINT_OVERRIDE).evaluateAttributeExpressions().getValue()).isEmpty() == false){ final S3ClientOptions s3Options = new S3ClientOptions(); s3Options.setPathStyleAccess(true); s3.setS3ClientOptions(s3Options); } }
private void setAuthenticator(OkHttpClient.Builder okHttpClientBuilder, ConfigurationContext context) { final String authUser = trimToEmpty(context.getProperty(PROP_BASIC_AUTH_USERNAME).evaluateAttributeExpressions().getValue()); this.basicUser = authUser; isDigest = context.getProperty(PROP_DIGEST_AUTH).asBoolean(); final String authPass = trimToEmpty(context.getProperty(PROP_BASIC_AUTH_PASSWORD).evaluateAttributeExpressions().getValue()); this.basicPass = authPass; // If the username/password properties are set then check if digest auth is being used if (!authUser.isEmpty() && isDigest) { /* * OkHttp doesn't have built-in Digest Auth Support. A ticket for adding it is here[1] but they authors decided instead to rely on a 3rd party lib. * * [1] https://github.com/square/okhttp/issues/205#issuecomment-154047052 */ final Map<String, CachingAuthenticator> authCache = new ConcurrentHashMap<>(); com.burgstaller.okhttp.digest.Credentials credentials = new com.burgstaller.okhttp.digest.Credentials(authUser, authPass); final DigestAuthenticator digestAuthenticator = new DigestAuthenticator(credentials); okHttpClientBuilder.interceptors().add(new AuthenticationCacheInterceptor(authCache)); okHttpClientBuilder.authenticator(new CachingAuthenticatorDecorator(digestAuthenticator, authCache)); } }
public Result providerInvokeForKey(Invoker<?> invoker, Invocation invocation) throws RpcException { CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance(); CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory(); RemoteCoordinator transactionCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant(); String instanceId = StringUtils.trimToEmpty(invocation.getAttachment(RemoteCoordinator.class.getName())); this.registerRemoteParticipantIfNecessary(instanceId); RpcResult result = new RpcResult(); CompensableServiceFilter.InvocationResult wrapped = new CompensableServiceFilter.InvocationResult(); wrapped.setVariable(RemoteCoordinator.class.getName(), transactionCoordinator.getIdentifier()); result.setException(null); result.setValue(wrapped); return result; }
public Result providerInvokeForKey(Invoker<?> invoker, Invocation invocation) throws RpcException { CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance(); CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory(); RemoteCoordinator transactionCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant(); String instanceId = StringUtils.trimToEmpty(invocation.getAttachment(RemoteCoordinator.class.getName())); this.registerRemoteParticipantIfNecessary(instanceId); RpcResult result = new RpcResult(); CompensableServiceFilter.InvocationResult wrapped = new CompensableServiceFilter.InvocationResult(); wrapped.setVariable(RemoteCoordinator.class.getName(), transactionCoordinator.getIdentifier()); result.setException(null); result.setValue(wrapped); return result; }
@Override public FileStatus getFileStatus(Path path) throws IOException { ChannelSftp channelSftp = null; ChannelExec channelExec1 = null; ChannelExec channelExec2 = null; try { channelSftp = this.fsHelper.getSftpChannel(); SftpATTRS sftpAttrs = channelSftp.stat(HadoopUtils.toUriPath(path)); FsPermission permission = new FsPermission((short) sftpAttrs.getPermissions()); channelExec1 = this.fsHelper.getExecChannel("id " + sftpAttrs.getUId()); String userName = IOUtils.toString(channelExec1.getInputStream()); channelExec2 = this.fsHelper.getExecChannel("id " + sftpAttrs.getGId()); String groupName = IOUtils.toString(channelExec2.getInputStream()); FileStatus fs = new FileStatus(sftpAttrs.getSize(), sftpAttrs.isDir(), 1, 0l, sftpAttrs.getMTime(), sftpAttrs.getATime(), permission, StringUtils.trimToEmpty(userName), StringUtils.trimToEmpty(groupName), path); return fs; } catch (SftpException e) { throw new IOException(e); } finally { safeDisconnect(channelSftp); safeDisconnect(channelExec1); safeDisconnect(channelExec2); } }
private void invokeAfterRecvResponse(ClientHttpResponse httpResponse, boolean serverFlag) throws IOException { RemoteCoordinatorRegistry participantRegistry = RemoteCoordinatorRegistry.getInstance(); SpringBootBeanRegistry beanRegistry = SpringBootBeanRegistry.getInstance(); CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory(); TransactionInterceptor transactionInterceptor = beanFactory.getTransactionInterceptor(); HttpHeaders respHeaders = httpResponse.getHeaders(); String respTransactionStr = respHeaders.getFirst(HEADER_TRANCACTION_KEY); String respPropagationStr = respHeaders.getFirst(HEADER_PROPAGATION_KEY); String instanceId = StringUtils.trimToEmpty(respPropagationStr); RemoteAddr remoteAddr = CommonUtils.getRemoteAddr(instanceId); RemoteNode remoteNode = CommonUtils.getRemoteNode(instanceId); if (remoteAddr != null && remoteNode != null) { participantRegistry.putRemoteNode(remoteAddr, remoteNode); } String transactionText = StringUtils.trimToNull(respTransactionStr); byte[] byteArray = StringUtils.isBlank(transactionText) ? null : Base64.getDecoder().decode(transactionText); TransactionContext serverContext = byteArray == null || byteArray.length == 0 // ? null : (TransactionContext) SerializeUtils.deserializeObject(byteArray); TransactionResponseImpl txResp = new TransactionResponseImpl(); txResp.setTransactionContext(serverContext); RemoteCoordinator serverCoordinator = beanRegistry.getConsumeCoordinator(instanceId); txResp.setSourceTransactionCoordinator(serverCoordinator); txResp.setParticipantDelistFlag(serverFlag ? false : true); transactionInterceptor.afterReceiveResponse(txResp); }
protected void initializeRegionAndEndpoint(ProcessContext context) { // if the processor supports REGION, get the configured region. if (getSupportedPropertyDescriptors().contains(REGION)) { final String region = context.getProperty(REGION).getValue(); if (region != null) { this.region = Region.getRegion(Regions.fromName(region)); client.setRegion(this.region); } else { this.region = null; } } // if the endpoint override has been configured, set the endpoint. // (per Amazon docs this should only be configured at client creation) if (getSupportedPropertyDescriptors().contains(ENDPOINT_OVERRIDE)) { final String urlstr = StringUtils.trimToEmpty(context.getProperty(ENDPOINT_OVERRIDE).evaluateAttributeExpressions().getValue()); if (!urlstr.isEmpty()) { getLogger().info("Overriding endpoint with {}", new Object[]{urlstr}); if (urlstr.endsWith(".vpce.amazonaws.com")) { String region = parseRegionForVPCE(urlstr); this.client.setEndpoint(urlstr, this.client.getServiceName(), region); } else { this.client.setEndpoint(urlstr); } } } }