Example usage for java.net MalformedURLException toString

List of usage examples for java.net MalformedURLException toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.util.DownloadNCBITraceXML.java

public void saveFullXMLFiles(int p) {

    BufferedReader br = null;//from   w  w  w  .j  a va  2 s  .c om
    BufferedWriter bw = null;

    try {
        String pagesquery = "http://www.ncbi.nlm.nih.gov/Traces/trace.cgi?&cmd=retrieve&val=PROJECT_NAME%3D%22TCGA%22%20and%20LOAD_DATE%3E%3D%22"
                + latestLoaddate + "%22&size=" + querysize + "&dopt=xml_info&dispmax=" + pagesize + "&page="
                + p;
        //String pagesquery = "http://www.ncbi.nlm.nih.gov/Traces/trace.cgi?&cmd=retrieve&val=project_name%3D%22TCGA%22%20and%20load_date%3E%3D%2204%2F09%2F2008%22&dopt=info&size=490552&dispmax=5&page=4&next=%3E%3E
        URL url = new URL(pagesquery);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        //System.out.println( "url = " + url );
        is = connection.getInputStream();
        //noinspection IOResourceOpenedButNotSafelyClosed
        br = new BufferedReader(new InputStreamReader(is));
        String line;
        fw = new FileWriter(downloaddir + File.separator + xmlfiles + "." + p + ".xml");
        //fw= new FileWriter("C:\\larry\\WorkingDoc\\"+ latestLoaddate + "\\" + xmlfiles + "." + p + ".xml");
        //noinspection IOResourceOpenedButNotSafelyClosed
        bw = new BufferedWriter(fw);
        bw.write("<traces>");
        while ((line = br.readLine()) != null) {
            for (int i = 0; i < allFieldsWeCare.length; i++) {
                if (line.contains(allFieldsWeCare[i])) {
                    if (line.contains("<pre><trace>")) {
                        line = "<trace>";
                        //System.out.println(line);
                        bw.write(line);
                        bw.newLine();
                    } else {
                        //System.out.println(line);
                        bw.write(line);
                        bw.newLine();
                    }
                }
            }
        }
        bw.write("</traces>");
        is.close();
        connection.disconnect();
    } catch (MalformedURLException e) {
        getLogger().logToLogger(Level.ERROR,
                "DownloadNCBITraceXML saveXMLFiles MalformedURLException " + e.toString());
    } catch (IOException e) {
        getLogger().logToLogger(Level.ERROR, "DownloadNCBITraceXML saveXMLFiles IOException " + e.toString());
    } finally {
        IOUtils.closeQuietly(br);
        IOUtils.closeQuietly(bw);
    }
}

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.util.DownloadNCBITraceXML.java

public void saveXMLFiles(int p) {

    BufferedReader br = null;/*w w w.  jav a 2  s . c om*/
    BufferedWriter bw = null;

    try {
        String pagesquery = "http://www.ncbi.nlm.nih.gov/Traces/trace.cgi?&cmd=retrieve&val=PROJECT_NAME%3D%22TCGA%22%20and%20LOAD_DATE%3E%3D%22"
                + latestLoaddate + "%22&size=" + querysize + "&dopt=xml_info&dispmax=" + pagesize + "&page="
                + p;
        //String pagesquery = "http://www.ncbi.nlm.nih.gov/Traces/trace.cgi?&cmd=retrieve&val=project_name%3D%22TCGA%22%20and%20load_date%3E%3D%2204%2F09%2F2008%22&dopt=info&size=490552&dispmax=5&page=4&next=%3E%3E
        URL url = new URL(pagesquery);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        //System.out.println( "url = " + url );
        is = connection.getInputStream();
        //noinspection IOResourceOpenedButNotSafelyClosed
        br = new BufferedReader(new InputStreamReader(is));
        String line;
        fw = new FileWriter(downloaddir + File.separator + xmlfiles + "." + p + ".xml");
        //fw= new FileWriter("C:\\larry\\WorkingDoc\\"+ latestLoaddate + "\\" + xmlfiles + "." + p + ".xml");
        //noinspection IOResourceOpenedButNotSafelyClosed
        bw = new BufferedWriter(fw);
        bw.write("<traces>");
        while ((line = br.readLine()) != null) {
            for (int i = 0; i < fieldsWeCareForNow.length; i++) {
                if (line.contains(fieldsWeCareForNow[i])) {
                    if (line.contains("<pre><trace>")) {
                        line = "<trace>";
                        //System.out.println(line);
                        bw.write(line);
                        bw.newLine();
                    } else {
                        //System.out.println(line);
                        bw.write(line);
                        bw.newLine();
                    }
                }
            }
        }
        bw.write("</traces>");
        //fw.close();
        is.close();
        connection.disconnect();
    } catch (MalformedURLException e) {
        getLogger().logToLogger(Level.ERROR,
                "DownloadNCBITraceXML saveXMLFiles MalformedURLException " + e.toString());
    } catch (IOException e) {
        getLogger().logToLogger(Level.ERROR, "DownloadNCBITraceXML saveXMLFiles IOException " + e.toString());
    } finally {
        IOUtils.closeQuietly(br);
        IOUtils.closeQuietly(bw);
    }
}

