use of java.io.UnsupportedEncodingException in project hazelcast by hazelcast.
the class HttpPostCommandProcessor method handleWanSyncAllMaps.
private void handleWanSyncAllMaps(HttpPostCommand command) throws UnsupportedEncodingException {
String res;
byte[] data = command.getData();
String[] strList = bytesToString(data).split("&");
String wanRepName = URLDecoder.decode(strList[0], "UTF-8");
String targetGroup = URLDecoder.decode(strList[1], "UTF-8");
try {
textCommandService.getNode().getNodeEngine().getWanReplicationService().syncAllMaps(wanRepName, targetGroup);
res = response(ResponseType.SUCCESS, "message", "Sync initiated");
} catch (Exception ex) {
logger.warning("Error occurred while syncing maps", ex);
res = exceptionResponse(ex);
}
sendResponse(command, res);
}
use of java.io.UnsupportedEncodingException in project hazelcast by hazelcast.
the class HttpPostCommandProcessor method handleAddWanConfig.
private void handleAddWanConfig(HttpPostCommand command) throws UnsupportedEncodingException {
String res;
byte[] data = command.getData();
String[] strList = bytesToString(data).split("&");
String wanConfigJson = URLDecoder.decode(strList[0], "UTF-8");
try {
OperationService opService = textCommandService.getNode().getNodeEngine().getOperationService();
final Set<Member> members = textCommandService.getNode().getClusterService().getMembers();
WanReplicationConfig wanReplicationConfig = new WanReplicationConfig();
WanReplicationConfigDTO dto = new WanReplicationConfigDTO(wanReplicationConfig);
dto.fromJson(Json.parse(wanConfigJson).asObject());
List<InternalCompletableFuture> futureList = new ArrayList<InternalCompletableFuture>(members.size());
for (Member member : members) {
InternalCompletableFuture<Object> future = opService.invokeOnTarget(WanReplicationService.SERVICE_NAME, new AddWanConfigOperation(dto.getConfig()), member.getAddress());
futureList.add(future);
}
for (InternalCompletableFuture future : futureList) {
future.get();
}
res = response(ResponseType.SUCCESS, "message", "WAN configuration added.");
} catch (Exception ex) {
logger.warning("Error occurred while adding WAN config", ex);
res = exceptionResponse(ex);
}
command.setResponse(HttpCommand.CONTENT_TYPE_JSON, stringToBytes(res));
}
use of java.io.UnsupportedEncodingException in project grails-core by grails.
the class UrlMappingUtils method buildDispatchUrlForMapping.
@SuppressWarnings("rawtypes")
private static String buildDispatchUrlForMapping(UrlMappingInfo info, boolean includeParams) {
if (info.getURI() != null) {
return info.getURI();
}
final StringBuilder forwardUrl = new StringBuilder();
if (info.getViewName() != null) {
String viewName = info.getViewName();
if (viewName.startsWith("/")) {
forwardUrl.append(viewName);
} else {
forwardUrl.append(WebUtils.SLASH).append(viewName);
}
} else {
forwardUrl.append(WebUtils.SLASH).append(info.getControllerName());
if (!GrailsStringUtils.isBlank(info.getActionName())) {
forwardUrl.append(WebUtils.SLASH).append(info.getActionName());
}
}
final Map parameters = info.getParameters();
if (parameters != null && !parameters.isEmpty() && includeParams) {
try {
forwardUrl.append(WebUtils.toQueryString(parameters));
} catch (UnsupportedEncodingException e) {
throw new ControllerExecutionException("Unable to include ");
}
}
return forwardUrl.toString();
}
use of java.io.UnsupportedEncodingException in project grails-core by grails.
the class RegexUrlMapping method createURLInternal.
@SuppressWarnings({ "unchecked" })
private String createURLInternal(Map paramValues, String encoding, boolean includeContextPath) {
if (encoding == null)
encoding = "utf-8";
String contextPath = "";
if (includeContextPath) {
GrailsWebRequest webRequest = (GrailsWebRequest) RequestContextHolder.getRequestAttributes();
if (webRequest != null) {
contextPath = webRequest.getContextPath();
}
}
if (paramValues == null)
paramValues = Collections.emptyMap();
StringBuilder uri = new StringBuilder(contextPath);
Set usedParams = new HashSet();
String[] tokens = urlData.getTokens();
int paramIndex = 0;
for (int i = 0; i < tokens.length; i++) {
String token = tokens[i];
if (i == tokens.length - 1 && urlData.hasOptionalExtension()) {
token += OPTIONAL_EXTENSION_WILDCARD;
}
Matcher m = OPTIONAL_EXTENSION_WILDCARD_PATTERN.matcher(token);
if (m.find()) {
boolean tokenSet = false;
if (token.startsWith(CAPTURED_WILDCARD)) {
ConstrainedProperty prop = constraints[paramIndex++];
String propName = prop.getPropertyName();
Object value = paramValues.get(propName);
usedParams.add(propName);
if (value != null) {
token = token.replaceFirst(DOUBLE_WILDCARD_PATTERN.pattern(), value.toString());
tokenSet = true;
} else {
token = token.replaceFirst(DOUBLE_WILDCARD_PATTERN.pattern(), "");
}
} else {
tokenSet = true;
}
if (tokenSet) {
uri.append(SLASH);
}
ConstrainedProperty prop = constraints[paramIndex++];
String propName = prop.getPropertyName();
Object value = paramValues.get(propName);
usedParams.add(propName);
if (value != null) {
String ext = "." + value;
uri.append(token.replace(OPTIONAL_EXTENSION_WILDCARD + '?', ext).replace(OPTIONAL_EXTENSION_WILDCARD, ext));
} else {
uri.append(token.replace(OPTIONAL_EXTENSION_WILDCARD + '?', "").replace(OPTIONAL_EXTENSION_WILDCARD, ""));
}
continue;
}
if (token.endsWith("?")) {
token = token.substring(0, token.length() - 1);
}
m = DOUBLE_WILDCARD_PATTERN.matcher(token);
if (m.find()) {
StringBuffer buf = new StringBuffer();
do {
ConstrainedProperty prop = constraints[paramIndex++];
String propName = prop.getPropertyName();
Object value = paramValues.get(propName);
usedParams.add(propName);
if (value == null && !prop.isNullable()) {
throw new UrlMappingException("Unable to create URL for mapping [" + this + "] and parameters [" + paramValues + "]. Parameter [" + prop.getPropertyName() + "] is required, but was not specified!");
} else if (value == null) {
m.appendReplacement(buf, "");
} else {
m.appendReplacement(buf, Matcher.quoteReplacement(value.toString()));
}
} while (m.find());
m.appendTail(buf);
try {
String v = buf.toString();
if (v.indexOf(SLASH) > -1 && CAPTURED_DOUBLE_WILDCARD.equals(token)) {
// individually URL encode path segments
if (v.startsWith(SLASH)) {
// get rid of leading slash
v = v.substring(SLASH.length());
}
String[] segs = v.split(SLASH);
for (String segment : segs) {
uri.append(SLASH).append(encode(segment, encoding));
}
} else if (v.length() > 0) {
// original behavior
uri.append(SLASH).append(encode(v, encoding));
} else {
// Stop processing tokens once we hit an empty one.
break;
}
} catch (UnsupportedEncodingException e) {
throw new ControllerExecutionException("Error creating URL for parameters [" + paramValues + "], problem encoding URL part [" + buf + "]: " + e.getMessage(), e);
}
} else {
uri.append(SLASH).append(token);
}
}
populateParameterList(paramValues, encoding, uri, usedParams);
if (LOG.isDebugEnabled()) {
LOG.debug("Created reverse URL mapping [" + uri.toString() + "] for parameters [" + paramValues + "]");
}
return uri.toString();
}
use of java.io.UnsupportedEncodingException in project gradle by gradle.
the class ExternalResourceResolver method createChecksumFile.
private byte[] createChecksumFile(File src, String algorithm, int checksumLength) {
HashValue hash = HashUtil.createHash(src, algorithm);
String formattedHashString = hash.asZeroPaddedHexString(checksumLength);
try {
return formattedHashString.getBytes("US-ASCII");
} catch (UnsupportedEncodingException e) {
throw UncheckedException.throwAsUncheckedException(e);
}
}
Aggregations