Package org.apache.cxf.message

Examples of org.apache.cxf.message.MessageImpl


   
    private static Message createMessage(Exchange exchange) {
        Endpoint ep = exchange.get(Endpoint.class);
        Message msg = null;
        if (ep != null) {
            msg = new MessageImpl();
            msg.setExchange(exchange);
            msg = ep.getBinding().createMessage(msg);
        }
        return msg;
    }
View Full Code Here


        sf.setResourceClasses(resourceClass);
        sf.create();
        List<ClassResourceInfo> resources = ((JAXRSServiceImpl)sf.getService()).getClassResourceInfos();
        String contentType = "*/*";
       
        Message m = new MessageImpl();
        m.put(Message.CONTENT_TYPE, contentType);
        Exchange ex = new ExchangeImpl();
        ex.setInMessage(m);
        m.setExchange(ex);
        Endpoint e = EasyMock.createMock(Endpoint.class);
        e.isEmpty();
        EasyMock.expectLastCall().andReturn(true).anyTimes();
        e.size();
        EasyMock.expectLastCall().andReturn(0).anyTimes();
        e.getEndpointInfo();
        EasyMock.expectLastCall().andReturn(null).anyTimes();
        e.get(ProviderFactory.class.getName());
        EasyMock.expectLastCall().andReturn(ProviderFactory.getInstance()).times(2);
        e.get("org.apache.cxf.jaxrs.comparator");
        EasyMock.expectLastCall().andReturn(null);
        EasyMock.replay(e);
        ex.put(Endpoint.class, e);
       
        MetadataMap<String, String> values = new MetadataMap<String, String>();
        ClassResourceInfo resource = JAXRSUtils.selectResourceClass(resources, path, values,
                                                                    m);
    
        OperationResourceInfo ori = JAXRSUtils.findTargetMethod(resource, m, "GET",
                                                values, contentType,
                                                JAXRSUtils.sortMediaTypes(acceptContentTypes, "q"),
                                                true);

        assertNotNull(ori);
        assertEquals(expectedMethodName,  ori.getMethodToInvoke().getName());
        assertEquals(expectedResponseType, m.getExchange().get(Message.CONTENT_TYPE));
    }
View Full Code Here

        sf.create();
        List<ClassResourceInfo> resources = ((JAXRSServiceImpl)sf.getService()).getClassResourceInfos();
        String contentTypes = "text/xml";
        String acceptContentTypes = "text/xml";
       
        Message m = new MessageImpl();
        m.put(Message.CONTENT_TYPE, "text/xml");
        Exchange ex = new ExchangeImpl();
        ex.setInMessage(m);
        m.setExchange(ex);
        Endpoint e = EasyMock.createMock(Endpoint.class);
        e.isEmpty();
        EasyMock.expectLastCall().andReturn(true).anyTimes();
        e.size();
        EasyMock.expectLastCall().andReturn(0).anyTimes();
        e.getEndpointInfo();
        EasyMock.expectLastCall().andReturn(null).anyTimes();
        e.get(ProviderFactory.class.getName());
        EasyMock.expectLastCall().andReturn(ProviderFactory.getInstance()).times(3);
        e.get("org.apache.cxf.jaxrs.comparator");
        EasyMock.expectLastCall().andReturn(null);
        EasyMock.replay(e);
        ex.put(Endpoint.class, e);
       
        MetadataMap<String, String> values = new MetadataMap<String, String>();
        ClassResourceInfo resource = JAXRSUtils.selectResourceClass(resources, "/books", values,
                                                                    m);
        OperationResourceInfo ori = JAXRSUtils.findTargetMethod(resource,
                                                                m,
                                    methodName, values, contentTypes,
                                    JAXRSUtils.sortMediaTypes(acceptContentTypes, "q"),
                                    true);
        assertNotNull(ori);
        assertEquals("resourceMethod needs to be selected", methodName.toLowerCase() + "Entity",
                     ori.getMethodToInvoke().getName());
       
        String value = "<Book><name>The Book</name><id>2</id></Book>";
        m.setContent(InputStream.class, new ByteArrayInputStream(value.getBytes()));
        List<Object> params = JAXRSUtils.processParameters(ori, values, m);
        assertEquals(1, params.size());
        Book book = (Book)params.get(0);
        assertNotNull(book);
        assertEquals(2L, book.getId());
