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:org.lockss.util.TestUrlUtil.java

static String normalizePath(String path) {
    switch (1) {/*from w  w  w  .j a  va 2s  .c om*/
    case 1:
        try {
            return UrlUtil.normalizePath(path, UrlUtil.PATH_TRAVERSAL_ACTION_ALLOW);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e.toString());
        }
    case 2:
        try {
            Object urin = PrivilegedAccessor.invokeConstructor("JavaUriNormalizer");
            return (String) PrivilegedAccessor.invokeMethod(urin, "normalizePath",
                    ListUtil.list(path).toArray());
        } catch (Exception e) {
            log.warning("Couldn't invoke JavaUriNormalizer", e);
            return null;
        }
    }
    throw new RuntimeException();
}

From source file:org.openadaptor.util.URLUtils.java

/**
 * Checks the supplied url string to make sure that it is valid. It does this by checking that it:
 * //  ww  w  . ja  v  a  2 s. c om
 * <pre>
 *   a. a valid url format
 *   b. points to a data source that contains data
 * </pre>
 * 
 * Note that in the case of files you do not need to supply the "file:" protocol.
 * 
 * @throws RuntimeException
 *           if the url is null, or it does not exist, or it does not contain any data
 */
public static void validateURLAsDataSource(String url) {
    if (url == null || url.equals(""))
        throw new RuntimeException("Null url");

    // check the url is of valid format, exists and contains data
    try {
        URL u;

        try {
            u = new URL(url);
        } catch (MalformedURLException e) {
            // we assume that if it is not a valid URL then we are dealing with
            // a file and need to check that it exists and is not a directory
            File f = new File(url);

            if (!f.exists())
                throw new Exception("File not found and " + e.getMessage());

            if (f.isDirectory())
                throw new Exception("URL points to a directory");

            u = f.toURL();
        }

        InputStream in = u.openStream();
        int numBytes = in.available();
        in.close();

        if (numBytes <= 0) {
            log.warn("Number of bytes available from [" + url + "] = " + in.available());
            throw new Exception("Unable to read from file");
        }
    } catch (Exception e) {
        throw new RuntimeException("Invalid URL [" + url + "]: " + e.toString());
    }

    log.info("URL [" + url + "] is valid");
}

From source file:org.ofbiz.solr.SolrProductSearch.java

/**
 * Adds a List of products to the solr index.
 * <p>/*from   w w w.  j  av a2 s  .c  o  m*/
 * This is faster than reflushing the index each time.
 */
public static Map<String, Object> addListToSolrIndex(DispatchContext dctx, Map<String, Object> context)
        throws GenericEntityException {
    HttpSolrServer server = null;
    Map<String, Object> result;
    Boolean treatConnectErrorNonFatal = (Boolean) context.get("treatConnectErrorNonFatal");
    try {
        Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();

        // Construct Documents
        List<Map<String, Object>> fieldList = UtilGenerics
                .<Map<String, Object>>checkList(context.get("fieldList"));

        Debug.logInfo("Solr: Generating and adding " + fieldList.size() + " documents to solr index", module);

        for (Iterator<Map<String, Object>> fieldListIterator = fieldList.iterator(); fieldListIterator
                .hasNext();) {
            SolrInputDocument doc1 = SolrUtil.generateSolrDocument(fieldListIterator.next());
            if (Debug.verboseOn()) {
                Debug.logVerbose("Solr: Indexing document: " + doc1.toString(), module);
            }
            docs.add(doc1);
        }
        // push Documents to server
        server = new HttpSolrServer(SolrUtil.solrUrl);
        server.add(docs);
        server.commit();

        final String statusStr = "Added " + fieldList.size() + " documents to solr index";
        Debug.logInfo("Solr: " + statusStr, module);
        result = ServiceUtil.returnSuccess(statusStr);
    } catch (MalformedURLException e) {
        Debug.logError(e, e.getMessage(), module);
        result = ServiceUtil.returnError(e.toString());
        result.put("errorType", "urlError");
    } catch (SolrServerException e) {
        if (e.getCause() != null && e.getCause() instanceof ConnectException) {
            final String statusStr = "Failure connecting to solr server to commit product list; products not updated";
            if (Boolean.TRUE.equals(treatConnectErrorNonFatal)) {
                Debug.logWarning(e, "Solr: " + statusStr, module);
                result = ServiceUtil.returnFailure(statusStr);
            } else {
                Debug.logError(e, "Solr: " + statusStr, module);
                result = ServiceUtil.returnError(statusStr);
            }
            result.put("errorType", "connectError");
        } else {
            Debug.logError(e, e.getMessage(), module);
            result = ServiceUtil.returnError(e.toString());
            result.put("errorType", "solrServerError");
        }
    } catch (IOException e) {
        Debug.logError(e, e.getMessage(), module);
        result = ServiceUtil.returnError(e.toString());
        result.put("errorType", "ioError");
    }
    return result;
}

