Example usage for java.net MalformedURLException getCause

List of usage examples for java.net MalformedURLException getCause

Introduction

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

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:com.taobao.datax.engine.schedule.JarLoader.java

private static URL[] getUrl(String path) {
    /* check path exist */
    if (null == path || StringUtils.isBlank(path)) {
        throw new IllegalArgumentException("Path cannot be empty .");
    }/*from   ww w . j av a  2  s.c  o  m*/

    File jarPath = new File(path);
    if (!jarPath.exists() || !jarPath.isDirectory()) {
        throw new IllegalArgumentException("Path must be directory .");
    }

    /* set filter */
    FileFilter jarFilter = new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.getName().endsWith(".jar");
        }
    };

    /* iterate all jar */
    File[] allJars = new File(path).listFiles(jarFilter);
    URL[] jarUrls = new URL[allJars.length];

    for (int i = 0; i < allJars.length; i++) {
        try {
            jarUrls[i] = allJars[i].toURI().toURL();
        } catch (MalformedURLException e) {
            logger.error(ExceptionTracker.trace(e));
            throw new DataExchangeException(e.getCause());
        }
        logger.debug(jarUrls[i]);
    }

    return jarUrls;
}

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

/**
 * Rebuilds the solr index.//from w  ww .  j  a va2s. co m
 */
public static Map<String, Object> rebuildSolrIndex(DispatchContext dctx, Map<String, Object> context)
        throws GenericEntityException {
    HttpSolrClient client = null;
    Map<String, Object> result;
    GenericDelegator delegator = (GenericDelegator) dctx.getDelegator();
    LocalDispatcher dispatcher = dctx.getDispatcher();
    GenericValue userLogin = (GenericValue) context.get("userLogin");
    Locale locale = (Locale) context.get("locale");
    String solrIndexName = (String) context.get("indexName");

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

    try {
        client = SolrUtil.getInstance().getHttpSolrClient(solrIndexName);

        // now lets fetch all products
        List<Map<String, Object>> solrDocs = new ArrayList<Map<String, Object>>();
        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
        client.deleteByQuery("*:*");
        client.commit();

        // THis adds all products to the Index (instantly)
        Map<String, Object> runResult = dispatcher.runSync("addListToSolrIndex",
                UtilMisc.toMap("fieldList", solrDocs, "userLogin", userLogin, "locale", locale, "indexName",
                        solrIndexName, "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 = UtilProperties.getMessage(resource,
                    "SolrClearedSolrIndexAndReindexedDocuments", UtilMisc.toMap("numDocs", numDocs), locale);
            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 = UtilProperties.getMessage(resource,
                    "SolrFailureConnectingToSolrServerToRebuildIndex", locale);
            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());
    } finally {
        if (client != null) {
            try {
                client.close();
            } catch (IOException e) {
                // do nothing
            }
        }
    }
    return result;
}

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

/**
 * Adds a List of products to the solr index.
 * <p>//ww  w .j a  v a 2s. 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 {
    String solrIndexName = (String) context.get("indexName");
    Locale locale = (Locale) context.get("locale");
    HttpSolrClient client = 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
        client = SolrUtil.getInstance().getHttpSolrClient(solrIndexName);
        client.add(docs);
        client.commit();

        final String statusStr = UtilProperties.getMessage(resource, "SolrAddedDocumentsToSolrIndex",
                UtilMisc.toMap("fieldList", fieldList.size()), locale);
        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 = UtilProperties.getMessage(resource,
                    "SolrFailureConnectingToSolrServerToCommitProductList",
                    UtilMisc.toMap("productId", context.get("productId")), locale);
            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");
    } finally {
        if (client != null) {
            try {
                client.close();
            } catch (IOException e) {
                // do nothing
            }
        }
    }
    return result;
}

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

/**
 * Adds product to solr index./*from  w w w.  j  a  va 2 s.co m*/
 */
public static Map<String, Object> addToSolrIndex(DispatchContext dctx, Map<String, Object> context)
        throws GenericEntityException {
    HttpSolrClient client = null;
    Locale locale = (Locale) context.get("locale");
    Map<String, Object> result;
    String productId = (String) context.get("productId");
    String solrIndexName = (String) context.get("indexName");
    // 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);

        client = SolrUtil.getInstance().getHttpSolrClient(solrIndexName);
        //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
        client.add(docs);
        client.commit();

        final String statusStr = UtilProperties.getMessage(resource, "SolrDocumentForProductIdAddedToSolrIndex",
                UtilMisc.toMap("productId", context.get("productId")), locale);
        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 = UtilProperties.getMessage(resource,
                    "SolrFailureConnectingToSolrServerToCommitProductId",
                    UtilMisc.toMap("productId", context.get("productId")), locale);
            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");
    } finally {
        if (client != null) {
            try {
                client.close();
            } catch (IOException e) {
                // do nothing
            }
        }
    }
    return result;
}

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

/**
 * Rebuilds the solr index.//  w w w.  jav a2 s.c  om
 */
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 ww w .  j  a va2  s  . c  om*/
 */
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:org.ofbiz.solr.SolrProductSearch.java

/**
 * Adds a List of products to the solr index.
 * <p>//from   www  .  j  a v  a 2 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   www.  j a v  a2  s  . c  o  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:api.LabdooClient.java

public LabdooClient(String url, String apikey) throws APIException {
    XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
    client = new XmlRpcClient();
    try {/*ww w  . ja  va  2 s.co  m*/
        config.setServerURL(new URL(url + "?APIKEY=" + apikey));
    } catch (MalformedURLException e) {
        log.error(e.getMessage());
        APIException apiException = new APIException();
        apiException.initCause(e.getCause());
        throw apiException;
    }
    client.setConfig(config);

}

From source file:org.geoserver.geofence.gui.server.service.impl.InstancesManagerServiceImpl.java

public void testConnection(org.geoserver.geofence.gui.client.model.GSInstanceModel instance)
        throws ApplicationException {
    try {/*from w ww.jav  a  2s . c o  m*/
        String response = getURL(instance.getBaseURL() + "/rest/geofence/info", instance.getUsername(),
                instance.getPassword());
        if (response != null) {
            if (!response.equals(instance.getName())) {
                if (response.contains("Geoserver Configuration API")) { // some heuristic here
                    logger.error("GeoFence probe not installed on " + instance.getName());
                    throw new ApplicationException("GeoFence probe not installed on " + instance.getName());
                } else {
                    logger.error("Wrong instance name: " + response);
                    throw new ApplicationException(
                            "Wrong instance name: " + instance.getName() + ", should be :" + response);
                }
            }
        } else {
            throw new ApplicationException("Error contacting GeoServer");
        }
    } catch (MalformedURLException e) {
        logger.error(e.getLocalizedMessage(), e.getCause());
        throw new ApplicationException(e.getLocalizedMessage(), e.getCause());
    }
}