use of com.yahoo.container.jdisc.HttpRequest in project vespa by vespa-engine.
the class V2ExternalFeedTestCase method testIllegalVersion.
@Test
public final void testIllegalVersion() throws IOException {
InputStream in = new MetaStream(new byte[] { 1 });
ByteArrayOutputStream out = new ByteArrayOutputStream();
HttpRequest nalle = HttpRequest.createTestRequest("http://test4-steinar:19020/reserved-for-internal-use/feedapi", Method.POST, in);
nalle.getJDiscRequest().headers().add(Headers.VERSION, Integer.toString(Integer.MAX_VALUE));
HttpResponse r = handler.handle(nalle);
r.render(out);
assertEquals(Headers.HTTP_NOT_ACCEPTABLE, r.getStatus());
}
use of com.yahoo.container.jdisc.HttpRequest in project vespa by vespa-engine.
the class Templating method getPreviousResultURL.
/**
* An URL that may be used to obtain the previous result page.
*/
public String getPreviousResultURL() {
HttpRequest request = result.getQuery().getHttpRequest();
StringBuilder prevURL = new StringBuilder();
prevURL.append(getPath(request)).append("?");
parametersExceptOffset(request, prevURL);
int offset = getPrevFirstHitNo() - 1;
prevURL.append("&").append("offset=").append(Integer.toString(offset));
return prevURL.toString();
}
use of com.yahoo.container.jdisc.HttpRequest in project vespa by vespa-engine.
the class Templating method getCurrentResultURL.
public String getCurrentResultURL() {
HttpRequest request = result.getQuery().getHttpRequest();
StringBuilder thisURL = new StringBuilder();
thisURL.append(getPath(request)).append("?");
parameters(request, thisURL);
return thisURL.toString();
}
use of com.yahoo.container.jdisc.HttpRequest in project vespa by vespa-engine.
the class ConnectionControlSearcherTestCase method doSearch.
private Result doSearch(URI uri, long connectedAtMillis, long nowMillis) {
SocketAddress remoteAddress = Mockito.mock(SocketAddress.class);
Version version = Version.HTTP_1_1;
Method method = Method.GET;
CurrentContainer container = Mockito.mock(CurrentContainer.class);
Mockito.when(container.newReference(Mockito.any())).thenReturn(Mockito.mock(Container.class));
final com.yahoo.jdisc.http.HttpRequest serverRequest = com.yahoo.jdisc.http.HttpRequest.newServerRequest(container, uri, method, version, remoteAddress, connectedAtMillis);
HttpRequest incoming = new HttpRequest(serverRequest, new ByteArrayInputStream(new byte[0]));
Query query = new Query(incoming);
Execution e = new Execution(new Chain<Searcher>(ConnectionControlSearcher.createTestInstance(() -> nowMillis)), Execution.Context.createContextStub());
Result r = e.search(query);
return r;
}
use of com.yahoo.container.jdisc.HttpRequest in project vespa by vespa-engine.
the class ApplicationApiHandler method authenticatedUser.
private HttpResponse authenticatedUser(HttpRequest request) {
String userIdString = request.getProperty("userOverride");
if (userIdString == null)
userIdString = getUserId(request).map(UserId::id).orElseThrow(() -> new ForbiddenException("You must be authenticated or specify userOverride"));
UserId userId = new UserId(userIdString);
List<Tenant> tenants = controller.tenants().asList(userId);
Slime slime = new Slime();
Cursor response = slime.setObject();
response.setString("user", userId.id());
Cursor tenantsArray = response.setArray("tenants");
for (Tenant tenant : tenants) tenantInTenantsListToSlime(tenant, request.getUri(), tenantsArray.addObject());
response.setBool("tenantExists", tenants.stream().map(Tenant::getId).anyMatch(id -> id.isTenantFor(userId)));
return new SlimeJsonResponse(slime);
}
Aggregations