use of org.eclipse.jetty.util.Attributes in project jetty.project by eclipse.
the class ContextHandlerMBean method setContextAttribute.
@ManagedOperation(value = "Set context attribute", impact = "ACTION")
public void setContextAttribute(@Name(value = "name", description = "attribute name") String name, @Name(value = "value", description = "attribute value") String value) {
Attributes attrs = ((ContextHandler) _managed).getAttributes();
attrs.setAttribute(name, value);
}
use of org.eclipse.jetty.util.Attributes in project jetty.project by eclipse.
the class ContextHandlerMBean method getContextAttributes.
@ManagedAttribute("Map of context attributes")
public Map<String, Object> getContextAttributes() {
Map<String, Object> map = new HashMap<String, Object>();
Attributes attrs = ((ContextHandler) _managed).getAttributes();
Enumeration<String> en = attrs.getAttributeNames();
while (en.hasMoreElements()) {
String name = (String) en.nextElement();
Object value = attrs.getAttribute(name);
map.put(name, value);
}
return map;
}
use of org.eclipse.jetty.util.Attributes in project jetty.project by eclipse.
the class HttpClientAuthenticationTest method test_Authentication_ThrowsException.
@Test
public void test_Authentication_ThrowsException() throws Exception {
startBasic(new EmptyServerHandler());
// Request without Authentication would cause a 401,
// but the client will throw an exception trying to
// send the credentials to the server.
final String cause = "thrown_explicitly_by_test";
client.getAuthenticationStore().addAuthentication(new Authentication() {
@Override
public boolean matches(String type, URI uri, String realm) {
return true;
}
@Override
public Result authenticate(Request request, ContentResponse response, HeaderInfo headerInfo, Attributes context) {
throw new RuntimeException(cause);
}
});
final CountDownLatch latch = new CountDownLatch(1);
client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).path("/secure").timeout(5, TimeUnit.SECONDS).send(new Response.CompleteListener() {
@Override
public void onComplete(Result result) {
Assert.assertTrue(result.isFailed());
Assert.assertEquals(cause, result.getFailure().getMessage());
latch.countDown();
}
});
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
use of org.eclipse.jetty.util.Attributes in project knox by apache.
the class FrontendFunctionProcessorTest method testFrontendFunctionsWithFrontendUriConfigOnJsonRequestBody.
@Test
public void testFrontendFunctionsWithFrontendUriConfigOnJsonRequestBody() throws Exception {
// This hooks up the filter in rewrite.xml in this class' test resource directory.
Map<String, String> initParams = new HashMap<>();
initParams.put("response.body", "test-filter");
// This simulates having gateway.frontend.uri in gateway-site.xml
Attributes attributes = new AttributesMap();
attributes.setAttribute(FrontendFunctionDescriptor.FRONTEND_URI_ATTRIBUTE, new URI("mock-frontend-scheme://mock-frontend-host:777/mock-frontend-path"));
setUp("test-user", initParams, attributes);
String input = TestUtils.getResourceString(FrontendFunctionProcessorTest.class, "test-input-body.json", "UTF-8");
interaction.expect().method("GET").requestUrl("http://test-host:42/test-path");
interaction.respond().status(200).contentType("application/json").characterEncoding("UTF-8").content(input, Charset.forName("UTF-8"));
interactions.add(interaction);
request.setMethod("GET");
request.setURI("/test-path");
// request.setVersion( "HTTP/1.1" );
request.setHeader("Host", "test-host:42");
response = TestUtils.execute(server, request);
assertThat(response.getStatus(), Is.is(200));
String json = response.getContent();
// Note: The Jetty ServletTester/HttpTester doesn't return very good values.
JsonAssert.with(json).assertThat("$.url", is("mock-frontend-scheme://mock-frontend-host:777/mock-frontend-path"));
JsonAssert.with(json).assertThat("$.scheme", is("mock-frontend-scheme"));
JsonAssert.with(json).assertThat("$.host", is("mock-frontend-host"));
JsonAssert.with(json).assertThat("$.port", is("777"));
JsonAssert.with(json).assertThat("$.addr", is("mock-frontend-host:777"));
JsonAssert.with(json).assertThat("$.address", is("mock-frontend-host:777"));
JsonAssert.with(json).assertThat("$.path", is("/mock-frontend-path"));
}
Aggregations