List of usage examples for java.net URISyntaxException getMessage
public String getMessage()
From source file:vitro.vgw.wsiadapter.TCSWSIAdapter.java
public void discoverCoapEndpoint(String addr) { // create request according to specified method String method = "DISCOVER"; URI uri = null;//from w ww . j av a 2 s . c o m try { uri = new URI(addr); } catch (URISyntaxException e) { System.err.println("Failed to parse URI: " + e.getMessage()); return; } doRequest(method, uri); }
From source file:com.almende.eve.transport.http.DebugServlet.java
@Override public void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws IOException, ServletException { if (!handleSession(req, resp)) { if (!resp.isCommitted()) { resp.sendError(HttpServletResponse.SC_UNAUTHORIZED); }/* ww w . j av a 2s .com*/ resp.flushBuffer(); return; } // retrieve the url and the request body final String body = StringUtil.streamToString(req.getInputStream()); final String url = req.getRequestURI(); final String id = getId(url); if (id == null || id.equals("") || id.equals(myUrl.toASCIIString())) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Couldn't parse URL, missing 'id'"); resp.flushBuffer(); return; } String sender = req.getHeader("X-Eve-SenderUrl"); if (sender == null || sender.equals("")) { sender = "web://" + req.getRemoteUser() + "@" + req.getRemoteAddr(); } URI senderUrl = null; try { senderUrl = new URI(sender); } catch (final URISyntaxException e) { LOG.log(Level.WARNING, "Couldn't parse senderUrl:" + sender, e); } final HttpTransport transport = HttpService.get(myUrl, id); if (transport != null) { try { final String response = transport.receive(body, senderUrl); // TODO: It doesn't need to be json, should we handle mime-types // better? resp.addHeader("Content-Type", "application/json"); resp.getWriter().println(response); resp.getWriter().close(); } catch (final IOException e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Receiver raised exception:" + e.getMessage()); } } else { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Couldn't load transport"); } resp.flushBuffer(); }
From source file:com.srotya.collectd.storm.StormNimbusMetrics.java
@Override public int read() { Gson gson = new Gson(); login();//from w w w. ja v a 2 s . c om for (String nimbus : nimbusAddresses) { Subject.doAs(subject, new PrivilegedAction<Void>() { @Override public Void run() { HttpGet request = new HttpGet(nimbus + "/api/v1/topology/summary"); CloseableHttpClient client = builder.build(); try { HttpResponse response = client.execute(request, context); if (response.getStatusLine().getStatusCode() == 200) { HttpEntity entity = response.getEntity(); String result = EntityUtils.toString(entity); JsonObject topologySummary = gson.fromJson(result, JsonObject.class); List<String> ids = extractTopologyIds( topologySummary.get("topologies").getAsJsonArray()); if (ids.isEmpty()) { Collectd.logInfo("No storm topologies deployed"); } for (String id : ids) { PluginData pd = new PluginData(); pd.setPluginInstance(id); pd.setTime(System.currentTimeMillis()); try { pd.setHost(new URI(nimbus).getHost()); } catch (URISyntaxException e) { continue; } ValueList values = new ValueList(pd); fetchTopologyMetrics(nimbus, id, values, builder, gson); } } else { Collectd.logError("Unable to fetch Storm metrics:" + response.getStatusLine() + "\t" + EntityUtils.toString(response.getEntity())); } client.close(); } catch (Exception e) { e.printStackTrace(); Collectd.logError( "Failed to fetch metrics from Nimbus:" + nimbus + "\treason:" + e.getMessage()); } return null; } }); } return 0; }
From source file:com.cloud.network.resource.NccHttpCode.java
private synchronized Answer execute(NetScalerImplementNetworkCommand cmd, int numRetries) { String result = null;/* www. j a va 2 s . c o m*/ try { URI agentUri = null; agentUri = new URI("https", null, _ip, DEFAULT_PORT, "/cs/adcaas/v1/networks", null, null); org.json.JSONObject jsonBody = new JSONObject(cmd.getDetails()); s_logger.debug("Sending Network Implement to NCC:: " + jsonBody); result = postHttpRequest(jsonBody.toString(), agentUri, _sessionid); s_logger.debug("Result of Network Implement to NCC:: " + result); result = queryAsyncJob(result); s_logger.debug("Done query async of network implement request :: " + result); return new Answer(cmd, true, "Successfully allocated device"); } catch (URISyntaxException e) { String errMsg = "Could not generate URI for NetScaler ControlCenter "; s_logger.error(errMsg, e); } catch (ExecutionException e) { if (e.getMessage().equalsIgnoreCase(NccHttpCode.NOT_FOUND)) { return new Answer(cmd, true, "Successfully unallocated the device"); } else if (e.getMessage().startsWith("ERROR, ROLLBACK")) { s_logger.error(e.getMessage()); return new Answer(cmd, false, e.getMessage()); } else { if (shouldRetry(numRetries)) { s_logger.debug( "Retrying the command NetScalerImplementNetworkCommand retry count: " + numRetries); return retry(cmd, numRetries); } else { return new Answer(cmd, false, e.getMessage()); } } } catch (Exception e) { if (shouldRetry(numRetries)) { s_logger.debug("Retrying the command NetScalerImplementNetworkCommand retry count: " + numRetries); return retry(cmd, numRetries); } else { return new Answer(cmd, false, e.getMessage()); } } return Answer.createUnsupportedCommandAnswer(cmd); }
From source file:com.cloud.network.resource.NccHttpCode.java
private synchronized String login() throws ExecutionException { String result = null;//from ww w. ja v a2s . c o m JSONObject jsonResponse = null; try { URI agentUri = null; agentUri = new URI("https", null, _ip, DEFAULT_PORT, "/nitro/v2/config/" + "login", null, null); org.json.JSONObject jsonBody = new JSONObject(); org.json.JSONObject jsonCredentials = new JSONObject(); jsonCredentials.put("username", _username); jsonCredentials.put("password", _password); jsonBody.put("login", jsonCredentials); result = postHttpRequest(jsonBody.toString(), agentUri, _sessionid); if (result == null) { throw new ConfigurationException("No Response Received from the NetScalerControlCenter Device"); } else { jsonResponse = new JSONObject(result); org.json.JSONArray loginResponse = jsonResponse.getJSONArray("login"); _sessionid = jsonResponse.getJSONArray("login").getJSONObject(0).getString("sessionid"); s_logger.debug("New Session id from NCC :" + _sessionid); set_nccsession(_sessionid); s_logger.debug("session on Static Session variable" + get_nccsession()); } s_logger.debug("Login to NCC Device response :: " + result); return result; } catch (URISyntaxException e) { String errMsg = "Could not generate URI for Hyper-V agent"; s_logger.error(errMsg, e); } catch (JSONException e) { s_logger.debug("JSON Exception :" + e.getMessage()); throw new ExecutionException("Failed to log in to NCC device at " + _ip + " due to " + e.getMessage()); } catch (Exception e) { throw new ExecutionException("Failed to log in to NCC device at " + _ip + " due to " + e.getMessage()); } return result; }
From source file:com.gargoylesoftware.htmlunit.HttpWebConnection.java
/** * {@inheritDoc}/* w w w.j ava 2 s . com*/ */ @Override public WebResponse getResponse(final WebRequest request) throws IOException { final URL url = request.getUrl(); final HttpClientBuilder builder = reconfigureHttpClientIfNeeded(getHttpClientBuilder()); if (connectionManager_ == null) { connectionManager_ = createConnectionManager(builder); } builder.setConnectionManager(connectionManager_); HttpUriRequest httpMethod = null; try { try { httpMethod = makeHttpMethod(request, builder); } catch (final URISyntaxException e) { throw new IOException("Unable to create URI from URL: " + url.toExternalForm() + " (reason: " + e.getMessage() + ")", e); } final HttpHost hostConfiguration = getHostConfiguration(request); final long startTime = System.currentTimeMillis(); HttpResponse httpResponse = null; try { httpResponse = builder.build().execute(hostConfiguration, httpMethod, httpContext_); } catch (final SSLPeerUnverifiedException s) { // Try to use only SSLv3 instead if (webClient_.getOptions().isUseInsecureSSL()) { HtmlUnitSSLConnectionSocketFactory.setUseSSL3Only(httpContext_, true); httpResponse = builder.build().execute(hostConfiguration, httpMethod, httpContext_); } else { throw s; } } catch (final Error e) { // in case a StackOverflowError occurs while the connection is leased, it won't get released. // Calling code may catch the StackOverflowError, but due to the leak, the httpClient_ may // come out of connections and throw a ConnectionPoolTimeoutException. // => best solution, discard the HttpClient instance. httpClientBuilder_.set(null); throw e; } final DownloadedContent downloadedBody = downloadResponseBody(httpResponse); final long endTime = System.currentTimeMillis(); return makeWebResponse(httpResponse, request, downloadedBody, endTime - startTime); } finally { if (httpMethod != null) { onResponseGenerated(httpMethod); } } }
From source file:vitro.vgw.wsiadapter.TCSWSIAdapter.java
void doRequest(String method, URI uri) { Request request = newRequest(method); URI reqUri = uri;//w w w . j a v a 2s. c o m // if(useCoapProxy) { // System.out.println("Setting proxy for request"); // request.setOption(new Option(uri.toString(), OptionNumberRegistry.PROXY_URI)); // } if (method.equals("OBSERVE")) { request.setOption(new Option(0, OptionNumberRegistry.OBSERVE)); } // set request URI if (method.equals("DISCOVER") && (uri.getPath() == null || uri.getPath().isEmpty() || uri.getPath().equals("/"))) { // add discovery resource path to URI try { reqUri = new URI(uri.getScheme(), uri.getAuthority(), DISCOVERY_RESOURCE, uri.getQuery()); } catch (URISyntaxException e) { System.err.println("Failed to parse URI: " + e.getMessage()); System.exit(ERR_BAD_URI); } } if (useCoapProxy) { System.out.println("Setting proxy for request"); request.setOption(new Option(reqUri.toString(), OptionNumberRegistry.PROXY_URI)); // request.setURI(reqUri); // override peer address with proxy address EndpointAddress a = new EndpointAddress(proxyUri); request.setPeerAddress(a); } else { System.out.println("No proxy for request"); request.setURI(reqUri); } request.setPayload(""); request.setToken(TokenManager.getInstance().acquireToken()); System.out.println("Ici???s"); ResponseHandler respHandler = new ResponseHandler() { public void handleResponse(Response response) { System.out.println("On arrive ici"); doHandleResponse(response); } }; request.registerResponseHandler(respHandler); System.out.println("response handler registered"); // enable response queue in order to use blocking I/O // request.enableResponseQueue(true); // request.prettyPrint(); pendingRequests.add(request); System.out.println("request stored"); // execute request try { request.execute(); System.out.println("request executed"); } catch (UnknownHostException e) { System.err.println("Unknown host: " + e.getMessage()); System.exit(ERR_REQUEST_FAILED); } catch (IOException e) { System.err.println("Failed to execute request: " + e.getMessage()); System.exit(ERR_REQUEST_FAILED); } }
From source file:com.cloud.network.resource.NccHttpCode.java
public void getServicePackages() throws ExecutionException { String result = null;/*from w w w . j av a 2 s . c o m*/ try { URI agentUri = null; agentUri = new URI("https", null, _ip, DEFAULT_PORT, "/admin/v1/servicepackages", null, null); org.json.JSONObject jsonBody = new JSONObject(); org.json.JSONObject jsonCredentials = new JSONObject(); result = getHttpRequest(jsonBody.toString(), agentUri, _sessionid); s_logger.debug("List of Service Packages in NCC:: " + result); } catch (URISyntaxException e) { String errMsg = "Could not generate URI for Hyper-V agent"; s_logger.error(errMsg, e); } catch (Exception e) { throw new ExecutionException("Failed to log in to NCC device at " + _ip + " due to " + e.getMessage()); } }
From source file:com.pennassurancesoftware.tutum.client.TutumClient.java
private URI createUri(ApiRequest request) { URIBuilder ub = new URIBuilder(); ub.setScheme(Constants.HTTPS_SCHEME); ub.setHost(apiHost);/*from w ww . jav a 2s . c om*/ ub.setPath(createPath(request)); for (String paramName : request.getQueryParams().keySet()) { final List<String> values = request.getQueryParams().get(paramName); for (String value : values) { ub.setParameter(paramName, value); } } URI uri = null; try { uri = ub.build(); } catch (URISyntaxException use) { LOG.error(use.getMessage(), use); } return uri; }
From source file:nl.esciencecenter.ptk.web.WebClient.java
protected void init(WebConfig config) throws WebException { logger.debugPrintf("init():New WebClient for:%s\n", serverUri); if (config == null) { throw new NullPointerException("Can not have NULL WebConfig."); }/* www .j av a 2 s . c om*/ if (config.getAllowUserInteraction()) { ui = new SimpelUI(); } this.config = config; this.httpClient = null; this.resourceLoader = new ResourceLoader(); try { this.serverUri = config.getServerURI(); this.serviceUri = config.getServiceURI(); } catch (URISyntaxException e) { throw new WebException(Reason.URI_EXCEPTION, e.getMessage(), e); } }