From source file:fr.itldev.koya.services.impl.UserServiceImpl.java

/**
 * Authenticates user with authentication key that could be his login or
 * email./*from  ww  w .  j a  v a2s.co  m*/
 *
 *
 * TODO give md5 or other secured password instead of clear.
 *
 * @param authKey
 * @param password
 * @return
 * @throws fr.itldev.koya.services.exceptions.AlfrescoServiceException
 */
@Override
public User login(String authKey, String password) throws RestClientException, AlfrescoServiceException {

    //call rest ticket
    AuthTicket ticket = fromJSON(new TypeReference<AuthTicket>() {
    }, getTemplate().getForObject(getAlfrescoServerUrl() + REST_GET_LOGIN, String.class, authKey, password));
    //Get User Object
    Map emailPostWrapper = new HashMap();
    emailPostWrapper.put("authKey", authKey);
    User user = fromJSON(new TypeReference<User>() {
    }, getTemplate().postForObject(getAlfrescoServerUrl() + REST_POST_PERSONFROMMAIL, emailPostWrapper,
            String.class, ticket));

    //Authentication ticket integration
    user.setTicketAlfresco(ticket.toString());
    try {
        //set users authenticated rest template
        user.setRestTemplate(getAuthenticatedRestTemplate(user.getUserName(), password));
    } catch (MalformedURLException ex) {
        throw new AlfrescoServiceException(ex.toString());
    }
    //load users rest prefrences
    loadPreferences(user);
    //
    user.setPassword(password);
    return user;
}

From source file:se.lu.nateko.edca.svc.GetCapabilities.java

/**
 * Method that calls a geospatial server using a GetCapablities request and,
 * if successful, forwards the resulting XML object to the XML parser.
 * @return   Returns true if successful, otherwise false.
 *//*from w  w w.  j  a  v a 2  s .  c om*/
protected boolean getCapabilitiesRequest() {
    Log.d(TAG, "getCapabilitiesRequest() called.");

    /* Execute the HTTP request. */
    HttpGet httpGetMethod = new HttpGet(mServerURI);
    HttpResponse response;
    try {
        final HttpParams httpParameters = mHttpClient.getParams();
        HttpConnectionParams.setConnectionTimeout(httpParameters, TIME_OUT * 1000);
        HttpConnectionParams.setSoTimeout(httpParameters, TIME_OUT * 1000);

        response = mHttpClient.execute(httpGetMethod);
        Log.i(TAG, "GetCapabilities request made to server: " + httpGetMethod.getURI().toString());

        //          Log.v(TAG, "Length: " + response.getEntity().getContentLength() + ", Type: " + response.getEntity().getContentType() + ", Encoding: " + response.getEntity().getContentEncoding());

        InputStream xmlStream = response.getEntity().getContent();
        InputStreamReader reader = new InputStreamReader(xmlStream, "UTF-8");
        BufferedReader buffReader = new BufferedReader(reader, 4096);

        /* Remove all non-stored and inactive layers from the table to make room for the new result of the GetCapabilities XML parsing. */
        mService.clearRemoteLayers();

        /* Check for already stored layers so they are not duplicated. */
        Cursor storedCursor = mService.getSQLhelper().fetchData(LocalSQLDBhelper.TABLE_LAYER,
                LocalSQLDBhelper.KEY_LAYER_COLUMNS, LocalSQLDBhelper.ALL_RECORDS, null, true);
        mService.getActiveActivity().startManagingCursor(storedCursor);
        while (storedCursor.moveToNext()) {
            mStoredLayers.add(storedCursor.getString(1));
            Log.v(TAG, "Stored layer: " + storedCursor.getString(1));
        }

        try {
            Log.v(TAG, "Sending response (BufferedReader) to parser...");
            return parseXMLResponse(buffReader); // Send the HttpResponse as a Reader to parse its content.
        } finally {
            buffReader.close();
        }

    } catch (MalformedURLException e) {
        Log.e(TAG, e.toString());
        return false;
    } catch (IOException e) {
        Log.e(TAG, e.toString());
        return false;
    }
}

