Example usage for java.net URI create

List of usage examples for java.net URI create

Introduction

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

Prototype

public static URI create(String str) 

Source Link

Document

Creates a URI by parsing the given string.

Usage

From source file:org.apache.taverna.robundle.manifest.Proxy.java

public void setURI() {
    setURI(URI.create("urn:uuid:" + UUID.randomUUID()));
}

From source file:org.trustedanalytics.user.invite.EmailOrgUserInvitationService.java

private String getEmailHtml(String username) {
    final Context ctx = new Context();
    ctx.setVariable("serviceName", "Trusted Analytics");
    ctx.setVariable("username", username);
    URI authorizationUrl = URI.create(authorizationHost);
    String resetPasswordUrl = authorizationUrl.toString().replaceAll(authorizationUrl.getPath(),
            "/forgot_password");
    ctx.setVariable("resetPasswordUrl", resetPasswordUrl);
    ctx.setVariable("consoleUrl", getConsoleUrl());
    return templateEngine.process("invite_org", ctx);
}

From source file:org.ambraproject.model.article.ArticleTypeTest.java

@Test
public void testDefaultArticleType() {
    ArticleType dat = ArticleType.getDefaultArticleType();
    assertNotNull(dat, "Default Article Type was Null");

    String defaultHeading = "DefaultHeading";
    URI defaultArticleTypeUri = URI.create("http://rdf.plos.org/RDF/articleType/Research%20Article");

    assertTrue(defaultHeading.equals(dat.getHeading()), "Default ArticleType heading not as expected.");
    assertTrue(defaultArticleTypeUri.equals(dat.getUri()), "Default ArticleType URI not as expected.");
}

From source file:net.sf.taverna.t2.activities.rshell.RshellActivityFactory.java

@Override
public URI getActivityType() {
    return URI.create(RshellActivity.URI);
}

From source file:de.otto.jsonhome.controller.HtmlController.java

@Value("${jsonhome.relationTypeBaseUri}")
public void setRelationTypeBaseUri(String relationTypeBaseUri) {
    this.relationTypeBaseUri = URI.create(relationTypeBaseUri);
    LOG.info("RelationTypeBaseUri is {}", relationTypeBaseUri);
}

From source file:org.anarres.simplexml.serializers.spring.SimpleXmlSerializersConfigurationTest.java

@Test
public void testPersister() throws Exception {
    Persister persister = factory.newPersister();
    LOG.info("Serializer is " + persister);
    PersisterTestUtils.testSerialization(persister, new int[] { 1, 2, 3, 4, 5 });
    PersisterTestUtils.testSerialization(persister, InetAddress.getByAddress(new byte[] { 1, 2, 3, 4 }));

    Bean bean = new Bean();
    bean.aAddress = InetAddress.getByAddress(new byte[] { 3, 4, 5, 6 });
    bean.eAddress = InetAddress.getByAddress(new byte[] { 3, 4, 5, 7 });
    bean.aUri = URI.create("mailto:nobody@localhost");
    bean.eUri = URI.create("mailto:somebody@localhost");
    PersisterTestUtils.testSerialization(persister, bean);
}

From source file:com.aregner.pandora.XmlRpc.java

@SuppressWarnings("unchecked")
public Object callWithBody(String url, String body) throws XMLRPCException {

    postMethod.setURI(URI.create(url));

    try {// w  w w  .  j  a va  2s.c  o m
        // set POST body
        HttpEntity entity = new StringEntity(body);
        postMethod.setEntity(entity);

        //Log.d(Tag.LOG, "ros HTTP POST");
        // execute HTTP POST request
        HttpResponse response = client.execute(postMethod);
        //Log.d(Tag.LOG, "ros HTTP POSTed");

        // check status code
        int statusCode = response.getStatusLine().getStatusCode();
        //Log.d(Tag.LOG, "ros status code:" + statusCode);
        if (statusCode != HttpStatus.SC_OK) {
            throw new XMLRPCException("HTTP status code: " + statusCode + " != " + HttpStatus.SC_OK);
        }

        // parse response stuff
        //
        // setup pull parser
        XmlPullParser pullParser = XmlPullParserFactory.newInstance().newPullParser();
        entity = response.getEntity();
        Reader reader = new InputStreamReader(new BufferedInputStream(entity.getContent()));
        // for testing purposes only
        // reader = new StringReader("<?xml version='1.0'?><methodResponse><params><param><value>\n\n\n</value></param></params></methodResponse>");
        pullParser.setInput(reader);

        // lets start pulling...
        pullParser.nextTag();
        pullParser.require(XmlPullParser.START_TAG, null, Tag.METHOD_RESPONSE);

        pullParser.nextTag(); // either Tag.PARAMS (<params>) or Tag.FAULT (<fault>)  
        String tag = pullParser.getName();
        if (tag.equals(Tag.PARAMS)) {
            // normal response
            pullParser.nextTag(); // Tag.PARAM (<param>)
            pullParser.require(XmlPullParser.START_TAG, null, Tag.PARAM);
            pullParser.nextTag(); // Tag.VALUE (<value>)
            // no parser.require() here since its called in XMLRPCSerializer.deserialize() below

            // deserialize result
            Object obj = iXMLRPCSerializer.deserialize(pullParser);
            entity.consumeContent();
            return obj;
        } else if (tag.equals(Tag.FAULT)) {
            // fault response
            pullParser.nextTag(); // Tag.VALUE (<value>)
            // no parser.require() here since its called in XMLRPCSerializer.deserialize() below

            // deserialize fault result
            Map<String, Object> map = (Map<String, Object>) iXMLRPCSerializer.deserialize(pullParser);
            String faultString = (String) map.get(Tag.FAULT_STRING);
            int faultCode = (Integer) map.get(Tag.FAULT_CODE);
            entity.consumeContent();
            throw new XMLRPCFault(faultString, faultCode);
        } else {
            entity.consumeContent();
            throw new XMLRPCException(
                    "Bad tag <" + tag + "> in XMLRPC response - neither <params> nor <fault>");
        }
    } catch (XMLRPCException e) {
        e.printStackTrace();
        // catch & propagate XMLRPCException/XMLRPCFault
        throw e;
    } catch (Exception e) {
        e.printStackTrace();
        // wrap any other Exception(s) around XMLRPCException
        throw new XMLRPCException(e);
    }
}

From source file:net.majorkernelpanic.streaming.rtsp.UriParser.java

/**
 * Configures a Session according to the given URI.
 * Here are some examples of URIs that can be used to configure a Session:
 * <ul><li>rtsp://xxx.xxx.xxx.xxx:8086?h264&flash=on</li>
 * <li>rtsp://xxx.xxx.xxx.xxx:8086?h263&camera=front&flash=on</li>
 * <li>rtsp://xxx.xxx.xxx.xxx:8086?h264=200-20-320-240</li>
 * <li>rtsp://xxx.xxx.xxx.xxx:8086?aac</li></ul>
 * @param uri The URI//from  w w  w  . jav a 2  s  . co  m
 * @throws IllegalStateException
 * @throws IOException
 * @return A Session configured according to the URI
 */
