Search in sources :

Example 21 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project tomcat by apache.

the class DeployTask method execute.

// --------------------------------------------------------- Public Methods
/**
     * Execute the requested operation.
     *
     * @exception BuildException if an error occurs
     */
@Override
public void execute() throws BuildException {
    super.execute();
    if (path == null) {
        throw new BuildException("Must specify 'path' attribute");
    }
    if ((war == null) && (localWar == null) && (config == null) && (tag == null)) {
        throw new BuildException("Must specify either 'war', 'localWar', 'config', or 'tag' attribute");
    }
    // Building an input stream on the WAR to upload, if any
    BufferedInputStream stream = null;
    String contentType = null;
    long contentLength = -1;
    if (war != null) {
        if (PROTOCOL_PATTERN.matcher(war).lookingAt()) {
            try {
                URL url = new URL(war);
                URLConnection conn = url.openConnection();
                contentLength = conn.getContentLengthLong();
                stream = new BufferedInputStream(conn.getInputStream(), 1024);
            } catch (IOException e) {
                throw new BuildException(e);
            }
        } else {
            FileInputStream fsInput = null;
            try {
                fsInput = new FileInputStream(war);
                contentLength = fsInput.getChannel().size();
                stream = new BufferedInputStream(fsInput, 1024);
            } catch (IOException e) {
                if (fsInput != null) {
                    try {
                        fsInput.close();
                    } catch (IOException ioe) {
                    // Ignore
                    }
                }
                throw new BuildException(e);
            }
        }
        contentType = "application/octet-stream";
    }
    // Building URL
    StringBuilder sb = createQueryString("/deploy");
    try {
        if ((war == null) && (config != null)) {
            sb.append("&config=");
            sb.append(URLEncoder.encode(config, getCharset()));
        }
        if ((war == null) && (localWar != null)) {
            sb.append("&war=");
            sb.append(URLEncoder.encode(localWar, getCharset()));
        }
        if (update) {
            sb.append("&update=true");
        }
        if (tag != null) {
            sb.append("&tag=");
            sb.append(URLEncoder.encode(tag, getCharset()));
        }
        execute(sb.toString(), stream, contentType, contentLength);
    } catch (UnsupportedEncodingException e) {
        throw new BuildException("Invalid 'charset' attribute: " + getCharset());
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException ioe) {
            // Ignore
            }
        }
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection) FileInputStream(java.io.FileInputStream)

Example 22 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project tomcat by apache.

the class JKStatusUpdateTask method createLink.

/**
     * Create JkStatus link
     * <ul>
     * <li><b>load balance example:
     * </b>http://localhost/status?cmd=update&mime=txt&w=lb&lf=false&ls=true</li>
     * <li><b>worker example:
     * </b>http://localhost/status?cmd=update&mime=txt&w=node1&l=lb&wf=1&wd=false&ws=false
     * </li>
     * </ul>
     *
     * @return create jkstatus link
     */
private StringBuilder createLink() {
    // Building URL
    StringBuilder sb = new StringBuilder();
    try {
        sb.append("?cmd=update&mime=txt");
        sb.append("&w=");
        sb.append(URLEncoder.encode(worker, getCharset()));
        if (isLBMode) {
            //http://localhost/status?cmd=update&mime=txt&w=lb&lf=false&ls=true
            if ((lbRetries != null)) {
                // > 0
                sb.append("&lr=");
                sb.append(lbRetries);
            }
            if ((lbRecovertime != null)) {
                // > 59
                sb.append("&lt=");
                sb.append(lbRecovertime);
            }
            if ((lbStickySession != null)) {
                sb.append("&ls=");
                sb.append(lbStickySession);
            }
            if ((lbForceSession != null)) {
                sb.append("&lf=");
                sb.append(lbForceSession);
            }
        } else {
            //http://localhost/status?cmd=update&mime=txt&w=node1&l=lb&wf=1&wd=false&ws=false
            if ((workerLb != null)) {
                // must be configured
                sb.append("&l=");
                sb.append(URLEncoder.encode(workerLb, getCharset()));
            }
            if ((workerLoadFactor != null)) {
                // >= 1
                sb.append("&wf=");
                sb.append(workerLoadFactor);
            }
            if ((workerDisabled != null)) {
                sb.append("&wd=");
                sb.append(workerDisabled);
            }
            if ((workerStopped != null)) {
                sb.append("&ws=");
                sb.append(workerStopped);
            }
            if ((workerRedirect != null)) {
                // other worker conrecte lb's
                sb.append("&wr=");
            }
            if ((workerClusterDomain != null)) {
                sb.append("&wc=");
                sb.append(URLEncoder.encode(workerClusterDomain, getCharset()));
            }
        }
    } catch (UnsupportedEncodingException e) {
        throw new BuildException("Invalid 'charset' attribute: " + getCharset());
    }
    return sb;
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) BuildException(org.apache.tools.ant.BuildException)

