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.openmrs.module.dhisreport.web.controller.Dhis2ServerController.java

@RequestMapping(value = "/module/dhisreport/configureDhis2", method = RequestMethod.GET)
public void showConfigForm(ModelMap model, WebRequest webRequest) {
    DHIS2ReportingService service = Context.getService(DHIS2ReportingService.class);

    HttpDhis2Server server = service.getDhis2Server();
    String dhisurl = Context.getAdministrationService().getGlobalProperty("dhisreport.dhis2URL");
    String dhisusername = Context.getAdministrationService().getGlobalProperty("dhisreport.dhis2UserName");
    String dhispassword = Context.getAdministrationService().getGlobalProperty("dhisreport.dhis2Password");

    URL url = null;//from  www  . j a v  a  2  s  . c o  m
    try {
        url = new URL(dhisurl);
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    if (server == null) {
        server = new HttpDhis2Server();
    }
    server.setUrl(url);
    server.setUsername(dhisusername);
    server.setPassword(dhispassword);

    model.addAttribute("user", Context.getAuthenticatedUser());
    model.addAttribute("dhis2Server", server);

}

From source file:com.jpeterson.littles3.bo.FileS3ObjectTest.java

/**
 * Test the constructor.//from   ww  w. jav  a2s.c o  m
 */
public void test_constructor() {
    FileS3Object s3Object;
    URL storageUrl;

    try {
        storageUrl = new URL("file:///C:/temp/foo.txt");
    } catch (MalformedURLException e) {
        e.printStackTrace();
        fail("Unexpected exception");
        return;
    }
    s3Object = new FileS3Object("bucket", "key", storageUrl);

    assertEquals("Unexpected value", "bucket", s3Object.getBucket());
    assertEquals("Unexpected value", "key", s3Object.getKey());
    assertEquals("Unexpected value", storageUrl, s3Object.getStorageUrl());
}

From source file:eu.codeplumbers.cosi.api.tasks.CheckDesignDocumentsTask.java

@Override
protected String doInBackground(String... docTypes) {
    errorMessage = "";
    for (int i = 0; i < docTypes.length; i++) {
        String docType = docTypes[i].toLowerCase();
        publishProgress("Checking design: " + docType);

        URL urlO = null;//  w  w  w.  j av  a2 s.co  m
        try {

            // using all view can break notes, files app in cozy
            urlO = getCosiUrl(docType);

            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();

            if (result != "") {
                errorMessage = createDesignDocument(docType);
                if (errorMessage != "") {
                    return errorMessage;
                } else {
                    errorMessage = "";
                }
            } else {
                errorMessage = "Failed to parse API response";
                return errorMessage;
            }

            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();
        }
    }

    return errorMessage;
}

From source file:org.openmrs.module.dhisreport.web.controller.Dhis2ServerController.java

@RequestMapping(value = "/module/dhisreport/testconnection", method = RequestMethod.POST)
public String CheckConnectionWithDHIS2(ModelMap model, WebRequest webRequest) {
    DHIS2ReportingService service = Context.getService(DHIS2ReportingService.class);
    HttpDhis2Server server = service.getDhis2Server();
    String dhisurl = Context.getAdministrationService().getGlobalProperty("dhisreport.dhis2URL");
    String dhisusername = Context.getAdministrationService().getGlobalProperty("dhisreport.dhis2UserName");
    String dhispassword = Context.getAdministrationService().getGlobalProperty("dhisreport.dhis2Password");

    URL url = null;//from ww  w  . j a v  a  2 s  .co  m
    try {
        url = new URL(dhisurl);
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    boolean val = testConnection(url, dhisusername, dhispassword, server, webRequest, model);

    String referer = webRequest.getHeader("Referer");

    if (val == false) {
        webRequest.setAttribute(WebConstants.OPENMRS_ERROR_ATTR,
                Context.getMessageSourceService().getMessage("dhisreport.dhis2ConnectionFailure"),
                WebRequest.SCOPE_SESSION);
        return "redirect:" + referer;
    }
    webRequest.setAttribute(WebConstants.OPENMRS_MSG_ATTR,
            Context.getMessageSourceService().getMessage("dhisreport.dhis2ConnectionSuccess"),
            WebRequest.SCOPE_SESSION);
    return "redirect:" + referer;
}

From source file:gov.nih.nci.nbia.StandaloneDMV2.java

void submitUserCredential(String userId, String password) {
    List<String> seriesInfo = null;
    String encryptedPassword = null;
    try {// w w  w  .  j  a  va2s .c o  m
        encryptedPassword = this.encrypt(password, getKey());
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        seriesInfo = connectAndReadFromURL(new URL(serverUrl),
                fileLoc + basketId.substring(0, basketId.length() - 2), userId, encryptedPassword);
    } catch (MalformedURLException e1) {
        e1.printStackTrace();
    }
    if (seriesInfo == null) {
        statusLbl.setText("Invalid User name and/or password.  Please try it again.");
        statusLbl.setForeground(Color.red);
        return;
    } else {
        try {
            String[] strResult = new String[seriesInfo.size()];
            seriesInfo.toArray(strResult);

            List<SeriesData> seriesData = JnlpArgumentsParser.parse(strResult);

            DownloadManagerFrame manager = new DownloadManagerFrame(userId, encryptedPassword,
                    includeAnnotation, seriesData, serverUrl, noOfRetry);
            manager.setTitle(winTitle);
            manager.setDefaultDownloadDir(System.getProperty("user.home") + File.separator + "Desktop");
            manager.setVisible(true);
            frame.setVisible(false);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

From source file:com.walmart.gatling.commons.ScriptExecutor.java

private boolean getAbortStatus(String abortUrl, String trackingId) {
    log.info("Getting abort status: {}{}", abortUrl, trackingId);
    URL url = null;//from w w w  .j  a va 2s .  c  om
    try {
        url = new URL(abortUrl + trackingId);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    try (InputStream input = url.openStream()) {
        String resultString = IOUtils.toString(input, StandardCharsets.UTF_8);
        return Boolean.parseBoolean(resultString);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:czlab.wabbit.CljPodLoader.java

/**
 *//* w  w w .  ja v a  2 s.c  o  m*/
private CljPodLoader addUrl(File f) {
    if (f.exists())
        try {
            addURL(f.toURI().toURL());
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    return this;
}

From source file:org.alfresco.maven.plugin.AbstractRefreshWebappMojo.java

private URL buildFinalUrl(String specificRefreshUrlPath) {
    try {//from  ww  w.  j a  va2 s  . c  om
        return new URL("http://" + refreshHost + ":" + refreshPort + specificRefreshUrlPath);
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:py.pol.una.ii.pw.controller.RestEasyCliente.java

public void deleteCliente(Integer Id) {

    System.out.println("aaaaaaaaaaaaaaaentro en deletecliente???");
    try {//  w  w  w  . ja  v a 2  s .com
        System.out.println("entro en deletecliente???");
        String idEliminar = Integer.toString(Id);
        ClientRequest request = new ClientRequest(
                "http://localhost:8080/EjbJaxRS-web/rest/clientes/" + idEliminar);

        ClientResponse<String> response = request.delete(String.class);
        FacesMessage msg = new FacesMessage("Clientes", response.getEntity());
        FacesContext.getCurrentInstance().addMessage(null, msg);

    } catch (MalformedURLException e) {

        e.printStackTrace();

    } catch (IOException e) {

        e.printStackTrace();

    } catch (Exception e) {

        e.printStackTrace();

    }

}

From source file:com.wasteofplastic.acidisland.Update.java

/**
 * Query the API to find the latest approved file's details.
 * //from  w  w  w.j a  v a 2 s.  c  o m
 * @return true if successful
 */
public boolean query() {
    URL url = null;

    try {
        // Create the URL to query using the project's ID
        url = new URL(API_HOST + API_QUERY + projectID);
    } catch (MalformedURLException e) {
        // There was an error creating the URL

        e.printStackTrace();
        return false;
    }

    try {
        // Open a connection and query the project
        URLConnection conn = url.openConnection();

        if (apiKey != null) {
            // Add the API key to the request if present
            conn.addRequestProperty("X-API-Key", apiKey);
        }

        // Add the user-agent to identify the program
        conn.addRequestProperty("User-Agent", "ASkyBlockAcidIsland Update Checker");

        // Read the response of the query
        // The response will be in a JSON format, so only reading one line
        // is necessary.
        final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String response = reader.readLine();

        // Parse the array of files from the query's response
        JSONArray array = (JSONArray) JSONValue.parse(response);

        if (array.size() > 0) {
            // Get the newest file's details
            JSONObject latest = (JSONObject) array.get(array.size() - 1);

            // Get the version's title
            versionName = (String) latest.get(API_NAME_VALUE);

            // Get the version's link
            versionLink = (String) latest.get(API_LINK_VALUE);

            // Get the version's release type
            versionType = (String) latest.get(API_RELEASE_TYPE_VALUE);

            // Get the version's file name
            versionFileName = (String) latest.get(API_FILE_NAME_VALUE);

            // Get the version's game version
            versionGameVersion = (String) latest.get(API_GAME_VERSION_VALUE);

            return true;
        } else {
            System.out.println("There are no files for this project");
            return false;
        }
    } catch (IOException e) {
        // There was an error reading the query

        e.printStackTrace();
        return false;
    }
}