Example usage for java.net MalformedURLException getMessage

List of usage examples for java.net MalformedURLException getMessage

Introduction

In this page you can find the example usage for java.net MalformedURLException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.talend.dataprofiler.chart.util.ChartUtils.java

/**
 * DOC Administrator Comment method "openReferenceLink".
 * //from   w  w w.  j  a v a2 s. c  o  m
 * @param httpurl
 * */
public static void openReferenceLink(String httpurl) {

    if (httpurl != null) {
        try {
            WebBrowserEditor.open(new WebBrowserEditorInput(new URL(httpurl)));
        } catch (MalformedURLException e1) {
            log.log(Level.WARN, e1.getMessage());
        }
    }
}

From source file:com.fujitsu.dc.common.auth.token.CellLocalAccessToken.java

/**
 * issuer???Cell????.//  w  w  w  . j a v  a 2  s .c o m
 * @param token Token String
 * @param issuer Cell Root URL
 * @return ??CellLocalToken
 * @throws AbstractOAuth2Token.TokenParseException ????????
 */
public static CellLocalAccessToken parse(final String token, final String issuer)
        throws AbstractOAuth2Token.TokenParseException {
    if (!token.startsWith(PREFIX_ACCESS) || issuer == null) {
        throw AbstractOAuth2Token.PARSE_EXCEPTION;
    }
    String[] frag = LocalToken.doParse(token.substring(PREFIX_ACCESS.length()), issuer, IDX_COUNT);

    try {
        CellLocalAccessToken ret = new CellLocalAccessToken(
                Long.valueOf(StringUtils.reverse(frag[IDX_ISSUED_AT])), Long.valueOf(frag[IDX_LIFESPAN]),
                frag[IDX_ISSUER], frag[IDX_SUBJECT], AbstractOAuth2Token.parseRolesString(frag[IDX_ROLE_LIST]),
                frag[IDX_SCHEMA]);

        return ret;
    } catch (MalformedURLException e) {
        throw new TokenParseException(e.getMessage(), e);
    } catch (IllegalStateException e) {
        throw new TokenParseException(e.getMessage(), e);
    }
}

From source file:org.openflamingo.uploader.util.FileUtils.java

/**
 *  URL?  Input Stream? .//  www.ja  v  a2  s  . c  o m
 *
 * @param url URL
 * @return Input Stream
 */
public static InputStream openStream(String url) {
    String message = ExceptionUtils
            .getMessage("URL '{}' ?  Input Stream? ?  .", url);
    try {
        return new URL(url).openStream();
    } catch (MalformedURLException ex) {
        if (ex.getMessage().contains("no protocol") && url.startsWith("/")) {
            try {
                return new URL("file:" + url).openStream();
            } catch (Exception e) {
                throw new SystemException(message, e);
            }
        }
        throw new SystemException(message, ex);
    } catch (Exception ex) {
        throw new SystemException(message, ex);
    }
}

From source file:org.openflamingo.uploader.util.FileUtils.java

/**
 *  URL?    ?./*from  w w w  .j  ava2s  .  c o  m*/
 *
 * @param url URL
 * @return   <tt>true</tt>
 */