From source file:org.ofbiz.solr.SolrProductSearch.java

/**
 * Adds product to solr index.//from   w ww .  j a va2 s . co m
 */
public static Map<String, Object> addToSolrIndex(DispatchContext dctx, Map<String, Object> context)
        throws GenericEntityException {
    HttpSolrServer server = null;
    Map<String, Object> result;
    String productId = (String) context.get("productId");
    // connectErrorNonFatal is a necessary option because in some cases it may be considered normal that solr server is unavailable;
    // don't want to return error and abort transactions in these cases.
    Boolean treatConnectErrorNonFatal = (Boolean) context.get("treatConnectErrorNonFatal");
    try {
        Debug.logInfo("Solr: Generating and indexing document for productId '" + productId + "'", module);

        server = new HttpSolrServer(SolrUtil.solrUrl);
        //Debug.log(server.ping().toString());

        // Construct Documents
        SolrInputDocument doc1 = SolrUtil.generateSolrDocument(context);
        Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();

        if (Debug.verboseOn()) {
            Debug.logVerbose("Solr: Indexing document: " + doc1.toString(), module);
        }

        docs.add(doc1);

        // push Documents to server
        server.add(docs);
        server.commit();

        final String statusStr = "Document for productId " + productId + " added to solr index";
        Debug.logInfo("Solr: " + statusStr, module);
        result = ServiceUtil.returnSuccess(statusStr);
    } catch (MalformedURLException e) {
        Debug.logError(e, e.getMessage(), module);
        result = ServiceUtil.returnError(e.toString());
        result.put("errorType", "urlError");
    } catch (SolrServerException e) {
        if (e.getCause() != null && e.getCause() instanceof ConnectException) {
            final String statusStr = "Failure connecting to solr server to commit productId "
                    + context.get("productId") + "; product not updated";
            if (Boolean.TRUE.equals(treatConnectErrorNonFatal)) {
                Debug.logWarning(e, "Solr: " + statusStr, module);
                result = ServiceUtil.returnFailure(statusStr);
            } else {
                Debug.logError(e, "Solr: " + statusStr, module);
                result = ServiceUtil.returnError(statusStr);
            }
            result.put("errorType", "connectError");
        } else {
            Debug.logError(e, e.getMessage(), module);
            result = ServiceUtil.returnError(e.toString());
            result.put("errorType", "solrServerError");
        }
    } catch (IOException e) {
        Debug.logError(e, e.getMessage(), module);
        result = ServiceUtil.returnError(e.toString());
        result.put("errorType", "ioError");
    }
    return result;
}

From source file:org.ofbiz.solr.SolrProductSearch.java

/**
 * Rebuilds the solr index.//from   www. j a v a2  s .  c o m
 */
