Search in sources :

Example 76 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.

the class SelectMethodCandidatesTest method doTestConsumesResource.

private void doTestConsumesResource(Class<?> resourceClass, String ct, String expectedMethodName) throws Exception {
    JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
    sf.setResourceClasses(resourceClass);
    sf.create();
    List<ClassResourceInfo> resources = ((JAXRSServiceImpl) sf.getService()).getClassResourceInfos();
    String contentType = ct == null ? "application/xml" : ct;
    String acceptContentTypes = "*/*";
    Message m = new MessageImpl();
    m.put(Message.CONTENT_TYPE, contentType);
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(m);
    m.setExchange(ex);
    Endpoint e = mockEndpoint();
    ex.put(Endpoint.class, e);
    MetadataMap<String, String> values = new MetadataMap<>();
    OperationResourceInfo ori = findTargetResourceClass(resources, m, "/", "POST", values, contentType, sortMediaTypes(acceptContentTypes));
    assertNotNull(ori);
    assertEquals(expectedMethodName, ori.getMethodToInvoke().getName());
}
Also used : Message(org.apache.cxf.message.Message) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) Exchange(org.apache.cxf.message.Exchange) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) Endpoint(org.apache.cxf.endpoint.Endpoint) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 77 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.

the class SelectMethodCandidatesTest method doTestProducesResource.

private void doTestProducesResource(Class<?> resourceClass, String path, String acceptContentTypes, String expectedResponseType, String expectedMethodName) throws Exception {
    JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
    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 = mockEndpoint();
    ex.put(Endpoint.class, e);
    MetadataMap<String, String> values = new MetadataMap<>();
    Map<ClassResourceInfo, MultivaluedMap<String, String>> mResources = JAXRSUtils.selectResourceClass(resources, path, m);
    OperationResourceInfo ori = JAXRSUtils.findTargetMethod(mResources, m, "GET", values, contentType, sortMediaTypes(acceptContentTypes));
    assertNotNull(ori);
    assertEquals(expectedMethodName, ori.getMethodToInvoke().getName());
    assertEquals(expectedResponseType, m.getExchange().get(Message.CONTENT_TYPE));
}
Also used : Message(org.apache.cxf.message.Message) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) Exchange(org.apache.cxf.message.Exchange) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) Endpoint(org.apache.cxf.endpoint.Endpoint) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 78 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.

the class MessageContextImplTest method testGetPropertyFromExchange.

@Test
public void testGetPropertyFromExchange() {
    Message m = new MessageImpl();
    Exchange ex = new ExchangeImpl();
    ex.put("a", "b");
    ex.setInMessage(m);
    MessageContext mc = new MessageContextImpl(m);
    assertEquals("b", mc.get("a"));
    assertNull(mc.get("b"));
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 79 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.

the class SelectMethodCandidatesTest method doTestGenericSuperType.

private void doTestGenericSuperType(Class<?> serviceClass, String methodName) throws Exception {
    JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
    sf.setResourceClasses(serviceClass);
    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 = mockEndpoint();
    ex.put(Endpoint.class, e);
    MetadataMap<String, String> values = new MetadataMap<>();
    OperationResourceInfo ori = findTargetResourceClass(resources, m, "/books", methodName, values, contentTypes, sortMediaTypes(acceptContentTypes));
    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());
    assertEquals("The Book", book.getName());
}
Also used : Message(org.apache.cxf.message.Message) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) Exchange(org.apache.cxf.message.Exchange) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) Endpoint(org.apache.cxf.endpoint.Endpoint) ByteArrayInputStream(java.io.ByteArrayInputStream) Book(org.apache.cxf.jaxrs.resources.Book) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 80 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.

the class LogicalMessageImplTest method testGetPayloadOfJAXB.

@Test
public void testGetPayloadOfJAXB() throws Exception {
    // using Dispatch
    JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class);
    Message message = new MessageImpl();
    Exchange e = new ExchangeImpl();
    message.setExchange(e);
    LogicalMessageContextImpl lmci = new LogicalMessageContextImpl(message);
    JAXBElement<AddNumbers> el = new ObjectFactory().createAddNumbers(req);
    LogicalMessageImpl lmi = new LogicalMessageImpl(lmci);
    lmi.setPayload(el, ctx);
    Object obj = lmi.getPayload(ctx);
    assertTrue(obj instanceof JAXBElement);
    JAXBElement<?> el2 = (JAXBElement<?>) obj;
    assertTrue(el2.getValue() instanceof AddNumbers);
    AddNumbers resp = (AddNumbers) el2.getValue();
    assertEquals(req.getArg0(), resp.getArg0());
    assertEquals(req.getArg1(), resp.getArg1());
}
Also used : Message(org.apache.cxf.message.Message) LogicalMessageImpl(org.apache.cxf.jaxws.handler.logical.LogicalMessageImpl) JAXBContext(javax.xml.bind.JAXBContext) JAXBElement(javax.xml.bind.JAXBElement) Exchange(org.apache.cxf.message.Exchange) LogicalMessageContextImpl(org.apache.cxf.jaxws.handler.logical.LogicalMessageContextImpl) ObjectFactory(org.apache.handlers.types.ObjectFactory) AddNumbers(org.apache.handlers.types.AddNumbers) MessageImpl(org.apache.cxf.message.MessageImpl) LogicalMessageImpl(org.apache.cxf.jaxws.handler.logical.LogicalMessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Aggregations

ExchangeImpl (org.apache.cxf.message.ExchangeImpl)227 MessageImpl (org.apache.cxf.message.MessageImpl)189 Message (org.apache.cxf.message.Message)166 Exchange (org.apache.cxf.message.Exchange)159 Test (org.junit.Test)107 Endpoint (org.apache.cxf.endpoint.Endpoint)42 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)30 ByteArrayInputStream (java.io.ByteArrayInputStream)28 QName (javax.xml.namespace.QName)23 Bus (org.apache.cxf.Bus)23 HashMap (java.util.HashMap)22 List (java.util.List)22 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)20 SOAPMessage (javax.xml.soap.SOAPMessage)16 LogEvent (org.apache.cxf.ext.logging.event.LogEvent)16 ArrayList (java.util.ArrayList)15 IOException (java.io.IOException)14 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)14 Conduit (org.apache.cxf.transport.Conduit)14