org.apache.cxf.jaxrs.model.OperationResourceInfo Java Examples

The following examples show how to use org.apache.cxf.jaxrs.model.OperationResourceInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JAXRSUtilsTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testContextResolverParam() throws Exception {

    ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
    OperationResourceInfo ori =
        new OperationResourceInfo(
            Customer.class.getMethod("testContextResolvers",
                                     new Class[]{ContextResolver.class}),
                                     cri);
    ori.setHttpMethod("GET");

    Message m = createMessage();
    ContextResolver<JAXBContext> cr = new JAXBContextProvider();
    ProviderFactory.getInstance(m).registerUserProvider(cr);

    m.put(Message.BASE_PATH, "/");
    List<Object> params =
        JAXRSUtils.processParameters(ori, new MetadataMap<String, String>(), m);
    assertEquals("1 parameters expected", 1, params.size());
    assertSame(cr.getClass(), params.get(0).getClass());
}
 
Example #2
Source File: JAXRSUtilsTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testConversion() throws Exception {
    ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
    OperationResourceInfo ori =
        new OperationResourceInfo(
            Customer.class.getMethod("testConversion",
                                     new Class[]{PathSegmentImpl.class,
                                                 SimpleFactory.class}),
            cri);
    ori.setHttpMethod("GET");
    ori.setURITemplate(new URITemplate("{id1}/{id2}"));
    MultivaluedMap<String, String> values = new MetadataMap<>();
    values.putSingle("id1", "1");
    values.putSingle("id2", "2");

    Message m = createMessage();


    List<Object> params =
        JAXRSUtils.processParameters(ori, values, m);
    PathSegment ps = (PathSegment)params.get(0);
    assertEquals("1", ps.getPath());

    SimpleFactory sf = (SimpleFactory)params.get(1);
    assertEquals(2, sf.getId());
}
 
Example #3
Source File: ValidationUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static Object getResourceInstance(Message message) {
    final OperationResourceInfo ori = message.getExchange().get(OperationResourceInfo.class);
    if (ori == null) {
        return null;
    }
    if (!ori.getClassResourceInfo().isRoot()) {
        return message.getExchange().get("org.apache.cxf.service.object.last");
    }
    final ResourceProvider resourceProvider = ori.getClassResourceInfo().getResourceProvider();
    if (!resourceProvider.isSingleton()) {
        String error = "Service object is not a singleton, use a custom invoker to validate";
        LOG.warning(error);
        return null;
    }
    return resourceProvider.getInstance(message);
}
 
Example #4
Source File: JAXRSUtilsTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testWrongType() throws Exception {
    Class<?>[] argType = {HashMap.class}; //NOPMD
    Method m = Customer.class.getMethod("testWrongType", argType);
    Message messageImpl = createMessage();
    messageImpl.put(Message.QUERY_STRING, "p1=1");
    try {
        JAXRSUtils.processParameters(new OperationResourceInfo(m,
                                         new ClassResourceInfo(Customer.class)),
                                     null,
                                     messageImpl);
        fail("HashMap can not be handled as parameter");
    } catch (WebApplicationException ex) {
        assertEquals(500, ex.getResponse().getStatus());
        assertEquals("Parameter Class java.util.HashMap has no constructor with "
                     + "single String parameter, static valueOf(String) or fromString(String) methods",
                     ex.getResponse().getEntity().toString());
    }

}
 
Example #5
Source File: JAXRSUtilsTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testContextResolverFields() throws Exception {

    ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
    cri.setResourceProvider(new PerRequestResourceProvider(Customer.class));
    OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethod("postConstruct",
                                                                                   new Class[]{}), cri);

    Message m = createMessage();
    HttpServletResponse response = EasyMock.createMock(HttpServletResponse.class);
    m.put(AbstractHTTPDestination.HTTP_RESPONSE, response);
    Customer c = new Customer();
    ContextResolver<JAXBContext> cr = new JAXBContextProvider();
    ProviderFactory.getInstance(m).registerUserProvider(cr);

    m.put(Message.BASE_PATH, "/");
    InjectionUtils.injectContextFields(c, ori.getClassResourceInfo(), m);
    assertSame(cr.getClass(), c.getContextResolver().getClass());
}
 
