List of usage examples for java.net MalformedURLException getMessage
public String getMessage()
From source file:org.dataconservancy.access.connector.HttpDcsSearchIteratorTest.java
@Override protected DcsConnectorConfig getConnectorConfig() { DcsConnectorConfig config = new DcsConnectorConfig(); try {//from www .j a va 2s . c om URL u = new URL( String.format(accessServiceUrl, testServer.getServiceHostName(), testServer.getServicePort())); config.setScheme(u.getProtocol()); config.setHost(u.getHost()); config.setPort(u.getPort()); config.setContextPath(u.getPath()); config.setMaxOpenConn(1); } catch (MalformedURLException e) { fail("Unable to construct connector configuration: " + e.getMessage()); } return config; }
From source file:org.italiangrid.storm.webdav.authz.CopyMoveAuthzVoter.java
@Override public int vote(Authentication authentication, FilterInvocation filter, Collection<ConfigAttribute> attributes) { if (!isCopyOrMoveRequest(filter.getRequest())) { return ACCESS_ABSTAIN; }//from w w w. j ava 2s . c o m String destination = filter.getRequest().getHeader(DESTINATION); if (destination == null) { return ACCESS_ABSTAIN; } try { StorageAreaInfo sa = getSAFromPath(destination); if (sa == null) { return ACCESS_DENIED; } if (authentication.getAuthorities().contains(SAPermission.canWrite(sa.name()))) { return ACCESS_GRANTED; } if (logger.isDebugEnabled()) { logger.debug("Access denied. Principal does not have write permissions on " + "storage area {}", sa.name()); } return ACCESS_DENIED; } catch (MalformedURLException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:de.nrw.hbz.regal.sync.ingest.DippDownloader.java
protected void downloadObject(File dir, String pid) { try {/*from ww w . j a v a2 s . co m*/ logger.debug(pid + " start download!"); URL url = new URL(getServer() + "get/" + pid + "?xml=true"); File file = new File(dir.getAbsolutePath() + File.separator + URLEncoder.encode(pid, "utf-8") + ".xml"); String data = null; StringWriter writer = new StringWriter(); IOUtils.copy(url.openStream(), writer); data = writer.toString(); FileUtils.writeStringToFile(file, data, "utf-8"); downloadStreams(dir, pid); downloadConstituent(dir, pid); downloadRelatedObject(dir, pid, "rel:hasPart"); downloadRelatedObject(dir, pid, "rel:isPartOf"); downloadRelatedObject(new File(getDownloadLocation()), pid, "rel:isMemberOf"); downloadRelatedObject(new File(getDownloadLocation()), pid, "rel:isSubsetOf"); downloadRelatedObject(new File(getDownloadLocation()), pid, "rel:isMemberOfCollection"); } catch (MalformedURLException e) { logger.error(e.getMessage()); } catch (IOException e) { logger.error(e.getMessage()); } }
From source file:jp.classmethod.aws.InstanceMetadataFactoryBean.java
@Override public InstanceMetadata getObject() { Gson gson = new Gson(); InstanceMetadata metadata = null;// w w w . j av a 2 s . co m try (Reader reader = createUserDataReader()) { metadata = gson.fromJson(reader, InstanceMetadata.class); return metadata; } catch (MalformedURLException e) { throw new Error(e); } catch (IOException e) { logger.warn("IOException {}", e.getMessage()); } catch (Exception e) { logger.error("Exception {}", e.getMessage()); } if (metadata == null) { metadata = new InstanceMetadata(); metadata.setInstanceId("LOCAL"); } logger.info("loaded {}", metadata); return metadata; }
From source file:org.dataconservancy.access.connector.MultiThreadedConnectorTest.java
@Override protected DcsConnectorConfig getConnectorConfig() { final DcsConnectorConfig config = new DcsConnectorConfig(); try {/* w ww.j a va2s . c om*/ URL u = new URL( String.format(accessServiceUrl, testServer.getServiceHostName(), testServer.getServicePort())); config.setScheme(u.getProtocol()); config.setHost(u.getHost()); config.setPort(u.getPort()); config.setContextPath(u.getPath()); } catch (MalformedURLException e) { fail("Malformed DCS access http url: " + e.getMessage()); } config.setMaxOpenConn(2); return config; }
From source file:crawlercommons.fetcher.file.SimpleFileFetcher.java
@Override public FetchedResult get(String url, Payload payload) throws BaseFetchException { String path = null;//from www . ja va2 s .c om try { URL realUrl = new URL(url); if (!realUrl.getProtocol().equals("file")) { throw new BadProtocolFetchException(url); } path = realUrl.getPath(); if (path.length() == 0) { path = "/"; } } catch (MalformedURLException e) { throw new UrlFetchException(url, e.getMessage()); } File f = new File(path); FileInputStream fis = null; try { fis = new FileInputStream(f); long startTime = System.currentTimeMillis(); // TODO - limit to be no more than maxContentSize. We should read in // up to 16K, // then call Tika to detect the content type and use that to do // mime-type based // max size. // TODO - see Nutch's File protocol for doing a better job of // mapping file // errors (e.g. file not found) to HttpBaseException such as 404. // TODO - see Nutch's File protocol for handling directories - // return as HTML with links // TODO - see Nutch's File protocol for handling symlinks as // redirects. We'd want // to then enforce max redirects, which means moving the redirect // support back into // the BaseFetcher class. byte[] content = IOUtils.toByteArray(fis); long stopTime = System.currentTimeMillis(); long totalReadTime = Math.max(1, stopTime - startTime); long responseRate = (content.length * 1000L) / totalReadTime; String contentType = "application/octet-stream"; return new FetchedResult(url, url, System.currentTimeMillis(), new Metadata(), content, contentType, (int) responseRate, payload, url, 0, "localhost", HttpStatus.SC_OK, null); } catch (FileNotFoundException e) { throw new HttpFetchException(url, "Error fetching " + url, HttpStatus.SC_NOT_FOUND, new Metadata()); } catch (IOException e) { throw new IOFetchException(url, e); } finally { IOUtils.closeQuietly(fis); } }
From source file:com.ge.predix.sample.blobstore.connector.spring.BlobstoreServiceConnectorCreator.java
/** * Creates the BlobStore context using S3Client * * @param serviceInfo Object Store Service Info Object * @param serviceConnectorConfig Cloud Foundry Service Connector Configuration * * @return BlobstoreService Instance of the ObjectStore Service *//*from w ww. ja va2 s .com*/ @Override public BlobstoreService create(BlobstoreServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { log.info("create() invoked with serviceInfo? = " + (serviceInfo == null)); ClientConfiguration config = new ClientConfiguration(); config.setProtocol(Protocol.HTTPS); S3ClientOptions options = new S3ClientOptions(); config.setSignerOverride("S3SignerType"); BasicAWSCredentials creds = new BasicAWSCredentials(serviceInfo.getObjectStoreAccessKey(), serviceInfo.getObjectStoreSecretKey()); AmazonS3Client s3Client = new AmazonS3Client(creds, config); s3Client.setEndpoint(serviceInfo.getUrl()); s3Client.setS3ClientOptions(options); try { // Remove the Credentials from the Object Store URL URL url = new URL(serviceInfo.getUrl()); String urlWithoutCredentials = url.getProtocol() + "://" + url.getHost(); // Return BlobstoreService return new BlobstoreService(s3Client, serviceInfo.getBucket(), urlWithoutCredentials); } catch (MalformedURLException e) { log.error("create(): Couldnt parse the URL provided by VCAP_SERVICES. Exception = " + e.getMessage()); throw new RuntimeException("Blobstore URL is Invalid", e); } }
From source file:com.nicolacimmino.expensestracker.tracker.expenses_api.ExpensesApiRequest.java
public boolean performRequest() { jsonResponseArray = null;/*from w w w . jav a 2s.c o m*/ jsonResponseObject = null; HttpURLConnection connection = null; try { // Get the request JSON document as U*TF-8 encoded bytes, suitable for HTTP. mRequestData = ((mRequestData != null) ? mRequestData : new JSONObject()); byte[] postDataBytes = mRequestData.toString(0).getBytes("UTF-8"); URL url = new URL(mUrl); connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(mRequestMethod == "GET" ? false : true); // No body data for GET connection.setDoInput(true); connection.setInstanceFollowRedirects(true); connection.setRequestMethod(mRequestMethod); connection.setUseCaches(false); // For all methods except GET we need to include data in the body. if (mRequestMethod != "GET") { connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("charset", "utf-8"); connection.setRequestProperty("Content-Length", "" + Integer.toString(postDataBytes.length)); DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); wr.write(postDataBytes); wr.flush(); wr.close(); } if (connection.getResponseCode() == 200) { InputStreamReader in = new InputStreamReader((InputStream) connection.getContent()); BufferedReader buff = new BufferedReader(in); String line = buff.readLine().toString(); buff.close(); Object json = new JSONTokener(line).nextValue(); if (json.getClass() == JSONObject.class) { jsonResponseObject = (JSONObject) json; } else if (json.getClass() == JSONArray.class) { jsonResponseArray = (JSONArray) json; } // else members will be left to null indicating no valid response. return true; } } catch (MalformedURLException e) { Log.e(TAG, e.getMessage()); } catch (IOException e) { Log.e(TAG, e.getMessage()); } catch (JSONException e) { Log.e(TAG, e.getMessage()); } finally { if (connection != null) { connection.disconnect(); } } return false; }
From source file:org.gsafeproject.audit.client.AuditClient.java
private boolean validUri(String uri) { try {// w ww .j ava 2 s. co m new URL(uri); return true; } catch (MalformedURLException e) { LOGGER.error("Uri is not valid: " + uri, e); throw new IllegalArgumentException(e.getMessage(), e); } }
From source file:org.kemri.wellcome.dhisreport.api.model.HttpDhis2Server.java
public URL getUrl() { try {/*from w ww . jav a2 s. co m*/ url = new URL(sUrl); } catch (MalformedURLException e) { log.error(e.getMessage()); } return url; }