use of javax.ws.rs.core.MultivaluedHashMap in project cxf by apache.
the class JAXRSMultipartTest method testLargeHeader.
// The large Content Disposition header will be rejected here
@Test
public void testLargeHeader() throws Exception {
InputStream is1 = getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg");
String address = "http://localhost:" + PORT + "/bookstore/books/image";
WebClient client = WebClient.create(address);
client.type("multipart/mixed").accept("multipart/mixed");
WebClient.getConfig(client).getRequestContext().put("support.type.as.multipart", "true");
StringBuilder sb = new StringBuilder();
sb.append("form-data;");
for (int i = 0; i < 10000; i++) {
sb.append("aaaaaaaaaa");
}
MultivaluedMap<String, String> headers = new MultivaluedHashMap<>();
headers.putSingle("Content-ID", "root");
headers.putSingle("Content-Type", "application/octet-stream");
headers.putSingle("Content-Disposition", sb.toString());
DataHandler handler = new DataHandler(new InputStreamDataSource(is1, "application/octet-stream"));
Attachment att = new Attachment(headers, handler, null);
Response response = client.post(att);
assertEquals(response.getStatus(), 413);
client.close();
}
use of javax.ws.rs.core.MultivaluedHashMap in project cxf by apache.
the class InvocationBuilderImplTest method testHeadersMethod.
@Test
public void testHeadersMethod() {
// the javadoc for the Invocation.Builder.headers(MultivaluedMap) method says that
// invoking this method should remove all previously existing headers
Client client = ClientBuilder.newClient().register(TestFilter.class);
Builder builder = client.target("http://localhost:8080/notReal").request();
builder.header("Header1", "a");
builder.header("UnexpectedHeader", "should be removed");
MultivaluedMap<String, Object> map = new MultivaluedHashMap<>();
map.putSingle("Header1", "b");
builder.headers(map);
Response response = builder.get();
String sentHeaders = response.readEntity(String.class);
assertTrue(sentHeaders.contains("Header1=b"));
assertFalse(sentHeaders.contains("UnexpectedHeader"));
// null headers map should clear all headers
builder.headers(null);
response = builder.get();
assertEquals("", response.readEntity(String.class));
}
use of javax.ws.rs.core.MultivaluedHashMap in project pravega by pravega.
the class PravegaAuthManagerTest method registerInterceptors.
@Test
public void registerInterceptors() throws Exception {
// Test the registration method.
GRPCServerConfig config = GRPCServerConfigImpl.builder().authorizationEnabled(true).userPasswordFile(file.getAbsolutePath()).port(1000).build();
PravegaAuthManager manager = new PravegaAuthManager(config);
int port = TestUtils.getAvailableListenPort();
ServerBuilder<?> server = ServerBuilder.forPort(port).useTransportSecurity(new File("../config/cert.pem"), new File("../config/key.pem"));
server.addService(serviceImpl);
manager.registerInterceptors(server);
server.build().start();
InlineExecutor executor = new InlineExecutor();
Credentials creds = new DefaultCredentials("1111_aaaa", "admin");
final ControllerImpl controllerClient = new ControllerImpl(ControllerImplConfig.builder().clientConfig(ClientConfig.builder().controllerURI(URI.create("tcp://localhost:" + port)).build()).retryAttempts(1).build(), executor);
MultivaluedMap<String, String> map = new MultivaluedHashMap();
// Without specifying a valid handler.
assertThrows(AuthenticationException.class, () -> manager.authenticate("hi", map, AuthHandler.Permissions.READ));
// Non existent interceptor method.
map.add("method", "invalid");
assertThrows(AuthenticationException.class, () -> manager.authenticate("hi", map, AuthHandler.Permissions.READ));
// Specify a valid method but no parameters for default interceptor.
map.putSingle("method", "Pravega-Default");
assertThrows(AuthenticationException.class, () -> manager.authenticate("hi", map, AuthHandler.Permissions.READ));
// Specify a valid method but no password for default interceptor.
map.putSingle("username", "dummy3");
assertThrows(AuthenticationException.class, () -> manager.authenticate("hi", map, AuthHandler.Permissions.READ));
// Specify a valid method and parameters but invalid resource for default interceptor.
map.putSingle("password", "password");
assertFalse("Not existent resource should return false", manager.authenticate("invalid", map, AuthHandler.Permissions.READ));
// Valid parameters for default interceptor
map.putSingle("username", "dummy3");
map.putSingle("password", "password");
assertTrue("Read access for read resource should return true", manager.authenticate("readresource", map, AuthHandler.Permissions.READ));
// Stream/scope access should be extended to segment.
assertTrue("Read access for read resource should return true", manager.authenticate("readresource/segment", map, AuthHandler.Permissions.READ));
// Levels of access
assertFalse("Write access for read resource should return false", manager.authenticate("readresource", map, AuthHandler.Permissions.READ_UPDATE));
assertTrue("Read access for write resource should return true", manager.authenticate("totalaccess", map, AuthHandler.Permissions.READ));
assertTrue("Write access for write resource should return true", manager.authenticate("totalaccess", map, AuthHandler.Permissions.READ_UPDATE));
// Check the wildcard access
map.putSingle("username", "dummy4");
assertTrue("Write access for write resource should return true", manager.authenticate("totalaccess", map, AuthHandler.Permissions.READ_UPDATE));
map.putSingle("method", "testHandler");
assertTrue("Test handler should be called", manager.authenticate("any", map, AuthHandler.Permissions.READ));
assertThrows(RetriesExhaustedException.class, () -> controllerClient.createScope("hi").join());
}
use of javax.ws.rs.core.MultivaluedHashMap in project Payara by payara.
the class RestUtil method buildMultivalueMap.
// *******************************************************************************************************************
// *******************************************************************************************************************
protected static MultivaluedMap buildMultivalueMap(Map<String, Object> payload) {
MultivaluedMap formData = new MultivaluedHashMap();
if (payload == null || payload.isEmpty()) {
return formData;
}
for (final Map.Entry<String, Object> entry : payload.entrySet()) {
final Object value = entry.getValue();
final String key = entry.getKey();
if (value instanceof Collection) {
for (Object obj : ((Collection) value)) {
try {
formData.add(key, obj);
} catch (ClassCastException ex) {
Logger logger = GuiUtil.getLogger();
if (logger.isLoggable(Level.FINEST)) {
logger.log(Level.FINEST, GuiUtil.getCommonMessage("LOG_BUILD_MULTI_VALUE_MAP_ERROR", new Object[] { key, obj }));
}
// Allow it to continue b/c this property most likely
// should have been excluded for this request
}
}
} else {
// formData.putSingle(key, (value != null) ? value.toString() : value);
try {
if (key.equals("availabilityEnabled")) {
System.out.println("================== availabilityEnabled skipped ");
}
formData.putSingle(key, value);
} catch (ClassCastException ex) {
Logger logger = GuiUtil.getLogger();
if (logger.isLoggable(Level.FINEST)) {
logger.log(Level.FINEST, GuiUtil.getCommonMessage("LOG_BUILD_MULTI_VALUE_MAP_ERROR", new Object[] { key, value }));
}
// Allow it to continue b/c this property most likely
// should have been excluded for this request
}
}
}
return formData;
}
use of javax.ws.rs.core.MultivaluedHashMap in project Payara by payara.
the class AdminConsoleAuthModule method validateCredentials.
private RestResponse validateCredentials(HttpServletRequest request, String username, char[] password) {
WebTarget target = RestUtil.initialize(ClientBuilder.newBuilder()).build().target(restURL).register(HttpAuthenticationFeature.basic(username, new String(password)));
MultivaluedMap<String, String> payLoad = new MultivaluedHashMap<>();
payLoad.putSingle("remoteHostName", request.getRemoteHost());
return RestResponse.getRestResponse(target.request(RESPONSE_TYPE).post(Entity.entity(payLoad, APPLICATION_FORM_URLENCODED), Response.class));
}
Aggregations