Example #6
Source File: JAXRSUtilsTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@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<>();
    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(Long.valueOf(123), cb.getB());
    assertTrue(cb.isCb());
}
 
Example #7
Source File: JAXRSUtilsTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testCookieParameters() throws Exception {
    Class<?>[] argType = {String.class, Set.class, String.class, Set.class};
    Method m = Customer.class.getMethod("testCookieParam", argType);
    Message messageImpl = createMessage();
    MultivaluedMap<String, String> headers = new MetadataMap<>();
    headers.add("Cookie", "c1=c1Value");
    messageImpl.put(Message.PROTOCOL_HEADERS, headers);
    List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
                                                           new ClassResourceInfo(Customer.class)),
                                                       null,
                                                       messageImpl);
    assertEquals(4, params.size());
    assertEquals("c1Value", params.get(0));
    Set<Cookie> set1 = CastUtils.cast((Set<?>)params.get(1));
    assertEquals(1, set1.size());
    assertTrue(set1.contains(Cookie.valueOf("c1=c1Value")));
    assertEquals("c2Value", params.get(2));
    Set<Cookie> set2 = CastUtils.cast((Set<?>)params.get(3));
    assertTrue(set2.contains((Object)"c2Value"));
    assertEquals(1, set2.size());

}
 
Example #8
Source File: JAXRSUtilsTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryParameterDefaultValue() throws Exception {
    Message messageImpl = createMessage();
    ProviderFactory.getInstance(messageImpl).registerUserProvider(
        new GenericObjectParameterHandler());
    Class<?>[] argType = {String.class, String.class};
    Method m = Customer.class.getMethod("testGenericObjectParamDefaultValue", argType);

    messageImpl.put(Message.QUERY_STRING, "p1=thequery&p2");
    List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
                                                           new ClassResourceInfo(Customer.class)),
                                                       null,
                                                       messageImpl);
    assertEquals(2, params.size());
    String query = (String)params.get(0);
    assertEquals("thequery", query);
    query = (String)params.get(1);
    assertEquals("thequery", query);
}
 
Example #9
Source File: JAXRSUtilsTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static OperationResourceInfo findTargetResourceClass(List<ClassResourceInfo> resources,
                                                            Message message,
                                                            String path,
                                                            String httpMethod,
                                                            MultivaluedMap<String, String> values,
                                                            String requestContentType,
                                                            List<MediaType> acceptContentTypes) {

    Map<ClassResourceInfo, MultivaluedMap<String, String>> mResources
        = JAXRSUtils.selectResourceClass(resources, path, new MessageImpl());

    if (mResources != null) {
        OperationResourceInfo ori = JAXRSUtils.findTargetMethod(mResources, message, httpMethod,
                                               values, requestContentType, acceptContentTypes);
        if (ori != null) {
            return ori;
        }
    }

    return null;
}
 
Example #10
Source File: JAXRSUtilsTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@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<>();
    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(3, params.size());
    assertEquals("c1Value", params.get(0));
    assertEquals("c2Value", params.get(1));
    assertEquals("c3Value", ((Cookie)params.get(2)).getValue());
}
 
Example #11
Source File: JAXRSUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static Supplier<String> matchMessageLogSupplier(OperationResourceInfo ori,
    String path, String httpMethod, MediaType requestType, List<MediaType> acceptContentTypes,
    boolean added) {
    org.apache.cxf.common.i18n.Message errorMsg = added
        ? new org.apache.cxf.common.i18n.Message("OPER_SELECTED_POSSIBLY",
                                               BUNDLE, ori.getMethodToInvoke().getName())
        : new org.apache.cxf.common.i18n.Message("OPER_NO_MATCH",
                                               BUNDLE,
                                               ori.getMethodToInvoke().getName(),
                                               path,
                                               ori.getURITemplate().getValue(),
                                               httpMethod,
                                               ori.getHttpMethod(),
                                               requestType.toString(),
                                               convertTypesToString(ori.getConsumeTypes()),
                                               convertTypesToString(acceptContentTypes),
                                               convertTypesToString(ori.getProduceTypes()));
    return () -> errorMsg.toString();
}
 