public static Session parse(String uri) throws IllegalStateException, IOException {
    SessionBuilder builder = SessionBuilder.getInstance().clone();

    List<NameValuePair> params = URLEncodedUtils.parse(URI.create(uri), "UTF-8");
    if (params.size() > 0) {

        builder.setAudioEncoder(AUDIO_NONE).setVideoEncoder(VIDEO_NONE);

        // Those parameters must be parsed first or else they won't necessarily be taken into account
        for (Iterator<NameValuePair> it = params.iterator(); it.hasNext();) {
            NameValuePair param = it.next();

            // FLASH ON/OFF
            if (param.getName().equalsIgnoreCase("flash")) {
                if (param.getValue().equalsIgnoreCase("on"))
                    builder.setFlashEnabled(true);
                else
                    builder.setFlashEnabled(false);
            }

            // CAMERA -> the client can choose between the front facing camera and the back facing camera
            else if (param.getName().equalsIgnoreCase("camera")) {
                if (param.getValue().equalsIgnoreCase("back"))
                    builder.setCamera(CameraInfo.CAMERA_FACING_BACK);
                else if (param.getValue().equalsIgnoreCase("front"))
                    builder.setCamera(CameraInfo.CAMERA_FACING_FRONT);
            }

            // MULTICAST -> the stream will be sent to a multicast group
            // The default mutlicast address is 228.5.6.7, but the client can specify another
            else if (param.getName().equalsIgnoreCase("multicast")) {
                if (param.getValue() != null) {
                    try {
                        InetAddress addr = InetAddress.getByName(param.getValue());
                        if (!addr.isMulticastAddress()) {
                            throw new IllegalStateException("Invalid multicast address !");
                        }
                        builder.setDestination(addr);
                    } catch (UnknownHostException e) {
                        throw new IllegalStateException("Invalid multicast address !");
                    }
                } else {
                    // Default multicast address
                    builder.setDestination(InetAddress.getByName("228.5.6.7"));
                }
            }

            // UNICAST -> the client can use this to specify where he wants the stream to be sent
            else if (param.getName().equalsIgnoreCase("unicast")) {
                if (param.getValue() != null) {
                    try {
                        InetAddress addr = InetAddress.getByName(param.getValue());
                        builder.setDestination(addr);
                    } catch (UnknownHostException e) {
                        throw new IllegalStateException("Invalid destination address !");
                    }
                }
            }

            // TTL -> the client can modify the time to live of packets
            // By default ttl=64
            else if (param.getName().equalsIgnoreCase("ttl")) {
                if (param.getValue() != null) {
                    try {
                        int ttl = Integer.parseInt(param.getValue());
                        if (ttl < 0)
                            throw new IllegalStateException();
                        builder.setTimeToLive(ttl);
                    } catch (Exception e) {
                        throw new IllegalStateException("The TTL must be a positive integer !");
                    }
                }
            }

            // H.264
            else if (param.getName().equalsIgnoreCase("h264")) {
                VideoQuality quality = VideoQuality.parseQuality(param.getValue());
                builder.setVideoQuality(quality).setVideoEncoder(VIDEO_H264);
            }

            // H.263
            else if (param.getName().equalsIgnoreCase("h263")) {
                VideoQuality quality = VideoQuality.parseQuality(param.getValue());
                builder.setVideoQuality(quality).setVideoEncoder(VIDEO_H263);
            }

            // AMR
            else if (param.getName().equalsIgnoreCase("amrnb") || param.getName().equalsIgnoreCase("amr")) {
                AudioQuality quality = AudioQuality.parseQuality(param.getValue());
                builder.setAudioQuality(quality).setAudioEncoder(AUDIO_AMRNB);
            }

            // AAC
            else if (param.getName().equalsIgnoreCase("aac")) {
                AudioQuality quality = AudioQuality.parseQuality(param.getValue());
                builder.setAudioQuality(quality).setAudioEncoder(AUDIO_AAC);
            }

        }

    }

    if (builder.getVideoEncoder() == VIDEO_NONE && builder.getAudioEncoder() == AUDIO_NONE) {
        SessionBuilder b = SessionBuilder.getInstance();
        builder.setVideoEncoder(b.getVideoEncoder());
        builder.setAudioEncoder(b.getAudioEncoder());
    }

    return builder.build();

}

From source file:at.ac.tuwien.dsg.cloud.utilities.gateway.registry.KongService.java

public KongApiResponseObject registerApi(KongApiObject apiObject) {
    try {/*  w w w.  ja  v a  2s . c  o  m*/
        RequestEntity<KongApiObject> requestEntity = RequestEntity
                .post(URI.create(this.kongUris.getKongApisUri())).contentType(MediaType.APPLICATION_JSON)
                .accept(MediaType.ALL).body(apiObject);

        RestTemplate restTemplate = new RestTemplate();
        ResponseEntity<KongApiResponseObject> resp = restTemplate.exchange(requestEntity,
                KongApiResponseObject.class);

        logger.trace("Response from Kong: {}", resp.getBody());
        return resp.getBody();
    } catch (HttpStatusCodeException e) {
        String serverResp = e.getResponseBodyAsString();
        logger.error(String.format("Exception from server! " + "Following body was responded %s", serverResp),
                e);

        KongApiResponseObject resp = new KongApiResponseObject();
        resp.setError(true);
        resp.setErrorMsg(serverResp);
        return resp;
    }
}

From source file:com.facebook.presto.jdbc.QueryExecutor.java

@Nullable
private static HttpHost getSystemSocksProxy() {
    URI uri = URI.create("socket://0.0.0.0:80");
    for (Proxy proxy : ProxySelector.getDefault().select(uri)) {
        if (proxy.type() == Proxy.Type.SOCKS) {
            if (proxy.address() instanceof InetSocketAddress) {
                InetSocketAddress address = (InetSocketAddress) proxy.address();
                return new HttpHost(address.getHostName(), address.getPort());
            }//from   w w  w  . j  a v  a 2  s  . c  o m
        }
    }
    return null;
}