Example usage for java.net MalformedURLException printStackTrace

List of usage examples for java.net MalformedURLException printStackTrace

Introduction

In this page you can find the example usage for java.net MalformedURLException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.megam.deccanplato.provider.googleapp.handler.ContactImpl.java

/**
 * this method deletes a contact in a user account.
 * args map has all the value to update contact in a user account,
 * contact delete by calling ContactsService class's getEntry method 
 * with client credential service/*from  ww w.java2 s  . c o  m*/
 * @param outMap
 * @return outMap has the deleted contact id
 */
private Map<String, String> delete(Map<String, String> outMap) {

    URL postUrl;
    try {
        postUrl = new URL(PRE_URL + args.get(EMAIL_ID) + POST_URL + args.get(ID));
        ContactEntry contact = service.getEntry(postUrl, ContactEntry.class);
        contact.delete();
        outMap.put(OUTPUT, DELETE_STRING + contact.getId());
    } catch (MalformedURLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ServiceException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return outMap;
}

From source file:util.ImageDownloader.java

Bitmap downloadBitmap(String url) {
    final int IO_BUFFER_SIZE = 4 * 1024;

    // AndroidHttpClient is not allowed to be used from the main thread
    //        final HttpClient client = (mode == Mode.NO_ASYNC_TASK) ? new DefaultHttpClient() :
    //            AndroidHttpClient.newInstance("Android");
    //        final HttpGet getRequest = new HttpGet(url);

    try {//from  www .  jav a  2 s  . c  om
        return BitmapFactory.decodeStream(new URL(url).openConnection().getInputStream());
    } catch (MalformedURLException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    //        try {
    //            HttpResponse response = client.execute(getRequest);
    //            final int statusCode = response.getStatusLine().getStatusCode();
    //            if (statusCode != HttpStatus.SC_OK) {
    //                Log.w("ImageDownloader", "Error " + statusCode +
    //                        " while retrieving bitmap from " + url);
    //                return null;
    //            }
    //            final HttpEntity entity = response.getEntity();
    //            if (entity != null) {
    //                InputStream inputStream = null;
    //                try {
    //                    inputStream = entity.getContent();
    // return BitmapFactory.decodeStream(inputStream);
    // Bug on slow connections, fixed in future release.
    //                    return BitmapFactory.decodeStream(new FlushedInputStream(inputStream));
    //                } finally {
    //                    if (inputStream != null) {
    //                        inputStream.close();
    //                    }
    //                    entity.consumeContent();
    //                }
    //            }
    //        } catch (IOException e) {
    //            getRequest.abort();
    //            Log.w(LOG_TAG, "I/O error while retrieving bitmap from " + url, e);
    //        } catch (IllegalStateException e) {
    //            getRequest.abort();
    //            Log.w(LOG_TAG, "Incorrect URL: " + url);
    //        } catch (Exception e) {
    //            getRequest.abort();
    //            Log.w(LOG_TAG, "Error while retrieving bitmap from " + url, e);
    //        } finally {
    //            if ((client instanceof AndroidHttpClient)) {
    //                ((AndroidHttpClient) client).close();
    //            }
    //        }
    return null;
}

From source file:net.atos.aeon.AEONSDK.java

private void Init(String subscribeUrl, String id, String desc) {

    this.messages = new AEONSDKMessages();

    try {//  w  ww  .jav  a  2  s .  c  om
        if (subscribeUrl.indexOf("/subscribe") != -1) {
            if (subscribeUrl.startsWith("https")) {

                this.webClient = ClientHelper.createClient();

                SSLContext sc = SSLContext.getInstance("TLS");
                sc.init(null, ClientHelper.trustAllCerts, new SecureRandom());
                SocketIO.setDefaultSSLSocketFactory(sc);
                HttpsURLConnection.setDefaultHostnameVerifier(new RelaxedHostNameVerifier());

            } else
                this.webClient = Client.create();

            this.subscribeUrl = subscribeUrl;
            this.socketServer = getSocketServerEndpoint(getServerEndpoint(subscribeUrl));

            this.socket = new SocketIO(socketServer);
            this.socket.addHeader("force_new_connection", "true");
            // this.socket.addHeader("transports", "xhr-polling");
            // this.socket.addHeader("polling duration", "20");

            this.id = id;
            this.desc = desc;
            this.mode = "subscribe";
            sioLogger.setLevel(Level.OFF);
        } else
            this.mode = "error";
    } catch (MalformedURLException e) {
        e.printStackTrace();
        this.mode = "error";
    } catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        this.mode = "error";
    } catch (KeyManagementException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        this.mode = "error";
    }

}

From source file:eu.codeplumbers.cosi.services.CosiSmsService.java

private List<Sms> getRemoteMessages() {
    allSms.clear();/*from  w ww  .  j  a  v  a  2  s. com*/
    URL urlO = null;
    try {
        urlO = new URL(designUrl);
        HttpURLConnection conn = (HttpURLConnection) urlO.openConnection();
        conn.setConnectTimeout(5000);
        conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
        conn.setRequestProperty("Authorization", authHeader);
        conn.setDoInput(true);
        conn.setRequestMethod("POST");

        // read the response
        int status = conn.getResponseCode();
        InputStream in = null;

        if (status >= HttpURLConnection.HTTP_BAD_REQUEST) {
            in = conn.getErrorStream();
        } else {
            in = conn.getInputStream();
        }

        StringWriter writer = new StringWriter();
        IOUtils.copy(in, writer, "UTF-8");
        String result = writer.toString();

        JSONArray jsonArray = new JSONArray(result);

        if (jsonArray != null) {
            if (jsonArray.length() == 0) {
                EventBus.getDefault()
                        .post(new SmsSyncEvent(SYNC_MESSAGE, "Your Cozy has no Text messages stored."));
                Sms.setAllUnsynced();
            } else {
                for (int i = 0; i < jsonArray.length(); i++) {
                    mBuilder.setProgress(jsonArray.length(), i, false);
                    mNotifyManager.notify(notification_id, mBuilder.build());
                    EventBus.getDefault()
                            .post(new SmsSyncEvent(SYNC_MESSAGE, getString(R.string.lbl_sms_status_read_cozy)));

                    JSONObject smsJson = jsonArray.getJSONObject(i).getJSONObject("value");
                    Sms sms = Sms.getBySystemIdAddressAndBody(smsJson.get("systemId").toString(),
                            smsJson.getString("address"), smsJson.getString("body"));
                    if (sms == null) {
                        sms = new Sms(smsJson);
                    } else {
                        sms.setRemoteId(smsJson.getString("_id"));
                        sms.setSystemId(smsJson.getString("systemId"));
                        sms.setAddress(smsJson.getString("address"));
                        sms.setBody(smsJson.getString("body"));

                        if (smsJson.has("readState")) {
                            sms.setReadState(smsJson.getBoolean("readState"));
                        }

                        sms.setDateAndTime(smsJson.getString("dateAndTime"));
                        sms.setType(smsJson.getInt("type"));
                    }

                    sms.save();

                    allSms.add(sms);
                }
            }
        } else {
            errorMessage = "Failed to parse API response";
            EventBus.getDefault().post(new SmsSyncEvent(SERVICE_ERROR, "Failed to parse API response"));
        }

        in.close();
        conn.disconnect();

    } catch (MalformedURLException e) {
        e.printStackTrace();
        errorMessage = e.getLocalizedMessage();
    } catch (ProtocolException e) {
        errorMessage = e.getLocalizedMessage();
        e.printStackTrace();
    } catch (IOException e) {
        errorMessage = e.getLocalizedMessage();
        e.printStackTrace();
    } catch (JSONException e) {
        errorMessage = e.getLocalizedMessage();
        e.printStackTrace();
    }
    return allSms;
}

From source file:com.cellbots.eyes.EyesActivity.java

private void resetConnection() {
    //Log.e("server", server);
    try {//from   w  w w.j  a va2  s .c om
        String ip = new URL(putUrl).getHost();
        int port = new URL(putUrl).getPort();
        mConnection = new HttpConnection(ip, port == -1 ? 80 : port);
        mConnection.open();
    } catch (MalformedURLException e1) {
        e1.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.eviware.soapui.impl.wsdl.monitor.JProxyServletWsdlMonitorMessageExchange.java

public void setTargetURL(String url) {
    try {//from w  w  w.  ja  va  2  s. c  o  m
        this.targetURL = new URL(url);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
}

From source file:com.addongaming.hcessentials.rankup.RankUpdater.java

private void checkRank(Player p, String str) {
    JSONObject jo = null;//from  w  ww  . ja v  a 2  s.  co m
    try {
        System.out.println(req + "?license=" + str);
        jo = super.getJSON(new URL(req + "?license=" + str));
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    if (jo == null) {
        msg(p, "Sorry something went wrong. Please try again in a minute.");
        return;
    }
    if (jo.getString("action").equalsIgnoreCase("failure")) {
        switch (jo.getString("message")) {
        case "license_already_used":
            msg(p, "Sorry, this license code has already been used. If you have upgraded please wait five minutes and try again.");
            hashyMap.put(p.getName(), new Submission(p.getName(), str, "", "", false));
            return;
        case "no_rank_found":
            msg(p, "Sorry, we couldn't find your rank.");
            hashyMap.put(p.getName(), new Submission(p.getName(), str, "", "", false));
            return;
        case "no_license_found":
            msg(p, "Sorry, we couldn't find your license. Please double check your license and try again in five minutes.");
            hashyMap.put(p.getName(), new Submission(p.getName(), str, "", "", false));
            return;
        case "incorrect_license_syntax":
            msg(p, "Sorry, that license key doesn't follow the correct pattern. Please try again in five minutes.");
            hashyMap.put(p.getName(), new Submission(p.getName(), str, "", "", false));
            return;
        }
    }

    String group = jo.getString("rank");
    String server = jo.getString("server");
    String currentGroup = HcEssentials.permission.getPrimaryGroup(p);
    if (server.equalsIgnoreCase(this.server) && group.equalsIgnoreCase(currentGroup)) {
        msg(p, "This key entitles you to a rank you already have.");
        return;
    } else if (server.equalsIgnoreCase(this.server)) {
        msg(p, "Your key entitles you to " + group + " on this server. Please use " + ChatColor.BOLD
                + "/rank claim" + ChatColor.RESET + ChatColor.GREEN + " to claim your rank.");
    } else {
        msg(p, "Your key entitles you to " + group + " on " + server + ". This server is " + server
                + ". Please try the license again there.");
    }
    hashyMap.put(p.getName(), new Submission(p.getName(), str, group, server, true));

}

From source file:com.cellbots.local.EyesView.java

private void resetConnection() {
    if (isLocalUrl)
        return;/*w  w w.ja  va 2  s  .c  o m*/
    try {
        String ip = new URL(putUrl).getHost();
        int port = new URL(putUrl).getPort();
        mConnection = new HttpConnection(ip, port == -1 ? 80 : port);
        mConnection.open();
    } catch (MalformedURLException e1) {
        e1.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.googlecode.onevre.utils.ServerClassLoader.java

/**
 *
 * @see java.lang.ClassLoader#findResource(java.lang.String)
 *///from  ww  w.j a va2  s. c o m
protected URL findResource(String name) {
    try {
        URL url = getResourceURL(name);
        if (url != null) {
            File jar = cachedJars.get(url);
            try {
                String resource = jar.toURI().toURL().toString();
                return new URL("jar:" + resource + "!/" + name);
            } catch (MalformedURLException e) {
                e.printStackTrace();
                return null;
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.cbtec.eliademy.FacebookConnect.java

@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackId) {
    PluginResult pluginResult = new PluginResult(PluginResult.Status.INVALID_ACTION,
            "Unsupported operation: " + action);

    try {//from   w  w w  .  j  av a  2 s .com
        if (action.equals("initWithAppId"))
            pluginResult = this.initWithAppId(args, callbackId);
        else if (action.equals("login"))
            pluginResult = this.login(args, callbackId);
        else if (action.equals("requestWithGraphPath"))
            pluginResult = this.requestWithGraphPath(args, callbackId);
        else if (action.equals("dialog"))
            pluginResult = this.dialog(args, callbackId);
        else if (action.equals("logout"))
            pluginResult = this.logout(args, callbackId);
    } catch (MalformedURLException e) {
        e.printStackTrace();
        pluginResult = new PluginResult(PluginResult.Status.MALFORMED_URL_EXCEPTION);
    } catch (IOException e) {
        e.printStackTrace();
        pluginResult = new PluginResult(PluginResult.Status.IO_EXCEPTION);
    } catch (JSONException e) {
        e.printStackTrace();
        pluginResult = new PluginResult(PluginResult.Status.JSON_EXCEPTION);
    }

    callbackId.sendPluginResult(pluginResult);
    return true;
}