Example #12
Source File: UriInfoImplTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetMatchedURIsRoot() throws Exception {
    System.out.println("testGetMatchedURIsRoot");
    Message m = mockMessage("http://localhost:8080/app", "/foo");
    OperationResourceInfoStack oriStack = new OperationResourceInfoStack();
    ClassResourceInfo cri = getCri(RootResource.class, true);
    OperationResourceInfo ori = getOri(cri, "get");

    MethodInvocationInfo miInfo = new MethodInvocationInfo(ori, RootResource.class, new ArrayList<String>());
    oriStack.push(miInfo);
    m.put(OperationResourceInfoStack.class, oriStack);

    UriInfoImpl u = new UriInfoImpl(m);
    List<String> matchedUris = getMatchedURIs(u);
    assertEquals(1, matchedUris.size());
    assertTrue(matchedUris.contains("foo"));
}
 
Example #13
Source File: JAXRSUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static Object processParameter(Class<?> parameterClass,
                                       Type parameterType,
                                       Annotation[] parameterAnns,
                                       Parameter parameter,
                                       MultivaluedMap<String, String> values,
                                       Message message,
                                       OperationResourceInfo ori)
    throws IOException, WebApplicationException {

    if (parameter.getType() == ParameterType.REQUEST_BODY) {
        return processRequestBodyParameter(parameterClass, parameterType, parameterAnns, message, ori);
    } else if (parameter.getType() == ParameterType.CONTEXT) {
        return createContextValue(message, parameterType, parameterClass);
    } else if (parameter.getType() == ParameterType.BEAN) {
        return createBeanParamValue(message, parameterClass, ori);
    } else {

        return createHttpParameterValue(parameter,
                                        parameterClass,
                                        parameterType,
                                        parameterAnns,
                                        message,
                                        values,
                                        ori);
    }
}
 
Example #14
Source File: JAXRSUtilsTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryParametersIntegerArray() throws Exception {
    Class<?>[] argType = {Integer[].class};
    Method m = Customer.class.getMethod("testQueryIntegerArray", argType);
    Message messageImpl = createMessage();

    messageImpl.put(Message.QUERY_STRING, "query=1&query=2");
    List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
                                                           new ClassResourceInfo(Customer.class)),
                                                       null,
                                                       messageImpl);
    assertEquals(1, params.size());
    Integer[] intValues = (Integer[])params.get(0);
    assertEquals(2, intValues.length);
    assertEquals(1, (int)intValues[0]);
    assertEquals(2, (int)intValues[1]);
}
 
Example #15
Source File: JAXRSUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static Object createBeanParamValue(Message m, Class<?> clazz, OperationResourceInfo ori) {
    BeanParamInfo bmi = ServerProviderFactory.getInstance(m).getBeanParamInfo(clazz);
    if (bmi == null) {
        // we could've started introspecting now but the fact no bean info
        // is available indicates that the one created at start up has been
        // lost and hence it is 500
        LOG.warning("Bean parameter info is not available");
        throw ExceptionUtils.toInternalServerErrorException(null, null);
    }
    Object instance;
    try {
        instance = clazz.newInstance();
    } catch (Throwable t) {
        throw ExceptionUtils.toInternalServerErrorException(t, null);
    }
    JAXRSUtils.injectParameters(ori, bmi, instance, m);

    InjectionUtils.injectContexts(instance, bmi, m);

    return instance;
}
 
Example #16
Source File: JAXRSUtilsTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testAcceptTypesMatch() throws Exception {

    Method m = Customer.class.getMethod("test", new Class[]{});
    ClassResourceInfo cr = new ClassResourceInfo(Customer.class);

    assertTrue("text/xml can not be matched",
               JAXRSUtils.matchMimeTypes(JAXRSUtils.ALL_TYPES,
                                         new MediaType("text", "xml"),
                                         new OperationResourceInfo(m, cr)));
    assertTrue("text/xml can not be matched",
               JAXRSUtils.matchMimeTypes(JAXRSUtils.ALL_TYPES,
                                         new MediaType("text", "*"),
                                         new OperationResourceInfo(m, cr)));
    assertTrue("text/xml can not be matched",
               JAXRSUtils.matchMimeTypes(JAXRSUtils.ALL_TYPES,
                                         new MediaType("*", "*"),
                                         new OperationResourceInfo(m, cr)));
    assertFalse("text/plain was matched",
               JAXRSUtils.matchMimeTypes(JAXRSUtils.ALL_TYPES,
                                         new MediaType("text", "plain"),
                                         new OperationResourceInfo(m, cr)));
}
 
