List of usage examples for java.net URISyntaxException getMessage
public String getMessage()
From source file:fi.jyu.student.jatahama.onlineinquirytool.server.LoadSaveServlet.java
private String formSafeUtfName(String utfName) { String safeName = null;// ww w .ja v a 2 s .c o m try { // Try to encode uftName to URI format (see RFC6266) safeName = new URI(null, utfName, null).toASCIIString(); } catch (URISyntaxException e) { log.warning("URI constructor failure: " + e.getMessage()); // ASCII fallback safeName = formSafeAscii(utfName); } return safeName; }
From source file:conversandroid.pandora.PandoraConnection.java
/** * Sends the user message to the chatbot and returns the chatbot response * It is a simplification and adaptation to Android of the method with the same name in the * Pandorabots Java API: https://github.com/pandorabots/pb-java * @param input text for conversation/* w w w.j a v a 2 s.c o m*/ * @return text of bot's response * @throws PandoraException when the connection is not succesful */ public String talk(String input) throws PandoraException { String responses = ""; input = input.replace(" ", "%20"); URI uri = null; try { uri = new URI("https://" + host + "/talk/" + appId + "/" + botName + "?input=" + input + "&user_key=" + userKey); Log.d(LOGTAG, "Request to pandorabot: Botname=" + botName + ", input=\"" + input + "\"" + " uri=" + uri); } catch (URISyntaxException e) { Log.e(LOGTAG, e.getMessage()); throw new PandoraException(PandoraErrorCode.IDORHOST); } int SDK_INT = android.os.Build.VERSION.SDK_INT; if (SDK_INT > 8) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); //Why the strictmode: http://stackoverflow.com/questions/25093546/android-os-networkonmainthreadexception-at-android-os-strictmodeandroidblockgua try { Content content = Request.Post(uri).execute().returnContent(); String response = content.asString(); JSONObject jObj = new JSONObject(response); JSONArray jArray = jObj.getJSONArray("responses"); for (int i = 0; i < jArray.length(); i++) { responses += jArray.getString(i).trim(); } } catch (JSONException e) { Log.e(LOGTAG, e.getMessage()); throw new PandoraException(PandoraErrorCode.PARSE); } catch (IOException e) { Log.e(LOGTAG, e.getMessage()); throw new PandoraException(PandoraErrorCode.CONNECTION); } catch (Exception e) { throw new PandoraException(PandoraErrorCode.IDORHOST); } } if (responses.toLowerCase().contains("match failed")) { Log.e(LOGTAG, "Match failed"); throw new PandoraException(PandoraErrorCode.NOMATCH); } Log.d(LOGTAG, "Bot response:" + responses); return responses; }
From source file:org.dataconservancy.ui.it.support.CitableLocatorRequest.java
public HttpPost confirmAsHttpPost() throws MalformedURLException { HttpPost post = null;//from ww w . j a v a 2 s .co m try { post = new HttpPost(urlConfig.getCitableLocatorPostUrl().toURI()); } catch (URISyntaxException e) { throw new RuntimeException(e.getMessage(), e); } if (collectionId == null || reservedCitableLocator == null) { throw new RuntimeException( "confirmAsHttpPost must have non-null collectionID and reservedCitableLocator"); } List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("collectionId", collectionId)); params.add(new BasicNameValuePair("reservedCitableLocator", reservedCitableLocator)); params.add(new BasicNameValuePair(CONFIRM_STRIPES_EVENT, "Confirm EZID")); HttpEntity entity = null; try { entity = new UrlEncodedFormEntity(params, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage(), e); } post.setEntity(entity); return post; }
From source file:org.dataconservancy.ui.it.support.CitableLocatorRequest.java
public HttpPost cancelAsHttpPost() throws MalformedURLException { HttpPost post = null;// ww w . j a v a2 s . c o m try { post = new HttpPost(urlConfig.getCitableLocatorPostUrl().toURI()); } catch (URISyntaxException e) { throw new RuntimeException(e.getMessage(), e); } if (collectionId == null || reservedCitableLocator == null) { throw new RuntimeException( "cancelAsHttpPost must have non-null collectionID and reservedCitableLocator"); } List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("collectionId", collectionId)); params.add(new BasicNameValuePair("reservedCitableLocator", reservedCitableLocator)); params.add(new BasicNameValuePair(CANCEL_STRIPES_EVENT, "Cancel EZID")); HttpEntity entity = null; try { entity = new UrlEncodedFormEntity(params, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage(), e); } post.setEntity(entity); return post; }
From source file:ch.cyberduck.core.azure.AzureMetadataFeature.java
@Override public void setMetadata(final Path file, final Map<String, String> metadata) throws BackgroundException { try {/*from w ww.j av a 2 s .c om*/ final BlobRequestOptions options = new BlobRequestOptions(); if (containerService.isContainer(file)) { final CloudBlobContainer container = session.getClient() .getContainerReference(containerService.getContainer(file).getName()); container.setMetadata(new HashMap<String, String>(metadata)); container.uploadMetadata(AccessCondition.generateEmptyCondition(), options, context); } else { final CloudBlob blob = session.getClient() .getContainerReference(containerService.getContainer(file).getName()) .getBlobReferenceFromServer(containerService.getKey(file)); // Populates the blob properties and metadata blob.downloadAttributes(); // Replace metadata final HashMap<String, String> pruned = new HashMap<String, String>(); for (Map.Entry<String, String> m : metadata.entrySet()) { final BlobProperties properties = blob.getProperties(); if (HttpHeaders.CACHE_CONTROL.equalsIgnoreCase(m.getKey())) { // Update properties properties.setCacheControl(m.getValue()); continue; } if (HttpHeaders.CONTENT_TYPE.equalsIgnoreCase(m.getKey())) { // Update properties properties.setContentType(m.getValue()); continue; } pruned.put(m.getKey(), m.getValue()); } blob.setMetadata(pruned); blob.uploadMetadata(AccessCondition.generateEmptyCondition(), options, context); blob.uploadProperties(); } } catch (URISyntaxException e) { throw new NotfoundException(e.getMessage(), e); } catch (StorageException e) { throw new AzureExceptionMappingService().map("Failure to write attributes of {0}", e, file); } }
From source file:org.jboss.spring.vfs.VFSResource.java
public URI getURI() throws IOException { try {//w w w .j a v a 2s . co m return VFSUtil.invokeMethodWithExpectedExceptionType(VFSUtil.VIRTUAL_FILE_METHOD_TO_URI, file, URISyntaxException.class); } catch (URISyntaxException e) { IOException ioe = new IOException(e.getMessage()); ioe.initCause(e); throw ioe; } }
From source file:org.basinmc.maven.plugins.minecraft.launcher.DownloadDescriptor.java
/** * Fetches the artifact from the server and stores it in a specified file. *//*from ww w .ja v a 2 s. c om*/ public void fetch(@Nonnull Path outputFile) throws IOException { HttpClient client = HttpClients.createMinimal(); try { HttpGet request = new HttpGet(this.url.toURI()); HttpResponse response = client.execute(request); StatusLine line = response.getStatusLine(); if (line.getStatusCode() != 200) { throw new IOException( "Unexpected status code: " + line.getStatusCode() + " - " + line.getReasonPhrase()); } try (InputStream inputStream = response.getEntity().getContent()) { try (FileChannel fileChannel = FileChannel.open(outputFile, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) { try (ReadableByteChannel inputChannel = Channels.newChannel(inputStream)) { fileChannel.transferFrom(inputChannel, 0, Long.MAX_VALUE); } } } } catch (URISyntaxException ex) { throw new IOException("Received invalid URI from API: " + ex.getMessage(), ex); } }
From source file:it.geosolutions.geobatch.nrl.ndvi.BaseTest.java
protected File loadFile(String name) { try {/*from ww w . j a v a 2 s . c o m*/ URL url = this.getClass().getClassLoader().getResource(name); if (url == null) { throw new IllegalArgumentException("Cant get file '" + name + "'"); } File file = new File(url.toURI()); return file; } catch (URISyntaxException e) { LOGGER.error("Can't load file " + name + ": " + e.getMessage(), e); return null; } }
From source file:org.dataconservancy.ui.it.support.CreateCollectionRequest.java
public HttpPost asHttpPost() { if (!collectionSet) { throw new IllegalStateException("Collection not set: call setCollection(Collection) first."); }/*w w w. j av a 2 s. com*/ HttpPost post = null; try { post = new HttpPost(urlConfig.getAddCollectionUrl().toURI()); } catch (URISyntaxException e) { throw new RuntimeException(e.getMessage(), e); } List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("projectId", projectId)); params.add(new BasicNameValuePair("collection.title", title)); params.add(new BasicNameValuePair("collection.summary", summary)); params.add(new BasicNameValuePair("collection.id", id)); if (publicationDate != null) { params.add(new BasicNameValuePair("collection.publicationDate", publicationDate.toString())); } if (creators != null && creators.size() > 0) { for (int i = 0; i < creators.size(); i++) { params.add(new BasicNameValuePair("collection.creators[" + i + "].prefixes", creators.get(i).getPrefixes())); params.add(new BasicNameValuePair("collection.creators[" + i + "].givenNames", creators.get(i).getGivenNames())); params.add(new BasicNameValuePair("collection.creators[" + i + "].middleNames", creators.get(i).getMiddleNames())); params.add(new BasicNameValuePair("collection.creators[" + i + "].familyNames", creators.get(i).getFamilyNames())); params.add(new BasicNameValuePair("collection.creators[" + i + "].suffixes", creators.get(i).getSuffixes())); } } params.add(new BasicNameValuePair(STRIPES_EVENT, "Add Collection")); HttpEntity entity = null; try { entity = new UrlEncodedFormEntity(params, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e.getMessage(), e); } post.setEntity(entity); return post; }
From source file:eu.supersede.dm.rest.UserRest.java
/** * Return all the users with the given profile. * @param authentication//w w w .jav a 2s. c om * @param profile */ @RequestMapping(value = "", method = RequestMethod.GET) public List<User> getUsers(Authentication authentication, @RequestParam(required = false) String profile) { DatabaseUser currentUser = (DatabaseUser) authentication.getPrincipal(); List<eu.supersede.integration.api.datastore.fe.types.User> proxyUsers = null; try { proxyUsers = proxy.getFEDataStoreProxy().getUsers(currentUser.getTenantId(), false, currentUser.getToken()); } catch (URISyntaxException e) { throw new InternalServerErrorException(e.getMessage()); } List<User> us = new ArrayList<>(); if (profile != null) { for (eu.supersede.integration.api.datastore.fe.types.User proxyUser : proxyUsers) { if (hasProfile(proxyUser, profile)) { us.add(new User(new Long(proxyUser.getUser_id()), proxyUser.getFirst_name() + " " + proxyUser.getLast_name(), proxyUser.getEmail())); } } } else { for (eu.supersede.integration.api.datastore.fe.types.User proxyUser : proxyUsers) { us.add(new User(new Long(proxyUser.getUser_id()), proxyUser.getFirst_name() + " " + proxyUser.getLast_name(), proxyUser.getEmail())); } } return us; }