public static Map<String, Object> rebuildSolrIndex(DispatchContext dctx, Map<String, Object> context)
        throws GenericEntityException {
    HttpSolrServer server = null;
    Map<String, Object> result;
    GenericDelegator delegator = (GenericDelegator) dctx.getDelegator();
    LocalDispatcher dispatcher = dctx.getDispatcher();
    GenericValue userLogin = (GenericValue) context.get("userLogin");
    Locale locale = new Locale("de_DE");

    Boolean treatConnectErrorNonFatal = (Boolean) context.get("treatConnectErrorNonFatal");

    try {
        server = new HttpSolrServer(SolrUtil.solrUrl);

        // now lets fetch all products
        List<Map<String, Object>> solrDocs = FastList.newInstance();
        List<GenericValue> products = delegator.findList("Product", null, null, null, null, true);
        int numDocs = 0;
        if (products != null) {
            numDocs = products.size();
        }

        Debug.logInfo("Solr: Clearing solr index and rebuilding with " + numDocs + " found products", module);

        Iterator<GenericValue> productIterator = products.iterator();
        while (productIterator.hasNext()) {
            GenericValue product = productIterator.next();
            Map<String, Object> dispatchContext = ProductUtil.getProductContent(product, dctx, context);
            solrDocs.add(dispatchContext);
        }

        // this removes everything from the index
        server.deleteByQuery("*:*");
        server.commit();

        // THis adds all products to the Index (instantly)
        Map<String, Object> runResult = dispatcher.runSync("addListToSolrIndex",
                UtilMisc.toMap("fieldList", solrDocs, "userLogin", userLogin, "locale", locale,
                        "treatConnectErrorNonFatal", treatConnectErrorNonFatal));

        String runMsg = ServiceUtil.getErrorMessage(runResult);
        if (UtilValidate.isEmpty(runMsg)) {
            runMsg = null;
        }
        if (ServiceUtil.isError(runResult)) {
            result = ServiceUtil.returnError(runMsg);
        } else if (ServiceUtil.isFailure(runResult)) {
            result = ServiceUtil.returnFailure(runMsg);
        } else {
            final String statusMsg = "Cleared solr index and reindexed " + numDocs + " documents";
            result = ServiceUtil.returnSuccess(statusMsg);
        }
    } catch (MalformedURLException e) {
        Debug.logError(e, e.getMessage(), module);
        result = ServiceUtil.returnError(e.toString());
    } catch (SolrServerException e) {
        if (e.getCause() != null && e.getCause() instanceof ConnectException) {
            final String statusStr = "Failure connecting to solr server to rebuild index; index not updated";
            if (Boolean.TRUE.equals(treatConnectErrorNonFatal)) {
                Debug.logWarning(e, "Solr: " + statusStr, module);
                result = ServiceUtil.returnFailure(statusStr);
            } else {
                Debug.logError(e, "Solr: " + statusStr, module);
                result = ServiceUtil.returnError(statusStr);
            }
        } else {
            Debug.logError(e, e.getMessage(), module);
            result = ServiceUtil.returnError(e.toString());
        }
    } catch (IOException e) {
        Debug.logError(e, e.getMessage(), module);
        result = ServiceUtil.returnError(e.toString());
    } catch (ServiceAuthException e) {
        Debug.logError(e, e.getMessage(), module);
        result = ServiceUtil.returnError(e.toString());
    } catch (ServiceValidationException e) {
        Debug.logError(e, e.getMessage(), module);
        result = ServiceUtil.returnError(e.toString());
    } catch (GenericServiceException e) {
        Debug.logError(e, e.getMessage(), module);
        result = ServiceUtil.returnError(e.toString());
    } catch (Exception e) {
        Debug.logError(e, e.getMessage(), module);
        result = ServiceUtil.returnError(e.toString());
    }
    return result;
}

From source file:org.ofbiz.solr.SolrProductSearch.java

/**
 * Rebuilds the solr index./*from w  w w .  ja v a2  s  . c o m*/
 */
public static Map<String, Object> rebuildSolrIndexMultiThread(DispatchContext dctx, Map<String, Object> context)
        throws GenericEntityException {
    HttpSolrServer server = null;
    Map<String, Object> result;
    GenericDelegator delegator = (GenericDelegator) dctx.getDelegator();
    LocalDispatcher dispatcher = dctx.getDispatcher();
    GenericValue userLogin = (GenericValue) context.get("userLogin");
    Locale locale = new Locale("zh_CN");

    Boolean treatConnectErrorNonFatal = (Boolean) context.get("treatConnectErrorNonFatal");
    Integer sizePerThread = (Integer) context.get("sizePerThread");
    try {
        server = new HttpSolrServer(SolrUtil.solrUrl);

        // now lets fetch all products
        List<GenericValue> products = delegator.findList("Product", null, null, null, null, true);
        int numDocs = 0;
        if (products != null) {
            numDocs = products.size();
        }

        Debug.logInfo("Solr: Clearing solr index and rebuilding with " + numDocs + " found products", module);
        // this removes everything from the index
        server.deleteByQuery("*:*");
        server.commit();

        Iterator<GenericValue> productIterator = products.iterator();
        List<GenericValue> productList = FastList.newInstance();
        while (productIterator.hasNext()) {
            GenericValue product = productIterator.next();
            productList.add(product);
            if ((productList.size() % sizePerThread.intValue()) == 0) {
                List<GenericValue> tempProductList = FastList.newInstance();
                tempProductList.addAll(productList);
                dispatcher.runAsync("buildSolrIndexMultiThread",
                        UtilMisc.toMap("productList", tempProductList, "userLogin", userLogin, "locale", locale,
                                "treatConnectErrorNonFatal", treatConnectErrorNonFatal),
                        false);
                productList.clear();
            }
        }

        if (productList.size() > 0) {
            dispatcher.runAsync("buildSolrIndexMultiThread",
                    UtilMisc.toMap("productList", productList, "userLogin", userLogin, "locale", locale,
                            "treatConnectErrorNonFatal", treatConnectErrorNonFatal),
                    false);
        }

        final String statusMsg = "Cleared solr index and reindexed " + numDocs + " documents";
        result = ServiceUtil.returnSuccess(statusMsg);

    } catch (MalformedURLException e) {
        Debug.logError(e, e.getMessage(), module);
        result = ServiceUtil.returnError(e.toString());
    } catch (SolrServerException e) {
        if (e.getCause() != null && e.getCause() instanceof ConnectException) {
            final String statusStr = "Failure connecting to solr server to rebuild index; index not updated";
            if (Boolean.TRUE.equals(treatConnectErrorNonFatal)) {
                Debug.logWarning(e, "Solr: " + statusStr, module);
                result = ServiceUtil.returnFailure(statusStr);
            } else {
                Debug.logError(e, "Solr: " + statusStr, module);
                result = ServiceUtil.returnError(statusStr);
            }
        } else {
            Debug.logError(e, e.getMessage(), module);
            result = ServiceUtil.returnError(e.toString());
        }
    } catch (IOException e) {
        Debug.logError(e, e.getMessage(), module);
        result = ServiceUtil.returnError(e.toString());
    } catch (ServiceAuthException e) {
        Debug.logError(e, e.getMessage(), module);
        result = ServiceUtil.returnError(e.toString());
    } catch (ServiceValidationException e) {
        Debug.logError(e, e.getMessage(), module);
        result = ServiceUtil.returnError(e.toString());
    } catch (GenericServiceException e) {
        Debug.logError(e, e.getMessage(), module);
        result = ServiceUtil.returnError(e.toString());
    } catch (Exception e) {
        Debug.logError(e, e.getMessage(), module);
        result = ServiceUtil.returnError(e.toString());
    }
    return result;
}