Example #17
Source File: JAXRSUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static void runContainerResponseFilters(ServerProviderFactory pf,
                                               ResponseImpl r,
                                               Message m,
                                               OperationResourceInfo ori,
                                               Method invoked) throws IOException, Throwable {
    List<ProviderInfo<ContainerResponseFilter>> containerFilters =
        pf.getContainerResponseFilters(ori == null ? null : ori.getNameBindings());
    if (!containerFilters.isEmpty()) {
        ContainerRequestContext requestContext =
            new ContainerRequestContextImpl(m.getExchange().getInMessage(),
                                           false,
                                           true);
        ContainerResponseContext responseContext =
            new ContainerResponseContextImpl(r, m,
                ori == null ? null : ori.getClassResourceInfo().getServiceClass(), invoked);
        for (ProviderInfo<ContainerResponseFilter> filter : containerFilters) {
            InjectionUtils.injectContexts(filter.getProvider(), filter, m);
            filter.getProvider().filter(requestContext, responseContext);
        }
    }
}
 
Example #18
Source File: ResourceUtilsTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testClassResourceInfoWithOverriddenMethods() throws Exception {
    ClassResourceInfo cri =
            ResourceUtils.createClassResourceInfo(
                    OverriddenInterfaceImpl.class,
                    OverriddenInterfaceImpl.class,
                    true,
                    true);

    assertNotNull(cri);
    Method notSynthetic = OverriddenInterfaceImpl.class.getMethod("read", new Class[]{String.class});
    assertFalse(notSynthetic.isSynthetic());

    cri.hasSubResources();
    final Set<OperationResourceInfo> oris = cri.getMethodDispatcher().getOperationResourceInfos();
    assertEquals("there must be one read method", 1, oris.size());
    assertEquals(notSynthetic, oris.iterator().next().getMethodToInvoke());
}
 
Example #19
Source File: MicroProfileClientProxyImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
protected Message createMessage(Object body,
                                OperationResourceInfo ori,
                                MultivaluedMap<String, String> headers,
                                URI currentURI,
                                Exchange exchange,
                                Map<String, Object> invocationContext,
                                boolean proxy) {

    Method m = ori.getMethodToInvoke();

    Message msg = super.createMessage(body, ori, headers, currentURI, exchange, invocationContext, proxy);

    @SuppressWarnings("unchecked")
    Map<String, Object> filterProps = (Map<String, Object>) msg.getExchange()
                                                               .get("jaxrs.filter.properties");
    if (filterProps == null) {
        filterProps = new HashMap<>();
        msg.getExchange().put("jaxrs.filter.properties", filterProps);
    }
    filterProps.put("org.eclipse.microprofile.rest.client.invokedMethod", m);
    return msg;
}
 
Example #20
Source File: JavaDocProviderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void testGetStatus3JavaDocs(JavaDocProvider p, OperationResourceInfo ori) {
    assertEquals("Return Pet Status With 3 Params", p.getMethodDoc(ori));
    assertEquals(3, ori.getParameters().size());
    assertEquals("status", p.getMethodResponseDoc(ori));
    assertEquals("the pet id", p.getMethodParameterDoc(ori, 0));
    assertEquals("the query", p.getMethodParameterDoc(ori, 1));
    assertEquals("the query2", p.getMethodParameterDoc(ori, 2));
}
 
Example #21
Source File: JAXRSUtilsTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testFromValueEnum() throws Exception {
    Class<?>[] argType = {Timezone.class};
    Method m = Customer.class.getMethod("testFromValueParam", argType);
    Message messageImpl = createMessage();
    messageImpl.put(Message.QUERY_STRING, "p1=Europe%2FLondon");
    List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
                                                           new ClassResourceInfo(Customer.class)),
                                                       null,
                                                       messageImpl);
    assertEquals(1, params.size());
    assertSame("Timezone Parameter was not processed correctly",
               Timezone.EUROPE_LONDON, params.get(0));
}
 