Example 23 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project tomcat by apache.

the class JMXSetTask method execute.

/**
     * Execute the requested operation.
     *
     * @exception BuildException if an error occurs
     */
@Override
public void execute() throws BuildException {
    super.execute();
    if (bean == null || attribute == null || value == null) {
        throw new BuildException("Must specify 'bean', 'attribute' and 'value' attributes");
    }
    log("Setting attribute " + attribute + " in bean " + bean + " to " + value);
    try {
        execute("/jmxproxy/?set=" + URLEncoder.encode(bean, getCharset()) + "&att=" + URLEncoder.encode(attribute, getCharset()) + "&val=" + URLEncoder.encode(value, getCharset()));
    } catch (UnsupportedEncodingException e) {
        throw new BuildException("Invalid 'charset' attribute: " + getCharset());
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) BuildException(org.apache.tools.ant.BuildException)

Example 24 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project tomcat by apache.

the class Compiler method setupContextWriter.

private ServletWriter setupContextWriter(String javaFileName) throws FileNotFoundException, JasperException {
    ServletWriter writer;
    // Setup the ServletWriter
    String javaEncoding = ctxt.getOptions().getJavaEncoding();
    OutputStreamWriter osw = null;
    try {
        osw = new OutputStreamWriter(new FileOutputStream(javaFileName), javaEncoding);
    } catch (UnsupportedEncodingException ex) {
        errDispatcher.jspError("jsp.error.needAlternateJavaEncoding", javaEncoding);
    }
    writer = new ServletWriter(new PrintWriter(osw));
    ctxt.setWriter(writer);
    return writer;
}
Also used : FileOutputStream(java.io.FileOutputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OutputStreamWriter(java.io.OutputStreamWriter) PrintWriter(java.io.PrintWriter)

Example 25 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project zeppelin by apache.

the class PegdownYumlPlugin method createYumlUrl.

public static String createYumlUrl(Map<String, String> params, String body) {
    StringBuilder inlined = new StringBuilder();
    for (String line : body.split("\\r?\\n")) {
        line = line.trim();
        if (line.length() > 0) {
            if (inlined.length() > 0) {
                inlined.append(", ");
            }
            inlined.append(line);
        }
    }
    String encodedBody = null;
    try {
        encodedBody = URLEncoder.encode(inlined.toString(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        new RuntimeException("Failed to encode YUML markdown body", e);
    }
    StringBuilder mergedStyle = new StringBuilder();
    String style = defaultString(params.get("style"), "scruffy");
    String type = defaultString(params.get("type"), "class");
    String format = defaultString(params.get("format"), "svg");
    mergedStyle.append(style);
    if (null != params.get("dir")) {
        mergedStyle.append(";dir:" + params.get("dir"));
    }
    if (null != params.get("scale")) {
        mergedStyle.append(";scale:" + params.get("scale"));
    }
    return new StringBuilder().append("http://yuml.me/diagram/").append(mergedStyle.toString() + "/").append(type + "/").append(encodedBody).append("." + format).toString();
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) StringUtils.defaultString(org.apache.commons.lang3.StringUtils.defaultString)

Aggregations

UnsupportedEncodingException (java.io.UnsupportedEncodingException)1228 IOException (java.io.IOException)338 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)137 ArrayList (java.util.ArrayList)111 File (java.io.File)109 ByteArrayOutputStream (java.io.ByteArrayOutputStream)99 MessageDigest (java.security.MessageDigest)80 ByteArrayInputStream (java.io.ByteArrayInputStream)79 InputStream (java.io.InputStream)79 InputStreamReader (java.io.InputStreamReader)73 FileNotFoundException (java.io.FileNotFoundException)71 OutputStreamWriter (java.io.OutputStreamWriter)69 BufferedReader (java.io.BufferedReader)58 URL (java.net.URL)55 FileOutputStream (java.io.FileOutputStream)52 Map (java.util.Map)52 HashMap (java.util.HashMap)48 JSONException (org.json.JSONException)44 List (java.util.List)41 PrintStream (java.io.PrintStream)39