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