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:com.mycompany.geocoordinate.controller.PolygonController.java

@ResponseStatus(HttpStatus.CREATED)
@PostMapping(value = "/polygon", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public @ResponseBody ResponseEntity<List<Integer>> polygon(@RequestBody GeoObject geoObject)
        throws IOException, JsonException {

    boolean check = coordinateMapper.isThereGeoObjectFromPolygontype(GeoType.POLYGON) != null
            & coordinateMapper.selectCoordinateForLineorCircle(geoObject.getCoordinate()) != null;

    coordinateMapper.insertCoordinateForLineorCircle(GeoType.POLYGON, geoObject.getCoordinate());

    List<Integer> responseType = coordinateMapper.selectIdGeo(geoObject.getCoordinate());

    return ResponseEntity.created(URI.create("/polygon/id")).body(responseType);

}

From source file:cn.ysu.edu.realtimeshare.librtsp.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  .  j a v  a2  s . c om*/
 * @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();
    byte audioApi = 0, videoApi = 0;

    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(param.getValue());
                    } catch (UnknownHostException e) {
                        throw new IllegalStateException("Invalid multicast address !");
                    }
                } else {
                    // Default multicast address
                    builder.setDestination("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) {
                    builder.setDestination(param.getValue());
                }
            }

            // VIDEOAPI -> can be used to specify what api will be used to encode video (the MediaRecorder API or the MediaCodec API)
            else if (param.getName().equalsIgnoreCase("videoapi")) {
                if (param.getValue() != null) {
                    if (param.getValue().equalsIgnoreCase("mr")) {
                        videoApi = MediaStream.MODE_MEDIARECORDER_API;
                    } else if (param.getValue().equalsIgnoreCase("mc")) {
                        videoApi = MediaStream.MODE_MEDIACODEC_API;
                    }
                }
            }

            // AUDIOAPI -> can be used to specify what api will be used to encode audio (the MediaRecorder API or the MediaCodec API)
            else if (param.getName().equalsIgnoreCase("audioapi")) {
                if (param.getValue() != null) {
                    if (param.getValue().equalsIgnoreCase("mr")) {
                        audioApi = MediaStream.MODE_MEDIARECORDER_API;
                    } else if (param.getValue().equalsIgnoreCase("mc")) {
                        audioApi = MediaStream.MODE_MEDIACODEC_API;
                    }
                }
            }

            // 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());
    }

    Session session = builder.build();

    if (videoApi > 0 && session.getVideoTrack() != null) {
        session.getVideoTrack().setStreamingMethod(videoApi);
    }

    if (audioApi > 0 && session.getAudioTrack() != null) {
        session.getAudioTrack().setStreamingMethod(audioApi);
    }

    return session;

}

From source file:me.j360.boot.standard.test.SessionRedisApplicationTests.java

@Test
public void sessionExpiry() throws Exception {

    String port = null;//from   w ww  . j av a 2s  .  com

    try {
        ConfigurableApplicationContext context = new SpringApplicationBuilder().sources(J360Configuration.class)
                .properties("server.port:0").initializers(new ServerPortInfoApplicationContextInitializer())
                .run();
        port = context.getEnvironment().getProperty("local.server.port");
    } catch (RuntimeException ex) {
        if (!redisServerRunning(ex)) {
            return;
        }
    }

    URI uri = URI.create("http://localhost:" + port + "/");
    RestTemplate restTemplate = new RestTemplate();

    ResponseEntity<String> response = restTemplate.getForEntity(uri, String.class);
    String uuid1 = response.getBody();
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.set("Cookie", response.getHeaders().getFirst("Set-Cookie"));

    RequestEntity<Void> request = new RequestEntity<Void>(requestHeaders, HttpMethod.GET, uri);

    String uuid2 = restTemplate.exchange(request, String.class).getBody();
    assertThat(uuid1, is(equalTo(uuid2)));

    Thread.sleep(5000);

    String uuid3 = restTemplate.exchange(request, String.class).getBody();
    assertThat(uuid2, is(not(equalTo(uuid3))));
}

From source file:com.collective.celos.ci.deploy.WorkflowFilesDeployerTest.java

@Test
public void testGetWorkflowJsUri1() throws FileSystemException, URISyntaxException {
    CelosCiContext context = mock(CelosCiContext.class);
    WorkflowFilesDeployer deployer = new WorkflowFilesDeployer(context);

    CelosCiTarget target = new CelosCiTarget(URI.create(""), URI.create(""), emptyURI, emptyURI,
            URI.create("hiveJdbc"));
    doReturn(target).when(context).getTarget();
    doReturn("workflow").when(context).getWorkflowName();
    Assert.assertEquals(deployer.getTargetJsFileUri(URI.create("")), URI.create("/workflow.js"));
}

From source file:com.googlecode.jsonschema2pojo.SchemaStoreTest.java

@Test
public void createWithRelativePath() throws URISyntaxException {

    URI addressSchemaUri = getClass().getResource("/schema/address.json").toURI();

    SchemaStore schemaStore = new SchemaStore();
    Schema addressSchema = schemaStore.create(addressSchemaUri);
    Schema enumSchema = schemaStore.create(addressSchema, "enum.json");

    String expectedUri = removeEnd(addressSchemaUri.toString(), "address.json") + "enum.json";

    assertThat(enumSchema, is(notNullValue()));
    assertThat(enumSchema.getId(), is(equalTo(URI.create(expectedUri))));
    assertThat(enumSchema.getContent().has("enum"), is(true));

}

From source file:com.vanillasource.gerec.it.HttpTestsBase.java

@BeforeMethod
protected void setUp() throws Exception {
    httpClient = HttpAsyncClients.createDefault();
    httpClient.start();//from   w ww.ja va2  s.c o  m
    reference = new AsyncHttpClientResourceReference(new AsyncApacheHttpClient(httpClient),
            URI.create("http://localhost:8091/"));
    WireMock.reset();
}

From source file:net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportActivityFactoryTest.java

/**
 * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetImportActivity#getActivityType()}.
 *//*from  www  .  ja  v  a  2  s.c  om*/
@Test
public void testGetActivityURI() {
    assertEquals(URI.create(SpreadsheetImportActivity.URI), factory.getActivityType());
}

From source file:org.apache.taverna.gis.GisActivityHealthChecker.java

public VisitReport visit(GisActivity activity, List<Object> ancestry) {
    JsonNode config = activity.getConfiguration();

    // We'll build a list of subreports
    List<VisitReport> subReports = new ArrayList<>();

    if (!URI.create(config.get("exampleUri").asText()).isAbsolute()) {
        // Report Severe problems we know won't work
        VisitReport report = new VisitReport(HealthCheck.getInstance(), activity,
                "Example URI must be absolute", HealthCheck.INVALID_URL, Status.SEVERE);
        subReports.add(report);/*  w w  w .ja  va  2s .  c om*/
    }

    if (config.get("exampleString").asText().equals("")) {
        // Warning on possible problems
        subReports.add(new VisitReport(HealthCheck.getInstance(), activity, "Example string empty",
                HealthCheck.NO_CONFIGURATION, Status.WARNING));
    }

    // The default explanation here will be used if the subreports list is
    // empty
    return new VisitReport(HealthCheck.getInstance(), activity, "Gis service OK", HealthCheck.NO_PROBLEM,
            subReports);
}

From source file:org.cloudml.connectors.CloudFoundryConnector.java

public CloudFoundryConnector(String APIEndPoint, String login, String passwd, String organization,
        String space) {/*w ww . j av a  2 s.  co  m*/
    try {
        URL cloudControllerUrl = URI.create(APIEndPoint).toURL();
        journal.log(Level.INFO, ">> Connecting to CloudFoundry ...");
        connectedClient = new CloudFoundryClient(new CloudCredentials(login, passwd), cloudControllerUrl,
                organization, space);
        connectedClient.login();
        defaultDomainName = connectedClient.getDefaultDomain().getName();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:example.springdata.rest.headers.CrossOriginIntegrationTests.java

@Test
public void executeCrossOriginRequest() throws Exception {

    String origin = "http://localhost";
    URI uri = URI.create("/customers");

    MockHttpServletResponse response = mvc.perform(get(uri).header(ORIGIN, origin)).//
            andExpect(header().string(ACCESS_CONTROL_ALLOW_CREDENTIALS, is("true"))).//
            andExpect(header().string(ACCESS_CONTROL_ALLOW_ORIGIN, is(origin))).//
            andDo(document("cors")).//
            andReturn().getResponse();//  w w w . j a va 2  s  .  c o  m
}