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:key.access.manager.HttpHandler.java

public String connect(String url, ArrayList data) throws IOException {
    try {//from  w w w  .  ja  v  a2 s  .  c o m
        // open a connection to the site
        URL connectionUrl = new URL(url);
        URLConnection con = connectionUrl.openConnection();
        // activate the output
        con.setDoOutput(true);
        PrintStream ps = new PrintStream(con.getOutputStream());
        // send your parameters to your site
        for (int i = 0; i < data.size(); i++) {
            ps.print(data.get(i));
            //System.out.println(data.get(i));
            if (i != data.size() - 1) {
                ps.print("&");
            }
        }

        // we have to get the input stream in order to actually send the request
        InputStream inStream = con.getInputStream();
        Scanner s = new Scanner(inStream).useDelimiter("\\A");
        String result = s.hasNext() ? s.next() : "";
        System.out.println(result);

        // close the print stream
        ps.close();
        return result;
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return "error";
    } catch (IOException e) {
        e.printStackTrace();
        return "error";
    }
}

From source file:revServTest.IoTTestForPUT.java

public String testPut(String url0, StringEntity input) {
    String result;/*from   ww w.j  a  v  a 2  s . c o m*/
    HttpResponse response = null;
    try {

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPut putRequest = new HttpPut(url0);

        input.setContentType("application/xml");
        putRequest.setEntity(input);

        response = httpClient.execute(putRequest);

        if (response.getStatusLine().getStatusCode() != 409 && response.getStatusLine().getStatusCode() != 201
                && response.getStatusLine().getStatusCode() != 400
                && response.getStatusLine().getStatusCode() != 200
                && response.getStatusLine().getStatusCode() != 404
                && response.getStatusLine().getStatusCode() != 500) {
            throw new RuntimeException(
                    "Failed : HTTP error code : " + response.getStatusLine().getStatusCode());
        }

        BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));

        String output;
        System.out.println("Output from Server .... \n");
        while ((output = br.readLine()) != null) {
            System.out.println(output);
        }
        httpClient.getConnectionManager().shutdown();

    } catch (MalformedURLException e) {

        e.printStackTrace();

    } catch (IOException e) {

        e.printStackTrace();

    }

    //      if (response.getStatusLine().getStatusCode() == 409 || response.getStatusLine().getStatusCode() == 201 || response.getStatusLine().getStatusCode() == 400
    //            || response.getStatusLine().getStatusCode() == 200 || response.getStatusLine().getStatusCode() == 404 || response.getStatusLine().getStatusCode() == 500) {
    //
    //         result = RevocationOutCome.code;
    //
    //      } else {
    //         String res = Integer.toString(response.getStatusLine().getStatusCode());
    //         result = res;
    //      }
    //      return result;
    return RevocationOutCome.code;

}

From source file:edu.uci.ics.crawler4j.robotstxt.RobotstxtServer.java