View Full Code Here

        String contentTypes = "*/*";
        String acceptContentTypes = "text/xml,*/*";
       
        MetadataMap<String, String> values = new MetadataMap<String, String>();
        ClassResourceInfo resource = JAXRSUtils.selectResourceClass(resources, path, values,
                                                                    new MessageImpl());
        OperationResourceInfo ori = JAXRSUtils.findTargetMethod(resource,
                                    createMessage(),
                                    "GET", values, contentTypes,
                                    JAXRSUtils.sortMediaTypes(acceptContentTypes, "q"),
                                    true);
View Full Code Here

        String contentTypes = "*/*";
        String acceptContentTypes = "application/xml;q=0.5,application/json";
       
        MetadataMap<String, String> values = new MetadataMap<String, String>();
        ClassResourceInfo resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/resource1", values,
                                                                    new MessageImpl());
        OperationResourceInfo ori = JAXRSUtils.findTargetMethod(resource,
                                    createMessage(),
                                    "GET", values, contentTypes,
                                    JAXRSUtils.sortMediaTypes(acceptContentTypes, "q"),
                                    true);
View Full Code Here

        //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>();
        ClassResourceInfo resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d", values,
                                                                    new MessageImpl());
        OperationResourceInfo ori = JAXRSUtils.findTargetMethod(resource,
                                    createMessage(),
                                    "GET", values, contentTypes,
                                    Collections.singletonList(MediaType.valueOf(acceptContentTypes)), true);
        assertNotNull(ori);
        assertEquals("listMethod needs to be selected", "listMethod",
                     ori.getMethodToInvoke().getName());
       
       
        acceptContentTypes = "application/xml,application/json;q=0.8";
        resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/1", values,
                                                  new MessageImpl());
        ori = JAXRSUtils.findTargetMethod(resource,
                                        createMessage(),
                                        "GET", values, contentTypes,
                                        JAXRSUtils.parseMediaTypes(acceptContentTypes), true);
        assertNotNull(ori);
        assertEquals("readMethod needs to be selected", "readMethod",
                     ori.getMethodToInvoke().getName());
       
       
        contentTypes = "application/xml";
        acceptContentTypes = "application/xml";
        resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/1", values, new MessageImpl());
        ori = JAXRSUtils.findTargetMethod(resource,
                                        createMessage(),
                                        "GET", values, contentTypes,
                                        Collections.singletonList(MediaType.valueOf(acceptContentTypes))
                                        , true);
        assertNotNull(ori);
        assertEquals("readMethod needs to be selected", "readMethod",
                     ori.getMethodToInvoke().getName());
       
        contentTypes = "application/json";
        acceptContentTypes = "application/json";
        resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/1/bar/baz/baz", values,
                                                  new MessageImpl());
        ori = JAXRSUtils.findTargetMethod(resource,
                                        createMessage(),
                                        "GET", values, contentTypes,
                                        Collections.singletonList(MediaType.valueOf(acceptContentTypes)),
                                        true);
        assertNotNull(ori);
        assertEquals("readMethod2 needs to be selected", "readMethod2",
                     ori.getMethodToInvoke().getName());
       
        contentTypes = "application/json";
        acceptContentTypes = "application/json";
        resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/1", values, new MessageImpl());
        ori = JAXRSUtils.findTargetMethod(resource,
                                        createMessage(),
                                        "GET", values, contentTypes,
                                        Collections.singletonList(MediaType.valueOf(acceptContentTypes)),
                                        true);
        assertNotNull(ori);
        assertEquals("unlimitedPath needs to be selected", "unlimitedPath",
                     ori.getMethodToInvoke().getName());
       
        resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/1/2", values, new MessageImpl());
        ori = JAXRSUtils.findTargetMethod(resource,
                                        createMessage(),
                                        "GET", values, contentTypes,
                                        Collections.singletonList(MediaType.valueOf(acceptContentTypes)),
                                        true);
