Search in sources :

Example 31 with UnsupportedEncodingException

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);
}
Also used : StringUtil.bytesToString(com.hazelcast.util.StringUtil.bytesToString) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 32 with UnsupportedEncodingException

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));
}
Also used : WanReplicationConfig(com.hazelcast.config.WanReplicationConfig) WanReplicationConfigDTO(com.hazelcast.internal.management.dto.WanReplicationConfigDTO) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) ArrayList(java.util.ArrayList) StringUtil.bytesToString(com.hazelcast.util.StringUtil.bytesToString) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AddWanConfigOperation(com.hazelcast.internal.management.operation.AddWanConfigOperation) OperationService(com.hazelcast.spi.OperationService) Member(com.hazelcast.core.Member)

Example 33 with UnsupportedEncodingException

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();
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) ControllerExecutionException(org.grails.web.servlet.mvc.exceptions.ControllerExecutionException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 34 with UnsupportedEncodingException

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();
}
Also used : Matcher(java.util.regex.Matcher) UnsupportedEncodingException(java.io.UnsupportedEncodingException) UrlMappingException(grails.web.mapping.exceptions.UrlMappingException) ControllerExecutionException(org.grails.web.servlet.mvc.exceptions.ControllerExecutionException) GrailsWebRequest(org.grails.web.servlet.mvc.GrailsWebRequest) ConstrainedProperty(grails.gorm.validation.ConstrainedProperty)

Example 35 with UnsupportedEncodingException

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);
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) HashValue(org.gradle.internal.hash.HashValue)

Aggregations

UnsupportedEncodingException (java.io.UnsupportedEncodingException)1401 IOException (java.io.IOException)385 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)150 ArrayList (java.util.ArrayList)129 File (java.io.File)120 InputStream (java.io.InputStream)117 ByteArrayInputStream (java.io.ByteArrayInputStream)107 ByteArrayOutputStream (java.io.ByteArrayOutputStream)101 InputStreamReader (java.io.InputStreamReader)91 MessageDigest (java.security.MessageDigest)87 OutputStreamWriter (java.io.OutputStreamWriter)83 FileNotFoundException (java.io.FileNotFoundException)79 BufferedReader (java.io.BufferedReader)73 URL (java.net.URL)73 HashMap (java.util.HashMap)66 Map (java.util.Map)63 FileOutputStream (java.io.FileOutputStream)56 List (java.util.List)46 JSONException (org.json.JSONException)45 FileInputStream (java.io.FileInputStream)41