public boolean allows(WebURL webURL) {
    if (!config.isEnabled()) {
        return true;
    }//w ww.  j  a v  a 2  s.c  o  m
    try {
        URL url = new URL(webURL.getURL());
        String host = getHost(url);
        String path = url.getPath();
        HostDirectives directives = host2directivesCache.get(host);
        if (directives != null && directives.needsRefetch()) {
            synchronized (host2directivesCache) {
                host2directivesCache.remove(host);
                directives = null;
            }
        }
        if (directives == null) {
            directives = fetchDirectives(url);
        }
        return directives.allows(path);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return true;
}

From source file:edu.rit.chrisbitler.ritcraft.slackintegration.rtm.RTMClient.java

/**
 * Send a slack message to a channel via the web api
 * @param text The text to send to the channel
 * @param channel The channel ID to send it to (usually the relay channel)
 *///from   w  w  w  .j  a v  a 2  s .  c o m
public void sendSlackMessage(String text, String channel) {
    try {
        URL chat = new URL("https://slack.com/api/chat.postMessage?token=" + SlackIntegration.BOT_TOKEN
                + "&channel=" + channel + "&text=" + URLEncoder.encode(text, "UTF-8"));
        HttpURLConnection conn = (HttpURLConnection) chat.openConnection();
        conn.connect();
        conn.getContent();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:ca.mudar.parkcatcher.io.RemoteExecutor.java

public void execute(String request, JsonHandler handler) throws HandlerException {

    try {/* w  w  w  .j  av a  2 s .c  o  m*/
        URL url = new URL(request);

        final JSONTokener parser = ParserUtils.newJsonTokenerParser(url);
        handler.parseAndApply(parser, mResolver);

    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:net.bashtech.geobot.BotManager.java

public static String postDataLinkShortener(String postData) {
    URL url;/*from www . j a v a  2  s.c o  m*/
    HttpURLConnection conn;
    postData = "{\"longUrl\": \"" + postData + "\"}";

    try {
        url = new URL("https://www.googleapis.com/urlshortener/v1/url");

        conn = (HttpURLConnection) url.openConnection();
        conn.setDoOutput(true);
        conn.setRequestMethod("POST");
        conn.setRequestProperty("User-Agent", "CoeBot");
        conn.setRequestProperty("Content-Type", "application/json");
        conn.setRequestProperty("Content-Length", "" + Integer.toString(postData.getBytes().length));

        PrintWriter out = new PrintWriter(conn.getOutputStream());
        System.out.println(postData);
        out.print(postData);
        out.close();

        String response = "";

        Scanner inStream = new Scanner(conn.getInputStream());

        while (inStream.hasNextLine())
            response += (inStream.nextLine());

        inStream.close();
        return response;

    } catch (MalformedURLException ex) {
        ex.printStackTrace();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

    return "";

}

From source file:net.bashtech.geobot.BotManager.java

public static String putRemoteData(String urlString, String postData) throws IOException {

    URL url;/*w  w  w .  j a  v a 2 s  . c  o m*/
    HttpURLConnection conn;

    try {
        url = new URL(urlString);

        conn = (HttpURLConnection) url.openConnection();
        conn.setDoOutput(true);
        conn.setRequestMethod("PUT");

        conn.setFixedLengthStreamingMode(postData.getBytes().length);
        conn.setRequestProperty("Content-Type", "application/json");
        conn.setRequestProperty("Accept", "application/vnd.twitchtv.v2+json");
        conn.setRequestProperty("Authorization", "OAuth " + BotManager.getInstance().krakenOAuthToken);
        conn.setRequestProperty("Client-ID", BotManager.getInstance().krakenClientID);
        // conn.setConnectTimeout(5 * 1000);
        // conn.setReadTimeout(5 * 1000);

        PrintWriter out = new PrintWriter(conn.getOutputStream());
        out.print(postData);
        out.close();

        String response = "";

        Scanner inStream = new Scanner(conn.getInputStream());

        while (inStream.hasNextLine())
            response += (inStream.nextLine());

        return response;

    } catch (MalformedURLException ex) {
        ex.printStackTrace();
    }

    return "";
}

From source file:ca.mudar.parkcatcher.io.RemoteExecutor.java

/**
 * Execute a {@link HttpGet} request, passing a valid response through
 * {@link XmlHandler#parseAndApply(XmlPullParser, ContentResolver)}.
 */// w  w  w.  j av  a2s .c o m

public void executeGet(String request, JsonHandler handler) throws HandlerException {
    try {
        URL url = new URL(request);

        final JSONTokener parser = ParserUtils.newJsonTokenerParser(url);
        handler.parseAndApply(parser, mResolver);

    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.astifter.circatext.YahooJSONParser.java

@Override
public URL getURL(android.location.Location location, String cityName) {
    String urlCityName = cityName.replace(",", "%2C");
    String BASE_URL = "https://query.yahooapis.com/v1/public/yql?q=select%20item.condition%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22"
            + urlCityName + "%22)&format=json";
    try {/*from  w ww. ja  v  a 2  s .c  o  m*/
        return new URL(BASE_URL);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:de.uzk.hki.da.repository.CTFedora3RepositoryFacadeTest.java

@Before
public void setUp() throws IOException {
    try {/*w  ww  . j a  v  a 2s.c  om*/

        fedora = new Fedora3RepositoryFacade("http://localhost:8080/fedora", "fedoraAdmin",
                PasswordUtils.decryptPassword("BYi/MFjKDFd5Dpe52PSUoA=="));

    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

    if (!abc.exists())
        abc.createNewFile();
    if (!abd.exists())
        abd.createNewFile();
}