List of usage examples for java.net URISyntaxException getMessage
public String getMessage()
From source file:core.com.qiniu.regions.RegionUtils.java
/** * Get the URI object for the given endpoint. URI class cannot correctly * parse the endpoint if it doesn't include protocol. This method will add * the protocol if this happens.//from w w w. ja v a 2 s . c o m */ private static URI getUriByEndpoint(String endpoint) { URI targetEndpointUri = null; try { targetEndpointUri = new URI(endpoint); if (targetEndpointUri.getHost() == null) { targetEndpointUri = new URI("http://" + endpoint); } } catch (URISyntaxException e) { throw new RuntimeException("Unable to parse service endpoint: " + e.getMessage()); } return targetEndpointUri; }
From source file:com.netflix.genie.common.client.BaseGenieClient.java
/** * Build a HTTP request from the given parameters. * * @param verb The type of HTTP request to use. Not null. * @param requestUri The URI to send the request to. Not null/empty/blank. * @param params Any query parameters to send along with the request. * @param entity An entity. Required for POST or PUT. * @return The HTTP request./*from ww w . ja va 2 s . c o m*/ * @throws GenieException On any error. */ public static HttpRequest buildRequest(final Verb verb, final String requestUri, final Multimap<String, String> params, final Object entity) throws GenieException { if (verb == null) { throw new GeniePreconditionException("No http verb entered unable to continue."); } if ((verb == Verb.POST || verb == Verb.PUT) && entity == null) { throw new GeniePreconditionException("Must have an entity to perform a post or a put."); } if (StringUtils.isBlank(requestUri)) { throw new GeniePreconditionException("No request uri entered. Unable to continue."); } try { final HttpRequest.Builder builder = HttpRequest.newBuilder().verb(verb) .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON).uri(new URI(requestUri)).entity(entity); if (params != null) { for (final Entry<String, String> param : params.entries()) { builder.queryParams(param.getKey(), param.getValue()); } } return builder.build(); } catch (final URISyntaxException use) { LOGGER.error(use.getMessage(), use); throw new GenieBadRequestException(use); } }
From source file:jfix.util.Reflections.java
/** * Returns all instanceable (sub-)classes of given type in given package. */// ww w . jav a 2s. com public static <E> E[] find(Class<E> classType, Package pckage) { File directory; try { String name = "/" + pckage.getName().replace('.', '/'); directory = new File(classType.getResource(name).toURI()); } catch (URISyntaxException e) { throw new RuntimeException(e.getMessage(), e); } List<E> result = new ArrayList<>(); if (directory.exists()) { String[] files = directory.list(); for (int i = 0; i < files.length; i++) { if (files[i].endsWith(".class")) { String classname = files[i].substring(0, files[i].length() - 6); try { Object o = Class.forName(pckage.getName() + "." + classname).newInstance(); if (classType.isInstance(o)) { result.add((E) o); } } catch (ClassNotFoundException cnfex) { System.err.println(cnfex); } catch (InstantiationException iex) { } catch (IllegalAccessException iaex) { } } } } result.sort(new Comparator<Object>() { public int compare(Object o1, Object o2) { return o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName()); } }); return result.toArray((E[]) Array.newInstance(classType, result.size())); }
From source file:org.yaoha.ApiConnector.java
public static List<URI> getRequestUriXapi(String longitudeLow, String latitudeLow, String longitudeHigh, String latitudeHigh, String name, String amenity, String shop, boolean edit_mode) { String requestString = "node[bbox=" + longitudeLow + "," + latitudeLow + "," + longitudeHigh + "," + latitudeHigh + "]"; if (name != null) requestString += "[name=*" + name + "*]"; else//from w w w . j av a 2 s .c o m requestString += "[name=*]"; if (!edit_mode) requestString += "[opening_hours=*]"; String requestStringAmenity = requestString; String requestStringShop = requestString; if (edit_mode) { if (amenity != null) requestStringAmenity += "[amenity=*" + amenity + "*]"; else requestStringAmenity += "[amenity=*]"; if (shop != null) requestStringShop += "[shop=*" + shop + "*]"; else requestStringShop += "[shop=*]"; } List<URI> requestStrings = new ArrayList<URI>(); try { URI uri = new URI("http", xapiUrl, "/api/xapi", requestStringAmenity, null); requestStrings.add(uri); } catch (URISyntaxException e) { Log.d(ApiConnector.class.getSimpleName(), e.getMessage()); } if (!requestStringAmenity.contentEquals(requestStringShop)) { try { URI uri = new URI("http", xapiUrl, "/api/xapi", requestStringShop, null); requestStrings.add(uri); } catch (URISyntaxException e) { Log.d(ApiConnector.class.getSimpleName(), e.getMessage()); } } return requestStrings; }
From source file:org.cruk.genologics.api.jaxb.URIAdapter.java
/** * Remove any "state=" parameter from the given URI. * * @param uri The URI to modify.//from ww w. j a v a 2s . c om * * @return A new URI which is {@code uri} without the state information. */ public static URI removeStateParameter(URI uri) { if (uri != null) { try { uri = new URI(removeStateParameter(uri.toString())); } catch (URISyntaxException e) { throw new AssertionError( "Removing state information from URI " + uri + " failed: " + e.getMessage()); } } return uri; }
From source file:no.digipost.api.useragreements.client.ApiService.java
private static URI buildUri(URIBuilder builder) { try {/*from w w w. j ava2 s.c o m*/ return builder.build(); } catch (URISyntaxException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:com.vmware.identity.interop.PlatformUtils.java
/** * Create URI with specified scheme, hostname and port * @param scheme/*from w w w . j a v a 2s . c om*/ * @param hostName * @param port * @return an URI object, or null in case of URISyntaxException. */ public static URI getConnectionUri(String scheme, String hostName, int port) { String uriStr = String.format("%s://%s:%d", scheme, hostName, port); try { return new URI(uriStr); } catch (URISyntaxException e) { logger.error(String.format("invalid uri string [%s] : %s", uriStr, e.getMessage())); return null; } }
From source file:mitm.common.security.crl.CRLUtils.java
/** * Returns all the CRL distribution point URLs from the provided distPoint extension. *///www . ja va 2 s . com public static Set<URI> getAllDistributionPointURIs(CRLDistPoint distPoint) throws CRLException { Set<URI> uris = new HashSet<URI>(); if (distPoint == null) { return uris; } Set<String> names = CRLDistributionPointsInspector.getURIDistributionPointNames(distPoint); for (String name : names) { try { /* * Encode the input when the URI is not valid because some certificates contain * incorrectly encoded URL's. */ URI uri = URIUtils.toURI(name, true /* encode */); if (uri != null) { uris.add(uri); } } catch (URISyntaxException e) { logger.warn("Could not create URI from '" + name + "'. Reason: " + e.getMessage()); } } return uris; }
From source file:org.sensapp.android.sensappdroid.restrequests.RestRequest.java
public static String deleteSensor(Uri uri, Sensor sensor) throws RequestErrorException { URI target;//from w w w . jav a 2 s . c o m try { target = new URI(uri.toString() + SENSOR_PATH + "/" + sensor.getName()); } catch (URISyntaxException e) { e.printStackTrace(); throw new RequestErrorException(e.getMessage()); } HttpClient client = new DefaultHttpClient(); HttpDelete request = new HttpDelete(target); request.setHeader("Content-type", "application/json"); String response = null; try { response = resolveResponse(client.execute(request)); } catch (Exception e) { throw new RequestErrorException(e.getMessage()); } return response; }
From source file:org.sensapp.android.sensappdroid.restrequests.RestRequest.java
public static boolean isSensorRegistered(Sensor sensor) throws RequestErrorException { URI target;/*from w w w.j a va2s .c om*/ try { target = new URI(sensor.getUri().toString() + SENSOR_PATH + "/" + sensor.getName()); } catch (URISyntaxException e) { e.printStackTrace(); throw new RequestErrorException(e.getMessage()); } HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(target); StatusLine status; try { status = client.execute(request).getStatusLine(); } catch (Exception e) { throw new RequestErrorException(e.getMessage()); } if (status.getStatusCode() == 200) { return true; } return false; }