Search in sources :

Example 26 with HttpURI

use of org.eclipse.jetty.http.HttpURI in project jetty.project by eclipse.

the class Request method getServerPort.

/* ------------------------------------------------------------ */
/*
     * @see javax.servlet.ServletRequest#getServerPort()
     */
@Override
public int getServerPort() {
    MetaData.Request metadata = _metaData;
    HttpURI uri = metadata == null ? null : metadata.getURI();
    int port = (uri == null || uri.getHost() == null) ? findServerPort() : uri.getPort();
    // If no port specified, return the default port for the scheme
    if (port <= 0) {
        if (getScheme().equalsIgnoreCase(URIUtil.HTTPS))
            return 443;
        return 80;
    }
    // return a specific port
    return port;
}
Also used : MetaData(org.eclipse.jetty.http.MetaData) HttpURI(org.eclipse.jetty.http.HttpURI)

Example 27 with HttpURI

use of org.eclipse.jetty.http.HttpURI in project gocd by gocd.

the class DeploymentContextWriterTest method shouldSetShouldRedirectToFalseWhenSecureSiteURLIsNotSetAndSiteUrlIsNonHTTPS.

@Test
public void shouldSetShouldRedirectToFalseWhenSecureSiteURLIsNotSetAndSiteUrlIsNonHTTPS() throws URISyntaxException {
    final ServerConfigService serverConfigService = mock(ServerConfigService.class);
    when(serverConfigService.hasAnyUrlConfigured()).thenReturn(true);
    when(serverConfigService.siteUrlFor("http://url:8153/go/admin?tab=oAuth", true)).thenReturn("http://url:8153/go/admin?tab=oAuth");
    Request req = new Request(mock(HttpChannel.class), mock(HttpInput.class));
    req.setUri(new HttpURI("/go/admin?tab=oAuth"));
    req.setServerName("url");
    req.setServerPort(8153);
    // req.setProtocol("http");
    DeploymentContextWriter writer = new DeploymentContextWriter() {

        @Override
        protected BaseUrlProvider getBaseUrlProvider(HttpServletRequest req) {
            return serverConfigService;
        }
    };
    writer.writeSecureSiteUrl(req);
    assertThat(req.getAttribute("secure_site"), is(nullValue()));
    assertThat(req.getAttribute("force_ssl"), is(nullValue()));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServerConfigService(com.thoughtworks.go.server.service.ServerConfigService) HttpInput(org.eclipse.jetty.server.HttpInput) Request(org.eclipse.jetty.server.Request) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpChannel(org.eclipse.jetty.server.HttpChannel) HttpURI(org.eclipse.jetty.http.HttpURI) Test(org.junit.Test)

Example 28 with HttpURI

use of org.eclipse.jetty.http.HttpURI in project cxf by apache.

the class Http2TestClient method request.

public ClientResponse request(final String address, final String path, final HttpVersion version, final String method, final String accept) throws InterruptedException, ExecutionException, TimeoutException {
    final URI uri = URI.create(address);
    final FuturePromise<Session> sessionPromise = new FuturePromise<>();
    client.connect(sslContextFactory, new InetSocketAddress(uri.getHost(), uri.getPort()), new ServerSessionListener.Adapter(), sessionPromise);
    final Session session = sessionPromise.get();
    final HttpFields requestFields = new HttpFields();
    requestFields.add(HttpHeader.ACCEPT, accept);
    requestFields.add(HttpHeader.HOST, "localhost");
    final MetaData.Request request = new MetaData.Request(method, new HttpURI(address + path), version, requestFields);
    final CompletableFuture<ClientResponse> future = new CompletableFuture<>();
    final Stream.Listener responseListener = new ResponseListener(future);
    final HeadersFrame headersFrame = new HeadersFrame(request, null, true);
    session.newStream(headersFrame, new FuturePromise<>(), responseListener);
    return future.get(5, TimeUnit.SECONDS);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) FuturePromise(org.eclipse.jetty.util.FuturePromise) HttpURI(org.eclipse.jetty.http.HttpURI) URI(java.net.URI) HttpURI(org.eclipse.jetty.http.HttpURI) HeadersFrame(org.eclipse.jetty.http2.frames.HeadersFrame) CompletableFuture(java.util.concurrent.CompletableFuture) MetaData(org.eclipse.jetty.http.MetaData) HttpFields(org.eclipse.jetty.http.HttpFields) Stream(org.eclipse.jetty.http2.api.Stream) ServerSessionListener(org.eclipse.jetty.http2.api.server.ServerSessionListener) Session(org.eclipse.jetty.http2.api.Session)

Example 29 with HttpURI

use of org.eclipse.jetty.http.HttpURI in project scheduling by ow2-proactive.

the class PCAProxyRuleTest method runTest.

private void runTest(String requestPath, HttpMethod method, String referer, String expectedTarget, boolean expectedRedirection) throws IOException {
    PCAProxyRule rule = new PCAProxyRule();
    Request request = Mockito.mock(Request.class);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    String target = requestPath;
    HttpURI requestUri = new HttpURI(target);
    when(request.getMethod()).thenReturn(method.asString());
    when(request.getHeader(HttpHeaders.REFERER)).thenReturn(referer);
    when(request.getUri()).thenReturn(requestUri);
    ArgumentCaptor<String> redirectString = ArgumentCaptor.forClass(String.class);
    when(response.encodeRedirectURL(anyString())).then(returnsFirstArg());
    String newTarget = rule.matchAndApply(target, request, response);
    Assert.assertEquals(expectedTarget, newTarget);
    if (HttpMethod.GET.is(method.asString()) && expectedRedirection) {
        verify(response, times(1)).sendRedirect(redirectString.capture());
        Assert.assertEquals(expectedTarget, redirectString.getValue());
    } else {
        verify(response, times(0)).sendRedirect(redirectString.capture());
    }
}
Also used : Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Matchers.anyString(org.mockito.Matchers.anyString) HttpURI(org.eclipse.jetty.http.HttpURI)

Example 30 with HttpURI

use of org.eclipse.jetty.http.HttpURI in project qpid-broker-j by apache.

the class OAuth2InteractiveAuthenticatorTest method getRedirectParameters.

private Map<String, String> getRedirectParameters(final String redirectLocation) {
    final MultiMap<String> parameterMap = new MultiMap<>();
    HttpURI httpURI = new HttpURI(redirectLocation);
    httpURI.decodeQueryTo(parameterMap);
    Map<String, String> parameters = new HashMap<>(parameterMap.size());
    for (Map.Entry<String, List<String>> paramEntry : parameterMap.entrySet()) {
        assertEquals(String.format("param '%s' specified more than once", paramEntry.getKey()), (long) 1, (long) paramEntry.getValue().size());
        parameters.put(paramEntry.getKey(), paramEntry.getValue().get(0));
    }
    return parameters;
}
Also used : MultiMap(org.eclipse.jetty.util.MultiMap) HashMap(java.util.HashMap) List(java.util.List) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HttpURI(org.eclipse.jetty.http.HttpURI) Map(java.util.Map) HashMap(java.util.HashMap) MultiMap(org.eclipse.jetty.util.MultiMap)

Aggregations

HttpURI (org.eclipse.jetty.http.HttpURI)31 HttpServletRequest (javax.servlet.http.HttpServletRequest)12 MetaData (org.eclipse.jetty.http.MetaData)10 Request (org.eclipse.jetty.server.Request)10 HttpFields (org.eclipse.jetty.http.HttpFields)9 Stream (org.eclipse.jetty.http2.api.Stream)8 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)8 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 Test (org.junit.Test)7 InetSocketAddress (java.net.InetSocketAddress)6 Session (org.eclipse.jetty.http2.api.Session)6 FuturePromise (org.eclipse.jetty.util.FuturePromise)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 Promise (org.eclipse.jetty.util.Promise)5 ServerSessionListener (org.eclipse.jetty.http2.api.server.ServerSessionListener)4 DataFrame (org.eclipse.jetty.http2.frames.DataFrame)4 ServerConfigService (com.thoughtworks.go.server.service.ServerConfigService)3 HttpChannel (org.eclipse.jetty.server.HttpChannel)3 HttpInput (org.eclipse.jetty.server.HttpInput)3 IOException (java.io.IOException)2