Example usage for java.net URISyntaxException getMessage

List of usage examples for java.net URISyntaxException getMessage

Introduction

In this page you can find the example usage for java.net URISyntaxException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns a string describing the parse error.

Usage

From source file:org.craftercms.search.service.impl.RestClientSearchService.java

public Map<String, Object> search(Query query) throws SearchException {
    String searchUrl = serverUrl + URL_ROOT + URL_SEARCH + "?" + query.toQueryString();

    try {/*from   ww w.  ja v  a 2  s  . com*/
        return restTemplate.getForObject(new URI(searchUrl), Map.class);
    } catch (URISyntaxException e) {
        throw new SearchException("Invalid URI: " + searchUrl, e);
    } catch (HttpStatusCodeException e) {
        throw new SearchException("Search for query " + query + " failed: [" + e.getStatusText() + "] "
                + e.getResponseBodyAsString());
    } catch (Exception e) {
        throw new SearchException("Search for query " + query + " failed: " + e.getMessage(), e);
    }
}

From source file:org.openremote.modeler.beehive.Beehive30API.java

/**
 * Uploads resources from the given input stream to Beehive server. The Beehive REST API
 * used assumes a zip compressed stream including all relevant resources. The input stream
 * parameter must match these expectations. <p>
 *
 * The access to Beehive is authenticated using the given user's credentials.
 *
 * @param archive       zip compressed byte stream containing all the resources to upload
 *                      to Beehive//from   w  w w .ja  v  a  2  s  . c om
 * @param currentUserAccount  The user to authenticate in Beehive, along with account information
 *
 *
 * @throws ConfigurationException
 *            If the Beehive REST URL has been incorrectly configured. Will require
 *            reconfiguration and re-deployment of the application.
 *
 * @throws NetworkException
 *            If there's an I/O error on the upload stream or the Beehive server
 *            returns an error status
 *
 */
@Override
public void uploadResources(InputStream archive, UserAccount currentUserAccount)
        throws ConfigurationException, NetworkException {
    final String ARCHIVE_NAME = "openremote.zip";

    // TODO : must be HTTPS

    Account acct = currentUserAccount.getAccount();

    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost();

    addHTTPAuthenticationHeader(httpPost, currentUserAccount.getUsernamePassword().getUsername(),
            currentUserAccount.getUsernamePassword().getPassword());

    String beehiveRootRestURL = config.getBeehiveRESTRootUrl();
    String url = beehiveRootRestURL + "account/" + acct.getOid() + "/" + ARCHIVE_NAME;

    try {
        httpPost.setURI(new URI(url));
    }

    catch (URISyntaxException e) {
        throw new ConfigurationException("Incorrectly configured Beehive REST URL ''{0}'' : {1}", e,
                beehiveRootRestURL, e.getMessage());
    }

    InputStreamBody resource = new InputStreamBody(archive, ARCHIVE_NAME);

    MultipartEntity entity = new MultipartEntity();
    entity.addPart("resource", resource);
    httpPost.setEntity(entity);

    HttpResponse response;

    try {
        response = httpClient.execute(httpPost);
    }

    catch (IOException e) {
        throw new NetworkException("Network I/O error while uploading resource artifacts to Beehive : {0}", e,
                e.getMessage());
    }

    if (response.getStatusLine().getStatusCode() != HttpURLConnection.HTTP_OK) {
        throw new NetworkException("Failed to save resources to Beehive, status code: {0}",
                response.getStatusLine().getStatusCode());
    }

    // TODO :
    //   - should probably check other return codes explicitly here too, such as
    //     authentication errors (which is most likely not recoverable whereas
    //     a regular network connection glitch might well be)...
}

From source file:org.craftercms.search.service.impl.RestClientSearchService.java

@Override
public String updateDocument(String site, String id, File document, Map<String, String> additionalFields)
        throws SearchException {
    FileSystemResource fsrDoc = new FileSystemResource(document);
    MultiValueMap<String, Object> form = new LinkedMultiValueMap<String, Object>();

    form.add(REQUEST_PARAM_SITE, site);/*  w w w .  jav a 2s  .c  om*/
    form.add(REQUEST_PARAM_ID, id);
    form.add(REQUEST_PARAM_DOCUMENT, fsrDoc);

    if (MapUtils.isNotEmpty(additionalFields)) {
        for (Map.Entry<String, String> additionalField : additionalFields.entrySet()) {
            String fieldName = additionalField.getKey();

            if (fieldName.equals(REQUEST_PARAM_SITE) || fieldName.equals(REQUEST_PARAM_ID)
                    || fieldName.equals(REQUEST_PARAM_DOCUMENT)) {
                throw new SearchException(
                        String.format("An additional field shouldn't have the following names: %s, %s, %s",
                                REQUEST_PARAM_SITE, REQUEST_PARAM_ID, REQUEST_PARAM_DOCUMENT));
            }

            form.add(fieldName, additionalField.getValue());
        }
    }

    String updateDocumentUrl = serverUrl + URL_ROOT + URL_UPDATE_DOCUMENT;

    try {
        return restTemplate.postForObject(new URI(updateDocumentUrl), form, String.class);
    } catch (URISyntaxException e) {
        throw new SearchException("Invalid URI: " + updateDocumentUrl, e);
    } catch (HttpStatusCodeException e) {
        throw new SearchException("Update for document '" + id + "' failed: [" + e.getStatusText() + "] "
                + e.getResponseBodyAsString());
    } catch (Exception e) {
        throw new SearchException("Update for document '" + id + "' failed: " + e.getMessage(), e);
    }
}

From source file:com.visionspace.jenkins.vstart.plugin.VSPluginPerformer.java

public Long runVstart(Long id, BuildListener listener, int timeInterval) {
    try {//from  ww  w . ja  v a 2  s.  c  om
        //Run VSTART
        org.json.JSONObject runObject = vstObject.run(id);
        listener.getLogger().println("\nVSTART is now running!");
        Long reportId = runObject.getLong("reportId");

        //Inform which test case is running
        //listener.getLogger().println("The test case " + vstObject.getTestCase(testCaseId) + "has started.");

        //For concurrency issues
        Object obj = new Object();

        synchronized (obj) {
            long timeStamp = 0;
            org.json.JSONObject logger = null;

            do {
                logger = vstObject.getLog(reportId, timeStamp);
                JSONArray jArray = logger.getJSONArray("log");
                for (int i = 0; i < jArray.length(); i++) {
                    org.json.JSONObject json = jArray.getJSONObject(i);
                    Long eventTimeStamp = json.getLong("timestamp");
                    Date date = new Date(eventTimeStamp);
                    listener.getLogger().println(json.getString("level") + " " + /*eventTimeStamp*/date + " ["
                            + json.getString("resource") + "]" + " - " + json.getString("message") + "\n");

                    //Stores the latest timestamp
                    if (eventTimeStamp > timeStamp) {
                        timeStamp = eventTimeStamp;
                    }
                }
                if (!logger.getBoolean("finished")) {
                    obj.wait(timeInterval);
                }
            } while (!logger.getBoolean("finished"));
        }

        //inform the finishing of the test case execution
        //listener.getLogger().println("The test case " + vstObject.getTestCase(testCaseId) + "has finished its execution.");

        //Finished run
        listener.getLogger().println("VSTART run has now ended!");

        return reportId;
    } catch (URISyntaxException ex) {
        Logger.getLogger(VSPluginPerformer.class.getName()).log(Level.SEVERE, null, ex);
        listener.getLogger().println("Exception during the VSTART run! -> " + ex.getReason());
        return 0l;
    } catch (IOException ex) {
        Logger.getLogger(VSPluginPerformer.class.getName()).log(Level.SEVERE, null, ex);
        listener.getLogger().println("Exception during the VSTART run! -> " + ex.getMessage());
        return 0l;
    } catch (InterruptedException ex) {
        Logger.getLogger(VSPluginPerformer.class.getName()).log(Level.SEVERE, null, ex);
        listener.getLogger().println("Exception during the VSTART run! -> " + ex.getMessage());
        return 0l;
    }
}

From source file:com.qwazr.crawler.web.manager.WebCrawlThread.java

WebCrawlThread(String sessionName, WebCrawlDefinition crawlDefinition) throws ServerException {
    timeTracker = new TimeTracker();
    this.session = new CurrentSessionImpl(crawlDefinition, sessionName, timeTracker);
    this.crawlDefinition = crawlDefinition;
    if (crawlDefinition.browser_type == null)
        throw new ServerException(Status.NOT_ACCEPTABLE, "The browser_type is missing");
    if (crawlDefinition.entry_url == null)
        throw new ServerException(Status.NOT_ACCEPTABLE, "The entry_url is missing");
    parametersMatcherList = getRegExpMatcherList(crawlDefinition.parameters_patterns);
    exclusionMatcherList = getWildcardMatcherList(crawlDefinition.exclusion_patterns);
    inclusionMatcherList = getWildcardMatcherList(crawlDefinition.inclusion_patterns);
    if (crawlDefinition.robots_txt_enabled != null && crawlDefinition.robots_txt_enabled)
        robotsTxtMap = new HashMap<>();
    else//from w w  w .ja  v a2  s.c  o  m
        robotsTxtMap = null;
    robotsTxtUserAgent = crawlDefinition.robots_txt_useragent == null ? "QWAZR_BOT"
            : crawlDefinition.robots_txt_useragent;
    try {
        URI uri = new URI(crawlDefinition.entry_url);
        String host = uri.getHost();
        if (host == null)
            throw new URISyntaxException(crawlDefinition.entry_url, "No host found.", -1);
        internetDomainName = InternetDomainName.from(host);
    } catch (URISyntaxException e) {
        throw new ServerException(Status.NOT_ACCEPTABLE, e.getMessage());
    } finally {
        timeTracker.next("Initialization");
    }
}

From source file:fedora.server.storage.translation.AtomDODeserializer.java

/**
 * Returns the an Entry's contentSrc as a File relative to {@link #m_tempDir}.
 * //from  ww  w  . j  a v  a  2 s  .co m
 * @param contentSrc
 * @return the contentSrc as a File relative to m_tempDir.
 * @throws ObjectIntegrityException
 */
protected File getContentSrcAsFile(IRI contentSrc) throws ObjectIntegrityException {
    if (contentSrc.isAbsolute() || contentSrc.isPathAbsolute()) {
        throw new ObjectIntegrityException("contentSrc must not be absolute");
    }
    try {
        // Normalize the IRI to resolve percent-encoding and 
        // backtracking (e.g. "../")
        NormalizedURI nUri = new NormalizedURI(m_tempDir.toURI().toString() + contentSrc.toString());
        nUri.normalize();

        File f = new File(nUri.toURI());
        if (f.getParentFile().equals(m_tempDir)) {
            return f;
        } else {
            throw new ObjectIntegrityException(contentSrc.toString() + " is not a valid path.");
        }
    } catch (URISyntaxException e) {
        throw new ObjectIntegrityException(e.getMessage(), e);
    }
}

From source file:com.persistent.cloudninja.scheduler.StorageUtility.java

/**
 * Returns the Blob for given String URI
 * //from  w  ww .  ja  va  2  s  .c  o  m
 * @param String URI
 * @return BufferedReader
 */
public CloudBlob getBlobFromStringURI(String uri) {
    CloudBlob blob = null;
    try {
        CloudBlobContainer container = blobClientDiagnostic
                .getContainerReference(SchedulerSettings.WebTomcatLogsContainer);
        blob = container.getBlockBlobReference(uri);
    } catch (URISyntaxException uriSyntaxException) {
        LOGGER.error(uriSyntaxException.getMessage(), uriSyntaxException);
    } catch (StorageException strgException) {
        LOGGER.error(strgException.getMessage(), strgException);
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }

    return blob;
}

From source file:org.hfoss.posit.web.Communicator.java

/**
 * A wrapper(does some cleanup too) for sending HTTP GET requests to the URI 
 * //from  w  w w . j  a va 2 s  .  c  om
 * @param Uri
 * @return the request from the remote server
 */