Example #22
Source File: OpenApiCustomizer.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Allows to customize the responses of the given {@link Operation} instance; the method is invoked
 * for all instances available.
 *
 * @param operation operation instance
 * @param ori CXF data about the given operation instance
 */
protected void customizeResponses(final Operation operation, final OperationResourceInfo ori) {
    if (operation.getResponses() != null && !operation.getResponses().isEmpty()) {
        ApiResponse response = operation.getResponses().entrySet().iterator().next().getValue();
        if (StringUtils.isBlank(response.getDescription())
                || (StringUtils.isNotBlank(javadocProvider.getMethodResponseDoc(ori))
                && Reader.DEFAULT_DESCRIPTION.equals(response.getDescription()))) {

            response.setDescription(javadocProvider.getMethodResponseDoc(ori));
        }
    }
}
 
Example #23
Source File: WadlGenerator.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Annotation[] getBodyAnnotations(OperationResourceInfo ori, boolean inbound) {
    Method opMethod = getMethod(ori);
    if (inbound) {
        for (Parameter pm : ori.getParameters()) {
            if (pm.getType() == ParameterType.REQUEST_BODY) {
                return opMethod.getParameterAnnotations()[pm.getIndex()];
            }
        }
        return new Annotation[] {};
    }
    return opMethod.getDeclaredAnnotations();
}
 
Example #24
Source File: SelectMethodCandidatesTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private OperationResourceInfo findTargetResourceClass(List<ClassResourceInfo> resources,
                                                      Message message,
                                                      String path,
                                                      String httpMethod,
                                                      MultivaluedMap<String, String> values,
                                                      String requestContentType,
                                                      List<MediaType> acceptContentTypes) {
    return findTargetResourceClass(resources, message, path, httpMethod, values, requestContentType,
                                   acceptContentTypes, false);

}
 
Example #25
Source File: JAXRSUtilsTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultipleQueryParameters() throws Exception {
    Class<?>[] argType = {String.class, String.class, Long.class,
                          Boolean.TYPE, char.class, String.class, Boolean.class, String.class};
    Method m = Customer.class.getMethod("testMultipleQuery", argType);
    Message messageImpl = createMessage();

    messageImpl.put(Message.QUERY_STRING,
                    "query=first&query2=second&query3=3&query4=true&query6=&query7=true&query8");
    List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m,
                                                           new ClassResourceInfo(Customer.class)),
                                                       null, messageImpl);
    assertEquals("First Query Parameter of multiple was not matched correctly", "first",
                 params.get(0));
    assertEquals("Second Query Parameter of multiple was not matched correctly",
                 "second", params.get(1));
    assertEquals("Third Query Parameter of multiple was not matched correctly",
                3L, params.get(2));
    assertSame("Fourth Query Parameter of multiple was not matched correctly",
                 Boolean.TRUE, params.get(3));
    assertEquals("Fifth Query Parameter of multiple was not matched correctly",
                 '\u0000', params.get(4));
    assertEquals("Sixth Query Parameter of multiple was not matched correctly",
                 "", params.get(5));
    assertSame("Seventh Query Parameter of multiple was not matched correctly",
            Boolean.TRUE, params.get(6));
    assertNull("Eighth Query Parameter of multiple was not matched correctly",
            params.get(7));
}
 
Example #26
Source File: JAXRSServiceImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
public List<ServiceInfo> getServiceInfos() {
    if (!createServiceModel) {
        return Collections.emptyList();
    }
    // try to convert to WSDL-centric model so that CXF DataBindings can get initialized
    // might become useful too if we support wsdl2

    // make databindings to use databinding-specific information
    // like @XmlRootElement for ex to select a namespace
    this.put("org.apache.cxf.databinding.namespace", "true");

    List<ServiceInfo> infos = new ArrayList<>();
    for (ClassResourceInfo cri : classResourceInfos) {
        ServiceInfo si = new ServiceInfo();
        infos.add(si);
        QName qname = JAXRSUtils.getClassQName(cri.getServiceClass());
        si.setName(qname);
        InterfaceInfo inf = new InterfaceInfo(si, qname);
        si.setInterface(inf);
        for (OperationResourceInfo ori : cri.getMethodDispatcher().getOperationResourceInfos()) {
            Method m = ori.getMethodToInvoke();
            QName oname = new QName(qname.getNamespaceURI(), m.getName());
            OperationInfo oi = inf.addOperation(oname);
            createMessagePartInfo(oi, m.getReturnType(), qname, m, false);
            for (Parameter pm : ori.getParameters()) {

                if (pm.getType() == ParameterType.REQUEST_BODY) {
                    createMessagePartInfo(oi,
                                          ori.getMethodToInvoke().getParameterTypes()[pm.getIndex()],
                                          qname, m, true);
                }
            }
        }

    }
    return infos;
}
 