public static boolean isExist(String url) {
    String message = ExceptionUtils
            .getMessage("URL '{}' ?  Input Stream? ?  .", url);
    InputStream inputStream = null;
    try {
        inputStream = new URL(url).openStream();
        return true;
    } catch (MalformedURLException ex) {
        if (ex.getMessage().contains("no protocol") && url.startsWith("/")) {
            try {
                inputStream = new URL("file:" + url).openStream();
                return true;
            } catch (Exception e) {
                return false;
            }
        }
        return false;
    } catch (Exception ex) {
        return false;
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
}

From source file:io.uengine.util.FileUtils.java

/**
 *  URL?  Input Stream? .//from  w w  w  . j a  v a  2  s . c  o  m
 *
 * @param url URL
 * @return Input Stream
 */
public static InputStream openStream(String url) {
    String message = ExceptionUtils
            .getMessage("URL '{}' ?  Input Stream? ?  .", url);
    try {
        return new URL(url).openStream();
    } catch (MalformedURLException ex) {
        if (ex.getMessage().contains("no protocol") && url.startsWith("/")) {
            try {
                return new URL("file:" + url).openStream();
            } catch (Exception e) {
                throw new ServiceException(message, e);
            }
        }
        throw new ServiceException(message, ex);
    } catch (Exception ex) {
        throw new ServiceException(message, ex);
    }
}

From source file:uk.dsxt.voting.common.utils.PropertiesHelper.java

public static URL getConfOrResourceFile(String fileName) {
    File confFile = getConfFile(fileName);
    log.debug("Configuration path: {}", confFile.getAbsolutePath());
    if (confFile.exists()) {
        try {/* www  .  j  av  a  2s. com*/
            return confFile.toURI().toURL();
        } catch (MalformedURLException e) {
            log.error("Couldn't get URL from file: {}. error={}", confFile, e.getMessage());
        }
    }
    return getResource(fileName);
}

From source file:io.personium.common.auth.token.CellLocalAccessToken.java

public static CellLocalAccessToken parseCode(String code, String issuer)
        throws AbstractOAuth2Token.TokenParseException {
    if (!code.startsWith(PREFIX_CODE) || issuer == null) {
        throw AbstractOAuth2Token.PARSE_EXCEPTION;
    }//from  w  w  w. j a va  2s.c  o  m
    String[] frag = LocalToken.doParse(code.substring(PREFIX_CODE.length()), issuer, IDX_COUNT + 1);

    try {
        CellLocalAccessToken ret = new CellLocalAccessToken(
                Long.valueOf(StringUtils.reverse(frag[IDX_ISSUED_AT])), Long.valueOf(frag[IDX_LIFESPAN + 1]),
                frag[IDX_ISSUER + 1], frag[IDX_SUBJECT + 1],
                AbstractOAuth2Token.parseRolesString(frag[IDX_ROLE_LIST + 1]), frag[IDX_SCHEMA + 1]);

        return ret;
    } catch (MalformedURLException e) {
        throw new TokenParseException(e.getMessage(), e);
    } catch (IllegalStateException e) {
        throw new TokenParseException(e.getMessage(), e);
    }
}

From source file:com.janrain.oauth2.OAuth2.java

/**
 * @param redirectUri the redirect_uri (per OAuth2) to validate; may be null, which is permitted/valid
 *
 * @throws ValidationException if the supplied redirectUri fails the OAuth2 prescribed checks
 *///ww  w  . j  a v  a2 s .  co  m
public static void validateRedirectUri(String redirectUri, @Nullable String expected)
        throws ValidationException {
    if (StringUtils.isNotEmpty(redirectUri)) {
        try {
            URL url = new URL(redirectUri);
            if (StringUtils.isEmpty(url.getProtocol())) {
                throw new ValidationException(OAUTH2_TOKEN_INVALID_REQUEST,
                        "redirect_uri is not absolute: " + redirectUri);
            }
            if (StringUtils.isNotEmpty(url.getRef())) {
                throw new ValidationException(OAUTH2_TOKEN_INVALID_REQUEST,
                        "redirect_uri MUST not contain a fragment: " + redirectUri);
            }
            if (StringUtils.isNotEmpty(expected) && !redirectUri.equals(expected)) {
                throw new ValidationException(OAUTH2_TOKEN_INVALID_GRANT,
                        "Redirect URI mismatch, expected: " + expected);
            }
        } catch (MalformedURLException e) {
            throw new ValidationException(OAUTH2_TOKEN_INVALID_REQUEST,
                    "Invalid redirect_uri: " + e.getMessage());
        }
    }
}

From source file:es.tid.cep.esperanza.Utils.java

public static boolean DoHTTPPost(String urlStr, String content) {
    try {/*w  ww. j  a v  a  2  s  . co m*/
        URL url = new URL(urlStr);
        HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
        urlConn.setDoOutput(true);
        urlConn.setRequestProperty("Content-Type", "application/json; charset=utf-8");
        OutputStreamWriter printout = new OutputStreamWriter(urlConn.getOutputStream(),
                Charset.forName("UTF-8"));
        printout.write(content);
        printout.flush();
        printout.close();

        int code = urlConn.getResponseCode();
        String message = urlConn.getResponseMessage();
        logger.debug("action http response " + code + " " + message);
        if (code / 100 == 2) {
            InputStream input = urlConn.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(input));
            for (String line; (line = reader.readLine()) != null;) {
                logger.debug("action response body: " + line);
            }
            input.close();
            return true;

        } else {
            logger.error("action response is not OK: " + code + " " + message);
            InputStream error = urlConn.getErrorStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(error));
            for (String line; (line = reader.readLine()) != null;) {
                logger.error("action error response body: " + line);
            }
            error.close();
            return false;
        }
    } catch (MalformedURLException me) {
        logger.error("exception MalformedURLException: " + me.getMessage());
        return false;
    } catch (IOException ioe) {
        logger.error("exception IOException: " + ioe.getMessage());
        return false;
    }
}

From source file:mpimp.assemblxweb.util.J5FileUtils.java

public static String createDownloadUrl(AssemblXWebModel model, String filePath) throws Exception {
    String downloadUrl = "";
    URL url = null;/* w w w. j  ava2 s.co  m*/
    String host = model.getHost();
    String protocol = model.getProtocol();
    int serverPort = model.getServerPort();

    if (!filePath.startsWith("/")) {
        filePath = "/" + filePath;
    }
    try {
        if (serverPort == 0) {
            url = new URL(protocol, host, filePath);
        } else {
            url = new URL(protocol, host, serverPort, filePath);
        }
    } catch (MalformedURLException me) {
        throw new AssemblXException(me.getMessage(), J5FileUtils.class);
    }
    if (url != null) {
        downloadUrl = url.toString();
    }
    return downloadUrl;
}