List of usage examples for java.net MalformedURLException MalformedURLException
public MalformedURLException()
From source file:gobblin.metastore.util.MySqlJdbcUrl.java
private MySqlJdbcUrl(String url) throws MalformedURLException, URISyntaxException { if (!url.startsWith(PREFIX)) { throw new MalformedURLException(); }//from w ww. jav a 2 s .c o m builder = new URIBuilder(url.substring(PREFIX.length())); }
From source file:org.wandora.utils.DataURL.java
public DataURL(File file) throws MalformedURLException { if (file != null) { mimetype = MimeTypes.getMimeType(file); setData(file);/*from ww w .j a v a 2s. c o m*/ } else { throw new MalformedURLException(); } }
From source file:com.andrada.sitracker.reader.Samlib.java
@Override public int addAuthorForUrl(@NotNull String url) { Author author = null;/* w w w . j a v a 2 s .com*/ int message = -1; try { if (url.equals("") || !url.matches(Constants.SIMPLE_URL_REGEX)) { throw new MalformedURLException(); } url = url.replace("zhurnal.lib.ru", "samlib.ru"); if (!url.endsWith(Constants.AUTHOR_PAGE_URL_ENDING_WO_SLASH) && !url.endsWith(Constants.AUTHOR_PAGE_ALT_URL_ENDING_WO_SLASH)) { url = (url.endsWith("/")) ? url + Constants.AUTHOR_PAGE_URL_ENDING_WO_SLASH : url + Constants.AUTHOR_PAGE_URL_ENDING_WI_SLASH; } if (!url.startsWith(Constants.HTTP_PROTOCOL) && !url.startsWith(Constants.HTTPS_PROTOCOL)) { url = Constants.HTTP_PROTOCOL + url; } String urlId = SamlibPageHelper.getUrlIdFromCompleteUrl(url); if (helper.getAuthorDao().queryBuilder().where().eq("urlId", urlId).query().size() != 0) { throw new AddAuthorException(AddAuthorException.AuthorAddErrors.AUTHOR_ALREADY_EXISTS); } HttpRequest request = HttpRequest.get(new URL(url)); if (request.code() == 404) { throw new MalformedURLException(); } AuthorPageReader reader = new SamlibAuthorPageReader(request.body()); author = reader.getAuthor(url); helper.getAuthorDao().create(author); final List<Publication> items = reader.getPublications(author); if (items.size() == 0) { helper.getAuthorDao().delete(author); throw new AddAuthorException(AddAuthorException.AuthorAddErrors.AUTHOR_NO_PUBLICATIONS); } helper.getPublicationDao().callBatchTasks(new Callable<Object>() { @Nullable @Override public Object call() throws Exception { for (Publication publication : items) { helper.getPublicationDao().create(publication); } return null; } }); } catch (HttpRequest.HttpRequestException e) { message = R.string.cannot_add_author_network; } catch (MalformedURLException e) { message = R.string.cannot_add_author_malformed; } catch (SQLException e) { if (author != null) { try { helper.getAuthorDao().delete(author); } catch (SQLException e1) { //Swallow the exception as the author just wasn't saved } } message = R.string.cannot_add_author_internal; } catch (AddAuthorException e) { switch (e.getError()) { case AUTHOR_ALREADY_EXISTS: message = R.string.cannot_add_author_already_exits; break; case AUTHOR_DATE_NOT_FOUND: message = R.string.cannot_add_author_no_update_date; break; case AUTHOR_NAME_NOT_FOUND: message = R.string.cannot_add_author_no_name; break; case AUTHOR_NO_PUBLICATIONS: message = R.string.cannot_add_author_no_publications; break; default: message = R.string.cannot_add_author_unknown; break; } } catch (Exception e) { e.printStackTrace(); } return message; }
From source file:org.wandora.utils.DataURL.java
public DataURL(URL url) throws MalformedURLException { if (url != null) { mimetype = MimeTypes.getMimeType(url); setData(url);/*from www. jav a 2 s . co m*/ } else { throw new MalformedURLException(); } }
From source file:nl.strohalm.cyclos.utils.validation.URLValidation.java
@Override public ValidationError validate(final Object object, final Object property, final Object value) { String str = (String) value; if (StringUtils.isEmpty(str)) { return null; }/* w w w. j ava 2s . c o m*/ try { // Use http as the default protocol if (!str.contains("://")) { str = "http://" + str; } final URL url = new URL(str); final String protocol = url.getProtocol(); // Only allow http or https if (!protocol.equalsIgnoreCase("http") && !protocol.equalsIgnoreCase("https")) { throw new MalformedURLException(); } if (requireDotOnHostname) { // Ensure there is at least one dot on the hostname if (url.getHost().indexOf('.') < 0) { throw new MalformedURLException(); } } // The conversion to URI will enforce the RFC2396 compliance url.toURI(); return null; } catch (final MalformedURLException e) { return new InvalidError(); } catch (final URISyntaxException e) { return new InvalidError(); } }
From source file:TextUtils.java
/** * Using the java API URL class, extract the http/https * hostname.//www .ja v a 2 s . c o m * * e.g: http://www.google.com/search will return http://www.google.com * * @return */ public String getHTTPHostname(final String urlStr) { try { URL url = new URL(urlStr); String curHostname = url.getHost(); String scheme = url.getProtocol(); String fullNewURL = ""; if (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https")) { fullNewURL = scheme + "://" + curHostname; return fullNewURL; } else { throw new MalformedURLException(); } } catch (MalformedURLException e) { return "invalid-hostname"; } }
From source file:org.wso2.carbon.dss.jmx.statistics.test.utils.JMXClient.java
/** * connect to org.wso2.carbon for JMX monitoring * * @return - return MBeanServerConnection * @throws java.io.IOException - error in making connection * @throws javax.management.MalformedObjectNameException * - error in making connection *//*from ww w. ja v a2 s . co m*/ public MBeanServerConnection connect() throws IOException, MalformedObjectNameException { try { //need to read rmi ports from environment config JMXServiceURL url = new JMXServiceURL( "service:jmx:rmi://localhost:11111/jndi/rmi://" + hostName + ":9999/jmxrmi"); Hashtable<String, String[]> hashT = new Hashtable<String, String[]>(); String[] credentials = new String[] { userName, password }; hashT.put("jmx.remote.credentials", credentials); jmxc = JMXConnectorFactory.connect(url, hashT); mbsc = jmxc.getMBeanServerConnection(); if (mbsc != null) { return mbsc; } } catch (MalformedURLException e) { log.error("Error while creating Jmx connection ", e); throw new MalformedURLException(); } catch (IOException e) { log.error("Error while creating Jmx connection ", e); throw new IOException("Error while creating Jmx connection " + e); } return null; }
From source file:org.wso2.esb.integration.common.utils.clients.JMXClient.java
/** * connect to org.wso2.carbon for JMX monitoring * * @return return MBeanServerConnection * @throws java.io.IOException - error in making connection * @throws javax.management.MalformedObjectNameException - error in making connection *///w w w.j a va 2s .co m public MBeanServerConnection connect() throws IOException, MalformedObjectNameException { try { JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://localhost:" + rmiServerPort + "/jndi/rmi://" + hostName + ":" + rmiRegistryPort + "/jmxrmi"); Hashtable<String, String[]> hashT = new Hashtable<String, String[]>(); String[] credentials = new String[] { userName, password }; hashT.put("jmx.remote.credentials", credentials); jmxc = JMXConnectorFactory.connect(url, hashT); mbsc = jmxc.getMBeanServerConnection(); if (mbsc != null) { return mbsc; } } catch (MalformedURLException e) { log.error("Error while creating Jmx connection ", e); throw new MalformedURLException(); } catch (IOException e) { log.error("Error while creating Jmx connection ", e); throw new IOException("Error while creating Jmx connection " + e); } return null; }
From source file:com.liferay.portlet.PortletContextImpl.java
public URL getResource(String path) throws MalformedURLException { if ((path == null) || (!path.startsWith(StringPool.SLASH))) { throw new MalformedURLException(); }/*ww w . j a v a 2s .c o m*/ return _ctx.getResource(path); }
From source file:org.eclipse.emf.emfstore.internal.client.model.connectionmanager.xmlrpc.XmlRpcClientManager.java
private void checkUrl(String url) throws MalformedURLException { if (url != null && !url.equals(StringUtils.EMPTY)) { if (!(url.contains(":") || url.contains("/"))) { //$NON-NLS-1$ //$NON-NLS-2$ return; }/*from w w w. j a va2 s . c om*/ } throw new MalformedURLException(); }