Example #27
Source File: WadlGenerator.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Class<?> getFormClass(OperationResourceInfo ori) {
    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])) {
            return null;
        }
    }
    return MultivaluedMap.class;
}
 
Example #28
Source File: UriInfoImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
public List<String> getMatchedURIs(boolean decode) {
    if (stack != null) {
        List<String> objects = new ArrayList<>();
        List<String> uris = new LinkedList<>();
        StringBuilder sumPath = new StringBuilder("");
        for (MethodInvocationInfo invocation : stack) {
            List<String> templateObjects = invocation.getTemplateValues();
            OperationResourceInfo ori = invocation.getMethodInfo();
            URITemplate[] paths = {
                ori.getClassResourceInfo().getURITemplate(),
                ori.getURITemplate()
            };
            if (paths[0] != null) {
                int count = paths[0].getVariables().size();
                List<String> rootObjects = new ArrayList<>(count);
                for (int i = 0; i < count && i < templateObjects.size(); i++) {
                    rootObjects.add(templateObjects.get(i));
                }
                uris.add(0, createMatchedPath(paths[0].getValue(), rootObjects, decode));
            }
            if (paths[1] != null && paths[1].getValue().length() > 1) {
                for (URITemplate t : paths) {
                    if (t != null) {
                        sumPath.append('/').append(t.getValue());
                    }
                }
                objects.addAll(templateObjects);
                uris.add(0, createMatchedPath(sumPath.toString(), objects, decode));
            }
        }
        return uris;
    }
    LOG.fine("No resource stack information, returning empty list");
    return Collections.emptyList();
}
 
Example #29
Source File: ComparableResourceComparator.java    From aries-jax-rs-whiteboard with Apache License 2.0 5 votes vote down vote up
@Override
public int compare(
    OperationResourceInfo oper1, OperationResourceInfo oper2,
    Message message) {

    return 0;
}
 
Example #30
Source File: SelectMethodCandidatesTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testFindFromAbstractGenericImpl6() throws Exception {
    JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
    sf.setResourceClasses(CustomerServiceResource.class);

    sf.create();
    List<ClassResourceInfo> resources = ((JAXRSServiceImpl)sf.getService()).getClassResourceInfos();
    Message m = createMessage();
    m.put(Message.CONTENT_TYPE, "text/xml");

    MetadataMap<String, String> values = new MetadataMap<>();
    OperationResourceInfo ori = findTargetResourceClass(resources, m,
                                                        "/process",
                                                        "POST",
                                                        values, "text/xml",
                                                        sortMediaTypes("*/*"));
    assertNotNull(ori);
    assertEquals("resourceMethod needs to be selected", "process",
                 ori.getMethodToInvoke().getName());

    String value = "<CustomerRequest><customerId>1</customerId><requestId>100</requestId></CustomerRequest>";
    m.setContent(InputStream.class, new ByteArrayInputStream(value.getBytes()));
    List<Object> params = JAXRSUtils.processParameters(ori, values, m);
    assertEquals(1, params.size());
    CustomerServiceRequest request = (CustomerServiceRequest)params.get(0);
    assertNotNull(request);
    assertEquals(1, request.getCustomerId());
    assertEquals(100, request.getRequestId());
    
    final Method notSynthetic = CustomerServiceResource.class.getMethod("process", 
        new Class[]{CustomerServiceRequest.class});
    assertEquals(notSynthetic, ori.getMethodToInvoke());
}