Example usage for java.net URI URI

List of usage examples for java.net URI URI

Introduction

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

Prototype

public URI(String str) throws URISyntaxException 

Source Link

Document

Constructs a URI by parsing the given string.

Usage

From source file:jp.go.nict.langrid.commons.jxpath.BPELUtil.java

/**
 * /*from  w  ww . jav a  2  s . c o  m*/
 * 
 */
public static URI getWSBPEL_2_0_TargetNamespace(InputStream body)
        throws IOException, SAXException, URISyntaxException {
    String value = (String) newWSBPEL_2_0_Context(body, "_").getValue("_:process/@targetNamespace");
    if (value == null)
        return null;
    return new URI(value);
}

From source file:de.itomig.itoplib.GetItopJSON.java

/**
 * request data from itop server in json format
 * //from  w w w . j a  va  2s. c  o m
 * @param operation
 * @param itopClass
 * @param key
 * @param output_fields
 * @return
 */
public static String postJsonToItopServer(String operation, String itopClass, String key,
        String output_fields) {
    AndroidHttpClient client = AndroidHttpClient.newInstance("Android");
    String result = "";

    try {
        HttpPost request = new HttpPost();
        String url = ItopConfig.getItopUrl();

        String req = url + "/webservices/rest.php?version=1.0";
        if (debug)
            Log.i(TAG, "req.=" + req);
        request.setURI(new URI(req));

        ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
        postParameters.add(ItopConfig.getItopUserNameValuePair());
        postParameters.add(ItopConfig.getItopPwdNameValuePair());

        JSONObject jsd = new JSONObject();
        jsd.put("operation", operation);
        jsd.put("class", itopClass);
        jsd.put("key", key);
        jsd.put("output_fields", output_fields);

        postParameters.add(new BasicNameValuePair("json_data", jsd.toString()));
        UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
        request.setEntity(formEntity);

        // request.addHeader(HTTP.CONTENT_TYPE, "application/json");
        HttpResponse response = client.execute(request);
        String status = response.getStatusLine().toString();
        if (debug)
            Log.i(TAG, "status: " + status);

        if (status.contains("200") && status.contains("OK")) {

            // request worked fine, retrieved some data
            InputStream instream = response.getEntity().getContent();
            result = convertStreamToString(instream);
            Log.d(TAG, "result is: " + result);
        } else // some error in http response
        {
            Log.e(TAG, "Get data - http-ERROR: " + status);
            result = "ERROR: http status " + status;
        }

    } catch (Exception e) {
        // Toast does not work in background task
        Log.e(TAG, "Get data -  " + e.toString());
        result = "ERROR: " + e.toString();
    } finally {
        client.close(); // needs to be done for androidhttpclient
        if (debug)
            Log.i(TAG, "...finally.. get data finished");
    }
    return result;

}

From source file:es.mityc.firmaJava.libreria.xades.elementos.EncodingEnum.java

private EncodingEnum(String uri) {
    try {// ww  w.j  a  va 2 s  .c om
        this.uri = new URI(uri);
    } catch (URISyntaxException ex) {
        Log logger = LogFactory.getLog(EncodingEnum.class);
        logger.error("Error creando enumerado de encoding", ex);
    }
}

From source file:se.kodapan.io.http.HttpGetReader.java

public HttpGetReader(String uri, HttpClient httpClient) throws URISyntaxException {
    this.uri = new URI(uri);
    this.httpClient = httpClient;
}

From source file:com.teletalk.jserver.SubComponentTest.java

