Search in sources :

Example 1 with OperationResourceInfoStack

use of org.apache.cxf.jaxrs.model.OperationResourceInfoStack in project camel by apache.

the class DefaultCxfRsBinding method copyOperationResourceInfoStack.

protected void copyOperationResourceInfoStack(org.apache.cxf.message.Message cxfMessage, Message camelMessage) {
    OperationResourceInfoStack stack = cxfMessage.get(OperationResourceInfoStack.class);
    if (stack != null) {
        // make a copy of the operation resource info for looking up the sub resource location
        OperationResourceInfoStack copyStack = (OperationResourceInfoStack) stack.clone();
        camelMessage.setHeader(CxfConstants.CAMEL_CXF_RS_OPERATION_RESOURCE_INFO_STACK, copyStack);
    }
}
Also used : OperationResourceInfoStack(org.apache.cxf.jaxrs.model.OperationResourceInfoStack)

Example 2 with OperationResourceInfoStack

use of org.apache.cxf.jaxrs.model.OperationResourceInfoStack in project tomee by apache.

the class JAXRSUtils method pushOntoStack.

public static void pushOntoStack(OperationResourceInfo ori, MultivaluedMap<String, String> params, Message msg) {
    OperationResourceInfoStack stack = msg.get(OperationResourceInfoStack.class);
    if (stack == null) {
        stack = new OperationResourceInfoStack();
        msg.put(OperationResourceInfoStack.class, stack);
    }
    final List<String> values;
    if (params.size() <= 1) {
        values = Collections.emptyList();
    } else {
        values = new ArrayList<>(params.size() - 1);
        addTemplateVarValues(values, params, ori.getClassResourceInfo().getURITemplate());
        addTemplateVarValues(values, params, ori.getURITemplate());
    }
    Class<?> realClass = ori.getClassResourceInfo().getServiceClass();
    stack.push(new MethodInvocationInfo(ori, realClass, values));
}
Also used : OperationResourceInfoStack(org.apache.cxf.jaxrs.model.OperationResourceInfoStack) MethodInvocationInfo(org.apache.cxf.jaxrs.model.MethodInvocationInfo)

Example 3 with OperationResourceInfoStack

use of org.apache.cxf.jaxrs.model.OperationResourceInfoStack in project meecrowave by apache.

the class JAXRSFieldInjectionInterceptor method doInject.

private void doInject(final InvocationContext ic) throws Exception {
    final Message current = JAXRSUtils.getCurrentMessage();
    if (current != null) {
        final OperationResourceInfoStack stack = OperationResourceInfoStack.class.cast(current.get(OperationResourceInfoStack.class.getName()));
        if (stack != null && !stack.isEmpty()) {
            final Object instance;
            if (ConstructorInterceptorInvocationContext.class.isInstance(ic)) {
                final ConstructorInterceptorInvocationContext constructorInterceptorInvocationContext = ConstructorInterceptorInvocationContext.class.cast(ic);
                constructorInterceptorInvocationContext.directProceed();
                instance = constructorInterceptorInvocationContext.getNewInstance();
            } else {
                instance = ic.getTarget();
            }
            Application application = null;
            final Object appInfo = current.getExchange().getEndpoint().get(Application.class.getName());
            if (ApplicationInfo.class.isInstance(appInfo)) {
                application = ApplicationInfo.class.cast(appInfo).getProvider();
            }
            synchronized (this) {
                if (injected.get()) {
                    return;
                }
                InjectionUtils.injectContextProxiesAndApplication(stack.lastElement().getMethodInfo().getClassResourceInfo(), instance, application, ProviderFactory.getInstance(current));
                injected.compareAndSet(false, true);
            }
        }
    }
}
Also used : ConstructorInterceptorInvocationContext(org.apache.webbeans.intercept.ConstructorInterceptorInvocationContext) Message(org.apache.cxf.message.Message) OperationResourceInfoStack(org.apache.cxf.jaxrs.model.OperationResourceInfoStack) Application(javax.ws.rs.core.Application)

Example 4 with OperationResourceInfoStack

use of org.apache.cxf.jaxrs.model.OperationResourceInfoStack in project cxf by apache.

the class UriInfoImplTest method testGetMatchedURIsSubResourceLocator.

@Test
public void testGetMatchedURIsSubResourceLocator() throws Exception {
    System.out.println("testGetMatchedURIsSubResourceLocator");
    Message m = mockMessage("http://localhost:8080/app", "/foo/sub");
    OperationResourceInfoStack oriStack = new OperationResourceInfoStack();
    ClassResourceInfo rootCri = getCri(RootResource.class, true);
    OperationResourceInfo rootOri = getOri(rootCri, "getSubResourceLocator");
    MethodInvocationInfo miInfo = new MethodInvocationInfo(rootOri, RootResource.class, new ArrayList<String>());
    oriStack.push(miInfo);
    ClassResourceInfo subCri = getCri(SubResource.class, false);
    OperationResourceInfo subOri = getOri(subCri, "getFromSub");
    miInfo = new MethodInvocationInfo(subOri, SubResource.class, new ArrayList<String>());
    oriStack.push(miInfo);
    m.put(OperationResourceInfoStack.class, oriStack);
    UriInfoImpl u = new UriInfoImpl(m);
    List<String> matchedUris = getMatchedURIs(u);
    assertEquals(2, matchedUris.size());
    assertEquals("foo/sub", matchedUris.get(0));
    assertEquals("foo", matchedUris.get(1));
}
Also used : Message(org.apache.cxf.message.Message) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) ArrayList(java.util.ArrayList) OperationResourceInfoStack(org.apache.cxf.jaxrs.model.OperationResourceInfoStack) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) MethodInvocationInfo(org.apache.cxf.jaxrs.model.MethodInvocationInfo) Test(org.junit.Test)

Example 5 with OperationResourceInfoStack

use of org.apache.cxf.jaxrs.model.OperationResourceInfoStack in project cxf by apache.

the class UriInfoImplTest method testGetMatchedURIsRootSub.

@Test
public void testGetMatchedURIsRootSub() throws Exception {
    System.out.println("testGetMatchedURIsRootSub");
    Message m = mockMessage("http://localhost:8080/app", "/foo/bar");
    OperationResourceInfoStack oriStack = new OperationResourceInfoStack();
    ClassResourceInfo cri = getCri(RootResource.class, true);
    OperationResourceInfo ori = getOri(cri, "getSubMethod");
    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(2, matchedUris.size());
    assertEquals("foo/bar", matchedUris.get(0));
    assertEquals("foo", matchedUris.get(1));
}
Also used : Message(org.apache.cxf.message.Message) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) OperationResourceInfoStack(org.apache.cxf.jaxrs.model.OperationResourceInfoStack) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) MethodInvocationInfo(org.apache.cxf.jaxrs.model.MethodInvocationInfo) Test(org.junit.Test)

Aggregations

OperationResourceInfoStack (org.apache.cxf.jaxrs.model.OperationResourceInfoStack)8 MethodInvocationInfo (org.apache.cxf.jaxrs.model.MethodInvocationInfo)6 Message (org.apache.cxf.message.Message)5 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)4 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 Application (javax.ws.rs.core.Application)1 ConstructorInterceptorInvocationContext (org.apache.webbeans.intercept.ConstructorInterceptorInvocationContext)1