use of org.apache.cxf.jaxrs.model.Parameter in project cxf by apache.
the class WadlGenerator method handleFormRepresentation.
private void handleFormRepresentation(StringBuilder sb, Set<Class<?>> jaxbTypes, ElementQNameResolver qnameResolver, Map<Class<?>, QName> clsMap, OperationResourceInfo ori, Class<?> type, boolean isJson) {
if (type != null) {
handleRepresentation(sb, jaxbTypes, qnameResolver, clsMap, ori, type, false, true);
} else {
List<MediaType> types = ori.getConsumeTypes();
MediaType formType = isWildcard(types) ? MediaType.APPLICATION_FORM_URLENCODED_TYPE : types.get(0);
sb.append("<representation");
sb.append(" mediaType=\"").append(formType).append("\"");
if (isJson) {
sb.append("/>");
} else {
sb.append(">");
List<Parameter> params = ori.getParameters();
for (int i = 0; i < params.size(); i++) {
if (isFormParameter(params.get(i), getMethod(ori).getParameterTypes()[i], getMethod(ori).getParameterAnnotations()[i])) {
writeParam(sb, params.get(i), ori, isJson);
}
}
sb.append("</representation>");
}
}
}
use of org.apache.cxf.jaxrs.model.Parameter in project cxf by apache.
the class WadlGenerator method doHandleJaxrsBeanParamClassParams.
protected void doHandleJaxrsBeanParamClassParams(OperationResourceInfo ori, StringBuilder sb, Map<Parameter, Object> params, boolean isJson, ParameterType... pType) {
for (Map.Entry<Parameter, Object> entry : params.entrySet()) {
Parameter pm = entry.getKey();
Object obj = entry.getValue();
if (pm.getType() == ParameterType.BEAN) {
Class<?> cls = obj instanceof Method ? ((Method) obj).getParameterTypes()[0] : ((Field) obj).getType();
doWriteJaxrsBeanParam(sb, ori, cls, isJson, pType);
}
}
}
use of org.apache.cxf.jaxrs.model.Parameter in project cxf by apache.
the class WadlGenerator method doWriteJaxrsBeanParams.
private void doWriteJaxrsBeanParams(StringBuilder sb, OperationResourceInfo ori, boolean isJson, ParameterType... parameterTypes) {
for (Parameter p : ori.getParameters()) {
if (p.getType() == ParameterType.BEAN) {
Method method = getMethod(ori);
Class<?> type = method.getParameterTypes()[p.getIndex()];
doWriteJaxrsBeanParam(sb, ori, type, isJson, parameterTypes);
}
}
}
use of org.apache.cxf.jaxrs.model.Parameter in project cxf by apache.
the class ResourceUtilsTest method testClassResourceInfoUserResource.
@Test
public void testClassResourceInfoUserResource() throws Exception {
UserResource ur = new UserResource();
ur.setName(HashMap.class.getName());
ur.setPath("/hashmap");
UserOperation op = new UserOperation();
op.setPath("/key/{id}");
op.setName("get");
op.setVerb("POST");
op.setParameters(Collections.singletonList(new Parameter(ParameterType.PATH, "id")));
ur.setOperations(Collections.singletonList(op));
Map<String, UserResource> resources = new HashMap<>();
resources.put(ur.getName(), ur);
ClassResourceInfo cri = ResourceUtils.createClassResourceInfo(resources, ur, null, true, true, BusFactory.getDefaultBus());
assertNotNull(cri);
assertEquals("/hashmap", cri.getURITemplate().getValue());
Method method = HashMap.class.getMethod("get", new Class[] { Object.class });
OperationResourceInfo ori = cri.getMethodDispatcher().getOperationResourceInfo(method);
assertNotNull(ori);
assertEquals("/key/{id}", ori.getURITemplate().getValue());
List<Parameter> params = ori.getParameters();
assertNotNull(params);
Parameter p = params.get(0);
assertEquals("id", p.getName());
}
use of org.apache.cxf.jaxrs.model.Parameter in project cxf by apache.
the class ResourceUtilsTest method testUserResourceFromFile.
@Test
public void testUserResourceFromFile() throws Exception {
List<UserResource> list = ResourceUtils.getUserResources("classpath:/resources.xml");
assertNotNull(list);
assertEquals(1, list.size());
UserResource resource = list.get(0);
assertEquals("java.util.Map", resource.getName());
assertEquals("map", resource.getPath());
assertEquals("application/xml", resource.getProduces());
assertEquals("application/json", resource.getConsumes());
UserOperation oper = resource.getOperations().get(0);
assertEquals("putAll", oper.getName());
assertEquals("/putAll", oper.getPath());
assertEquals("PUT", oper.getVerb());
assertEquals("application/json", oper.getProduces());
assertEquals("application/xml", oper.getConsumes());
Parameter p = oper.getParameters().get(0);
assertEquals("map", p.getName());
assertEquals("emptyMap", p.getDefaultValue());
assertTrue(p.isEncoded());
assertEquals("REQUEST_BODY", p.getType().toString());
}
Aggregations