List of usage examples for java.net MalformedURLException printStackTrace
public void printStackTrace()
From source file:ch.ethz.tik.hrouting.providers.PlacesAutoCompleteAdapter.java
private StringBuilder getJsonResults(String requestType, List<String> parameters) { StringBuilder jsonResults = new StringBuilder(); HttpURLConnection connection = null; String query = buildQuery(requestType, parameters); try {/*from www . ja v a 2 s. co m*/ URL url = new URL(query); connection = (HttpURLConnection) url.openConnection(); InputStreamReader in = new InputStreamReader(connection.getInputStream()); // Load the results into a StringBuilder int read; char[] buff = new char[1024]; while ((read = in.read(buff)) != -1) { jsonResults.append(buff, 0, read); } } catch (MalformedURLException e) { Log.e(LOG_TAG, "Error processing Places API URL", e); e.printStackTrace(); return null; } catch (IOException e) { Log.e(LOG_TAG, "Error connecting to Places API", e); e.printStackTrace(); // Autocomplete is running in a thread, create a handler to post // message to the main thread Handler mHandler = new Handler(getContext().getMainLooper()); mHandler.post(new Runnable() { @Override public void run() { Toast.makeText(getContext().getApplicationContext(), "Not able to reach Google Place API", Toast.LENGTH_LONG).show(); } }); return null; } finally { if (connection != null) { connection.disconnect(); } } return jsonResults; }
From source file:de.nec.nle.siafu.model.SimulationData.java
/** * Instantiates a SimulationData object using the provided path. * /*from w w w .jav a 2s . c om*/ * @param givenPath the path to the data */ protected SimulationData(final File givenPath) { try { classLoader = new URLClassLoader(new URL[] { givenPath.toURI().toURL() }); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.orchestra.portale.profiler.FbProfiler.java
public List<String> getPoiStereotype() { if (access_token == null) { return null; }// w w w .j a v a 2 s . co m try { HttpURLConnection connection = openConnection("/poi_stereotype", "GET"); Map<String, String> params = new HashMap<String, String>(); params.put("access_token", access_token); connection = addParameter(connection, params); String json_response = streamToString(connection.getInputStream()); JsonParser parser = new JsonParser(); JsonElement element = parser.parse(json_response); JsonObject j_object = (JsonObject) element; JsonArray j_poi_list = (JsonArray) j_object.get("poi_list"); List<String> poi_list = new ArrayList<String>(); for (JsonElement p : j_poi_list) { poi_list.add(p.toString().replace("\"", "")); } return poi_list; } catch (MalformedURLException ex) { ex.printStackTrace(); } catch (IOException ioex) { ioex.printStackTrace(); } return null; }
From source file:com.conwet.wirecloud.ide.WirecloudAPI.java
public URL getAuthURL(String clientId, String redirectURI) throws OAuthSystemException, MalformedURLException { String url = new URL(this.url, AUTH_ENDPOINT).toString(); OAuthClientRequest request = OAuthClientRequest.authorizationLocation(url).setClientId(clientId) .setResponseType("code").setRedirectURI(redirectURI.toString()).buildQueryMessage(); try {//from www. java 2 s. c om return new URL(request.getLocationUri()); } catch (MalformedURLException e) { e.printStackTrace(); return null; } }
From source file:com.redhat.red.build.koji.it.AbstractIT.java
protected synchronized String formatUrl(String... path) { String baseUrl = getBaseUrl(); try {//from w w w . j av a 2s .co m return UrlUtils.buildUrl(baseUrl, path); } catch (MalformedURLException e) { e.printStackTrace(); Assert.fail(String.format("Failed to format URL from parts: [%s]. Reason: %s", StringUtils.join(path, ", "), e.getMessage())); } return null; }
From source file:de.codecentric.jira.jenkins.plugin.servlet.RecentBuildsServlet.java
/** * Gets BuldRss if authorization is required * @return BuildRss/*from www.j a v a 2s . c om*/ */ private Document getBuildRssAuth(String urlJenkinsServer, String view, String job) throws MalformedURLException, DocumentException { String url; // was there a certain job specified? if (StringUtils.isNotEmpty(job)) { url = (urlJenkinsServer + "job/" + URLEncoder.encodeForURL(job) + RSS_ALL); } else if (StringUtils.isNotEmpty(view)) { url = (urlJenkinsServer + "view/" + URLEncoder.encodeForURL(view) + RSS_ALL); } else { url = (urlJenkinsServer + RSS_ALL); } PostMethod post = new PostMethod(url); Document buildRss = null; post.setDoAuthentication(true); try { client.executeMethod(post); buildRss = new SAXReader().read(post.getResponseBodyAsStream()); } catch (MalformedURLException e) { e.printStackTrace(); } catch (SSLException e) { if (e.getMessage().equals("Unrecognized SSL message, plaintext connection?")) { urlJenkinsServer = urlJenkinsServer.replaceFirst("s", ""); this.getBuildRssAuth(urlJenkinsServer, view, job); } else { e.printStackTrace(); } } catch (IOException e) { e.printStackTrace(); } finally { post.releaseConnection(); } return buildRss; }
From source file:eu.codeplumbers.cosi.api.tasks.SyncDocumentTask.java
@Override protected String doInBackground(JSONObject... jsonObjects) { for (int i = 0; i < jsonObjects.length; i++) { JSONObject jsonObject = jsonObjects[i]; URL urlO = null;// w w w .j ava 2 s .c o m try { publishProgress("Syncing " + jsonObject.getString("docType") + ":", i + "", jsonObjects.length + ""); String remoteId = jsonObject.getString("remoteId"); String requestMethod = ""; if (remoteId.isEmpty()) { urlO = new URL(url); requestMethod = "POST"; } else { urlO = new URL(url + remoteId + "/"); requestMethod = "PUT"; } HttpURLConnection conn = (HttpURLConnection) urlO.openConnection(); conn.setConnectTimeout(5000); conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); conn.setRequestProperty("Authorization", authHeader); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestMethod(requestMethod); // set request body jsonObject.remove("remoteId"); objectId = jsonObject.getLong("id"); jsonObject.remove("id"); OutputStream os = conn.getOutputStream(); os.write(jsonObject.toString().getBytes("UTF-8")); os.flush(); // read the response InputStream in = new BufferedInputStream(conn.getInputStream()); StringWriter writer = new StringWriter(); IOUtils.copy(in, writer, "UTF-8"); String result = writer.toString(); JSONObject jsonObjectResult = new JSONObject(result); if (jsonObjectResult != null && jsonObjectResult.has("_id")) { result = jsonObjectResult.getString("_id"); if (jsonObject.get("docType").equals("Sms")) { Sms sms = Sms.load(Sms.class, objectId); sms.setRemoteId(result); sms.save(); } if (jsonObject.get("docType").equals("Note")) { Note note = Note.load(Note.class, objectId); note.setRemoteId(result); note.save(); } if (jsonObject.get("docType").equals("Call")) { Call call = Call.load(Call.class, objectId); call.setRemoteId(result); call.save(); } if (jsonObject.get("docType").equals("Expense")) { Expense expense = Expense.load(Expense.class, objectId); expense.setRemoteId(result); expense.save(); } } in.close(); conn.disconnect(); } catch (MalformedURLException e) { result = "error"; e.printStackTrace(); errorMessage = e.getLocalizedMessage(); } catch (ProtocolException e) { result = "error"; errorMessage = e.getLocalizedMessage(); e.printStackTrace(); } catch (IOException e) { result = "error"; errorMessage = e.getLocalizedMessage(); e.printStackTrace(); } catch (JSONException e) { result = "error"; errorMessage = e.getLocalizedMessage(); e.printStackTrace(); } } return result; }
From source file:org.example.camera.List14.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); URL myFileUrl = null;//www. j a v a2 s . co m try { URL url = new URL("http://wheelspotting.com/recent.json"); URLConnection tc = url.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(tc.getInputStream())); String line; while ((line = in.readLine()) != null) { JSONArray ja = new JSONArray(line); Log.i("jsondeal", ja.getString(0)); for (int i = 0; i < ja.length(); i++) { JSONObject jo = (JSONObject) ja.get(i); try { myFileUrl = new URL(jo.getString("medium_image")); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } HttpGet httpRequest = null; try { httpRequest = new HttpGet(myFileUrl.toURI()); } catch (URISyntaxException e) { e.printStackTrace(); } HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = (HttpResponse) httpclient.execute(httpRequest); HttpEntity entity = response.getEntity(); BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity); InputStream instream = bufHttpEntity.getContent(); Bitmap bmImg = BitmapFactory.decodeStream(instream); listPics.add(bmImg); listTitles.add(jo.getString("title")); listLargeUrls.add(jo.getString("large_image")); } } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } setListAdapter(new EfficientAdapter(this)); }
From source file:com.sillelien.dollar.DocTestingVisitor.java
@Override public void visit(@NotNull VerbatimNode node) { if ("java".equals(node.getType())) { try {/*from w w w .j a v a 2s . c o m*/ String name = "DocTemp" + System.currentTimeMillis(); File javaFile = new File("/tmp/" + name + ".java"); File clazzFile = new File("/tmp/" + name + ".class"); clazzFile.getParentFile().mkdirs(); FileUtils.write(javaFile, "import com.sillelien.dollar.api.*;\n" + "import static com.sillelien.dollar.api.DollarStatic.*;\n" + "public class " + name + " implements java.lang.Runnable{\n" + " public void run() {\n" + " " + node.getText() + "\n" + " }\n" + "}"); final JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); final StandardJavaFileManager jfm = javac.getStandardFileManager(null, null, null); JavaCompiler.CompilationTask task; DiagnosticListener<JavaFileObject> diagnosticListener = new DiagnosticListener<JavaFileObject>() { @Override public void report(Diagnostic diagnostic) { System.out.println(diagnostic); throw new RuntimeException(diagnostic.getMessage(Locale.getDefault())); } }; try (FileOutputStream fileOutputStream = FileUtils.openOutputStream(clazzFile)) { task = javac.getTask(new OutputStreamWriter(fileOutputStream), jfm, diagnosticListener, null, null, jfm.getJavaFileObjects(javaFile)); } task.call(); try { // Convert File to a URL URL url = clazzFile.getParentFile().toURL(); URL[] urls = new URL[] { url }; ClassLoader cl = new URLClassLoader(urls); Class cls = cl.loadClass(name); ((Runnable) cls.newInstance()).run(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } System.out.println("Parsed: " + node.getText()); } catch (IOException e) { throw new RuntimeException(e); } } }
From source file:com.comcast.cats.video.service.VideoServiceImpl.java
/** * Sets the video size requested by the client. * * @param vidSize Video Size / dimension of screen. *//* ww w . j a v a 2 s . c o m*/ public void setVideoSize(final Dimension vidSize) { this.videoController.setVideoDimension(vidSize); if (this.videoController.isConnected()) { try { this.videoController.connect(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }