Java Code Examples for javax.ws.rs.core.UriBuilder#uri()

The following examples show how to use javax.ws.rs.core.UriBuilder#uri() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FormWebUiAuthenticationFilter.java    From presto with Apache License 2.0 6 votes vote down vote up
private static URI buildLoginFormURI(UriInfo uriInfo)
{
    UriBuilder builder = uriInfo.getRequestUriBuilder()
            .uri(LOGIN_FORM_URI);

    String path = uriInfo.getRequestUri().getPath();
    if (!isNullOrEmpty(uriInfo.getRequestUri().getQuery())) {
        path += "?" + uriInfo.getRequestUri().getQuery();
    }

    if (path.equals("/ui") || path.equals("/ui/")) {
        return builder.build();
    }

    // this is a hack - the replaceQuery method encodes the value where the uri method just copies the value
    try {
        builder.uri(new URI(null, null, null, path, null));
    }
    catch (URISyntaxException ignored) {
    }

    return builder.build();
}
 
Example 2
Source File: WorkspaceLinksGeneratorTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@BeforeMethod
public void setUp() throws Exception {
  when(workspace.getId()).thenReturn("wside-123877234580");
  when(workspace.getNamespace()).thenReturn("my-namespace");
  when(workspace.getName()).thenReturn("my-name");

  when(runtimeCtx.getOutputChannel()).thenReturn(URI.create("ws://localhost/output/websocket"));
  when(runtimes.getRuntimeContext(workspace.getId())).thenReturn(Optional.of(runtimeCtx));

  final UriBuilder uriBuilder = new UriBuilderImpl();
  uriBuilder.uri(URI_BASE);
  lenient().when(serviceContextMock.getServiceUriBuilder()).thenReturn(uriBuilder);
  lenient().when(serviceContextMock.getBaseUriBuilder()).thenReturn(uriBuilder);

  linksGenerator = new WorkspaceLinksGenerator(runtimes, previewUrlGenerator, "ws://localhost");

  expectedStoppedLinks = new HashMap<>();
  expectedStoppedLinks.put(LINK_REL_SELF, "http://localhost/api/workspace/wside-123877234580");
  expectedStoppedLinks.put(LINK_REL_IDE_URL, "http://localhost/my-namespace/my-name");

  expectedRunningLinks = new HashMap<>(expectedStoppedLinks);
  expectedRunningLinks.put(LINK_REL_ENVIRONMENT_STATUS_CHANNEL, "ws://localhost");
  expectedRunningLinks.put(
      LINK_REL_ENVIRONMENT_OUTPUT_CHANNEL, "ws://localhost/output/websocket");
}
 
Example 3
Source File: WorkspaceLinksGeneratorTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void genOfDifferentUrl() throws Exception {
  // given
  UriBuilder uriBuilder = new UriBuilderImpl();
  uriBuilder.uri("https://mydomain:7345/api/workspace");
  doReturn(uriBuilder).when(serviceContextMock).getServiceUriBuilder();

  linksGenerator = new WorkspaceLinksGenerator(runtimes, previewUrlGenerator, "ws://localhost");
  // when
  Map<String, String> actual = linksGenerator.genLinks(workspace, serviceContextMock);
  // then
  expectedRunningLinks =
      ImmutableMap.of(
          LINK_REL_SELF,
          "https://mydomain:7345/api/workspace/wside-123877234580",
          LINK_REL_IDE_URL,
          "https://mydomain:7345/my-namespace/my-name",
          LINK_REL_ENVIRONMENT_STATUS_CHANNEL,
          "wss://mydomain:7345",
          LINK_REL_ENVIRONMENT_OUTPUT_CHANNEL,
          "ws://localhost/output/websocket");
  assertEquals(actual, expectedRunningLinks);
}
 
Example 4
Source File: OrganizationLinksInjectorTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@BeforeMethod
public void setUp() {
  final UriBuilder uriBuilder = new UriBuilderImpl();
  uriBuilder.uri(URI_BASE);

  when(context.getBaseUriBuilder()).thenReturn(uriBuilder);
}
 
Example 5
Source File: RoboZonkyFilter.java    From robozonky with Apache License 2.0 4 votes vote down vote up
static URI addQueryParams(final URI info, final Map<String, Object[]> params) {
    final UriBuilder builder = UriBuilder.fromUri(info);
    builder.uri(info);
    params.forEach(builder::queryParam);
    return builder.build();
}