use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class JAXRSSamlTest method testGetBookPreviousSAMLTokenInForm.
@Test
public void testGetBookPreviousSAMLTokenInForm() throws Exception {
String address = "https://localhost:" + PORT + "/samlform/bookstore/books";
FormEncodingProvider<Form> formProvider = new FormEncodingProvider<Form>();
formProvider.setExpectedEncoded(true);
WebClient wc = createWebClientForExistingToken(address, new SamlFormOutInterceptor(), formProvider);
wc.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_XML);
try {
Book book = wc.post(new Form(new MetadataMap<String, String>()).param("name", "CXF").param("id", "125"), Book.class);
assertEquals(125L, book.getId());
} catch (WebApplicationException ex) {
fail(ex.getMessage());
} catch (ProcessingException ex) {
if (ex.getCause() != null && ex.getCause().getMessage() != null) {
fail(ex.getCause().getMessage());
} else {
fail(ex.getMessage());
}
}
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class AbstractClient method getTemplateParametersMap.
protected MultivaluedMap<String, String> getTemplateParametersMap(URITemplate template, List<Object> values) {
if (values != null && values.size() != 0) {
List<String> vars = template.getVariables();
MultivaluedMap<String, String> templatesMap = new MetadataMap<String, String>(vars.size());
for (int i = 0; i < vars.size(); i++) {
if (i < values.size()) {
templatesMap.add(vars.get(i), values.get(i).toString());
}
}
return templatesMap;
}
return null;
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class JAXRSUtilsTest method testMultipleCookieParameters.
@Test
public void testMultipleCookieParameters() throws Exception {
Class<?>[] argType = { String.class, String.class, Cookie.class };
Method m = Customer.class.getMethod("testMultipleCookieParam", argType);
Message messageImpl = createMessage();
MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
headers.add("Cookie", "c1=c1Value; c2=c2Value");
headers.add("Cookie", "c3=c3Value");
messageImpl.put(Message.PROTOCOL_HEADERS, headers);
List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, new ClassResourceInfo(Customer.class)), null, messageImpl);
assertEquals(params.size(), 3);
assertEquals("c1Value", params.get(0));
assertEquals("c2Value", params.get(1));
assertEquals("c3Value", ((Cookie) params.get(2)).getValue());
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class JAXRSUtilsTest method testFindTargetResourceClassWithTemplates.
@Test
public void testFindTargetResourceClassWithTemplates() throws Exception {
JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
sf.setResourceClasses(org.apache.cxf.jaxrs.resources.BookStoreTemplates.class);
sf.create();
List<ClassResourceInfo> resources = ((JAXRSServiceImpl) sf.getService()).getClassResourceInfos();
String contentTypes = "*/*";
// If acceptContentTypes does not specify a specific Mime type, the
// method is declared with a most specific ProduceMime type is selected.
MetadataMap<String, String> values = new MetadataMap<String, String>();
OperationResourceInfo ori = findTargetResourceClass(resources, createMessage2(), "/1/2/", "GET", values, contentTypes, getTypes("*/*"));
assertNotNull(ori);
assertEquals("getBooks", ori.getMethodToInvoke().getName());
assertEquals("Only id and final match groups should be there", 2, values.size());
assertEquals("2 {id} values should've been picked up", 2, values.get("id").size());
assertEquals("FINAL_MATCH_GROUP should've been picked up", 1, values.get(URITemplate.FINAL_MATCH_GROUP).size());
assertEquals("First {id} is 1", "1", values.getFirst("id"));
assertEquals("Second id is 2", "2", values.get("id").get(1));
values = new MetadataMap<String, String>();
ori = findTargetResourceClass(resources, createMessage2(), "/2", "POST", values, contentTypes, getTypes("*/*"));
assertNotNull(ori);
assertEquals("updateBookStoreInfo", ori.getMethodToInvoke().getName());
assertEquals("Only id and final match groups should be there", 2, values.size());
assertEquals("Only single {id} should've been picked up", 1, values.get("id").size());
assertEquals("FINAL_MATCH_GROUP should've been picked up", 1, values.get(URITemplate.FINAL_MATCH_GROUP).size());
assertEquals("Only the first {id} should've been picked up", "2", values.getFirst("id"));
values = new MetadataMap<String, String>();
ori = findTargetResourceClass(resources, createMessage2(), "/3/4", "PUT", values, contentTypes, getTypes("*/*"));
assertNotNull(ori);
assertEquals("updateBook", ori.getMethodToInvoke().getName());
assertEquals("Only the first {id} should've been picked up", 3, values.size());
assertEquals("Only the first {id} should've been picked up", 1, values.get("id").size());
assertEquals("Only the first {id} should've been picked up", 1, values.get("bookId").size());
assertEquals("Only the first {id} should've been picked up", 1, values.get(URITemplate.FINAL_MATCH_GROUP).size());
assertEquals("Only the first {id} should've been picked up", "3", values.getFirst("id"));
assertEquals("Only the first {id} should've been picked up", "4", values.getFirst("bookId"));
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class JAXRSUtilsTest method testFormParametersBeanWithBoolean.
@Test
public void testFormParametersBeanWithBoolean() throws Exception {
Class<?>[] argType = { Customer.CustomerBean.class };
Method m = Customer.class.getMethod("testFormBean", argType);
Message messageImpl = createMessage();
messageImpl.put(Message.REQUEST_URI, "/bar");
MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
headers.putSingle("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
messageImpl.put(Message.PROTOCOL_HEADERS, headers);
String body = "a=aValue&b=123&cb=true";
messageImpl.setContent(InputStream.class, new ByteArrayInputStream(body.getBytes()));
List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, new ClassResourceInfo(Customer.class)), null, messageImpl);
assertEquals("Bean should be created", 1, params.size());
Customer.CustomerBean cb = (Customer.CustomerBean) params.get(0);
assertNotNull(cb);
assertEquals("aValue", cb.getA());
assertEquals(new Long(123), cb.getB());
assertTrue(cb.isCb());
}
Aggregations