List of usage examples for java.net MalformedURLException printStackTrace
public void printStackTrace()
From source file:com.esri.geoevent.processor.reversegeocoder.ReverseGeocoderProcessor.java
private String getReverseGeocode(URL url) { String output = ""; try {/*from w w w .ja v a 2s . com*/ HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Accept", "application/json"); if (conn.getResponseCode() != 200) { String errorString = "Failed : HTTP error code : " + conn.getResponseCode(); throw new RuntimeException(errorString); } BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); String line; while ((line = br.readLine()) != null) { output += line; } conn.disconnect(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return output; }
From source file:org.pathwaycommons.pcviz.service.PathwayCommonsGraphService.java
@Cacheable("metadataCache") public String getMetadata(String datatype) { String urlStr = getPathwayCommonsUrl() + "/metadata/" + datatype; try {//from www. ja va 2 s .c o m URL url = new URL(urlStr); URLConnection urlConnection = url.openConnection(); StringBuilder builder = new StringBuilder(); Scanner scanner = new Scanner(urlConnection.getInputStream()); while (scanner.hasNextLine()) { builder.append(scanner.nextLine() + "\n"); } scanner.close(); return builder.toString(); } catch (MalformedURLException e) { e.printStackTrace(); return null; } catch (IOException e) { e.printStackTrace(); return null; } }
From source file:com.denimgroup.threadfix.service.remoteprovider.VeracodeRemoteProvider.java
public InputStream getUrl(String urlString, String username, String password) { URL url = null;// w ww. j a v a2 s . c o m try { url = new URL(urlString); } catch (MalformedURLException e) { e.printStackTrace(); return null; } HttpsURLConnection m_connect; try { m_connect = (HttpsURLConnection) url.openConnection(); setupAuthorization(m_connect, username, password); InputStream is = m_connect.getInputStream(); return is; } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:com.pixem.core.activity.Example.java
/** Called when the activity is first created. */ @Override/* www . j a v a 2 s.c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (APP_ID == null) { Util.showAlert(this, "Warning", "Facebook Applicaton ID must be " + "specified before running this example: see Example.java"); } setContentView(R.layout.facebook); mLoginButton = (LoginButton) findViewById(R.id.login); mText = (TextView) Example.this.findViewById(R.id.txt); mRequestButton = (Button) findViewById(R.id.requestButton); mPostButton = (Button) findViewById(R.id.postButton); mDeleteButton = (Button) findViewById(R.id.deletePostButton); mUploadButton = (Button) findViewById(R.id.uploadButton); mFacebook = new Facebook(APP_ID); mAsyncRunner = new AsyncFacebookRunner(mFacebook); SessionStore.restore(mFacebook, this); SessionEvents.addAuthListener(new SampleAuthListener()); SessionEvents.addLogoutListener(new SampleLogoutListener()); mLoginButton.init(this, mFacebook); mRequestButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { mAsyncRunner.request("me", new SampleRequestListener()); } }); mRequestButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE); mUploadButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Bundle params = new Bundle(); params.putString("method", "photos.upload"); URL uploadFileUrl = null; try { uploadFileUrl = new URL("http://www.facebook.com/images/devsite/iphone_connect_btn.jpg"); } catch (MalformedURLException e) { e.printStackTrace(); } try { HttpURLConnection conn = (HttpURLConnection) uploadFileUrl.openConnection(); conn.setDoInput(true); conn.connect(); int length = conn.getContentLength(); byte[] imgData = new byte[length]; InputStream is = conn.getInputStream(); is.read(imgData); params.putByteArray("picture", imgData); } catch (IOException e) { e.printStackTrace(); } mAsyncRunner.request(null, params, "POST", new SampleUploadListener(), null); } }); mUploadButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE); mPostButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { mFacebook.dialog(Example.this, "feed", new SampleDialogListener()); } }); mPostButton.setVisibility(mFacebook.isSessionValid() ? View.VISIBLE : View.INVISIBLE); }
From source file:es.usc.citius.composit.transformer.wsc.wscxml.WSCTransformer.java
/** * Interface method for transforming services defined in the WSC XML format. Note that, given the service * definition of the WSC does not have valid urls pointing to the ontology, and since they use instances * instead of concepts for the inputs and outputs, a single stream with the service definition is not enough. * Two more files are required: a taxonomy.xml to easily translate instances to concepts, and a valid taxonomy.owl * ontology, which is a translation of the taxonomy.xml into owl to import into iServe. The baseUri is used to * automatically locate these files without specifying anything more to the transformer. By default, if the * baseUri is http://localhost/, this method will try to open http://localhost/taxonomy.xml and will use * http://localhost/taxonomy.owl as the model reference URL. * * @param originalDescription The semantic Web service description(s) stream * @param baseUri The base URI to use while transforming the service description. The baseUri should point to * a valid location where the baseUri/taxonomy.xml and baseUri/taxonomy.owl can be located. * @return// w w w . j a v a 2 s . c om */ @Override public List<Service> transform(InputStream originalDescription, String baseUri) throws TransformationException { // De-serialize from XML // Use the baseUri to locate automatically the taxonomy.xml and ontology.owl if (baseUri == null) { throw new NullPointerException( "BaseUri cannot be null. Please specify a baseUri to locate" + " the WSC files"); } baseUri = baseUri.endsWith("/") ? baseUri : baseUri + "/"; // Define the URL for the taxonomy xml file URL taxonomyXmlUrl; String taxonomyUrlStr = baseUri + this.taxonomyFile; try { taxonomyXmlUrl = new URL(taxonomyUrlStr); } catch (MalformedURLException e) { e.printStackTrace(); throw new TransformationException("There was a problem using the provided base uri " + baseUri + ". " + " The taxonomy.xml URL " + taxonomyUrlStr + " is malformed."); } String ontologyUrlStr = baseUri + this.ontologyFile; URL ontologyOwlUrl; try { ontologyOwlUrl = new URL(ontologyUrlStr); } catch (MalformedURLException e) { e.printStackTrace(); throw new TransformationException("There was a problem using the provided base uri " + baseUri + ". " + " The taxonomy.owl URL " + taxonomyUrlStr + " is malformed."); } // Create a reasoner to process the taxonomy.xml try { this.reasoner = new WSCXMLSemanticReasoner(taxonomyXmlUrl.openStream()); } catch (IOException e) { e.printStackTrace(); throw new TransformationException("Taxonomy XML file could not be located at " + taxonomyXmlUrl); } // Obtain the original xml:base uri from the owl file. URL ontologyBaseUri = null; try { ontologyBaseUri = obtainXmlBaseUri(ontologyOwlUrl); if (ontologyBaseUri == null) { throw new NullPointerException("The ontology xml:base uri cannot be derived automatically " + "from " + ontologyOwlUrl + ". Please check that the ontology has an attribute " + "xml:base within the <rdf:RDF> tag"); } } catch (Exception e) { TransformationException ex = new TransformationException( "Cannot obtain the base uri for the ontology. " + e.getMessage()); ex.initCause(e); throw ex; } // Transform and return the result try { return transform(originalDescription, ontologyBaseUri, reasoner); } catch (URISyntaxException e) { TransformationException ex = new TransformationException( "There were some problems trying to generate modelReferences. " + e.getMessage()); ex.initCause(e); throw ex; } }
From source file:net.sf.okapi.filters.drupal.DrupalConnector.java
/** * Get all nodes//from w ww.j ava2 s . c o m * @return */ public List<NodeInfo> getNodes() { URL url; HttpURLConnection conn; List<NodeInfo> nodes = new ArrayList<NodeInfo>(); try { url = new URL(host + "rest/node"); conn = createConnection(url, "GET", false); if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) { conn.disconnect(); throw new RuntimeException("Operation failed: " + conn.getResponseCode()); } BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); JSONParser parser = new JSONParser(); JSONArray array = (JSONArray) parser.parse(reader); for (Object object : array) { JSONObject node = (JSONObject) object; NodeInfo ni = new NodeInfo((String) node.get("vid"), true); ni.setTitle((String) node.get("title")); ni.setType((String) node.get("type")); nodes.add(ni); } conn.disconnect(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } return nodes; }
From source file:com.zhonghui.tool.controller.HttpClient.java
/** * //from w ww. j a va 2 s .c o m * @param url ? * @param connectionTimeout HTTP * @param readTimeOut HTTP */ public HttpClient(String url, int connectionTimeout, int readTimeOut) { try { this.url = new URL(url); this.connectionTimeout = connectionTimeout; this.readTimeOut = readTimeOut; } catch (MalformedURLException e) { e.printStackTrace(); } }
From source file:de.thejeterlp.bukkit.updater.Updater.java
/** * Inits a new updater/*from w w w . j av a 2s . c o m*/ * Notice: Automatically generates a update-config.yml file to en- / disable the updater. * Bukkit has the rule that every updater needs to be able to get disabled. * * @param main: Your plugin's main file * @param id: Your project id. Can be found using (http://wiki.bukkit.org/ServerMods_API#Searching_for_project_IDs) * @param link: Your project slug. http://dev.bukkit.org/bukkit-plugins/ is added automatically. */ public Updater(JavaPlugin main, int id, String link) { main.getLogger().info("Loading updater by TheJeterLP. Project id: " + id); config = new Config(main, "update-config.yml"); this.type = Config.Values.UPDATE_TYPE.getUpdateType(config); this.rType = Config.Values.RELEASE_TYPE.getReleaseType(config); this.main = main; this.id = id; this.link = "http://dev.bukkit.org/bukkit-plugins/" + link; boolean enable = (id == -1 ? false : Config.Values.ENABLED.getBoolean(config)); try { this.url = new URL("https://api.curseforge.com/servermods/files?projectIds=" + this.id); } catch (MalformedURLException ex) { enable = false; ex.printStackTrace(); } if (enable) { main.getServer().getPluginManager().registerEvents(new UpdateListener(this), main); } this.enabled = enable; main.getLogger().info("Updatechecker is " + (this.enabled ? "enabled" : "disabled") + "."); }
From source file:eu.seaclouds.platform.planner.optimizerTest.service.OptimizerServiceTestIT.java
@Test(enabled = TestConstants.EnabledTest) public void testPresenceHeartbeat() { log.info("=== TEST for presence of OPTIMIZER service heartbeat in " + BASE_URL + "==="); String outputLine;//from ww w. j a va2 s . c om String completeOutput = ""; try { URL url = new URL(BASE_URL + "heartbeat"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); Assert.assertTrue(conn.getResponseCode() == 200, "Error requesting heartbeat in " + BASE_URL + ". Instead of 200 we have received code " + conn.getResponseCode()); BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); while ((outputLine = br.readLine()) != null) { completeOutput += NL + outputLine; } conn.disconnect(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Assert.assertTrue(completeOutput.contains("alive"), "Optimizer NOT alive. Response of heartbeat is: " + completeOutput); log.info("=== TEST for presence of OPTIMIZER service heartbeat in " + BASE_URL + " FINISHED ==="); }
From source file:com.zhonghui.tool.controller.HttpClient.java
/** * <br>// ww w . ja v a 2 s. c o m * httpcgt_sdk.properties? * @param url ? */ public HttpClient(String url) { try { this.url = new URL(url); SDKConfig config = SDKConfig.getConfig(); this.connectionTimeout = config.getConnectionTimeout(); this.readTimeOut = config.getReadTimeout(); } catch (MalformedURLException e) { e.printStackTrace(); } }