public void testAddRemove() {
    logger.info("BEGIN testAddRemove.");

    String confFile = null;/*from   www. java 2s .  com*/
    try {
        confFile = new File(new URI(this.getClass().getResource("SubComponentTest.xml").toExternalForm()))
                .getAbsolutePath();
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (confFile == null) {
        super.fail("Configuration file SubComponentTest.xml not found!");
    }

    JServer jserver = new JServer(TestUtils.TEST_SERVER_NAME, new XmlConfigurationFile(confFile), false, false);

    SubComponent a = new TestSubComponent();
    a.setCascadeEngageAndShutDown(true);
    SubComponent b = new TestSubComponent("B");
    b.setCascadeEngageAndShutDown(true);
    SubComponent c = new TestSubComponent("Wrong");
    c.setCascadeEngageAndShutDown(true);

    jserver.addSubComponent(a);

    a.rename("A");
    a.engage();

    a.addSubComponent(b);
    b.engage();

    b.addSubComponent(c, "C");
    c.engage();

    if (!(TestUtils.TEST_SERVER_NAME + ".A.B.C").equals(c.getFullName())) {
        super.fail("Invalid full name for component C - " + c.getFullName() + "!");
    }
    if (b.getLogLevel() != Level.WARN_INT) {
        super.fail("Invalid log level component B - " + b.getLogLevel() + "!");
    }
    if (c.getLogLevel() != Level.WARN_INT) {
        super.fail("Invalid log level component C - " + c.getLogLevel() + "!");
    }

    b.rename("X", true);

    if (!(TestUtils.TEST_SERVER_NAME + ".A.X.C").equals(c.getFullName())) {
        super.fail("Invalid full name for component C - " + c.getFullName() + "!");
    }
    if (b.getLogLevel() != Level.DEBUG_INT) {
        super.fail("Invalid log level component X - " + b.getLogLevel() + "!");
    }
    if (c.getLogLevel() != Level.DEBUG_INT) {
        super.fail("Invalid log level component C - " + c.getLogLevel() + "!");
    }

    jserver.destroyJServer(30000);
    jserver = null;

    logger.info("END testAddRemove.");
}

From source file:edu.jhu.pha.vospace.node.VospaceId.java

public VospaceId(String idStr) throws URISyntaxException {
    URI voURI = new URI(idStr);

    if (!validId(voURI)) {
        throw new URISyntaxException(idStr, "InvalidURI");
    }// w ww . ja  va 2s  .c o  m

    if (!StringUtils.contains(idStr, "vospace")) {
        throw new URISyntaxException(idStr, "InvalidURI");
    }

    this.uri = StringUtils.substringBetween(idStr, "vos://", "!vospace");

    if (this.uri == null)
        throw new URISyntaxException(idStr, "InvalidURI");

    try {
        String pathStr = URLDecoder.decode(StringUtils.substringAfter(idStr, "!vospace"), "UTF-8");
        this.nodePath = new NodePath(pathStr);
    } catch (UnsupportedEncodingException e) {
        // should not happen
        logger.error(e.getMessage());
    }

}

From source file:ca.sfu.federation.action.ShowWebSiteAction.java

/**
 * Handle action performed event./*from  w w  w. j  a va2s . c om*/
 * @param ae Event
 */
public void actionPerformed(ActionEvent ae) {
    try {
        URI uri = new URI(ApplicationContext.PROJECT_WEBSITE_URL);
        // open the default web browser for the HTML page
        logger.log(Level.INFO, "Opening desktop browser to {0}", uri.toString());
        Desktop.getDesktop().browse(uri);
    } catch (Exception ex) {
        String stack = ExceptionUtils.getFullStackTrace(ex);
        logger.log(Level.WARNING, "Could not open browser for URL {0}\n\n{1}",
                new Object[] { ApplicationContext.PROJECT_WEBSITE_URL, stack });
    }
}

From source file:de.dan_nrw.web.tests.WebClientTestSuite.java

@Test
public void getResponseString_should_not_throw_exception_invoked_with_valid_uri() throws Exception {
    WebClient webClient = new WebClient();
    URI uri = new URI("http://www.google.com");

    webClient.getResponseString(uri);/*from w  w  w .  ja v  a 2s .co  m*/
}

From source file:com.github.wnameless.spring.papertrail.test.jpa.JpaPaperTrailGetTest.java

@Test
public void testGet() throws Exception {
    long records = repo.count();

    RequestEntity<Void> req = RequestEntity.get(new URI(host + "/get")).header("Authorization", encodedAuth)
            .build();/*from  w  w w.j a v a2  s. c  o m*/
    template.exchange(req, String.class);

    assertEquals(records, repo.count());
}

From source file:biz.gabrys.lesscss.extended.compiler.source.HttpSourceFactory.java

public HttpSource createRelativeSource(final LessSource source, final String importRelativePath) {
    try {/*from   w ww  . ja v  a  2  s  .c om*/
        final String sourcePath = source.getPath();
        final String parentPath = sourcePath.substring(0, sourcePath.lastIndexOf('/'));
        final URI importUri = new URI(parentPath + '/' + importRelativePath).normalize();
        return new HttpSource(importUri.toURL());
    } catch (final URISyntaxException e) {
        throw new SourceFactoryException("Cannot normalize URL", e);
    } catch (final MalformedURLException e) {
        throw new SourceFactoryException("Cannot create relative URL", e);
    }
}