use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class OAuthJSONProviderTest method testReadTokenIntrospectionMultipleAuds.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testReadTokenIntrospectionMultipleAuds() throws Exception {
String response = "{\"active\":true,\"client_id\":\"WjcK94pnec7CyA\",\"username\":\"alice\",\"token_type\":\"Bearer\"" + ",\"scope\":\"a\",\"aud\":[\"https://localhost:8082/service\",\"https://localhost:8083/service\"]," + "\"iat\":1453472181,\"exp\":1453475781}";
OAuthJSONProvider provider = new OAuthJSONProvider();
TokenIntrospection t = (TokenIntrospection) provider.readFrom((Class) TokenIntrospection.class, TokenIntrospection.class, new Annotation[] {}, MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, String>(), new ByteArrayInputStream(response.getBytes()));
assertTrue(t.isActive());
assertEquals("WjcK94pnec7CyA", t.getClientId());
assertEquals("alice", t.getUsername());
assertEquals("a", t.getScope());
assertEquals(2, t.getAud().size());
assertEquals("https://localhost:8082/service", t.getAud().get(0));
assertEquals("https://localhost:8083/service", t.getAud().get(1));
assertEquals(1453472181L, t.getIat().longValue());
assertEquals(1453475781L, t.getExp().longValue());
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class OidcRpAuthenticationFilter method toRequestState.
private MultivaluedMap<String, String> toRequestState(ContainerRequestContext rc) {
MultivaluedMap<String, String> requestState = new MetadataMap<String, String>();
requestState.putAll(rc.getUriInfo().getQueryParameters(true));
if (MediaType.APPLICATION_FORM_URLENCODED_TYPE.isCompatible(rc.getMediaType())) {
String body = FormUtils.readBody(rc.getEntityStream(), StandardCharsets.UTF_8.name());
FormUtils.populateMapFromString(requestState, JAXRSUtils.getCurrentMessage(), body, StandardCharsets.UTF_8.name(), true);
rc.setEntityStream(new ByteArrayInputStream(StringUtils.toBytesUTF8(body)));
}
return requestState;
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class MultipartProvider method createDataHandler.
private <T> Attachment createDataHandler(T obj, Class<T> cls, Type genericType, Annotation[] anns, String mimeType, String mainMediaType, int id) throws IOException {
DataHandler dh = null;
if (InputStream.class.isAssignableFrom(obj.getClass())) {
dh = createInputStreamDH((InputStream) obj, mimeType);
} else if (DataHandler.class.isAssignableFrom(obj.getClass())) {
dh = (DataHandler) obj;
} else if (DataSource.class.isAssignableFrom(obj.getClass())) {
dh = new DataHandler((DataSource) obj);
} else if (File.class.isAssignableFrom(obj.getClass())) {
File f = (File) obj;
ContentDisposition cd = mainMediaType.startsWith(MediaType.MULTIPART_FORM_DATA) ? new ContentDisposition("form-data;name=file;filename=" + f.getName()) : null;
return new Attachment(AttachmentUtil.BODY_ATTACHMENT_ID, Files.newInputStream(f.toPath()), cd);
} else if (Attachment.class.isAssignableFrom(obj.getClass())) {
Attachment att = (Attachment) obj;
if (att.getObject() == null) {
return att;
}
dh = getHandlerForObject(att.getObject(), att.getObject().getClass(), new Annotation[] {}, att.getContentType().toString(), id);
return new Attachment(att.getContentId(), dh, att.getHeaders());
} else if (byte[].class.isAssignableFrom(obj.getClass())) {
ByteDataSource source = new ByteDataSource((byte[]) obj);
source.setContentType(mimeType);
dh = new DataHandler(source);
} else {
dh = getHandlerForObject(obj, cls, genericType, anns, mimeType, id);
}
String contentId = getContentId(anns, id);
MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
headers.putSingle("Content-Type", mimeType);
return new Attachment(contentId, dh, headers);
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class ProviderFactoryTest method prepareMessage.
private Message prepareMessage(String contentType, String acceptType) {
Message message = new MessageImpl();
Map<String, List<String>> headers = new MetadataMap<String, String>();
message.put(Message.PROTOCOL_HEADERS, headers);
Exchange exchange = new ExchangeImpl();
exchange.setInMessage(message);
if (acceptType != null) {
headers.put("Accept", Collections.singletonList(acceptType));
exchange.setOutMessage(new MessageImpl());
} else {
headers.put("Content-Type", Collections.singletonList(contentType));
}
message.put("Content-Type", contentType);
message.setExchange(exchange);
return message;
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class JAXRSUtilsTest method doTestFormParameters.
@SuppressWarnings("unchecked")
private void doTestFormParameters(boolean useMediaType) throws Exception {
Class<?>[] argType = { String.class, List.class };
Method m = Customer.class.getMethod("testFormParam", argType);
Message messageImpl = createMessage();
String body = "p1=1&p2=2&p2=3";
messageImpl.put(Message.REQUEST_URI, "/foo");
MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
if (useMediaType) {
headers.putSingle("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
}
messageImpl.put(Message.PROTOCOL_HEADERS, headers);
messageImpl.setContent(InputStream.class, new ByteArrayInputStream(body.getBytes()));
List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, new ClassResourceInfo(Customer.class)), null, messageImpl);
assertEquals("2 form params should've been identified", 2, params.size());
assertEquals("First Form Parameter not matched correctly", "1", params.get(0));
List<String> list = (List<String>) params.get(1);
assertEquals(2, list.size());
assertEquals("2", list.get(0));
assertEquals("3", list.get(1));
}
Aggregations