Search in sources :

Example 26 with Parameter

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>");
        }
    }
}
Also used : MediaType(javax.ws.rs.core.MediaType) Parameter(org.apache.cxf.jaxrs.model.Parameter) Endpoint(org.apache.cxf.endpoint.Endpoint)

Example 27 with Parameter

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);
        }
    }
}
Also used : Parameter(org.apache.cxf.jaxrs.model.Parameter) Method(java.lang.reflect.Method) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap)

Example 28 with Parameter

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);
        }
    }
}
Also used : Parameter(org.apache.cxf.jaxrs.model.Parameter) Method(java.lang.reflect.Method)

Example 29 with Parameter

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());
}
Also used : HashMap(java.util.HashMap) UserOperation(org.apache.cxf.jaxrs.model.UserOperation) UserResource(org.apache.cxf.jaxrs.model.UserResource) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) Parameter(org.apache.cxf.jaxrs.model.Parameter) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 30 with Parameter

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());
}
Also used : UserOperation(org.apache.cxf.jaxrs.model.UserOperation) UserResource(org.apache.cxf.jaxrs.model.UserResource) Parameter(org.apache.cxf.jaxrs.model.Parameter) Test(org.junit.Test)

Aggregations

Parameter (org.apache.cxf.jaxrs.model.Parameter)38 UserOperation (org.apache.cxf.jaxrs.model.UserOperation)13 Method (java.lang.reflect.Method)12 ParameterType (org.apache.cxf.jaxrs.model.ParameterType)10 Endpoint (org.apache.cxf.endpoint.Endpoint)9 UserResource (org.apache.cxf.jaxrs.model.UserResource)9 LinkedHashMap (java.util.LinkedHashMap)8 HashMap (java.util.HashMap)7 UserApplication (org.apache.cxf.jaxrs.model.UserApplication)7 MediaType (javax.ws.rs.core.MediaType)6 Annotation (java.lang.annotation.Annotation)5 Type (java.lang.reflect.Type)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)5 MetadataMap (org.apache.cxf.jaxrs.impl.MetadataMap)5 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)5 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)5 LinkedList (java.util.LinkedList)4 Test (org.junit.Test)4