From source file:AppletMethods.java

/** Initialize the sound file object and the GUI. */
public void init() {
    System.out.println("In AppletMethods.init()");
    try {//from w w w.  j ava 2 s.  c  om
        snd = getAudioClip(new URL(getCodeBase(), "laugh.au"));
    } catch (MalformedURLException e) {
        showStatus(e.toString());
    }
    setSize(200, 100); // take the place of a GUI
}

From source file:eu.impact_project.wsclient.XmlServiceProviderTest.java

/**
 * Test of getServiceList method, of class XmlServiceProvider.
 *///  www  . j a v  a  2  s . com
@Test
public void testGetServiceList() {

    try {

        // Load the directory as a resource
        URL file_url = new URL("http://localhost:9001/services.xml");
        // Turn the resource into a File object            
        XmlServiceProvider sp = new XmlServiceProvider(file_url);
        sp.getServiceList();

        XmlService service = sp.new XmlService(1, "prueba", "prueba", new URL("http://prueba"));
        service.getDescription();
        service.getIdentifier();
        service.getTitle();
        service.getURL();
        service.compareTo(service);

    } catch (MalformedURLException ex) {
        fail("Should not raise exception " + ex.toString());
    } catch (ConfigurationException ex) {
        fail("Should not raise exception " + ex.toString());
    }

}

From source file:soap.client.Application.java

@Bean
public Wsdl11DestinationProvider wsdl11DestinationProvider() {
    Wsdl11DestinationProvider wsdl11DestinationProvider = new Wsdl11DestinationProvider();
    try {/*from ww w. j  a va2s .c  o  m*/
        wsdl11DestinationProvider
                .setWsdl(new UrlResource("http://localhost:8181/VBankService/services/VBankPort?wsdl"));
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        System.out.println(e.toString());
    }
    System.out.println(wsdl11DestinationProvider.getDestination());

    return wsdl11DestinationProvider;
}

From source file:com.easy.facebook.android.facebook.Facebook.java

public boolean sessionIsValid() {

    Bundle params = new Bundle();
    params.putString("format", "json");
    params.putString("access_token", getAccessToken());

    String jsonResponse;/*w w w.  j av  a2s  . co  m*/
    try {
        jsonResponse = Util.openUrl("https://graph.facebook.com/me/feed", "GET", params);

        JSONObject objectJSON = new JSONObject(jsonResponse);

        if (!objectJSON.isNull("error")) {
            Log.e("EasyFacebookAndroid", "Invalid EasyFacebookAndroid session");
            return false;
        }

        if (!objectJSON.isNull("data")) {
            return true;
        } else {
            Log.e("EasyFacebookAndroid", "Invalid EasyFacebookAndroid session");
            return false;
        }

    } catch (MalformedURLException e) {
        Log.e("EasyFacebookAndroid", e.toString());
        return false;
    } catch (IOException e) {
        Log.e("EasyFacebookAndroid", e.toString());
        return false;
    } catch (JSONException e) {
        Log.e("EasyFacebookAndroid", e.toString());
        return false;
    }

}