List of usage examples for java.net URISyntaxException getMessage
public String getMessage()
From source file:org.sensapp.android.sensappdroid.restrequests.RestRequest.java
public static boolean isCompositeRegistered(Composite composite) throws RequestErrorException { URI target;// ww w.j a v a 2s . c o m try { target = new URI(composite.getUri().toString() + COMPOSITE_PATH + "/" + composite.getName()); } catch (URISyntaxException e1) { e1.printStackTrace(); throw new RequestErrorException(e1.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; }
From source file:org.sensapp.android.sensappdroid.restrequests.RestRequest.java
public static String postComposite(Composite composite) throws RequestErrorException { String content = JsonPrinter.compositeToJson(composite); URI target;//from w w w . ja va2 s . c o m try { target = new URI(composite.getUri().toString() + COMPOSITE_PATH); } catch (URISyntaxException e1) { e1.printStackTrace(); throw new RequestErrorException(e1.getMessage()); } HttpClient client = new DefaultHttpClient(); HttpPost request = new HttpPost(target); request.setHeader("Content-type", "application/json"); String response = null; try { StringEntity seContent = new StringEntity(content); seContent.setContentType("text/json"); request.setEntity(seContent); 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 String putData(Uri uri, String data) throws RequestErrorException { URI target;/*from w w w . j a va 2 s .c om*/ try { target = new URI(uri.toString() + DISPATCHER_PATH); } catch (URISyntaxException e1) { e1.printStackTrace(); throw new RequestErrorException(e1.getMessage()); } HttpClient client = new DefaultHttpClient(); HttpPut request = new HttpPut(target); request.setHeader("Content-type", "application/json"); String response = null; try { StringEntity seContent = new StringEntity(data); seContent.setContentType("text/json"); request.setEntity(seContent); response = resolveResponse(client.execute(request)); } catch (Exception e) { throw new RequestErrorException(e.getMessage()); } if (response.trim().length() > 2) { throw new RequestErrorException("Sensor not registred: " + response); } return response; }
From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.KubernetesProviderUtils.java
static URI proxyServiceEndpoint(Proxy proxy, String namespace, String serviceName, int servicePort) { try {//from ww w.j a v a2 s .c o m return new URIBuilder().setPort(proxy.getPort()).setHost("localhost").setScheme("http").setPath( "/api/v1/proxy/namespaces/" + namespace + "/services/" + serviceName + ":" + servicePort) .build(); } catch (URISyntaxException e) { throw new HalException(Severity.FATAL, "Malformed service details: " + e.getMessage()); } }
From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.v1.KubernetesV1ProviderUtils.java
static URI proxyServiceEndpoint(Proxy proxy, String namespace, String serviceName, int servicePort) { try {/* w w w. j a v a 2 s .c o m*/ return new URIBuilder().setPort(proxy.getPort()).setHost("localhost").setScheme("http").setPath( "/api/v1/namespaces/" + namespace + "/services/" + serviceName + ":" + servicePort + "/proxy") .build(); } catch (URISyntaxException e) { throw new HalException(Severity.FATAL, "Malformed service details: " + e.getMessage()); } }
From source file:com.twinsoft.convertigo.engine.util.HttpUtils.java
public static String originalRequestURI(HttpServletRequest request) { String uri = HeaderName.XConvertigoRequestURI.getHeader(request); if (uri == null) { uri = request.getRequestURI();//w ww. j ava 2s.co m } else { String frontal = HeaderName.XConvertigoFrontal.getHeader(request); if ("apache".equalsIgnoreCase(frontal)) { try { uri = new URI(null, null, uri, null).toASCIIString(); } catch (URISyntaxException e) { // Transformation failed, keep existing uri Engine.logEngine.debug("(HttpUtils) Apache URI escape failed : " + e.getMessage()); } } } return uri; }
From source file:net.orpiske.sdm.lib.net.Downloader.java
/** * Download a file//from ww w .j a va 2 s.c om * @param url the URL to the file * @param overwrite whether or not to overwrite existent files * @throws ResourceExchangeException if unable to download the file */ public static void download(final String url, boolean overwrite) throws ResourceExchangeException { try { URI uri = new URI(url); File outputFile = setupOutputFile(url, overwrite); ResourceExchange resourceExchange = ResourceExchangeFactory.newResourceExchange(uri); ResourceInfo resourceInfo = resourceExchange.info(uri); try { long outSize = FileUtils.sizeOf(outputFile); long sourceSize = resourceInfo.getSize(); if (sourceSize == outSize) { logger.info("Destination file and source file appears to be " + "the same. Using cached file instead."); } else { Resource<InputStream> resource = resourceExchange.get(uri); saveDownload(outputFile, resource); if (logger.isDebugEnabled()) { logger.debug("Downloaded " + outputFile.getPath()); } } } finally { logger.debug("Releasing resources"); resourceExchange.release(); } } catch (URISyntaxException e) { throw new ResourceExchangeException("Invalid URI: " + url, e); } catch (IOException e) { throw new ResourceExchangeException("I/O error: " + e.getMessage(), e); } }
From source file:heybot.heybot.java
private static String getWorkspacePath() { try {/* w w w . j a v a 2 s . c o m*/ return new java.io.File( heybot.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getParent() + "/workspace"; } catch (URISyntaxException ex) { System.err.println("Ooops! URISyntaxException caught." + ex.getMessage()); } return ""; }
From source file:be.fedict.trust.crl.CrlTrustLinker.java
private static URI toURI(String str) { try {//from w w w. j av a 2s . c om URI uri = new URI(str); return uri; } catch (URISyntaxException e) { throw new InvalidParameterException("CRL URI syntax error: " + e.getMessage()); } }
From source file:edu.jhu.pha.vospace.oauth.MySQLOAuthProvider2.java
/** * Set the access token/*from w w w . j ava2s .c o m*/ * If userId != null, creates link to user's container as root matching the name in consumer. The container should exist already. * @param accessor The OAuth accessor object * @param userId the owner userId * @throws OAuthException */ public static synchronized void markAsAuthorized(final Token requestToken, final String userId) { try { if (null == requestToken.getAttributes().getFirst("root_container")) { // No predefined one (can be predefined for sharing); in this case set the default one final String default_root_container = ((Consumer) requestToken.getConsumer()).getAttributes() .getFirst("container"); if (!UserHelper.userExists(userId)) { UserHelper.addDefaultUser(userId); } //First check if the root node exists VospaceId identifier = new VospaceId(new NodePath(default_root_container)); Node node = NodeFactory.createNode(identifier, userId, NodeType.CONTAINER_NODE); logger.debug("Marking as authorized, root node: " + identifier.toString()); if (!node.isStoredMetadata()) { node.setNode(null); logger.debug("Creating the node " + node.getUri()); } DbPoolServlet.goSql("Mark oauth token as authorized", "update oauth_accessors set container_id = (select container_id from containers join user_identities on containers.user_id = user_identities.user_id where identity = ? and container_name = ?), authorized = 1 where request_token = ?;", new SqlWorker<Integer>() { @Override public Integer go(Connection conn, PreparedStatement stmt) throws SQLException { stmt.setString(1, userId); stmt.setString(2, default_root_container); stmt.setString(3, requestToken.getToken()); return stmt.executeUpdate(); } }); } else { // the container is already set up (sharing) DbPoolServlet.goSql("Mark oauth token as authorized", "update oauth_accessors set authorized = 1 where request_token = ?;", new SqlWorker<Integer>() { @Override public Integer go(Connection conn, PreparedStatement stmt) throws SQLException { stmt.setString(1, requestToken.getToken()); return stmt.executeUpdate(); } }); } } catch (URISyntaxException ex) { logger.error("Error creating root (app) node for user: " + ex.getMessage()); } }