List of usage examples for java.net URISyntaxException printStackTrace
public void printStackTrace()
From source file:info.rmapproject.core.model.impl.openrdf.ORAdapterTest.java
@Test public void testUri2OpenRdfIri() { String urString = "http://rmap-project.info/rmap/"; URI uri = null;/* w w w . j av a 2 s .com*/ try { uri = new URI(urString); } catch (URISyntaxException e) { e.printStackTrace(); fail(); } IRI rIri = ORAdapter.uri2OpenRdfIri(uri); assertEquals(urString, rIri.stringValue()); URI uri2 = ORAdapter.openRdfIri2URI(rIri); assertEquals(urString, uri2.toASCIIString()); assertEquals(uri, uri2); }
From source file:info.rmapproject.core.model.impl.openrdf.ORAdapterTest.java
@Test public void testRMapIri2OpenRdfIri() throws RMapException, RMapDefectiveArgumentException { String urString = "http://rmap-project.info/rmap/"; URI uri = null;// w ww .java2s . c o m try { uri = new URI(urString); } catch (URISyntaxException e) { e.printStackTrace(); fail(); } RMapIri rmIri = new RMapIri(uri); IRI rIri = ORAdapter.rMapIri2OpenRdfIri(rmIri); assertEquals(urString, rIri.stringValue()); URI uri2 = ORAdapter.openRdfIri2URI(rIri); assertEquals(urString, uri2.toASCIIString()); assertEquals(uri, uri2); }
From source file:eionet.gdem.utils.Utils.java
/** * Utility method for checking whether the resource exists. The resource can be web or file system resource that matches the URI * with "http", "https" or "file" schemes Returns false, if the resource does not exist * * @param strUri// ww w . j a va 2 s. c o m * @return */ public static boolean resourceExists(String strUri) { strUri = StringUtils.replace(strUri, "\\", "/"); try { URI uri = new URI(strUri); String scheme = uri.getScheme(); if (scheme.startsWith("http")) { return HttpUtils.urlExists(strUri); } else if (scheme.equals("file")) { File f = new File(uri.getPath()); return f.exists(); } } catch (URISyntaxException e) { e.printStackTrace(); return false; } return false; }
From source file:com.bazaarvoice.seo.sdk.url.BVSeoSdkURLBuilder.java
private URI httpUri(String path) { boolean isStaging = Boolean .parseBoolean(bvConfiguration.getProperty(BVClientConfig.STAGING.getPropertyName())); boolean isHttpsEnabled = Boolean .parseBoolean(bvConfiguration.getProperty(BVClientConfig.SSL_ENABLED.getPropertyName())); String s3Hostname = isStaging ? bvConfiguration.getProperty(BVCoreConfig.STAGING_S3_HOSTNAME.getPropertyName()) : bvConfiguration.getProperty(BVCoreConfig.PRODUCTION_S3_HOSTNAME.getPropertyName()); String cloudKey = bvConfiguration.getProperty(BVClientConfig.CLOUD_KEY.getPropertyName()); String urlPath = "/" + cloudKey + "/" + path; URIBuilder builder = new URIBuilder(); String httpScheme = isHttpsEnabled ? "https" : "http"; builder.setScheme(httpScheme).setHost(s3Hostname).setPath(urlPath); try {//w w w . ja v a2s . com return builder.build(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:org.seadpdt.impl.RepoServicesImpl.java
@POST @Path("/") @Consumes(MediaType.APPLICATION_JSON)//from ww w. j a va2s .c om @Produces(MediaType.APPLICATION_JSON) public Response registerRepository(String profileString) { JSONObject profile = new JSONObject(profileString); if (!profile.has("orgidentifier")) { return Response.status(Status.BAD_REQUEST) .entity(new BasicDBObject("Failure", "Invalid request format: " + "Request must contain the field \"orgidentifier\"")) .build(); } String newID = (String) profile.get("orgidentifier"); FindIterable<Document> iter = repositoriesCollection.find(new Document("orgidentifier", newID)); if (iter.iterator().hasNext()) { return Response.status(Status.CONFLICT) .entity(new BasicDBObject("Failure", "Repository with Identifier " + newID + " already exists")) .build(); } else { repositoriesCollection.insertOne(Document.parse(profile.toString())); URI resource = null; try { resource = new URI("./" + newID); } catch (URISyntaxException e) { // Should not happen given simple ids e.printStackTrace(); } return Response.created(resource).entity(new Document("orgidentifier", newID)).build(); } }
From source file:org.apache.tika.batch.fs.FSBatchTestBase.java
private String[] commandLine(String testConfig, String loggerProps, String[] args) { List<String> commandLine = new ArrayList<>(); commandLine.add("java"); commandLine.add("-Dlog4j.configuration=file:" + this.getClass().getResource(loggerProps).getFile()); commandLine.add("-Xmx128m"); commandLine.add("-cp"); String cp = System.getProperty("java.class.path"); //need to test for " " on *nix, can't just add double quotes //across platforms. if (cp.contains(" ")) { cp = "\"" + cp + "\""; }/*from ww w.j av a 2 s .c o m*/ commandLine.add(cp); commandLine.add("org.apache.tika.batch.fs.FSBatchProcessCLI"); String configFile = null; try { configFile = Paths.get(this.getClass().getResource(testConfig).toURI()).toAbsolutePath().toString(); } catch (URISyntaxException e) { e.printStackTrace(); } commandLine.add("-bc"); commandLine.add(configFile); for (String s : args) { commandLine.add(s); } return commandLine.toArray(new String[commandLine.size()]); }
From source file:com.aretha.net.HttpConnectionHelper.java
/** * Obtain a {@link HttpPost} request// w w w . jav a 2 s . c o m * * @param url * Remote url * @param params * Request parameters * @return */ public HttpPost obtainHttpPostRequest(String url, List<NameValuePair> params) { try { return obtainHttpPostRequest(new URI(url), params); } catch (URISyntaxException e) { e.printStackTrace(); } return null; }
From source file:com.grameenfoundation.ictchallenge.controllers.ConnectedAppREST.java
private JSONObject showFarmers(String instanceUrl, String accessToken) throws ServletException, IOException { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet(); //add key and value httpGet.addHeader("Authorization", "OAuth " + accessToken); try {/* w w w .ja v a 2 s .c om*/ URIBuilder builder = new URIBuilder(instanceUrl + "/services/data/v30.0/query"); //builder.setParameter("q", "SELECT Name, Id from Account LIMIT 100"); builder.setParameter("q", "SELECT Name__c,Date_Of_Birth__c,Land_size__c,Farmer_I_D__c,Picture__c from Farmer__c LIMIT 100"); httpGet.setURI(builder.build()); log.log(Level.INFO, "URl to salesforce {0}", builder.build().getPath()); CloseableHttpResponse closeableresponse = httpclient.execute(httpGet); System.out.println("Response Status line :" + closeableresponse.getStatusLine()); if (closeableresponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { // Now lets use the standard java json classes to work with the // results try { // Do the needful with entity. HttpEntity entity = closeableresponse.getEntity(); InputStream rstream = entity.getContent(); JSONObject authResponse = new JSONObject(new JSONTokener(rstream)); log.log(Level.INFO, "Query response: {0}", authResponse.toString(2)); log.log(Level.INFO, "{0} record(s) returned\n\n", authResponse.getInt("totalSize")); return authResponse; } catch (JSONException e) { e.printStackTrace(); throw new ServletException(e); } } } catch (URISyntaxException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } finally { httpclient.close(); } return null; }
From source file:controller.setup.Setup.java
private void updateHibernateCfgFile(String bd, String bdHost, String bdPort, String bdName, String bdUser, String bdUserMdp) {//w w w. ja va 2s . c o m System.out.println( "------------------------------ Creation hibernate config file -----------------------------"); try { URL resource = Thread.currentThread().getContextClassLoader().getResource("hibernate.cfg.xml"); File f = new File(resource.toURI()); SAXReader xmlReader = new SAXReader(); Document doc = xmlReader.read(f); Element sessionFactory = (Element) doc.getRootElement().elements().get(0); if (sessionFactory.elements().size() != 0) for (Iterator elt = sessionFactory.elements().iterator(); elt.hasNext();) sessionFactory.remove((Element) elt.next()); if (bd.equals("mysql")) { sessionFactory.addElement("property").addAttribute("name", "dialect") .addText("org.hibernate.dialect.MySQLDialect"); sessionFactory.addElement("property").addAttribute("name", "connection.url") .addText("jdbc:mysql://" + bdHost + ":" + bdPort + "/" + bdName); sessionFactory.addElement("property").addAttribute("name", "connection.driver_class") .addText("com.mysql.jdbc.Driver"); } else if (bd.equals("pgsql")) { sessionFactory.addElement("property").addAttribute("name", "dialect") .addText("org.hibernate.dialect.PostgreSQLDialect"); sessionFactory.addElement("property").addAttribute("name", "connection.url") .addText("jdbc:postgresql://" + bdHost + ":" + bdPort + "/" + bdName); sessionFactory.addElement("property").addAttribute("name", "connection.driver_class") .addText("org.postgresql.Driver"); } else if (bd.equals("oracle")) { sessionFactory.addElement("property").addAttribute("name", "dialect") .addText("org.hibernate.dialect.OracleDialect"); sessionFactory.addElement("property").addAttribute("name", "connection.url") .addText("jdbc:oracle:thin:@" + bdHost + ":" + bdPort + ":" + bdName); sessionFactory.addElement("property").addAttribute("name", "connection.driver_class") .addText("oracle.jdbc.OracleDriver"); } else if (bd.equals("mssqlserver")) { sessionFactory.addElement("property").addAttribute("name", "dialect") .addText("org.hibernate.dialect.SQLServerDialect"); sessionFactory.addElement("property").addAttribute("name", "connection.url") .addText("jdbc:sqlserver://" + bdHost + ":" + bdPort + ";databaseName=" + bdName + ";"); sessionFactory.addElement("property").addAttribute("name", "connection.driver_class") .addText("com.microsoft.sqlserver.jdbc.SQLServerDriver"); } sessionFactory.addElement("property").addAttribute("name", "connection.username").addText(bdUser); sessionFactory.addElement("property").addAttribute("name", "connection.password").addText(bdUserMdp); sessionFactory.addElement("property").addAttribute("name", "hbm2ddl.auto").addText("update"); XMLWriter writer = new XMLWriter(new FileWriter(f)); writer.write(doc); writer.close(); System.out.println( "------------------------------ Creation hibernate config file over -----------------------------"); } catch (URISyntaxException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.grameenfoundation.ictchallenge.controllers.ConnectedAppREST.java
private JSONObject getFarmerById(String instanceUrl, String accessToken, String id) throws ServletException, IOException { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet(); //add key and value httpGet.addHeader("Authorization", "OAuth " + accessToken); try {/* w w w .j av a 2 s. com*/ URIBuilder builder = new URIBuilder(instanceUrl + "/services/data/v30.0/query"); //builder.setParameter("q", "SELECT Name, Id from Account LIMIT 100"); builder.setParameter("q", "SELECT Name__c,Date_Of_Birth__c,Land_size__c,Farmer_I_D__c,Picture__c from Farmer__c " + " WHERE Farmer_I_D__c=" + "'" + id + "'"); httpGet.setURI(builder.build()); CloseableHttpResponse closeableresponse = httpclient.execute(httpGet); System.out.println("Response Status line :" + closeableresponse.getStatusLine()); if (closeableresponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { // Now lets use the standard java json classes to work with the // results try { // Do the needful with entity. HttpEntity entity = closeableresponse.getEntity(); InputStream rstream = entity.getContent(); JSONObject authResponse = new JSONObject(new JSONTokener(rstream)); log.log(Level.INFO, "Query response: {0}", authResponse.toString(2)); log.log(Level.INFO, "{0} record(s) returned\n\n", authResponse.getInt("totalSize")); return authResponse; } catch (JSONException e) { e.printStackTrace(); } } } catch (URISyntaxException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException ex) { Logger.getLogger(ConnectedAppREST.class.getName()).log(Level.SEVERE, null, ex); } finally { httpclient.close(); } return null; }