Search in sources :

Example 11 with LoggingOutInterceptor

use of org.apache.cxf.ext.logging.LoggingOutInterceptor in project cxf by apache.

the class JAXRSMultipartTest method testAddBookJaxbJsonImageWebClientRelated2.

@Test
public void testAddBookJaxbJsonImageWebClientRelated2() throws Exception {
    String address = "http://localhost:" + PORT + "/bookstore/books/jaxbimagejson";
    WebClient client = WebClient.create(address);
    WebClient.getConfig(client).getOutInterceptors().add(new LoggingOutInterceptor());
    WebClient.getConfig(client).getInInterceptors().add(new LoggingInInterceptor());
    client.type("multipart/mixed").accept("multipart/mixed");
    Book jaxb = new Book("jaxb", 1L);
    Book json = new Book("json", 2L);
    InputStream is1 = getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg");
    Map<String, Object> objects = new LinkedHashMap<String, Object>();
    MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
    headers.putSingle("Content-Type", "application/xml");
    headers.putSingle("Content-ID", "theroot");
    headers.putSingle("Content-Transfer-Encoding", "customxml");
    Attachment attJaxb = new Attachment(headers, jaxb);
    headers = new MetadataMap<String, String>();
    headers.putSingle("Content-Type", "application/json");
    headers.putSingle("Content-ID", "thejson");
    headers.putSingle("Content-Transfer-Encoding", "customjson");
    Attachment attJson = new Attachment(headers, json);
    headers = new MetadataMap<String, String>();
    headers.putSingle("Content-Type", "application/octet-stream");
    headers.putSingle("Content-ID", "theimage");
    headers.putSingle("Content-Transfer-Encoding", "customstream");
    Attachment attIs = new Attachment(headers, is1);
    objects.put(MediaType.APPLICATION_XML, attJaxb);
    objects.put(MediaType.APPLICATION_JSON, attJson);
    objects.put(MediaType.APPLICATION_OCTET_STREAM, attIs);
    Collection<? extends Attachment> coll = client.postAndGetCollection(objects, Attachment.class);
    List<Attachment> result = new ArrayList<>(coll);
    Book jaxb2 = readBookFromInputStream(result.get(0).getDataHandler().getInputStream());
    assertEquals("jaxb", jaxb2.getName());
    assertEquals(1L, jaxb2.getId());
    Book json2 = readJSONBookFromInputStream(result.get(1).getDataHandler().getInputStream());
    assertEquals("json", json2.getName());
    assertEquals(2L, json2.getId());
    InputStream is2 = result.get(2).getDataHandler().getInputStream();
    byte[] image1 = IOUtils.readBytesFromStream(getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg"));
    byte[] image2 = IOUtils.readBytesFromStream(is2);
    assertTrue(Arrays.equals(image1, image2));
}
Also used : PushbackInputStream(java.io.PushbackInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Attachment(org.apache.cxf.jaxrs.ext.multipart.Attachment) WebClient(org.apache.cxf.jaxrs.client.WebClient) LinkedHashMap(java.util.LinkedHashMap) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Test(org.junit.Test)

Example 12 with LoggingOutInterceptor

use of org.apache.cxf.ext.logging.LoggingOutInterceptor in project cxf by apache.

the class JAXRSMultipartTest method testAddBookJsonImageStream.

@Test
public void testAddBookJsonImageStream() throws Exception {
    String address = "http://localhost:" + PORT + "/bookstore/books/jsonimagestream";
    WebClient client = WebClient.create(address);
    WebClient.getConfig(client).getOutInterceptors().add(new LoggingOutInterceptor());
    WebClient.getConfig(client).getInInterceptors().add(new LoggingInInterceptor());
    client.type("multipart/mixed").accept("multipart/mixed");
    Book json = new Book("json", 1L);
    InputStream is1 = getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg");
    Map<String, Object> objects = new LinkedHashMap<String, Object>();
    MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
    headers = new MetadataMap<String, String>();
    headers.putSingle("Content-Type", "application/json");
    headers.putSingle("Content-ID", "thejson");
    headers.putSingle("Content-Transfer-Encoding", "customjson");
    Attachment attJson = new Attachment(headers, json);
    headers = new MetadataMap<String, String>();
    headers.putSingle("Content-Type", "application/octet-stream");
    headers.putSingle("Content-ID", "theimage");
    headers.putSingle("Content-Transfer-Encoding", "customstream");
    Attachment attIs = new Attachment(headers, is1);
    objects.put(MediaType.APPLICATION_JSON, attJson);
    objects.put(MediaType.APPLICATION_OCTET_STREAM, attIs);
    Collection<? extends Attachment> coll = client.postAndGetCollection(objects, Attachment.class);
    List<Attachment> result = new ArrayList<>(coll);
    assertEquals(2, result.size());
    Book json2 = readJSONBookFromInputStream(result.get(0).getDataHandler().getInputStream());
    assertEquals("json", json2.getName());
    assertEquals(1L, json2.getId());
    InputStream is2 = result.get(1).getDataHandler().getInputStream();
    byte[] image1 = IOUtils.readBytesFromStream(getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg"));
    byte[] image2 = IOUtils.readBytesFromStream(is2);
    assertTrue(Arrays.equals(image1, image2));
}
Also used : PushbackInputStream(java.io.PushbackInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Attachment(org.apache.cxf.jaxrs.ext.multipart.Attachment) WebClient(org.apache.cxf.jaxrs.client.WebClient) LinkedHashMap(java.util.LinkedHashMap) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Test(org.junit.Test)

Example 13 with LoggingOutInterceptor

use of org.apache.cxf.ext.logging.LoggingOutInterceptor in project cxf by apache.

the class JAXRSSoapBookTest method testAddOrderFormBean.

@Test
public void testAddOrderFormBean() throws Exception {
    String baseAddress = "http://localhost:" + PORT + "/test/services/rest";
    BookStoreJaxrsJaxws proxy = JAXRSClientFactory.create(baseAddress, BookStoreJaxrsJaxws.class);
    WebClient.getConfig(proxy).getOutInterceptors().add(new LoggingOutInterceptor());
    WebClient.getConfig(proxy).getInInterceptors().add(new LoggingInInterceptor());
    BookSubresource bs = proxy.getBookSubresource("139");
    OrderBean order = new OrderBean();
    order.setId(123L);
    order.setWeight(100);
    order.setCustomerTitle(OrderBean.Title.MS);
    OrderBean order2 = bs.addOrder(order);
    assertEquals(Long.valueOf(123L), Long.valueOf(order2.getId()));
    assertEquals(OrderBean.Title.MS, order2.getCustomerTitle());
}
Also used : BookStoreJaxrsJaxws(org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Test(org.junit.Test)

Example 14 with LoggingOutInterceptor

use of org.apache.cxf.ext.logging.LoggingOutInterceptor in project cxf by apache.

the class AegisClientServerTest method testComplexMapResult.

@Test
public void testComplexMapResult() throws Exception {
    AegisDatabinding aegisBinding = new AegisDatabinding();
    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    proxyFactory.setDataBinding(aegisBinding);
    proxyFactory.setServiceClass(SportsService.class);
    proxyFactory.setAddress("http://localhost:" + PORT + "/jaxwsAndAegisSports");
    proxyFactory.getInInterceptors().add(new LoggingInInterceptor());
    proxyFactory.getOutInterceptors().add(new LoggingOutInterceptor());
    SportsService service = (SportsService) proxyFactory.create();
    Map<String, Map<Integer, Integer>> result = service.testComplexMapResult();
    assertEquals(result.size(), 1);
    assertTrue(result.containsKey("key1"));
    assertNotNull(result.get("key1"));
    assertEquals(result.toString(), "{key1={1=3}}");
}
Also used : LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) AegisDatabinding(org.apache.cxf.aegis.databinding.AegisDatabinding) Map(java.util.Map) Test(org.junit.Test)

Example 15 with LoggingOutInterceptor

use of org.apache.cxf.ext.logging.LoggingOutInterceptor in project cxf by apache.

the class AegisClientServerTest method testReturnQualifiedPair.

@Test
public void testReturnQualifiedPair() throws Exception {
    AegisDatabinding aegisBinding = new AegisDatabinding();
    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    proxyFactory.setDataBinding(aegisBinding);
    proxyFactory.setServiceClass(SportsService.class);
    proxyFactory.setAddress("http://localhost:" + PORT + "/jaxwsAndAegisSports");
    proxyFactory.getInInterceptors().add(new LoggingInInterceptor());
    proxyFactory.getOutInterceptors().add(new LoggingOutInterceptor());
    SportsService service = (SportsService) proxyFactory.create();
    Pair<Integer, String> ret = service.getReturnQualifiedPair(111, "ffang");
    assertEquals(new Integer(111), ret.getFirst());
    assertEquals("ffang", ret.getSecond());
}
Also used : LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) AegisDatabinding(org.apache.cxf.aegis.databinding.AegisDatabinding) Test(org.junit.Test)

Aggregations

LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)224 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)207 Test (org.junit.Test)175 Service (org.apache.cxf.service.Service)138 Client (org.apache.cxf.endpoint.Client)135 HashMap (java.util.HashMap)101 WSSSecurityProperties (org.apache.wss4j.stax.ext.WSSSecurityProperties)89 ArrayList (java.util.ArrayList)68 Properties (java.util.Properties)65 WSSConstants (org.apache.wss4j.stax.ext.WSSConstants)61 QName (javax.xml.namespace.QName)35 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)22 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)21 AbstractSecurityTest (org.apache.cxf.ws.security.wss4j.AbstractSecurityTest)18 Echo (org.apache.cxf.ws.security.wss4j.Echo)18 Bus (org.apache.cxf.Bus)16 URL (java.net.URL)15 Server (org.apache.cxf.endpoint.Server)14 Greeter (org.apache.cxf.greeter_control.Greeter)14 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)13