Search in sources :

Example 11 with UriComponentsBuilder

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

the class HLSController method createStreamUrl.

private String createStreamUrl(HttpServletRequest request, Player player, int id, int offset, int duration, Pair<Integer, Dimension> bitRate) {
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(getContextPath(request) + "ext/stream/stream.ts");
    builder.queryParam("id", id);
    builder.queryParam("hls", "true");
    builder.queryParam("timeOffset", offset);
    builder.queryParam("player", player.getId());
    builder.queryParam("duration", duration);
    if (bitRate != null) {
        builder.queryParam("maxBitRate", bitRate.getFirst());
        Dimension dimension = bitRate.getSecond();
        if (dimension != null) {
            builder.queryParam("size", dimension.width);
            builder.queryParam("x", dimension.height);
        }
    }
    jwtSecurityService.addJWTToken(builder);
    return builder.toUriString();
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder)

Example 12 with UriComponentsBuilder

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

the class OAuth2ClientContextFilter method redirectUser.

/**
	 * Redirect the user according to the specified exception.
	 * 
	 * @param e
	 *            The user redirect exception.
	 * @param request
	 *            The request.
	 * @param response
	 *            The response.
	 */
protected void redirectUser(UserRedirectRequiredException e, HttpServletRequest request, HttpServletResponse response) throws IOException {
    String redirectUri = e.getRedirectUri();
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(redirectUri);
    Map<String, String> requestParams = e.getRequestParams();
    for (Map.Entry<String, String> param : requestParams.entrySet()) {
        builder.queryParam(param.getKey(), param.getValue());
    }
    if (e.getStateKey() != null) {
        builder.queryParam("state", e.getStateKey());
    }
    this.redirectStrategy.sendRedirect(request, response, builder.build().encode().toUriString());
}
Also used : UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) ServletUriComponentsBuilder(org.springframework.web.servlet.support.ServletUriComponentsBuilder) Map(java.util.Map)

Example 13 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 14 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 15 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)

Aggregations

UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)25 UriComponents (org.springframework.web.util.UriComponents)10 Test (org.junit.Test)8 MvcUriComponentsBuilder (org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder)7 Map (java.util.Map)2 ServletUriComponentsBuilder (org.springframework.web.servlet.support.ServletUriComponentsBuilder)2 Claim (com.auth0.jwt.interfaces.Claim)1 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)1 IOException (java.io.IOException)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Random (java.util.Random)1 Res (org.fourthline.cling.support.model.Res)1 OutboundMessageResponse (org.hisp.dhis.outboundmessage.OutboundMessageResponse)1 Player (org.libresonic.player.domain.Player)1 MimeType (org.seamless.util.MimeType)1 MockServletContext (org.springframework.mock.web.test.MockServletContext)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1 InsufficientAuthenticationException (org.springframework.security.authentication.InsufficientAuthenticationException)1