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.dataconservancy.access.connector.HttpDcsConnector.java

@Override
public String uploadFile(InputStream is, long length) throws DcsClientFault {
    HttpPost post;//from ww  w .  j  ava2 s  . c  om

    try {
        post = new HttpPost(config.getUploadFileUrl().toURI());
    } catch (URISyntaxException e) {
        final String msg = "Malformed upload file endpoint URL " + config.getUploadFileUrl() + ": "
                + e.getMessage();
        log.debug(msg, e);
        throw new DcsClientFault(msg, e);
    }

    InputStreamEntity data = new InputStreamEntity(is, length);
    data.setContentType("binary/octet-stream");
    data.setChunked(true);
    post.setEntity(data);

    HttpResponse resp = execute(post, HttpStatus.SC_ACCEPTED);

    try {
        resp.getEntity().consumeContent();
    } catch (IOException e) {
        throw new DcsClientFault("Problem releasing resources", e);
    }

    Header header = resp.getFirstHeader("X-dcs-src");

    if (header == null) {
        throw new DcsClientFault(
                "Server response missing required header X-dcs-src for post to " + config.getUploadFileUrl());
    }

    return header.getValue();
}

From source file:hsyndicate.rest.client.SyndicateUGHttpClient.java

public SyndicateUGHttpClient(String host, int port, String sessionName, String sessionKey)
        throws InstantiationException {
    if (host == null) {
        throw new IllegalArgumentException("host is null");
    }/*from w w w.ja  v a2 s.c  om*/

    if (port <= 0) {
        throw new IllegalArgumentException("port is illegal");
    }

    try {
        URI serviceURI = new URI(String.format("http://%s:%d/", host, port));
        initialize(serviceURI, sessionName, sessionKey, API_CALL_DEFAULT);
    } catch (URISyntaxException ex) {
        LOG.error("exception occurred", ex);
        throw new InstantiationException(ex.getMessage());
    }
}

From source file:hsyndicate.rest.client.SyndicateUGHttpClient.java

public SyndicateUGHttpClient(String host, int port, String sessionName, String sessionKey, API_CALL api_call)
        throws InstantiationException {
    if (host == null) {
        throw new IllegalArgumentException("host is null");
    }//from  www.  j  a v  a 2 s .  c  o  m

    if (port <= 0) {
        throw new IllegalArgumentException("port is illegal");
    }

    try {
        URI serviceURI = new URI(String.format("http://%s:%d/", host, port));
        initialize(serviceURI, sessionName, sessionKey, api_call);
    } catch (URISyntaxException ex) {
        LOG.error("exception occurred", ex);
        throw new InstantiationException(ex.getMessage());
    }
}

From source file:info.magnolia.cms.beans.config.ModuleRegistration.java

/**
 * @param xmlUrl//from w  ww.j  a  v  a  2  s  .co  m
 * @return
 */
protected File getModuleRoot(URL xmlUrl) {
    String xmlString = xmlUrl.getFile();
    String protocol = xmlUrl.getProtocol();

    File moduleRoot = null;

    if ("jar".equals(protocol)) {
        xmlString = StringUtils.substringBefore(xmlString, ".jar!") + ".jar";
        try {
            moduleRoot = new File(new URI(xmlString));
        } catch (URISyntaxException e) {
            // should never happen
            log.error(e.getMessage(), e);
        }
    } else {
        try {
            File xmlFile = new File(new URI(xmlUrl.toString()));
            moduleRoot = xmlFile.getParentFile().getParentFile().getParentFile();
        } catch (URISyntaxException e) {
            // should never happen
            log.error(e.getMessage(), e);
        }
    }
    return moduleRoot;
}

From source file:org.apache.fop.afp.AFPResourceManager.java

/**
 * Creates an included resource object by loading the contained object from a file.
 * @param resourceName the name of the resource
 * @param accessor resource accessor to access the resource with
 * @param resourceObjectType the resource object type ({@link ResourceObject}.*)
 * @throws IOException if an I/O error occurs while loading the resource
 *//*from  ww  w.jav a 2  s  . com*/