From source file:com.orange.datavenue.DatasourceListFragment.java

private void createDatasource() {
    final android.app.Dialog dialog = new android.app.Dialog(getActivity());

    dialog.setContentView(R.layout.create_datasource_dialog);

    dialog.setTitle(R.string.add_datasource);

    final LinearLayout callbackLayout = (LinearLayout) dialog.findViewById(R.id.callback_layout);
    final EditText name = (EditText) dialog.findViewById(R.id.name);
    final EditText description = (EditText) dialog.findViewById(R.id.description);
    final EditText serial = (EditText) dialog.findViewById(R.id.serial);
    final EditText callback = (EditText) dialog.findViewById(R.id.callback);
    final CheckBox status = (CheckBox) dialog.findViewById(R.id.status);

    status.setChecked(true); // by default status is activated

    Button actionButton = (Button) dialog.findViewById(R.id.add_button);

    actionButton.setOnClickListener(new View.OnClickListener() {
        @Override//from w  w w. j a  v  a  2 s . com
        public void onClick(View view) {
            Log.d(TAG_NAME, "name : " + name.getText().toString());
            Log.d(TAG_NAME, "description : " + description.getText().toString());
            Log.d(TAG_NAME, "serial : " + serial.getText().toString());
            Log.d(TAG_NAME, "status : " + status.isChecked());

            Datasource newDatasource = new Datasource();

            newDatasource.setName(name.getText().toString());
            newDatasource.setDescription(description.getText().toString());
            newDatasource.setSerial(serial.getText().toString());

            String callbackUrl = callback.getText().toString();

            if ("".equals(callbackUrl)) {
                newDatasource.setCallback(null);
            } else {
                try {
                    URL url = new URL(callbackUrl);
                    Callback newCallback = new Callback();
                    newCallback.setUrl(url.toString());
                    newCallback.setStatus("activated");
                    newCallback.setName("Callback");
                    newCallback.setDescription("application callback");
                    newDatasource.setCallback(newCallback);
                } catch (MalformedURLException e) {
                    Log.e(TAG_NAME, e.toString());
                    newDatasource.setCallback(null);
                    callback.setText("");
                }
            }

            if (status.isChecked()) {
                newDatasource.setStatus("activated");
            } else {
                newDatasource.setStatus("deactivated");
            }

            CreateDatasourceOperation createDatasourceOperation = new CreateDatasourceOperation(
                    Model.instance.oapiKey, Model.instance.key, newDatasource, new OperationCallback() {
                        @Override
                        public void process(Object object, Exception exception) {
                            if (exception == null) {
                                getDatasources();
                            } else {
                                Errors.displayError(getActivity(), exception);
                            }
                        }
                    });

            createDatasourceOperation.execute("");

            dialog.dismiss();
        }
    });

    Button cancelButton = (Button) dialog.findViewById(R.id.cancel_button);
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dialog.dismiss();
        }
    });

    dialog.setCancelable(false);
    dialog.show();
}

From source file:eionet.gdem.qa.XQueryService.java

/**
 * Request from XML/RPC client Stores the xqScript and starts a job in the workqueue.
 *
 * @param sourceURL - URL of the source XML
 * @param xqScript - XQueryScript to be processed
 * @param scriptType - xquery, xsl or xgawk
 *//*www  .jav a2s .  co m*/