View Full Code Here

        sf.create();
        List<ClassResourceInfo> resources = ((JAXRSServiceImpl)sf.getService()).getClassResourceInfos();
       
        MetadataMap<String, String> values = new MetadataMap<String, String>();
        ClassResourceInfo resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/custom", values,
                                                                    new MessageImpl());
       
        String contentTypes = "*/*";
        String acceptContentTypes = "application/bar,application/foo;q=0.8";
        OperationResourceInfo ori = JAXRSUtils.findTargetMethod(resource,
                                    createMessage(),
                                    "GET", values, contentTypes,
                                    JAXRSUtils.sortMediaTypes(acceptContentTypes, "q"),
                                    true);
        assertNotNull(ori);
        assertEquals("readBar", ori.getMethodToInvoke().getName());
        acceptContentTypes = "application/foo,application/bar;q=0.8";
        resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/custom", values, new MessageImpl());
        ori = JAXRSUtils.findTargetMethod(resource,
                                    createMessage(),
                                    "GET", values, contentTypes,
                                    JAXRSUtils.sortMediaTypes(acceptContentTypes, "q"),
                                    true);
        assertNotNull(ori);
        assertEquals("readFoo", ori.getMethodToInvoke().getName());
       
        acceptContentTypes = "application/foo;q=0.5,application/bar";
        resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/custom", values, new MessageImpl());
        ori = JAXRSUtils.findTargetMethod(resource,
                                    createMessage(),
                                    "GET", values, contentTypes,
                                    JAXRSUtils.sortMediaTypes(acceptContentTypes, "q"),
                                    true);
        assertNotNull(ori);
        assertEquals("readBar", ori.getMethodToInvoke().getName());
       
        acceptContentTypes = "application/foo,application/bar;q=0.5";
        resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/custom", values, new MessageImpl());
        ori = JAXRSUtils.findTargetMethod(resource,
                                    createMessage(),
                                    "GET", values, contentTypes,
                                    JAXRSUtils.sortMediaTypes(acceptContentTypes, "q"),
                                    true);
View Full Code Here

       
    }
   
    private Message createMessage() {
        ProviderFactory factory = ProviderFactory.getInstance();
        Message m = new MessageImpl();
        m.put("org.apache.cxf.http.case_insensitive_queries", false);
        Exchange e = new ExchangeImpl();
        m.setExchange(e);
        e.setInMessage(m);
        Endpoint endpoint = EasyMock.createMock(Endpoint.class);
        endpoint.getEndpointInfo();
        EasyMock.expectLastCall().andReturn(null).anyTimes();
        endpoint.get("org.apache.cxf.jaxrs.comparator");
View Full Code Here

        keyRequirements.setKeyType(keyType);
        parameters.setKeyRequirements(keyRequirements);
       
        parameters.setPrincipal(new CustomTokenPrincipal("alice"));
        // Mock up message context
        MessageImpl msg = new MessageImpl();
        WrappedMessageContext msgCtx = new WrappedMessageContext(msg);
        WebServiceContextImpl webServiceContext = new WebServiceContextImpl(msgCtx);
        parameters.setWebServiceContext(webServiceContext);
       
        if (appliesTo != null) {
View Full Code Here

    /**
     * @return
     */
    private WebServiceContextImpl setupMessageContext() {
        MessageImpl msg = new MessageImpl();
        WrappedMessageContext msgCtx = new WrappedMessageContext(msg);
        msgCtx.put(
            SecurityContext.class.getName(),
            createSecurityContext(new CustomTokenPrincipal("alice"))
        );
View Full Code Here

TOP

Related Classes of org.apache.cxf.message.MessageImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.