public void createIncludedResource(String resourceName, ResourceAccessor accessor, byte resourceObjectType)
        throws IOException {
    URI uri;
    try {
        uri = new URI(resourceName.trim());
    } catch (URISyntaxException e) {
        throw new IOException(
                "Could not create URI from resource name: " + resourceName + " (" + e.getMessage() + ")");
    }

    createIncludedResource(resourceName, uri, accessor, resourceObjectType);
}

From source file:com.sphereon.sdk.template.processor.api.IntegrationTest.java

private File getFile(String fileName) {
    try {//from ww  w.  j a v a 2  s  .  co  m
        URL resource = getClass().getClassLoader().getResource(fileName);
        File file = new File(resource.toURI());
        Assert.assertTrue(file.exists());
        return file;
    } catch (URISyntaxException e) {
        Assert.fail(e.getMessage());
    }
    return null;
}

From source file:edu.ucsb.nceas.ezid.EZIDService.java

/**
 * Log into the EZID service using account credentials provided by EZID. The cookie
 * returned by EZID is cached in a local CookieStore for the duration of the EZIDService,
 * and so subsequent calls uning this instance of the service will function as
 * fully authenticated. An exception is thrown if authentication fails.
 * @param username to identify the user account from EZID
 * @param password the secret password for this account
 * @throws EZIDException if authentication fails for any reason
 *///from  ww  w  .j  a va 2s.co m
public void login(String username, String password) throws EZIDException {
    try {
        URI serviceUri = new URI(loginServiceEndpoint);
        HttpHost targetHost = new HttpHost(serviceUri.getHost(), serviceUri.getPort(), serviceUri.getScheme());
        CredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()),
                new UsernamePasswordCredentials(username, password));
        AuthCache authCache = new BasicAuthCache();
        BasicScheme basicAuth = new BasicScheme();
        authCache.put(targetHost, basicAuth);
        HttpClientContext localcontext = HttpClientContext.create();
        localcontext.setAuthCache(authCache);
        localcontext.setCredentialsProvider(credsProvider);

        ResponseHandler<byte[]> handler = new ResponseHandler<byte[]>() {
            public byte[] handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
                HttpEntity entity = response.getEntity();
                if (entity != null) {
                    return EntityUtils.toByteArray(entity);
                } else {
                    return null;
                }
            }
        };
        byte[] body = null;

        HttpGet httpget = new HttpGet(loginServiceEndpoint);
        body = httpclient.execute(httpget, handler, localcontext);
        String message = new String(body);
        String msg = parseIdentifierResponse(message);
    } catch (URISyntaxException e) {
        throw new EZIDException(e.getMessage());
    } catch (ClientProtocolException e) {
        throw new EZIDException(e.getMessage());
    } catch (IOException e) {
        throw new EZIDException(e.getMessage());
    }
}

From source file:net.niyonkuru.koodroid.service.SessionService.java

private void login(String email, String password) throws IOException {
    try {//  w  w w. j  ava2s  .c  o m
        mPostRequest = new HttpPost(new URI(Config.LOGIN_URL));
    } catch (URISyntaxException e) {
        throw new ServiceException(e.getMessage());
    }

    List<NameValuePair> formData = buildFormData(email, password, getString(R.string.locale));
    try {
        /* fill the login request with form values */
        mPostRequest.setEntity(new UrlEncodedFormEntity(formData, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new ServiceException(e.getMessage());
    }

    Document doc;

    try {
        final HttpResponse response = mHttpClient.execute(mPostRequest);
        final Integer status = response.getStatusLine().getStatusCode();

        /* scumbag server did not return a 200 code */
        if (status != HttpStatus.SC_OK)
            throw new ServiceException(status.toString());

        HttpEntity entity = response.getEntity();

        doc = Jsoup.parse(EntityUtils.toString(response.getEntity()));

        if (entity != null) {
            entity.consumeContent();
        }
    } catch (UnknownHostException e) {
        throw new ServiceException(e.getMessage());
    } catch (ConnectTimeoutException e) {
        throw new ServiceException(getString(R.string.error_connection_timeout));
    } catch (ClientProtocolException e) {
        throw new ServiceException(e.getMessage());
    } catch (ParseException e) {
        throw new ServiceException(e.getMessage());
    } catch (SocketTimeoutException e) {
        throw new ServiceException(getString(R.string.error_response_timeout));
    } catch (IOException e) {
        // This could be caused by closing the httpclient connection manager
        throw new ServiceException(e.getMessage());
    }

    final Resources resources = getResources();
    final ContentResolver resolver = getContentResolver();

    /* this is a new user logging in */
    if (!email.equalsIgnoreCase(mSettings.email())) {
        /* clear old preferences */
        resolver.delete(Settings.CONTENT_URI, null, null);
    }

    try {
        new SubscribersHandler(resources, email).parseAndApply(doc, resolver);
        new LinksHandler(resources).parseAndApply(doc, resolver);

        ContentValues values = new ContentValues(3);
        values.put(Settings.EMAIL, email);
        values.put(Settings.PASSWORD, password);
        values.put(Settings.LAST_LOGIN, System.currentTimeMillis());

        resolver.insert(Settings.CONTENT_URI, values);

        new BackupManager(this).dataChanged();

    } catch (HandlerException e) {
        /* check if these errors could be caused by invalid pages */
        new ErrorHandler(resources).parseAndThrow(doc);
        throw e;
    }
}

From source file:org.springframework.boot.cli.command.init.ProjectGenerationRequest.java

/**
 * Generates the URI to use to generate a project represented by this request.
 * @param metadata the metadata that describes the service
 * @return the project generation URI//from  www.  j ava2  s.  c om
 */
URI generateUrl(InitializrServiceMetadata metadata) {
    try {
        URIBuilder builder = new URIBuilder(this.serviceUrl);
        StringBuilder sb = new StringBuilder();
        if (builder.getPath() != null) {
            sb.append(builder.getPath());
        }

        ProjectType projectType = determineProjectType(metadata);
        this.type = projectType.getId();
        sb.append(projectType.getAction());
        builder.setPath(sb.toString());

        if (!this.dependencies.isEmpty()) {
            builder.setParameter("dependencies",
                    StringUtils.collectionToCommaDelimitedString(this.dependencies));
        }

        if (this.groupId != null) {
            builder.setParameter("groupId", this.groupId);
        }
        String resolvedArtifactId = resolveArtifactId();
        if (resolvedArtifactId != null) {
            builder.setParameter("artifactId", resolvedArtifactId);
        }
        if (this.version != null) {
            builder.setParameter("version", this.version);
        }
        if (this.name != null) {
            builder.setParameter("name", this.name);
        }
        if (this.description != null) {
            builder.setParameter("description", this.description);
        }
        if (this.packageName != null) {
            builder.setParameter("packageName", this.packageName);
        }
        if (this.type != null) {
            builder.setParameter("type", projectType.getId());
        }
        if (this.packaging != null) {
            builder.setParameter("packaging", this.packaging);
        }
        if (this.javaVersion != null) {
            builder.setParameter("javaVersion", this.javaVersion);
        }
        if (this.language != null) {
            builder.setParameter("language", this.language);
        }
        if (this.bootVersion != null) {
            builder.setParameter("bootVersion", this.bootVersion);
        }

        return builder.build();
    } catch (URISyntaxException e) {
        throw new ReportableException("Invalid service URL (" + e.getMessage() + ")");
    }
}

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

public String commit() throws SearchException {
    String commitUrl = serverUrl + URL_ROOT + URL_COMMIT;

    try {//from  w w  w . j a v  a2  s.  co  m
        return restTemplate.postForObject(new URI(commitUrl), null, String.class);
    } catch (URISyntaxException e) {
        throw new SearchException("Invalid URI: " + commitUrl, e);
    } catch (HttpStatusCodeException e) {
        throw new SearchException("Commit failed: [" + e.getStatusText() + "] " + e.getResponseBodyAsString());
    } catch (Exception e) {
        throw new SearchException("Commit failed: " + e.getMessage(), e);
    }
}