public String analyze(String sourceURL, String xqScript, String scriptType) throws GDEMException {
    String xqFile = "";

    LOGGER.info("XML/RPC call for analyze xml: " + sourceURL);
    // save XQScript in a text file for the WQ
    try {
        xqFile = Utils.saveStrToFile(xqScript, scriptType);
    } catch (FileNotFoundException fne) {
        throw new GDEMException("Folder does not exist: :" + fne.toString());
    } catch (IOException ioe) {
        throw new GDEMException("Error storing XQScript into file:" + ioe.toString());
    }

    // name for temporary output file where the esult is stored:
    String resultFile = Properties.tmpFolder + File.separatorChar + "gdem_" + System.currentTimeMillis()
            + ".html";
    String newId = "-1"; // should not be returned with value -1;

    // start a job in the Workqueue
    try {
        // get the trusted URL from source file adapter
        sourceURL = SourceFileManager.getSourceFileAdapterURL(getTicket(), sourceURL, isTrustedMode());
        newId = xqJobDao.startXQJob(sourceURL, xqFile, resultFile);

    } catch (SQLException sqe) {
        sqe.printStackTrace();
        LOGGER.error("DB operation failed: " + sqe.toString());
        throw new GDEMException("DB operation failed: " + sqe.toString());
    } catch (MalformedURLException e) {
        e.printStackTrace();
        LOGGER.error("Source file URL is wrong: " + e.toString());
        throw new GDEMException("Source file URL is wrong: " + e.toString());
    } catch (IOException e) {
        e.printStackTrace();
        LOGGER.error("Error opening source file: " + e.toString());
        throw new GDEMException("Error opening source file: " + e.toString());
    }
    return newId;
}

From source file:util.Check.java

/**
 * This method checks if a String is a valid URL
 *//*from  www  . ja va2 s.c  om*/
public boolean isUrl(final String link) {

    boolean check = true;

    try {
        final URL url = new URL(link);
        System.out.println("Gltige URL: " + url); // unterdrckt Warnung, dass url nie gebraucht wird
    } catch (final MalformedURLException e) {
        LOG.info("isUrl: " + link + "\040" + e.toString());
        check = false;
    }

    return check;
}

From source file:org.kuali.mobility.bus.dao.BusDaoUMImpl.java

@Override
public void loadAlerts() {
    XStream xstream = new XStream();
    xstream.processAnnotations(UMBusAlertReader.class);
    xstream.processAnnotations(UMBusAlert.class);
    xstream.addImplicitCollection(UMBusAlertReader.class, "alerts");

    UMBusAlertReader busAlertReader = null;
    try {//w w  w .  j ava  2  s. c o m
        busAlertReader = (UMBusAlertReader) xstream.fromXML(new URL(getBusAlertUrl()));
    } catch (MalformedURLException ex) {
        LOG.error(ex.toString());
    }
    List<BusAlert> busAlerts = new ArrayList<BusAlert>();
    if (busAlertReader == null) {
        LOG.debug("busAlertReader == null");
    } else if (busAlertReader.getAlerts() == null) {
        LOG.debug("busAlertReader.getAlerts() == null");
    } else {
        for (UMBusAlert b : busAlertReader.getAlerts()) {
            BusAlert busAlert = (BusAlert) getApplicationContext().getBean("busAlert");
            busAlert.setTitle(b.getTitle());
            busAlert.setMessage(b.getMessage());
            busAlert.setColor(b.getColor());
            busAlert.setMessageType(b.getMessageType());
            busAlerts.add(busAlert);
        }
    }
    this.setAlerts(busAlerts);
}

From source file:org.kuali.mobility.bus.dao.BusDaoUMImpl.java

@Override
public void loadBusLocations() {
    XStream xstream = new XStream();
    xstream.processAnnotations(UMBusReader.class);
    xstream.processAnnotations(UMBus.class);
    xstream.addImplicitCollection(UMBusReader.class, "items");

    UMBusReader busReader = null;// w w w .j a  v  a  2  s.  c o  m
    try {
        busReader = (UMBusReader) xstream.fromXML(new URL(getBusLocationUrl()));
    } catch (MalformedURLException ex) {
        LOG.error(ex.toString());
    }

    List<Bus> busData = new ArrayList<Bus>();
    if (busReader == null) {
        LOG.debug("busReader == null");
    } else if (busReader.getItems() == null) {
        LOG.debug("busReader.getItems() == null");
    } else {
        for (UMBus b : busReader.getItems()) {
            Bus bus = (Bus) getApplicationContext().getBean("bus");
            bus.setName(b.getRouteName());
            bus.setId(b.getId());
            bus.setRouteId(b.getRouteId());
            bus.setRouteName(b.getRouteName());
            bus.setHeading(b.getHeading());
            bus.setColor(b.getColor());
            bus.setLatitude(b.getLatitude());
            bus.setLongitude(b.getLongitude());
            busData.add(bus);
        }
    }
    this.setBuses(busData);
}