public String doHTTPGET(String Uri) {
    if (Uri == null)
        throw new NullPointerException("The URL has to be passed");
    String responseString = null;
    HttpGet httpGet = new HttpGet();

    try {
        httpGet.setURI(new URI(Uri));
    } catch (URISyntaxException e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
        return "[Error]" + e.getMessage();
    }
    if (Utils.debug) {
        Log.i(TAG, "doHTTPGet Uri = " + Uri);
    }
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    mStart = System.currentTimeMillis();

    try {
        responseString = mHttpClient.execute(httpGet, responseHandler);
    } catch (ClientProtocolException e) {
        Log.e(TAG, "ClientProtocolException" + e.getMessage());
        e.printStackTrace();
        return "[Error]" + e.getMessage();
    } catch (IOException e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
        return "[Error]" + e.getMessage();
    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
        return "[Error]" + e.getMessage();
    }

    long time = System.currentTimeMillis() - mStart;
    mTotalTime += time;
    Log.i(TAG, "TIME = " + time + " millisecs");

    if (Utils.debug)
        Log.i(TAG, "doHTTPGet Response: " + responseString);
    return responseString;
}

From source file:no.met.jtimeseries.service.TimeSeriesService.java

/**
 * Get location forecast schema url/*from w ww.j  av a 2s  .  c o  m*/
 * @return location forecast schema url or null
 */
private URL getLocationForecastSchemaUrl() {
    try {
        ConfigUtils cfg = new no.met.halo.common.ConfigUtils("/config/jtimeseries.properties", JTIMESERIES_ENV);
        String scheme = cfg.getRequired("datasource.scheme");
        String server = cfg.getRequired("datasource.server");
        String port = cfg.getRequired("datasource.port");
        String path = cfg.getRequired("datasource.meteogram.path");

        URI uri = new URI(scheme, server + ":" + port, path + "schema", null, null);
        return uri.toURL();
    } catch (URISyntaxException ex) {
        Logger.getLogger(TimeSeriesService.class.getName()).log(Level.WARNING, ex.getMessage(), ex);
    } catch (MalformedURLException ex) {
        Logger.getLogger(TimeSeriesService.class.getName()).log(Level.WARNING, ex.getMessage(), ex);
    }
    return null;
}

From source file:org.hfoss.posit.web.Communicator.java

/**
 * Sends a HttpPost request to the given URL. Any JSON 
 * @param Uri the URL to send to/receive from
 * @param sendMap the hashMap of data to send to the server as POST data
 * @return the response from the URL/*from   w  w w  .j ava 2  s.c o m*/
 */
private String doHTTPPost(String Uri, HashMap<String, String> sendMap) {

    if (Uri == null)
        throw new NullPointerException("The URL has to be passed");
    String responseString = null;
    HttpPost post = new HttpPost();
    if (Utils.debug)
        Log.i(TAG, "doHTTPPost() URI = " + Uri);
    try {
        post.setURI(new URI(Uri));
    } catch (URISyntaxException e) {
        Log.e(TAG, "URISyntaxException " + e.getMessage());
        e.printStackTrace();
        return e.getMessage();
    }
    List<NameValuePair> nvp = PositHttpUtils.getNameValuePairs(sendMap);
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    try {
        post.setEntity(new UrlEncodedFormEntity(nvp, HTTP.UTF_8));
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, "UnsupportedEncodingException " + e.getMessage());
    }
    mStart = System.currentTimeMillis();

    try {
        responseString = mHttpClient.execute(post, responseHandler);
    } catch (ClientProtocolException e) {
        Log.e(TAG, "ClientProtocolExcpetion" + e.getMessage());
        e.printStackTrace();
        return e.getMessage();
    } catch (IOException e) {
        Log.e(TAG, "IOException " + e.getMessage());
        e.printStackTrace();
        return e.getMessage();
    } catch (IllegalStateException e) {
        Log.e(TAG, "IllegalStateException: " + e.getMessage());
        e.printStackTrace();
        return e.getMessage();
    } catch (Exception e) {
        Log.e(TAG, "Exception on HttpPost " + e.getMessage());
        e.printStackTrace();
        return e.getMessage();
    }
    long time = System.currentTimeMillis() - mStart;
    mTotalTime += time;
    Log.i(TAG, "TIME = " + time + " millisecs");

    return responseString;
}