Search in sources :

Example 66 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project spring-framework by spring-projects.

the class MvcUriComponentsBuilderTests method testFromControllerWithCustomBaseUrlViaStaticCall.

@Test
public void testFromControllerWithCustomBaseUrlViaStaticCall() {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("http://example.org:9090/base");
    UriComponents uriComponents = fromController(builder, PersonControllerImpl.class).build();
    assertEquals("http://example.org:9090/base/people", uriComponents.toString());
    assertEquals("http://example.org:9090/base", builder.toUriString());
}
Also used : UriComponents(org.springframework.web.util.UriComponents) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) MvcUriComponentsBuilder(org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder) Test(org.junit.Test)

Example 67 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project spring-framework by spring-projects.

the class MvcUriComponentsBuilderTests method testFromMethodCallWithCustomBaseUrlViaStaticCall.

@Test
public void testFromMethodCallWithCustomBaseUrlViaStaticCall() {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("http://example.org:9090/base");
    UriComponents uriComponents = fromMethodCall(builder, on(ControllerWithMethods.class).myMethod(null)).build();
    assertEquals("http://example.org:9090/base/something/else", uriComponents.toString());
    assertEquals("http://example.org:9090/base", builder.toUriString());
}
Also used : UriComponents(org.springframework.web.util.UriComponents) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) MvcUriComponentsBuilder(org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder) Test(org.junit.Test)

Example 68 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project spring-framework by spring-projects.

the class MvcUriComponentsBuilderTests method testFromMethodNameWithCustomBaseUrlViaStaticCall.

@Test
public void testFromMethodNameWithCustomBaseUrlViaStaticCall() throws Exception {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("http://example.org:9090/base");
    UriComponents uriComponents = fromMethodName(builder, ControllerWithMethods.class, "methodWithPathVariable", new Object[] { "1" }).build();
    assertEquals("http://example.org:9090/base/something/1/foo", uriComponents.toString());
    assertEquals("http://example.org:9090/base", builder.toUriString());
}
Also used : UriComponents(org.springframework.web.util.UriComponents) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) MvcUriComponentsBuilder(org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder) Test(org.junit.Test)

Example 69 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project libresonic by Libresonic.

the class JWTSecurityServiceTest method addJWTToken.

@Test
public void addJWTToken() throws Exception {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(uriString);
    String actualUri = service.addJWTToken(builder).build().toUriString();
    String jwtToken = UriComponentsBuilder.fromUriString(actualUri).build().getQueryParams().getFirst(JWTSecurityService.JWT_PARAM_NAME);
    DecodedJWT verify = verifier.verify(jwtToken);
    Claim claim = verify.getClaim(JWTSecurityService.CLAIM_PATH);
    assertEquals(expectedClaimString, claim.asString());
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) Claim(com.auth0.jwt.interfaces.Claim) Test(org.junit.Test)

Example 70 with UriComponentsBuilder

use of org.springframework.web.util.UriComponentsBuilder in project libresonic by Libresonic.

the class HLSController method generateVariantPlaylist.

private void generateVariantPlaylist(HttpServletRequest request, int id, Player player, List<Pair<Integer, Dimension>> bitRates, PrintWriter writer) {
    writer.println("#EXTM3U");
    writer.println("#EXT-X-VERSION:1");
    //        writer.println("#EXT-X-TARGETDURATION:" + SEGMENT_DURATION);
    String contextPath = getContextPath(request);
    for (Pair<Integer, Dimension> bitRate : bitRates) {
        Integer kbps = bitRate.getFirst();
        writer.println("#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=" + kbps * 1000L);
        UriComponentsBuilder url = (UriComponentsBuilder.fromUriString(contextPath + "ext/hls/hls.m3u8").queryParam("id", id).queryParam("player", player.getId()).queryParam("bitRate", kbps));
        jwtSecurityService.addJWTToken(url);
        writer.print(url.toUriString());
        Dimension dimension = bitRate.getSecond();
        if (dimension != null) {
            writer.print("@" + dimension.width + "x" + dimension.height);
        }
        writer.println();
    }
//        writer.println("#EXT-X-ENDLIST");
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder)

Aggregations

UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)131 Test (org.junit.Test)34 UriComponents (org.springframework.web.util.UriComponents)23 ServletUriComponentsBuilder (org.springframework.web.servlet.support.ServletUriComponentsBuilder)12 URI (java.net.URI)9 Test (org.junit.jupiter.api.Test)9 SearchRequest (org.nzbhydra.searching.searchrequests.SearchRequest)8 MvcUriComponentsBuilder (org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder)8 ArrayList (java.util.ArrayList)7 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)7 List (java.util.List)6 User (com.serotonin.m2m2.vo.User)5 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)5 HashMap (java.util.HashMap)5 HttpEntity (org.springframework.http.HttpEntity)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)5 IOException (java.io.IOException)4 Map (java.util.Map)4