List of usage examples for java.net MalformedURLException MalformedURLException
public MalformedURLException(String msg)
From source file:android.databinding.tool.store.LayoutFileParser.java
public static File urlToFile(URL url) throws MalformedURLException { try {/*from w w w. java 2 s . com*/ return new File(url.toURI()); } catch (IllegalArgumentException e) { MalformedURLException ex = new MalformedURLException(e.getLocalizedMessage()); ex.initCause(e); throw ex; } catch (URISyntaxException e) { return new File(url.getPath()); } }
From source file:org.ambraproject.util.TextUtils.java
/** * Make a valid url from the given input url or url fragment * @param url url//from w w w.ja v a2 s . c om * @return valid url * @throws MalformedURLException MalformedURLException */ public static String makeValidUrl(final String url) throws MalformedURLException { String finalUrl = url; if (!verifyUrl(finalUrl)) { finalUrl = HTTP_PREFIX + finalUrl; if (!verifyUrl(finalUrl)) { throw new MalformedURLException("Invalid url:" + url); } } return finalUrl; }
From source file:au.com.onegeek.lambda.core.Lambda.java
/** * Set's the Test Website hostname (including protocol) for this test suite. * /* w w w . j a va 2s . c o m*/ * @param hostname * The name of the host to connect to i.e. http://www.google.com * @throws IOException * If the hostname is malformed or host doesn't exist, an * IOException is thrown. */ public void setHostname(String hostname) throws IOException { try { URL url = new URL(hostname); URLConnection conn = url.openConnection(); // conn.connect(); //conn.getInputStream(); } catch (MalformedURLException e) { throw new MalformedURLException("Test URL Provided is invalid: " + e.getMessage()); } catch (IOException e) { throw new IOException("Test URL Provided does not exist: " + e.getMessage()); } this.hostname = hostname; }
From source file:org.apache.nifi.processors.elasticsearch.ScrollElasticsearchHttp.java
private URL buildRequestURL(String baseUrl, String query, String index, String type, String fields, String sort, String scrollId, int pageSize, String scroll) throws MalformedURLException { if (StringUtils.isEmpty(baseUrl)) { throw new MalformedURLException("Base URL cannot be null"); }/*from ww w . j av a 2s. c o m*/ HttpUrl.Builder builder = HttpUrl.parse(baseUrl).newBuilder(); if (!StringUtils.isEmpty(scrollId)) { builder.addPathSegment("_search"); builder.addPathSegment("scroll"); builder.addQueryParameter(SCROLL_ID_QUERY_PARAM, scrollId); } else { builder.addPathSegment((StringUtils.isEmpty(index)) ? "_all" : index); if (!StringUtils.isEmpty(type)) { builder.addPathSegment(type); } builder.addPathSegment("_search"); builder.addQueryParameter(QUERY_QUERY_PARAM, query); builder.addQueryParameter(SIZE_QUERY_PARAM, String.valueOf(pageSize)); if (!StringUtils.isEmpty(fields)) { String trimmedFields = Stream.of(fields.split(",")).map(String::trim) .collect(Collectors.joining(",")); builder.addQueryParameter(FIELD_INCLUDE_QUERY_PARAM, trimmedFields); } if (!StringUtils.isEmpty(sort)) { String trimmedFields = Stream.of(sort.split(",")).map(String::trim) .collect(Collectors.joining(",")); builder.addQueryParameter(SORT_QUERY_PARAM, trimmedFields); } } builder.addQueryParameter(SCROLL_QUERY_PARAM, scroll); return builder.build().url(); }
From source file:org.apache.hawq.pxf.plugins.ignite.IgniteAccessor.java
/** * Send an INSERT REST request to the Ignite server. * * Note that/* ww w. ja v a 2 s . co m*/ * * The {@link sendRestRequest()} is used to handle network operations, thus all its exceptions may be thrown. They are: * @throws ProtocolException if Ignite reports error in it's JSON response * @throws MalformedURLException if URL is malformed * @throws IOException in case of connection failure */ private void sendInsertRestRequest(String query) throws ProtocolException, MalformedURLException, IOException { if (query == null) { LOG.error("sendInsertRestRequest(): Failed (malformed URL). URL is null"); throw new MalformedURLException("sendInsertRestRequest(): query is null"); } if (bufferWrite.isEmpty()) { return; } StringBuilder sb = new StringBuilder(query); String fieldDivisor = ""; for (OneRow row : bufferWrite) { sb.append(fieldDivisor); fieldDivisor = ", "; sb.append((String) row.getData()); } bufferWrite.clear(); // Send REST request 'qryfldexe' to Ignite JsonElement response = sendRestRequest(buildQueryFldexe(sb.toString(), null)); // Close the request immediately sendRestRequest(buildQueryCls(response.getAsJsonObject().get("queryId").getAsInt())); }
From source file:org.eclipse.orion.internal.server.servlets.xfer.ClientImport.java
/** * Sets the URL of the file to be imported (optional). *//*from ww w .j a v a 2 s . c om*/ public void setSourceURL(String urlString) throws MalformedURLException { //ensure it is a valid absolute URL if (new URL(urlString).getProtocol() == null) throw new MalformedURLException(NLS.bind("Expected an absolute URI: {0}", urlString)); props.put(KEY_SOURCE_URL, urlString); }
From source file:org.apache.nifi.processors.elasticsearch.QueryElasticsearchHttp.java
private URL buildRequestURL(String baseUrl, String query, String index, String type, String fields, String sort, int pageSize, int fromIndex) throws MalformedURLException { if (StringUtils.isEmpty(baseUrl)) { throw new MalformedURLException("Base URL cannot be null"); }// w w w .j av a 2 s .c o m HttpUrl.Builder builder = HttpUrl.parse(baseUrl).newBuilder(); builder.addPathSegment((StringUtils.isEmpty(index)) ? "_all" : index); if (!StringUtils.isEmpty(type)) { builder.addPathSegment(type); } builder.addPathSegment("_search"); builder.addQueryParameter(QUERY_QUERY_PARAM, query); builder.addQueryParameter(SIZE_QUERY_PARAM, String.valueOf(pageSize)); builder.addQueryParameter(FROM_QUERY_PARAM, String.valueOf(fromIndex)); if (!StringUtils.isEmpty(fields)) { String trimmedFields = Stream.of(fields.split(",")).map(String::trim).collect(Collectors.joining(",")); builder.addQueryParameter(FIELD_INCLUDE_QUERY_PARAM, trimmedFields); } if (!StringUtils.isEmpty(sort)) { String trimmedFields = Stream.of(sort.split(",")).map(String::trim).collect(Collectors.joining(",")); builder.addQueryParameter(SORT_QUERY_PARAM, trimmedFields); } return builder.build().url(); }
From source file:net.community.chest.gitcloud.facade.frontend.git.GitController.java
private ResolvedRepositoryData resolveTargetRepository(RequestMethod method, HttpServletRequest req) throws IOException { ResolvedRepositoryData repoData = new ResolvedRepositoryData(); String op = StringUtils.trimToEmpty(req.getParameter("service")), uriPath = req.getPathInfo(); if (StringUtils.isEmpty(op)) { int pos = uriPath.lastIndexOf('/'); if ((pos > 0) && (pos < (uriPath.length() - 1))) { op = uriPath.substring(pos + 1); }/*from w ww. j av a 2 s. c om*/ } if (!ALLOWED_SERVICES.contains(op)) { throw ExtendedLogUtils.thrownLogging(logger, Level.WARNING, "resolveTargetRepository(" + method + " " + uriPath + ")", new UnsupportedOperationException("Unsupported operation: " + op)); } repoData.setOperation(op); String repoName = extractRepositoryName(uriPath); if (StringUtils.isEmpty(repoName)) { throw ExtendedLogUtils.thrownLogging(logger, Level.WARNING, "resolveTargetRepository(" + method + " " + uriPath + ")", new IllegalArgumentException("Failed to extract repo name from " + uriPath)); } repoData.setRepoName(repoName); // TODO access an injected resolver that returns the back-end location URL String query = req.getQueryString(); try { if (StringUtils.isEmpty(query)) { repoData.setRepoLocation(new URI("http://localhost:8080/git-backend/git" + uriPath)); } else { repoData.setRepoLocation(new URI("http://localhost:8080/git-backend/git" + uriPath + "?" + query)); } } catch (URISyntaxException e) { throw new MalformedURLException(e.getClass().getSimpleName() + ": " + e.getMessage()); } return repoData; }
From source file:org.openmrs.module.ModuleUtil.java
/** * Utility method to convert a {@link File} object to a local URL. * * @param file a file object/*from w ww. j a va 2 s. co m*/ * @return absolute URL that points to the given file * @throws MalformedURLException if file can't be represented as URL for some reason */ public static URL file2url(final File file) throws MalformedURLException { if (file == null) { return null; } try { return file.getCanonicalFile().toURI().toURL(); } catch (MalformedURLException mue) { throw mue; } catch (IOException ioe) { throw new MalformedURLException("Cannot convert: " + file.getName() + " to url"); } catch (NoSuchMethodError nsme) { throw new MalformedURLException("Cannot convert: " + file.getName() + " to url"); } }
From source file:org.exoplatform.social.service.rest.SpacesRestService.java
/** * Gets the router from path of file controller.xml * //from w ww. jav a 2 s. c o m * @param path * @return * @throws IOException * @throws RouterConfigException * @since 1.2.2 */ private Router getRouter(String path) throws IOException, RouterConfigException { File f = new File(path); if (!f.exists()) { throw new MalformedURLException("Could not resolve path " + path); } if (!f.isFile()) { throw new MalformedURLException("Could not resolve path " + path + " to a valid file"); } return this.getRouter(f.toURI().toURL()); }