List of usage examples for java.net URL toExternalForm
public String toExternalForm()
From source file:org.jasig.portlet.notice.service.ssp.SSPTaskNotificationService.java
/** * Map a single notification entry.//from w ww .j a va2 s . c om * * @param readContext the parsed JSON from SSP * @param index the index of the current entry to read * @param source the source value to use for the entry * @return a new Notification Entry. May return null if the entry is invalid or complete */ private NotificationEntry mapNotificationEntry(ReadContext readContext, int index, String source) { boolean completed = readContext.read(format(ROW_COMPLETED_QUERY_FMT, index), Boolean.class); if (completed) { return null; } NotificationEntry entry = new NotificationEntry(); entry.setSource(source); String id = readContext.read(format(ROW_ID_QUERY_FMT, index)); entry.setId(id); String title = readContext.read(format(ROW_NAME_QUERY_FMT, index)); entry.setTitle(title); String desc = readContext.read(format(ROW_DESCRIPTION_QUERY_FMT, index)); entry.setBody(desc); String link = readContext.read(format(ROW_LINK_QUERY_FMT, index)); URL fixedLink = normalizeLink(link); if (fixedLink != null) { entry.setUrl(fixedLink.toExternalForm()); } Date createDate = readContext.read(format("$.rows[%d].createdDate", index), Date.class); Map<NotificationState, Date> states = new HashMap<>(); states.put(NotificationState.ISSUED, createDate); try { // the date is in an odd format, need to parse by hand... String dateStr = readContext.read(format(ROW_DUE_DATE_QUERY_FMT, index)); if (!StringUtils.isBlank(dateStr)) { synchronized (dateFormat) { Date dueDate = dateFormat.parse(dateStr); entry.setDueDate(dueDate); } } } catch (Exception e) { log.warn("Error parsing due date. Ignoring", e); } return entry; }
From source file:de.undercouch.gradle.tasks.download.DownloadTest.java
/** * Test if a file can be "downloaded" from a file:// url with the * overwrite flag set to true/*from ww w.j a va 2 s . c o m*/ * @throws Exception if anything goes wrong */ @Test public void testFileDownloadURLOverwriteTrue() throws Exception { Download t = makeProjectAndTask(); String testContent = "file content"; File src = folder.newFile(); FileUtils.writeStringToFile(src, testContent, "UTF-8"); URL url = src.toURI().toURL(); File dst = folder.newFile(); assertTrue(dst.exists()); t.src(new Object[] { url.toExternalForm() }); t.dest(dst); t.overwrite(true); t.execute(); String content = FileUtils.readFileToString(dst, "UTF-8"); assertEquals(testContent, content); }
From source file:com.seleniumtests.browserfactory.RemoteDriverFactory.java
@Override public WebDriver createWebDriver() throws MalformedURLException, IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException { DriverConfig webDriverConfig = this.getWebDriverConfig(); DesiredCapabilities capability = null; URL url;/* ww w. j a va 2 s . co m*/ url = new URL(webDriverConfig.getHubUrl()); switch (webDriverConfig.getBrowser()) { case FireFox: capability = new FirefoxCapabilitiesFactory().createCapabilities(webDriverConfig); break; case InternetExplore: capability = new IECapabilitiesFactory().createCapabilities(webDriverConfig); break; case Chrome: capability = new ChromeCapabilitiesFactory().createCapabilities(webDriverConfig); break; case HtmlUnit: capability = new HtmlUnitCapabilitiesFactory().createCapabilities(webDriverConfig); break; case Safari: capability = new SafariCapabilitiesFactory().createCapabilities(webDriverConfig); break; case Android: capability = new AndroidCapabilitiesFactory().createCapabilities(webDriverConfig); break; case IPhone: capability = ((ICapabilitiesFactory) Class .forName("com.seleniumtests.browserfactory.IPhoneCapabilitiesFactory").getConstructor() .newInstance()).createCapabilities(webDriverConfig); break; case PhantomJS: capability = new PhantomJSCapabilitiesFactory().createCapabilities(webDriverConfig); break; default: break; } switch (webDriverConfig.getBrowser()) { case IPhone: case FireFox: try { driver = new ScreenShotRemoteWebDriver(url, capability); } catch (RuntimeException e) { if (e.getMessage().contains( "Unable to connect to host 127.0.0.1 on port 7062 after 45000 ms. Firefox console output")) { TestLogging.log("Firefox Driver creation got port customexception, retry after 5 seconds"); WaitHelper.waitForSeconds(5); driver = new ScreenShotRemoteWebDriver(url, capability); } else { throw e; } } break; default: driver = new ScreenShotRemoteWebDriver(url, capability); } setImplicitWaitTimeout(webDriverConfig.getImplicitWaitTimeout()); if (webDriverConfig.getPageLoadTimeout() >= 0) { setPageLoadTimeout(webDriverConfig.getPageLoadTimeout(), webDriverConfig.getBrowser()); } this.setWebDriver(driver); String hub = url.getHost(); int port = url.getPort(); // logging node ip address: try { HttpHost host = new HttpHost(hub, port); DefaultHttpClient client = new DefaultHttpClient(); String sessionUrl = "http://" + hub + ":" + port + "/grid/api/testsession?session="; URL session = new URL(sessionUrl + ((RemoteWebDriver) driver).getSessionId()); BasicHttpEntityEnclosingRequest req; req = new BasicHttpEntityEnclosingRequest("POST", session.toExternalForm()); org.apache.http.HttpResponse response = client.execute(host, req); String responseContent = EntityUtils.toString(response.getEntity()); try { JSONObject object = new JSONObject(responseContent); String proxyId = (String) object.get("proxyId"); String node = (proxyId.split("//")[1].split(":")[0]); String browserName = ((RemoteWebDriver) driver).getCapabilities().getBrowserName(); String version = ((RemoteWebDriver) driver).getCapabilities().getVersion(); System.out.println("WebDriver is running on node " + node + ", " + browserName + version + ", session " + ((RemoteWebDriver) driver).getSessionId()); TestLogging.log("WebDriver is running on node " + node + ", " + browserName + version + ", session " + ((RemoteWebDriver) driver).getSessionId()); } catch (org.json.JSONException e) { } } catch (Exception ex) { } return driver; }
From source file:net.sf.anathema.framework.presenter.action.about.AnathemaAboutAction.java
@SuppressWarnings("ConstantConditions") private void showCredits(MigPane parent) { try {//from w w w .ja v a 2s .c o m InputStream content = getClass().getClassLoader().getResourceAsStream("about.md"); URL stylesheet = getClass().getClassLoader().getResource("aboutPage.css"); String markdownContent = IOUtils.toString(content); HtmlText htmlText = new HtmlConverter().convert(new WikiText(markdownContent)); final WebView webView = new WebView(); webView.getEngine().setUserStyleSheetLocation(stylesheet.toExternalForm()); webView.getEngine().loadContent(htmlText.getHtmlText()); parent.add(webView, new CC().pad(0, 2, 0, 2)); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.apache.jena.security.model.SecuredModelDetailTest.java
@Before public void setup() { baseModel = ModelFactory.createDefaultModel(); baseModel.removeAll();/*from w ww . ja v a 2 s. com*/ URL url = SecuredModelDetailTest.class.getClassLoader() .getResource("org/apache/jena/security/model/detail.ttl"); baseModel.read(url.toExternalForm()); secEval = new DetailEvaluator(baseModel); securedModel = Factory.getInstance(secEval, "http://example.com/detailModelTest", baseModel); }
From source file:org.jboss.as.test.integration.security.loginmodules.DatabaseLoginModuleTestCase.java
/** * Tests access to a protected servlet.// w w w .j a va 2s . c om * * @param url * @throws MalformedURLException * @throws ClientProtocolException * @throws IOException * @throws URISyntaxException */ private void testAccess(URL url) throws MalformedURLException, ClientProtocolException, IOException, URISyntaxException { final URL servletUrl = new URL(url.toExternalForm() + SimpleSecuredServlet.SERVLET_PATH.substring(1)); //successful authentication and authorization assertEquals("Response body is not correct.", SimpleSecuredServlet.RESPONSE_BODY, Utils.makeCallWithBasicAuthn(servletUrl, ANIL, ANIL, 200)); //successful authentication and unsuccessful authorization Utils.makeCallWithBasicAuthn(servletUrl, MARCUS, MARCUS, 403); //unsuccessful authentication Utils.makeCallWithBasicAuthn(servletUrl, ANIL, MARCUS, 401); Utils.makeCallWithBasicAuthn(servletUrl, ANIL, Utils.hash(ANIL, MD5, Coding.BASE_64), 401); Utils.makeCallWithBasicAuthn(servletUrl, ANIL, Utils.hash(ANIL, MD5, Coding.HEX), 401); }
From source file:org.picketbox.test.config.ProtectedResourceManagerUnitTestCase.java
@Test public void testUnprotectedResource() throws Exception { URL url = new URL(urlStr + "notProtected"); DefaultHttpClient httpclient = null; try {/*from w w w.j a v a2s.co m*/ httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(url.toExternalForm()); HttpResponse response = httpclient.execute(httpget); assertEquals(404, response.getStatusLine().getStatusCode()); } finally { // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } }
From source file:org.picketbox.test.config.ProtectedResourceManagerUnitTestCase.java
@Test public void testProtectedResource() throws Exception { URL url = new URL(urlStr + "onlyManagers"); DefaultHttpClient httpclient = null; try {/* ww w. j a v a 2 s . co m*/ httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(url.toExternalForm()); HttpResponse response = httpclient.execute(httpget); assertEquals(401, response.getStatusLine().getStatusCode()); } finally { // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } }
From source file:com.sap.prd.mobile.ios.ota.webapp.BaseServlet.java
/** * Returns the base URL of the service having the specified <code>servletName</code>. * //from w w w. ja v a 2 s . c o m * @param request * @param servletName * @return base URL of the service * @throws MalformedURLException */ public URL getServiceBaseUrl(HttpServletRequest request, String servletName) throws MalformedURLException { URL applicationBaseUrl = getApplicationBaseUrl(); //e.g. "http://host:8765/ota-service" if (applicationBaseUrl == null) applicationBaseUrl = getApplicationBaseUrl(request); //e.g. "http://host:8765/ota-service" String serviceUrlPattern = Utils.getServletMappingUrlPattern(request, servletName); //e.g. "/PLIST" return new URL(applicationBaseUrl.toExternalForm() + serviceUrlPattern); }
From source file:org.picketbox.http.test.authentication.jetty.DelegatingSecurityFilterHTTPDigestUnitTestCase.java
@Test public void testDigestAuth() throws Exception { URL url = new URL(this.urlStr); DefaultHttpClient httpclient = null; try {/*from ww w.j ava2 s . c o m*/ String user = "Aladdin"; String pass = "Open Sesame"; httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(url.toExternalForm()); HttpResponse response = httpclient.execute(httpget); assertEquals(401, response.getStatusLine().getStatusCode()); Header[] headers = response.getHeaders(PicketBoxConstants.HTTP_WWW_AUTHENTICATE); HttpEntity entity = response.getEntity(); EntityUtils.consume(entity); Header header = headers[0]; String value = header.getValue(); value = value.substring(7).trim(); String[] tokens = HTTPDigestUtil.quoteTokenize(value); Digest digestHolder = HTTPDigestUtil.digest(tokens); DigestScheme digestAuth = new DigestScheme(); digestAuth.overrideParamter("algorithm", "MD5"); digestAuth.overrideParamter("realm", digestHolder.getRealm()); digestAuth.overrideParamter("nonce", digestHolder.getNonce()); digestAuth.overrideParamter("qop", "auth"); digestAuth.overrideParamter("nc", "0001"); digestAuth.overrideParamter("cnonce", DigestScheme.createCnonce()); digestAuth.overrideParamter("opaque", digestHolder.getOpaque()); httpget = new HttpGet(url.toExternalForm()); Header auth = digestAuth.authenticate(new UsernamePasswordCredentials(user, pass), httpget); System.out.println(auth.getName()); System.out.println(auth.getValue()); httpget.setHeader(auth); System.out.println("executing request" + httpget.getRequestLine()); response = httpclient.execute(httpget); entity = response.getEntity(); System.out.println("----------------------------------------"); StatusLine statusLine = response.getStatusLine(); System.out.println(statusLine); if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); } assertEquals(200, statusLine.getStatusCode()); EntityUtils.consume(entity); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } }