List of usage examples for java.net URI toString
public String toString()
From source file:com.talis.storage.http.ItemResource.java
@DELETE public Response delete(@PathParam("id") String id) { URI tmbURI = makeInternalURI(id); LOG.debug(String.format("DELETE request to URI : %s", tmbURI.toString())); try {/*from ww w.j a va 2 s .co m*/ myStore.delete(tmbURI); } catch (InvalidKeyException e) { throw new WebApplicationException(e, 400); } catch (IOException e) { throw new WebApplicationException(e, 500); } return Response.noContent().build(); }
From source file:org.cloudcrawler.domain.crawler.robotstxt.RobotsTxtService.java
/** * This method is used to evaluate if the provided uri is * allowed to be crawled against the robots.txt of the website. * * @param uri/*from w w w .j a v a 2 s .com*/ * @return * @throws Exception */ public boolean isAllowedUri(URI uri) throws Exception { URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setScheme(uri.getScheme()); uriBuilder.setHost(uri.getHost()); uriBuilder.setUserInfo(uri.getUserInfo()); uriBuilder.setPath("/robots.txt"); URI robotsTxtUri = uriBuilder.build(); BaseRobotRules rules = (BaseRobotRules) cache.get(robotsTxtUri.toString()); if (rules == null) { HttpResponse response = httpService.get(robotsTxtUri); try { // HACK! DANGER! Some sites will redirect the request to the top-level domain // page, without returning a 404. So look for a response which has a redirect, // and the fetched content is not plain text, and assume it's one of these... // which is the same as not having a robotstxt.txt file. String contentType = response.getEntity().getContentType().getValue(); boolean isPlainText = (contentType != null) && (contentType.startsWith("text/plain")); if (response.getStatusLine().getStatusCode() == 404 || !isPlainText) { rules = robotsTxtParser.failedFetch(HttpStatus.SC_GONE); } else { StringWriter writer = new StringWriter(); IOUtils.copy(response.getEntity().getContent(), writer); rules = robotsTxtParser.parseContent(uri.toString(), writer.toString().getBytes(), response.getEntity().getContentType().getValue(), httpService.getUserAgent()); } } catch (Exception e) { EntityUtils.consume(response.getEntity()); throw e; } EntityUtils.consume(response.getEntity()); cache.set(robotsTxtUri.toString(), 60 * 60 * 24, rules); } return rules.isAllowed(uri.toString()); }
From source file:org.gradle.internal.resource.transport.http.HttpResourceAccessor.java
/** * Same as #getResource except that it always gives access to the response body, * irrespective of the returned HTTP status code. Never returns {@code null}. *///from w w w. j av a 2 s .c o m public HttpResponseResource getRawResource(final URI uri) throws IOException { abortOpenResources(); String location = uri.toString(); LOGGER.debug("Constructing external resource: {}", location); HttpRequestBase request = new HttpGet(uri); HttpResponse response; try { response = http.performHttpRequest(request); } catch (IOException e) { throw new HttpRequestException( String.format("Could not %s '%s'.", request.getMethod(), request.getURI()), e); } HttpResponseResource resource = wrapResponse(uri, response); return recordOpenGetResource(resource); }
From source file:com.github.thesmartenergy.sparql.generate.jena.engine.Bnodes.java
public void test(String value) throws Exception { URL examplePath = Bnodes.class.getResource("/" + value); File exampleDir = new File(examplePath.toURI()); // read location-mapping URI confUri = exampleDir.toURI().resolve("configuration.ttl"); Model conf = RDFDataMgr.loadModel(confUri.toString()); // initialize file manager FileManager fileManager = FileManager.makeGlobal(); Locator loc = new LocatorFile(exampleDir.toURI().getPath()); LocationMapper mapper = new LocationMapper(conf); fileManager.addLocator(loc);/*from w w w .j av a 2 s . c o m*/ fileManager.setLocationMapper(mapper); String qstring = IOUtils.toString(fileManager.open("query.rqg"), "UTF-8"); SPARQLGenerateQuery q = (SPARQLGenerateQuery) QueryFactory.create(qstring, SPARQLGenerate.SYNTAX); // create generation plan PlanFactory factory = new PlanFactory(fileManager); RootPlan plan = factory.create(q); Model output = plan.exec(); // write output output.write(System.out, "TTL"); Model expectedOutput = fileManager.loadModel("expected_output.ttl"); StringWriter sw = new StringWriter(); expectedOutput.write(sw, "TTL"); LOG.debug("\n" + sw.toString()); Assert.assertTrue(output.isIsomorphicWith(expectedOutput)); }
From source file:com.bill99.yn.webmgmt.functional.rest.TaskRestFT.java
/** * //.//from www. ja va 2 s . co m */ @Test @Category(Smoke.class) public void createUpdateAndDeleteTask() { // create Task task = TaskData.randomTask(); URI taskUri = restTemplate.postForLocation(resoureUrl, task); System.out.println(taskUri.toString()); Task createdTask = restTemplate.getForObject(taskUri, Task.class); assertThat(createdTask.getTitle()).isEqualTo(task.getTitle()); // update String id = StringUtils.substringAfterLast(taskUri.toString(), "/"); task.setId(new Long(id)); task.setTitle(TaskData.randomTitle()); restTemplate.put(taskUri, task); Task updatedTask = restTemplate.getForObject(taskUri, Task.class); assertThat(updatedTask.getTitle()).isEqualTo(task.getTitle()); // delete restTemplate.delete(taskUri); try { restTemplate.getForObject(taskUri, Task.class); fail("Get should fail while feth a deleted task"); } catch (HttpStatusCodeException e) { assertThat(e.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); } }
From source file:info.rmapproject.api.auth.ApiUserServiceTest.java
/** * Tests retrieval of the System Agent URI to assign to an Event * Should return an agent URI/* w w w .j av a 2s.c o m*/ */ @Test @Ignore //see comment at top of page public void getSystemAgentUriForEventTest() { try { URI sysAgent = apiUserService.getCurrentSystemAgentUri(); assertTrue(sysAgent.toString().equals("rmap:rmaptestagent")); } catch (RMapApiException e) { fail("sysAgent not retrieved"); } }
From source file:angel.zhuoxiu.library.pusher.PusherConnection.java
public void connect() { try {//from ww w . jav a 2 s.c o m URI url = new URI(pusher.getUrl()); Log.d(LOG_TAG, "Connecting to " + url.toString()); mWebSocket = new WebSocketConnection(url); mWebSocket.setEventHandler(new WebSocketEventHandler() { @Override public void onOpen() { Log.d(LOG_TAG, "Successfully opened Websocket"); } @Override public void onMessage(WebSocketMessage message) { Log.d(LOG_TAG, "Received from Websocket " + message.getText()); try { JSONObject parsed = new JSONObject(message.getText()); String eventName = parsed.getString("event"); String channelName = parsed.optString("channel", null); String eventData = parsed.getString("data"); if (eventName.equals(Pusher.PUSHER_EVENT_CONNECTION_ESTABLISHED)) { JSONObject parsedEventData = new JSONObject(eventData); String socketId = parsedEventData.getString("socket_id"); pusher.onConnected(socketId); } else { pusher.dispatchEvents(eventName, eventData, channelName); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onClose() { Log.d(LOG_TAG, "Successfully closed Websocket"); } }); mWebSocket.connect(); } catch (URISyntaxException e) { e.printStackTrace(); } catch (WebSocketException e) { e.printStackTrace(); } }
From source file:cn.aozhi.songify.functional.rest.TaskRestFT.java
/** * //.// w w w . j a v a2 s .c o m */ @Test @Category(Smoke.class) public void createUpdateAndDeleteTask() { // create Task task = TaskData.randomTask(); URI createdTaskUri = restTemplate.postForLocation(resourceUrl, task); System.out.println(createdTaskUri.toString()); Task createdTask = restTemplate.getForObject(createdTaskUri, Task.class); assertThat(createdTask.getTitle()).isEqualTo(task.getTitle()); // update String id = StringUtils.substringAfterLast(createdTaskUri.toString(), "/"); task.setId(new Long(id)); task.setTitle(TaskData.randomTitle()); restTemplate.put(createdTaskUri, task); Task updatedTask = restTemplate.getForObject(createdTaskUri, Task.class); assertThat(updatedTask.getTitle()).isEqualTo(task.getTitle()); // delete restTemplate.delete(createdTaskUri); try { restTemplate.getForObject(createdTaskUri, Task.class); fail("Get should fail while feth a deleted task"); } catch (HttpStatusCodeException e) { assertThat(e.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); } }
From source file:com.prestomation.android.sospy.monitor.AppEngineClient.java
public HttpResponse makeRequest(String httpMethod, String urlPath, List<NameValuePair> params) throws Exception { HttpUriRequest request;// w ww .ja va 2 s . c om URI uri = new URI(BASE_URL + urlPath); Log.w(TAG, uri.toString()); if (httpMethod == "POST") { request = new HttpPost(uri); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8"); ((HttpPost) request).setEntity(entity); } else if (httpMethod == "DELETE") { request = new HttpDelete(uri); } else { //This should never happen return null; } HttpResponse res = makeRequestNoRetry(request, params); return res; }
From source file:oracle.custom.ui.servlet.LoginServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*w ww. j a v a 2s . c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); //System.out.println("User Agent " + request.getHeader("User-Agent")); try (PrintWriter out = response.getWriter()) { // if we come back here after the user is already authenticated it means // that we're looking for OAuth consent if (request.getSession().getAttribute("AUTHENTICATED") != null) { request.getRequestDispatcher("/oauthallowed.jsp").forward(request, response); } try { String tenantName = (String) DomainName.getDomainName(); String endpoint = OpenIdConfiguration.getInstance(tenantName).getAuthzEndpoint(); String clientId = CredentialsList.getCredentials().get(tenantName).getId(); StringBuffer url = request.getRequestURL(); String uri = request.getRequestURI(); String ctx = request.getContextPath(); String base = url.substring(0, url.length() - uri.length() + ctx.length()) + "/"; //String redirecturl = base + "atreturn/"; //String openIdConfig = endpoint + "?client_id=" + clientId + // "&response_type=code&redirect_uri=" + redirecturl + // "&scope=urn:opc:idm:t.user.me+openid+urn:opc:idm:__myscopes__&nonce=" + UUID.randomUUID().toString(); URIBuilder builder = new URIBuilder(endpoint); builder.addParameter("client_id", clientId); builder.addParameter("response_type", "code"); builder.addParameter("redirect_uri", base + "atreturn/"); builder.addParameter("scope", "urn:opc:idm:t.user.me openid urn:opc:idm:__myscopes__"); builder.addParameter("nonce", UUID.randomUUID().toString()); URI redirectUrl = builder.build(); System.out.println("Opend Id URL is " + redirectUrl.toString()); response.sendRedirect(redirectUrl.toString()); } catch (Exception ex) { ex.printStackTrace(); request.getRequestDispatcher("/error.jsp").forward(request, response); } } }