List of usage examples for java.net URL getPath
public String getPath()
From source file:com.eucalyptus.ws.MappingHttpRequest.java
public MappingHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri) { super(httpVersion); this.method = method; this.uri = uri; try {/*from w ww. j av a 2 s . c o m*/ URL url = new URL("http://eucalyptus" + uri); this.servicePath = url.getPath(); this.parameters = new HashMap<String, String>(); this.query = this.query == url.getQuery() ? this.query : url.getQuery();// new URLCodec().decode(url.toURI( ).getQuery( ) ).replaceAll( " ", "+" ); this.formFields = new HashMap<String, String>(); this.populateParameters(); } catch (MalformedURLException e) { throw new RuntimeException(e); } }
From source file:com.thinkberg.moxo.dav.WebdavHandler.java
/** * Get the destination object or collection. The destination header contains * a URL to the destination which is returned as a file object. * //w w w . jav a2s. c om * @param request * the servlet request * @return the file object of the destination * @throws FileSystemException * if the file system cannot create a file object * @throws MalformedURLException * if the url is misformatted */ FileObject getDestination(HttpServletRequest request) throws FileSystemException, MalformedURLException { String targetUrlStr = request.getHeader("Destination"); FileObject targetObject = null; if (null != targetUrlStr) { URL target = new URL(targetUrlStr); targetObject = getResourceManager().getFileObject(target.getPath()); log("Destination: " + targetObject.getName().getPath()); } return targetObject; }
From source file:com.linkedin.flashback.smartproxy.FlashbackRunnerTest.java
License:asdf
@Test public void testNotMatchUrl() throws IOException, InterruptedException { URL flashbackScene = getClass().getResource(FLASHBACK_SCENE_DIR); String rootPath = flashbackScene.getPath(); SceneConfiguration sceneConfiguration = new SceneConfiguration(rootPath, SCENE_MODE, HTTP_SCENE); try (FlashbackRunner flashbackRunner = new FlashbackRunner.Builder().mode(SCENE_MODE).sceneAccessLayer( new SceneAccessLayer(SceneFactory.create(sceneConfiguration), MatchRuleUtils.matchEntireRequest())) .build()) {/*from w w w . j ava 2 s . c o m*/ flashbackRunner.start(); HttpHost host = new HttpHost(PROXY_HOST, PROXY_PORT); String url = "http://www.notexist.org/"; HttpClient client = HttpClientBuilder.create().setProxy(host).build(); HttpGet request = new HttpGet(url); HttpResponse httpResponse = client.execute(request); Assert.assertEquals(httpResponse.getStatusLine().getStatusCode(), 400); Assert.assertTrue(EntityUtils.toString(httpResponse.getEntity()).contains("No Matching Request")); url = "http://www.example.org/"; request = new HttpGet(url); request.addHeader("a", "b"); httpResponse = client.execute(request); Assert.assertEquals(httpResponse.getStatusLine().getStatusCode(), 400); Assert.assertTrue(EntityUtils.toString(httpResponse.getEntity()).contains("No Matching Request")); } }
From source file:org.createnet.raptor.utils.TestUtils.java
protected JsonNode loadData(String filename) { try {//from ww w .j av a2 s . c o m String filepath = filename + ".json"; URL res = getClass().getClassLoader().getResource(filepath); if (res == null) { throw new IOException("Cannot load " + filepath); } String strpath = res.getPath(); Path path = Paths.get(strpath); byte[] content = Files.readAllBytes(path); return mapper.readTree(content); } catch (IOException ex) { throw new RuntimeException(ex); } }
From source file:com.stratio.ingestion.serializer.elasticsearch.TestElasticSearchSerializerWithMapping.java
@Before public void setUpES() throws IOException { FileUtils.deleteDirectory(new File("data/test")); String jsonMapping = IOUtils.toString(this.getClass().getResourceAsStream(MAPPING_PATH)); expectedESMapping = Strings.trimAllWhitespace("{\"" + INDEX_TYPE + "\":" + jsonMapping + "}"); URL resourceUrl = getClass().getResource(MAPPING_PATH); Context context = new Context(); context.put("mappingFile", resourceUrl.getPath()); serializer = new ElasticSearchSerializerWithMapping(); serializer.configure(context);/*from w w w. j a v a2 s . c o m*/ ImmutableSettings.Builder ESSettings = ImmutableSettings.settingsBuilder().put("http.enabled", "false") .put("cluster.name", "test"); node = nodeBuilder().local(true).settings(ESSettings.build()).node(); client = node.client(); }
From source file:com.dianping.cosmos.monitor.HttpClientService.java
private HttpUriRequest getGetRequest(String url, boolean useURI) throws Exception { HttpUriRequest request;//from w w w. j a va 2 s . c o m if (useURI) { URL requestURL = new URL(url); URI uri = new URI(requestURL.getProtocol(), null, requestURL.getHost(), requestURL.getPort(), requestURL.getPath(), requestURL.getQuery(), null); request = new HttpGet(uri); } else { request = new HttpGet(url); } return request; }
From source file:com.linkedin.flashback.smartproxy.FlashbackRunnerTest.java
License:asdf
@Test public void testSetCookieHeader() throws IOException, InterruptedException { URL flashbackScene = getClass().getResource(FLASHBACK_SCENE_DIR); String rootPath = flashbackScene.getPath(); SceneConfiguration sceneConfiguration = new SceneConfiguration(rootPath, SCENE_MODE, "setCookie"); try (FlashbackRunner flashbackRunner = new FlashbackRunner.Builder().mode(SCENE_MODE).sceneAccessLayer( new SceneAccessLayer(SceneFactory.create(sceneConfiguration), MatchRuleUtils.matchEntireRequest())) .build()) {//from www . ja v a 2s . c o m flashbackRunner.start(); HttpHost host = new HttpHost(PROXY_HOST, PROXY_PORT); String url = "http://www.example.org/"; HttpClient client = HttpClientBuilder.create().setProxy(host).build(); HttpGet request = new HttpGet(url); request.addHeader("Set-Cookie", "ABC=\\\"R:0|g:fcaa967e-asdfa-484a-8a5e-asdfa\\\"; Version=1; Max-Age=30; Expires=Thu, 23-Mar-2017 18:01:20 GMT; Path=/"); request.addHeader("Set-Cookie", "ABC=\\\"R:0|g:fcaa967e-asdfasdf-484a-8a5e-asdf|n:asdfasdfasd-37ca-42cf-a909-95e0dd19e334\\\"; Version=1; Max-Age=30; Expires=Thu, 23-Mar-2017 18:01:20 GMT; Path=/"); request.addHeader("Set-Cookie", "ABC=\\\"R:0|i:138507\\\"; Version=1; Max-Age=30; Expires=Thu, 23-Mar-2017 18:01:20 GMT; Path=/"); request.addHeader("Set-Cookie", "ABC=\\\"R:0|i:138507|e:42\\\"; Version=1; Max-Age=30; Expires=Thu, 23-Mar-2017 18:01:20 GMT; Path=/"); request.addHeader("Set-Cookie", "guestidc=0d28bda6-5d42-4ee9-bd1e-asdasda; Domain=asdafsdfasdfasdfa.com; Path=/"); HttpResponse httpResponse0 = client.execute(request); Assert.assertTrue(EntityUtils.toString(httpResponse0.getEntity()) .contains("I am from Flashback scene, not http://example.org")); } }
From source file:com.tremolosecurity.provisioning.customTasks.CallRemoteWorkflow.java
@Override public void init(WorkflowTask task, Map<String, Attribute> params) throws ProvisioningException { this.workflowName = params.get("workflowName").getValues().get(0); this.lastmileKeyName = params.get("lastMileKeyName").getValues().get(0); this.url = params.get("url").getValues().get(0); this.fromRequest = new HashSet<String>(); this.staticRequest = new HashMap<String, String>(); this.lastMileUid = params.get("lastMileUid").getValues().get(0); this.uidAttributeName = params.get("uidAttributeName").getValues().get(0); Attribute attr = params.get("attributeFromRequest"); if (attr != null) { this.fromRequest.addAll(attr.getValues()); }//w w w. j a v a2s.c om attr = params.get("staticRequestValues"); if (attr != null) { for (String p : attr.getValues()) { String name = p.substring(0, p.indexOf('=')); String val = p.substring(p.indexOf('=') + 1); this.staticRequest.put(name, val); } } this.lastMileUser = params.get("lastMileUser").getValues().get(0); this.timeSkew = Integer.parseInt(params.get("timeSkew").getValues().get(0)); this.task = task; try { URL uurl = new URL(this.url); this.uri = uurl.getPath(); } catch (MalformedURLException e) { throw new ProvisioningException("Could not initialize", e); } }
From source file:com.linkedin.flashback.smartproxy.FlashbackRunnerTest.java
License:asdf
@Test() public void testReplayHttp() throws InterruptedException, IOException { URL flashbackScene = getClass().getResource(FLASHBACK_SCENE_DIR); String rootPath = flashbackScene.getPath(); SceneConfiguration sceneConfiguration = new SceneConfiguration(rootPath, SCENE_MODE, HTTP_SCENE); try (FlashbackRunner flashbackRunner = new FlashbackRunner.Builder().mode(SCENE_MODE).sceneAccessLayer( new SceneAccessLayer(SceneFactory.create(sceneConfiguration), MatchRuleUtils.matchEntireRequest())) .build()) {/*from www . j av a2 s. co m*/ flashbackRunner.start(); HttpHost host = new HttpHost(PROXY_HOST, PROXY_PORT); String url = "http://www.example.org/"; HttpClient client = HttpClientBuilder.create().setProxy(host).build(); HttpGet request = new HttpGet(url); HttpResponse httpResponse0 = client.execute(request); Assert.assertTrue(EntityUtils.toString(httpResponse0.getEntity()) .contains("I am from Flashback scene, not http://example.org")); url = "http://www.nba.com/"; request = new HttpGet(url); HttpResponse httpResponse1 = client.execute(request); Assert.assertTrue(EntityUtils.toString(httpResponse1.getEntity()) .contains("I am from Flashback scene, not http://www.nba.com")); url = "http://www.notexist.org/"; request = new HttpGet(url); HttpResponse httpResponse2 = client.execute(request); Assert.assertEquals(httpResponse2.getStatusLine().getStatusCode(), 400); Assert.assertTrue(EntityUtils.toString(httpResponse2.getEntity()).contains("No Matching Request")); } }
From source file:crawler.java.edu.uci.ics.crawler4j.robotstxt.RobotstxtServer.java
/** Please note that in the case of a bad URL, TRUE will be returned */ public boolean allows(WebURL webURL) { if (config.isEnabled()) { try {/* w w w . j a v a2 s . co m*/ URL url = new URL(webURL.getURL()); String host = getHost(url); String path = url.getPath(); HostDirectives directives = host2directivesCache.get(host); if ((directives != null) && directives.needsRefetch()) { synchronized (host2directivesCache) { host2directivesCache.remove(host); directives = null; } } if (directives == null) { directives = fetchDirectives(url); } return directives.allows(path); } catch (MalformedURLException e) { logger.error("Bad URL in Robots.txt: " + webURL.getURL(), e); } } return true; }