Update logging to not depend on jaxws/jaxrs and then update everything outside of core to use logging feature
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/e1d95060 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/e1d95060 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/e1d95060 Branch: refs/heads/master Commit: e1d950605941ef77bd4a3e9e4ad47eb63ac8f221 Parents: e856de5 Author: Daniel Kulp <[email protected]> Authored: Fri Feb 10 14:07:59 2017 -0500 Committer: Daniel Kulp <[email protected]> Committed: Fri Feb 10 14:09:05 2017 -0500 ---------------------------------------------------------------------- .../transform/TransformOutInterceptor.java | 4 +- .../interceptor/LoggingOutInterceptorTest.java | 1 + rt/databinding/aegis/pom.xml | 5 + .../inheritance/ExceptionInheritanceTest.java | 2 - .../cxf/aegis/type/array/FlatArrayTest.java | 5 +- .../cxf/aegis/type/java5/map/StudentTest.java | 7 - .../cxf/clustering/FailoverTargetSelector.java | 2 +- rt/features/logging/pom.xml | 27 +-- .../ext/logging/AbstractLoggingInterceptor.java | 2 +- .../ext/logging/DefaultLogEventMapperTest.java | 25 --- .../apache/cxf/ext/logging/RESTLoggingTest.java | 185 ------------------ .../apache/cxf/ext/logging/SOAPLoggingTest.java | 148 -------------- .../apache/cxf/ext/logging/TestEventSender.java | 38 ---- .../org/apache/cxf/ext/logging/TestService.java | 26 --- .../apache/cxf/ext/logging/TestServiceRest.java | 32 ---- .../cxf/ext/logging/TestServiceRestBinary.java | 34 ---- rt/frontend/jaxrs/pom.xml | 6 + .../org/apache/cxf/jaxrs/utils/FormUtils.java | 3 +- rt/frontend/jaxws/pom.xml | 6 + .../org/apache/cxf/jaxws/CodeFirstTest.java | 6 +- .../apache/cxf/jaxws/SEIWithJAXBAnnoTest.java | 2 +- .../apache/cxf/jaxws/dispatch/DispatchTest.java | 2 +- .../apache/cxf/jaxws/dispatch/bus-dispatch.xml | 2 +- .../jaxws/handler/HandlerChainInvokerTest.java | 1 - .../jaxws/header/HeaderClientServerTest.java | 6 - .../header/ProviderHeaderClientServerTest.java | 7 +- .../cxf/jaxws/logging/SOAPLoggingTest.java | 178 +++++++++++++++++ .../cxf/jaxws/logging/TestEventSender.java | 38 ++++ .../apache/cxf/jaxws/logging/TestService.java | 26 +++ .../cxf/jaxws/spring/SpringBeansTest.java | 4 +- .../org/apache/cxf/jaxws/spring/clients.xml | 6 +- .../org/apache/cxf/jaxws/spring/endpoints.xml | 4 +- rt/frontend/simple/pom.xml | 6 + .../cxf/frontend/spring/SpringBeansTest.java | 4 +- .../org/apache/cxf/frontend/spring/clients.xml | 4 +- .../cxf/service/factory/RountripTest.java | 9 - rt/rs/client/pom.xml | 6 + .../CacheControlClientReaderInterceptor.java | 2 +- .../cache/CacheControlClientRequestFilter.java | 2 +- .../jaxrs/client/logging/RESTLoggingTest.java | 191 +++++++++++++++++++ .../jaxrs/client/logging/TestEventSender.java | 38 ++++ .../jaxrs/client/logging/TestServiceRest.java | 32 ++++ .../client/logging/TestServiceRestBinary.java | 34 ++++ .../oauth2/common/AccessTokenValidation.java | 2 +- 44 files changed, 595 insertions(+), 575 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java b/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java index a0fff5b..c1901bf 100644 --- a/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java +++ b/core/src/main/java/org/apache/cxf/interceptor/transform/TransformOutInterceptor.java @@ -27,7 +27,6 @@ import java.util.Map; import javax.xml.stream.XMLStreamWriter; import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor; -import org.apache.cxf.interceptor.LoggingOutInterceptor; import org.apache.cxf.interceptor.StaxOutEndingInterceptor; import org.apache.cxf.interceptor.StaxOutInterceptor; import org.apache.cxf.message.Message; @@ -63,7 +62,8 @@ public class TransformOutInterceptor extends AbstractPhaseInterceptor<Message> { public TransformOutInterceptor(String phase) { super(phase); addBefore(StaxOutInterceptor.class.getName()); - addAfter(LoggingOutInterceptor.class.getName()); + addAfter("org.apache.cxf.interceptor.LoggingOutInterceptor"); + addAfter("org.apache.cxf.ext.logging.LoggingOutInterceptor"); } @Override http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java b/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java index 88019e0..26227a7 100644 --- a/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java +++ b/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java @@ -43,6 +43,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; +@SuppressWarnings("deprecation") public class LoggingOutInterceptorTest extends Assert { protected IMocksControl control; http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/databinding/aegis/pom.xml ---------------------------------------------------------------------- diff --git a/rt/databinding/aegis/pom.xml b/rt/databinding/aegis/pom.xml index ba0ad6b..96541fe 100644 --- a/rt/databinding/aegis/pom.xml +++ b/rt/databinding/aegis/pom.xml @@ -84,6 +84,11 @@ </dependency> <dependency> <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-features-logging</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>${project.version}</version> <scope>test</scope> http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/inheritance/ExceptionInheritanceTest.java ---------------------------------------------------------------------- diff --git a/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/inheritance/ExceptionInheritanceTest.java b/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/inheritance/ExceptionInheritanceTest.java index f05f426..fd1d5b4 100644 --- a/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/inheritance/ExceptionInheritanceTest.java +++ b/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/inheritance/ExceptionInheritanceTest.java @@ -32,7 +32,6 @@ import org.apache.cxf.aegis.inheritance.ws1.WS1ExtendedException; import org.apache.cxf.aegis.inheritance.ws1.impl.WS1Impl; import org.apache.cxf.aegis.services.SimpleBean; import org.apache.cxf.endpoint.Server; -import org.apache.cxf.feature.LoggingFeature; import org.apache.cxf.frontend.ClientProxyFactoryBean; import org.apache.cxf.frontend.ServerFactoryBean; import org.apache.cxf.service.invoker.BeanInvoker; @@ -64,7 +63,6 @@ public class ExceptionInheritanceTest extends AbstractAegisTest { client = pf.create(WS1.class); Server server = createService(WS1.class, new WS1Impl(), "WS1", binding); - new LoggingFeature().initialize(server, null); server.getEndpoint().getService().setInvoker(new BeanInvoker(new WS1Impl())); } http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayTest.java ---------------------------------------------------------------------- diff --git a/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayTest.java b/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayTest.java index bece8ea..6741662 100644 --- a/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayTest.java +++ b/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/array/FlatArrayTest.java @@ -25,10 +25,8 @@ import org.w3c.dom.NodeList; import org.apache.cxf.aegis.AbstractAegisTest; import org.apache.cxf.aegis.databinding.AegisDatabinding; -import org.apache.cxf.endpoint.Server; import org.apache.cxf.frontend.ClientProxyFactoryBean; import org.apache.cxf.frontend.ServerFactoryBean; -import org.apache.cxf.interceptor.LoggingInInterceptor; import org.junit.Before; import org.junit.Test; @@ -53,8 +51,7 @@ public class FlatArrayTest extends AbstractAegisTest { sf.setServiceBean(service); sf.setAddress("local://FlatArray"); sf.setDataBinding(new AegisDatabinding()); - Server s = sf.create(); - s.getEndpoint().getInInterceptors().add(new LoggingInInterceptor()); + sf.create(); arrayWsdlDoc = getWSDLDocument("FlatArrayServiceInterface"); } http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/map/StudentTest.java ---------------------------------------------------------------------- diff --git a/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/map/StudentTest.java b/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/map/StudentTest.java index 8b42c77..2ab8c43 100644 --- a/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/map/StudentTest.java +++ b/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/type/java5/map/StudentTest.java @@ -27,8 +27,6 @@ import org.apache.cxf.aegis.AbstractAegisTest; import org.apache.cxf.endpoint.Server; import org.apache.cxf.frontend.ClientProxyFactoryBean; import org.apache.cxf.frontend.ServerFactoryBean; -import org.apache.cxf.interceptor.LoggingInInterceptor; -import org.apache.cxf.interceptor.LoggingOutInterceptor; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; import org.apache.cxf.jaxws.JaxWsServerFactoryBean; import org.junit.Test; @@ -110,8 +108,6 @@ public class StudentTest extends AbstractAegisTest { sf.setAddress("local://StudentServiceDocLiteral"); setupAegis(sf); Server server = sf.create(); - server.getEndpoint().getInInterceptors().add(new LoggingInInterceptor()); - server.getEndpoint().getOutInterceptors().add(new LoggingOutInterceptor()); server.start(); JaxWsProxyFactoryBean proxyFac = new JaxWsProxyFactoryBean(); @@ -119,9 +115,6 @@ public class StudentTest extends AbstractAegisTest { proxyFac.setBus(getBus()); setupAegis(proxyFac.getClientFactoryBean()); - proxyFac.getInInterceptors().add(new LoggingInInterceptor()); - proxyFac.getOutInterceptors().add(new LoggingOutInterceptor()); - StudentServiceDocLiteral clientInterface = proxyFac.create(StudentServiceDocLiteral.class); Map<Long, Student> fullMap = clientInterface.getStudentsMap(); assertNotNull(fullMap); http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/features/clustering/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java ---------------------------------------------------------------------- diff --git a/rt/features/clustering/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java b/rt/features/clustering/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java index f984063..467d2fc 100644 --- a/rt/features/clustering/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java +++ b/rt/features/clustering/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java @@ -65,7 +65,7 @@ public class FailoverTargetSelector extends AbstractConduitSelector { public FailoverTargetSelector(String clientBootstrapAddress) { super(); - this.setClientBootstrapAddress(clientBootstrapAddress); + this.clientBootstrapAddress = clientBootstrapAddress; } /** http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/features/logging/pom.xml ---------------------------------------------------------------------- diff --git a/rt/features/logging/pom.xml b/rt/features/logging/pom.xml index 87caf4d..29ff63e 100644 --- a/rt/features/logging/pom.xml +++ b/rt/features/logging/pom.xml @@ -54,30 +54,5 @@ <artifactId>easymock</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>org.apache.cxf</groupId> - <artifactId>cxf-rt-frontend-jaxws</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.cxf</groupId> - <artifactId>cxf-rt-frontend-jaxrs</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.cxf</groupId> - <artifactId>cxf-rt-rs-client</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.cxf</groupId> - <artifactId>cxf-rt-transports-http-jetty</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> - </dependencies> -</project> \ No newline at end of file +</project> http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/AbstractLoggingInterceptor.java ---------------------------------------------------------------------- diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/AbstractLoggingInterceptor.java b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/AbstractLoggingInterceptor.java index ae74648..cdc8618 100644 --- a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/AbstractLoggingInterceptor.java +++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/AbstractLoggingInterceptor.java @@ -29,7 +29,7 @@ import org.apache.cxf.phase.AbstractPhaseInterceptor; public abstract class AbstractLoggingInterceptor extends AbstractPhaseInterceptor<Message> { public static final int DEFAULT_LIMIT = 48 * 1024; - protected static final String CONTENT_SUPPRESSED = "--- Content suppressed ---"; + public static final String CONTENT_SUPPRESSED = "--- Content suppressed ---"; protected int limit = DEFAULT_LIMIT; protected long threshold = -1; http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/DefaultLogEventMapperTest.java ---------------------------------------------------------------------- diff --git a/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/DefaultLogEventMapperTest.java b/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/DefaultLogEventMapperTest.java index 0d64e64..8792e23 100644 --- a/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/DefaultLogEventMapperTest.java +++ b/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/DefaultLogEventMapperTest.java @@ -18,20 +18,12 @@ */ package org.apache.cxf.ext.logging; -import javax.xml.namespace.QName; - -import org.apache.cxf.binding.Binding; -import org.apache.cxf.binding.soap.SoapBinding; import org.apache.cxf.ext.logging.event.DefaultLogEventMapper; import org.apache.cxf.ext.logging.event.LogEvent; import org.apache.cxf.message.Exchange; import org.apache.cxf.message.ExchangeImpl; import org.apache.cxf.message.Message; import org.apache.cxf.message.MessageImpl; -import org.apache.cxf.service.model.BindingInfo; -import org.apache.cxf.service.model.BindingOperationInfo; -import org.apache.cxf.service.model.OperationInfo; -import org.apache.cxf.service.model.ServiceInfo; import org.junit.Assert; import org.junit.Test; @@ -64,22 +56,5 @@ public class DefaultLogEventMapperTest { Assert.assertEquals("", event.getOperationName()); } - @Test - public void testSoap() { - DefaultLogEventMapper mapper = new DefaultLogEventMapper(); - Message message = new MessageImpl(); - ExchangeImpl exchange = new ExchangeImpl(); - ServiceInfo service = new ServiceInfo(); - BindingInfo info = new BindingInfo(service, "bindingId"); - SoapBinding value = new SoapBinding(info); - exchange.put(Binding.class, value); - OperationInfo opInfo = new OperationInfo(); - opInfo.setName(new QName("http://my", "Operation")); - BindingOperationInfo boi = new BindingOperationInfo(info, opInfo); - exchange.put(BindingOperationInfo.class, boi); - message.setExchange(exchange); - LogEvent event = mapper.map(message); - Assert.assertEquals("{http://my}Operation", event.getOperationName()); - } } http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/RESTLoggingTest.java ---------------------------------------------------------------------- diff --git a/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/RESTLoggingTest.java b/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/RESTLoggingTest.java deleted file mode 100644 index 8bde31f..0000000 --- a/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/RESTLoggingTest.java +++ /dev/null @@ -1,185 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.ext.logging; - -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.util.Collections; -import java.util.List; - -import org.apache.cxf.endpoint.Server; -import org.apache.cxf.ext.logging.event.EventType; -import org.apache.cxf.ext.logging.event.LogEvent; -import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; -import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; -import org.apache.cxf.jaxrs.client.WebClient; -import org.junit.Assert; -import org.junit.Test; - -public class RESTLoggingTest { - - private static final String SERVICE_URI = "http://localhost:5679/testrest"; - private static final String SERVICE_URI_BINARY = "http://localhost:5680/testrest"; - - @Test - public void testSlf4j() throws IOException { - LoggingFeature loggingFeature = new LoggingFeature(); - Server server = createService(loggingFeature); - server.start(); - WebClient client = createClient(loggingFeature); - String result = client.get(String.class); - server.destroy(); - Assert.assertEquals("test1", result); - } - - @Test - public void testBinary() throws IOException { - LoggingFeature loggingFeature = new LoggingFeature(); - TestEventSender sender = new TestEventSender(); - loggingFeature.setSender(sender); - Server server = createServiceBinary(loggingFeature); - server.start(); - WebClient client = createClientBinary(loggingFeature); - client.get(InputStream.class).close(); - loggingFeature.setLogBinary(true); - client.get(InputStream.class).close(); - server.destroy(); - - assertLogged(sender.getEvents().get(0)); - assertLogged(sender.getEvents().get(1)); - assertNotLogged(sender.getEvents().get(2)); - assertNotLogged(sender.getEvents().get(3)); - - assertLogged(sender.getEvents().get(4)); - assertLogged(sender.getEvents().get(5)); - assertLogged(sender.getEvents().get(6)); - assertLogged(sender.getEvents().get(7)); - } - - private void assertLogged(LogEvent event) { - Assert.assertNotEquals(AbstractLoggingInterceptor.CONTENT_SUPPRESSED, event.getPayload()); - } - - private void assertNotLogged(LogEvent event) { - Assert.assertEquals(AbstractLoggingInterceptor.CONTENT_SUPPRESSED, event.getPayload()); - } - - private WebClient createClient(LoggingFeature loggingFeature) { - JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); - bean.setAddress(SERVICE_URI + "/test1"); - bean.setFeatures(Collections.singletonList(loggingFeature)); - return bean.createWebClient(); - } - - private Server createService(LoggingFeature loggingFeature) { - JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean(); - factory.setAddress(SERVICE_URI); - factory.setFeatures(Collections.singletonList(loggingFeature)); - factory.setServiceBean(new TestServiceRest()); - return factory.create(); - } - - private WebClient createClientBinary(LoggingFeature loggingFeature) { - JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); - bean.setAddress(SERVICE_URI_BINARY + "/test1"); - bean.setFeatures(Collections.singletonList(loggingFeature)); - return bean.createWebClient(); - } - - private Server createServiceBinary(LoggingFeature loggingFeature) { - JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean(); - factory.setAddress(SERVICE_URI_BINARY); - factory.setFeatures(Collections.singletonList(loggingFeature)); - factory.setServiceBean(new TestServiceRestBinary()); - return factory.create(); - } - - @Test - public void testEvents() throws MalformedURLException { - LoggingFeature loggingFeature = new LoggingFeature(); - loggingFeature.setLogBinary(true); - TestEventSender sender = new TestEventSender(); - loggingFeature.setSender(sender); - Server server = createService(loggingFeature); - server.start(); - WebClient client = createClient(loggingFeature); - String result = client.get(String.class); - Assert.assertEquals("test1", result); - server.destroy(); - List<LogEvent> events = sender.getEvents(); - Assert.assertEquals(4, events.size()); - checkRequestOut(events.get(0)); - checkRequestIn(events.get(1)); - checkResponseOut(events.get(2)); - checkResponseIn(events.get(3)); - } - - private void checkRequestOut(LogEvent requestOut) { - Assert.assertEquals(SERVICE_URI + "/test1", requestOut.getAddress()); - Assert.assertNull(requestOut.getContentType()); - Assert.assertEquals(EventType.REQ_OUT, requestOut.getType()); - Assert.assertNull(requestOut.getEncoding()); - Assert.assertNotNull(requestOut.getExchangeId()); - Assert.assertEquals("GET", requestOut.getHttpMethod()); - Assert.assertNotNull(requestOut.getMessageId()); - Assert.assertEquals("", requestOut.getPayload()); - } - - private void checkRequestIn(LogEvent requestIn) { - Assert.assertEquals(SERVICE_URI + "/test1", requestIn.getAddress()); - Assert.assertNull(requestIn.getContentType()); - Assert.assertEquals(EventType.REQ_IN, requestIn.getType()); - Assert.assertNull(requestIn.getEncoding()); - Assert.assertNotNull(requestIn.getExchangeId()); - Assert.assertEquals("GET", requestIn.getHttpMethod()); - Assert.assertNotNull(requestIn.getMessageId()); - Assert.assertEquals("", requestIn.getPayload()); - } - - private void checkResponseOut(LogEvent responseOut) { - // Not yet available - Assert.assertNull(responseOut.getAddress()); - Assert.assertEquals("application/octet-stream", responseOut.getContentType()); - Assert.assertEquals(EventType.RESP_OUT, responseOut.getType()); - Assert.assertNull(responseOut.getEncoding()); - Assert.assertNotNull(responseOut.getExchangeId()); - - // Not yet available - Assert.assertNull(responseOut.getHttpMethod()); - Assert.assertNotNull(responseOut.getMessageId()); - Assert.assertEquals("test1", responseOut.getPayload()); - } - - private void checkResponseIn(LogEvent responseIn) { - // Not yet available - Assert.assertNull(responseIn.getAddress()); - Assert.assertEquals("application/octet-stream", responseIn.getContentType()); - Assert.assertEquals(EventType.RESP_IN, responseIn.getType()); - Assert.assertEquals("ISO-8859-1", responseIn.getEncoding()); - Assert.assertNotNull(responseIn.getExchangeId()); - - // Not yet available - Assert.assertNull(responseIn.getHttpMethod()); - Assert.assertNotNull(responseIn.getMessageId()); - Assert.assertEquals("test1", responseIn.getPayload()); - } - - -} http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/SOAPLoggingTest.java ---------------------------------------------------------------------- diff --git a/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/SOAPLoggingTest.java b/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/SOAPLoggingTest.java deleted file mode 100644 index f2af1e8..0000000 --- a/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/SOAPLoggingTest.java +++ /dev/null @@ -1,148 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.ext.logging; - -import java.net.MalformedURLException; -import java.nio.charset.StandardCharsets; -import java.util.Collections; -import java.util.List; - -import javax.jws.WebService; -import javax.xml.ws.Endpoint; - -import org.apache.cxf.ext.logging.event.EventType; -import org.apache.cxf.ext.logging.event.LogEvent; -import org.apache.cxf.feature.Feature; -import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; -import org.junit.Assert; -import org.junit.Test; - -public class SOAPLoggingTest { - - private static final String SERVICE_URI = "http://localhost:5678/test"; - - @WebService(endpointInterface = "org.apache.cxf.ext.logging.TestService") - public final class TestServiceImplementation implements TestService { - @Override - public String echo(String msg) { - return msg; - } - } - - @Test - public void testSlf4j() throws MalformedURLException { - TestService serviceImpl = new TestServiceImplementation(); - LoggingFeature loggingFeature = new LoggingFeature(); - loggingFeature.setPrettyLogging(true); - // Setting the limit should omit parts of the body but the result should still be well formed xml - loggingFeature.setLimit(140); - Endpoint ep = Endpoint.publish(SERVICE_URI, serviceImpl, loggingFeature); - TestService client = createTestClient(loggingFeature); - client.echo("test"); - ep.stop(); - } - - @Test - public void testEvents() throws MalformedURLException { - TestService serviceImpl = new TestServiceImplementation(); - LoggingFeature loggingFeature = new LoggingFeature(); - TestEventSender sender = new TestEventSender(); - loggingFeature.setSender(sender); - Endpoint ep = Endpoint.publish(SERVICE_URI, serviceImpl, loggingFeature); - TestService client = createTestClient(loggingFeature); - client.echo("test"); - ep.stop(); - - List<LogEvent> events = sender.getEvents(); - Assert.assertEquals(4, events.size()); - checkRequestOut(events.get(0)); - checkRequestIn(events.get(1)); - checkResponseOut(events.get(2)); - checkResponseIn(events.get(3)); - } - - private void checkRequestOut(LogEvent requestOut) { - Assert.assertEquals(SERVICE_URI, requestOut.getAddress()); - Assert.assertEquals("text/xml", requestOut.getContentType()); - Assert.assertEquals(EventType.REQ_OUT, requestOut.getType()); - Assert.assertEquals(StandardCharsets.UTF_8.name(), requestOut.getEncoding()); - Assert.assertNotNull(requestOut.getExchangeId()); - Assert.assertEquals("POST", requestOut.getHttpMethod()); - Assert.assertNotNull(requestOut.getMessageId()); - Assert.assertTrue(requestOut.getPayload().contains("<arg0>test</arg0>")); - Assert.assertEquals("TestServicePort", requestOut.getPortName().getLocalPart()); - Assert.assertEquals("TestService", requestOut.getPortTypeName().getLocalPart()); - Assert.assertEquals("TestServiceService", requestOut.getServiceName().getLocalPart()); - } - - private void checkRequestIn(LogEvent requestIn) { - Assert.assertEquals(SERVICE_URI, requestIn.getAddress()); - Assert.assertEquals("text/xml; charset=UTF-8", requestIn.getContentType()); - Assert.assertEquals(EventType.REQ_IN, requestIn.getType()); - Assert.assertEquals(StandardCharsets.UTF_8.name(), requestIn.getEncoding()); - Assert.assertNotNull(requestIn.getExchangeId()); - Assert.assertEquals("POST", requestIn.getHttpMethod()); - Assert.assertNotNull(requestIn.getMessageId()); - Assert.assertTrue(requestIn.getPayload().contains("<arg0>test</arg0>")); - Assert.assertEquals("TestServiceImplementationPort", requestIn.getPortName().getLocalPart()); - Assert.assertEquals("TestService", requestIn.getPortTypeName().getLocalPart()); - Assert.assertEquals("TestServiceImplementationService", requestIn.getServiceName().getLocalPart()); - } - - private void checkResponseOut(LogEvent responseOut) { - // Not yet available - Assert.assertNull(responseOut.getAddress()); - Assert.assertEquals("text/xml", responseOut.getContentType()); - Assert.assertEquals(EventType.RESP_OUT, responseOut.getType()); - Assert.assertEquals(StandardCharsets.UTF_8.name(), responseOut.getEncoding()); - Assert.assertNotNull(responseOut.getExchangeId()); - - // Not yet available - Assert.assertNull(responseOut.getHttpMethod()); - Assert.assertNotNull(responseOut.getMessageId()); - Assert.assertTrue(responseOut.getPayload().contains("<return>test</return>")); - Assert.assertEquals("TestServiceImplementationPort", responseOut.getPortName().getLocalPart()); - Assert.assertEquals("TestService", responseOut.getPortTypeName().getLocalPart()); - Assert.assertEquals("TestServiceImplementationService", responseOut.getServiceName().getLocalPart()); - } - - private void checkResponseIn(LogEvent responseIn) { - Assert.assertNull(responseIn.getAddress()); - Assert.assertEquals("text/xml;charset=utf-8", responseIn.getContentType().toLowerCase().replace(" ", "")); - Assert.assertEquals(EventType.RESP_IN, responseIn.getType()); - Assert.assertEquals(StandardCharsets.UTF_8.name(), responseIn.getEncoding()); - Assert.assertNotNull(responseIn.getExchangeId()); - - // Not yet available - Assert.assertNull(responseIn.getHttpMethod()); - Assert.assertNotNull(responseIn.getMessageId()); - Assert.assertTrue(responseIn.getPayload().contains("<return>test</return>")); - Assert.assertEquals("TestServicePort", responseIn.getPortName().getLocalPart()); - Assert.assertEquals("TestService", responseIn.getPortTypeName().getLocalPart()); - Assert.assertEquals("TestServiceService", responseIn.getServiceName().getLocalPart()); - } - - private TestService createTestClient(Feature feature) throws MalformedURLException { - JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); - factory.setAddress(SERVICE_URI); - factory.setFeatures(Collections.singletonList(feature)); - return factory.create(TestService.class); - } - -} http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/TestEventSender.java ---------------------------------------------------------------------- diff --git a/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/TestEventSender.java b/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/TestEventSender.java deleted file mode 100644 index d268564..0000000 --- a/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/TestEventSender.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.ext.logging; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.cxf.ext.logging.event.LogEvent; -import org.apache.cxf.ext.logging.event.LogEventSender; - -final class TestEventSender implements LogEventSender { - private final List<LogEvent> events = new ArrayList<>(); - - @Override - public void send(LogEvent event) { - events.add(event); - } - - public List<LogEvent> getEvents() { - return events; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/TestService.java ---------------------------------------------------------------------- diff --git a/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/TestService.java b/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/TestService.java deleted file mode 100644 index ff5cd06..0000000 --- a/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/TestService.java +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.ext.logging; - -import javax.jws.WebService; - -@WebService -public interface TestService { - String echo(String msg); -} http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/TestServiceRest.java ---------------------------------------------------------------------- diff --git a/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/TestServiceRest.java b/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/TestServiceRest.java deleted file mode 100644 index 9ba323f..0000000 --- a/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/TestServiceRest.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.ext.logging; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; - -public class TestServiceRest { - @GET - @Path("{msg}") - public String echo(@PathParam("msg") String msg) { - return msg; - } - -} http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/TestServiceRestBinary.java ---------------------------------------------------------------------- diff --git a/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/TestServiceRestBinary.java b/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/TestServiceRestBinary.java deleted file mode 100644 index d7ac812..0000000 --- a/rt/features/logging/src/test/java/org/apache/cxf/ext/logging/TestServiceRestBinary.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.ext.logging; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - -public class TestServiceRestBinary { - @GET - @Path("test1") - @Produces(MediaType.APPLICATION_OCTET_STREAM) - public byte[] getBinary() { - return new byte[] {1, 2, 3, 4, 5, 6, 8, 9}; - } - -} http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/frontend/jaxrs/pom.xml ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxrs/pom.xml b/rt/frontend/jaxrs/pom.xml index 7f81332..acdb52a 100644 --- a/rt/frontend/jaxrs/pom.xml +++ b/rt/frontend/jaxrs/pom.xml @@ -125,6 +125,12 @@ </dependency> <dependency> <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-features-logging</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http-jetty</artifactId> <version>${project.version}</version> <scope>test</scope> http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java index 778770b..c4125ae 100644 --- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java +++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java @@ -41,7 +41,6 @@ import javax.ws.rs.core.MultivaluedMap; import org.apache.cxf.common.logging.LogUtils; import org.apache.cxf.common.util.StringUtils; import org.apache.cxf.helpers.IOUtils; -import org.apache.cxf.interceptor.LoggingInInterceptor; import org.apache.cxf.io.CachedOutputStream; import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition; @@ -177,7 +176,7 @@ public final class FormUtils { return; } String chain = PhaseInterceptorChain.getCurrentMessage().getInterceptorChain().toString(); - if (chain.contains(LoggingInInterceptor.class.getSimpleName())) { + if (chain.contains("LoggingInInterceptor")) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { writeMapToOutputStream(params, bos, enc, false); http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/frontend/jaxws/pom.xml ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxws/pom.xml b/rt/frontend/jaxws/pom.xml index efe11dc..3a20214 100644 --- a/rt/frontend/jaxws/pom.xml +++ b/rt/frontend/jaxws/pom.xml @@ -82,6 +82,12 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-features-logging</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>xml-resolver</groupId> <artifactId>xml-resolver</artifactId> </dependency> http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java index de5349b..2356ff7 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java @@ -43,12 +43,12 @@ import org.w3c.dom.Node; import org.apache.cxf.Bus; import org.apache.cxf.endpoint.Client; import org.apache.cxf.endpoint.Server; -import org.apache.cxf.feature.LoggingFeature; +import org.apache.cxf.ext.logging.LoggingFeature; +import org.apache.cxf.ext.logging.LoggingInInterceptor; +import org.apache.cxf.ext.logging.LoggingOutInterceptor; import org.apache.cxf.frontend.ClientProxy; import org.apache.cxf.frontend.ServerFactoryBean; import org.apache.cxf.interceptor.Interceptor; -import org.apache.cxf.interceptor.LoggingInInterceptor; -import org.apache.cxf.interceptor.LoggingOutInterceptor; import org.apache.cxf.jaxws.service.AddNumbersException; import org.apache.cxf.jaxws.service.AddNumbersSubException; import org.apache.cxf.jaxws.service.ArrayService; http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/SEIWithJAXBAnnoTest.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/SEIWithJAXBAnnoTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/SEIWithJAXBAnnoTest.java index 27537cd..f4b9aef 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/SEIWithJAXBAnnoTest.java +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/SEIWithJAXBAnnoTest.java @@ -26,8 +26,8 @@ import java.util.List; import javax.xml.ws.Endpoint; import org.apache.cxf.bus.spring.SpringBusFactory; +import org.apache.cxf.ext.logging.LoggingOutInterceptor; import org.apache.cxf.frontend.ClientProxy; -import org.apache.cxf.interceptor.LoggingOutInterceptor; import org.apache.cxf.jaxws.service.AddNumbers; import org.apache.cxf.jaxws.service.AddNumbersImpl; import org.junit.Test; http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/dispatch/DispatchTest.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/dispatch/DispatchTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/dispatch/DispatchTest.java index 599d19d..4601adc 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/dispatch/DispatchTest.java +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/dispatch/DispatchTest.java @@ -37,9 +37,9 @@ import org.apache.cxf.Bus; import org.apache.cxf.binding.soap.SoapMessage; import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor; import org.apache.cxf.bus.spring.SpringBusFactory; +import org.apache.cxf.ext.logging.LoggingInInterceptor; import org.apache.cxf.interceptor.Fault; import org.apache.cxf.interceptor.Interceptor; -import org.apache.cxf.interceptor.LoggingInInterceptor; import org.apache.cxf.jaxws.AbstractJaxWsTest; import org.apache.cxf.jaxws.DispatchImpl; import org.apache.cxf.jaxws.MessageReplayObserver; http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/dispatch/bus-dispatch.xml ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/dispatch/bus-dispatch.xml b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/dispatch/bus-dispatch.xml index 3715bf4..4885b85 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/dispatch/bus-dispatch.xml +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/dispatch/bus-dispatch.xml @@ -24,7 +24,7 @@ --> <jaxws:client name="{http://apache.org/hello_world_soap_http}SoapPort" createdFromAPI="true"> <jaxws:inInterceptors> - <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/> + <bean class="org.apache.cxf.ext.logging.LoggingInInterceptor"/> </jaxws:inInterceptors> </jaxws:client> </beans> http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainInvokerTest.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainInvokerTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainInvokerTest.java index ff374d2..f5ed7b8 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainInvokerTest.java +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/HandlerChainInvokerTest.java @@ -94,7 +94,6 @@ public class HandlerChainInvokerTest extends Assert { } - @SuppressWarnings("rawtypes") @Test public void testInvokeEmptyHandlerChain() { invoker = new HandlerChainInvoker(new ArrayList<>()); http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/header/HeaderClientServerTest.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/header/HeaderClientServerTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/header/HeaderClientServerTest.java index 0786900..db665f6 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/header/HeaderClientServerTest.java +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/header/HeaderClientServerTest.java @@ -29,8 +29,6 @@ import javax.xml.ws.Endpoint; import javax.xml.ws.Holder; import org.apache.cxf.BusFactory; -import org.apache.cxf.interceptor.LoggingInInterceptor; -import org.apache.cxf.interceptor.LoggingOutInterceptor; import org.apache.cxf.jaxws.AbstractJaxWsTest; import org.apache.cxf.jaxws.EndpointImpl; import org.apache.header_test.SOAPHeaderService; @@ -75,14 +73,10 @@ public class HeaderClientServerTest extends AbstractJaxWsTest { Object implementor = new TestHeaderImpl(); String address = "http://localhost:9104/SoapHeaderContext/SoapHeaderPort"; endpoint = (EndpointImpl) Endpoint.publish(address, implementor); - endpoint.getServer().getEndpoint().getInInterceptors().add(new LoggingInInterceptor()); - endpoint.getServer().getEndpoint().getOutInterceptors().add(new LoggingOutInterceptor()); implementor = new TestRPCHeaderImpl(); address = "http://localhost:9104/SoapHeaderRPCContext/SoapHeaderRPCPort"; rpcEndpoint = (EndpointImpl)Endpoint.publish(address, implementor); - rpcEndpoint.getServer().getEndpoint().getInInterceptors().add(new LoggingInInterceptor()); - rpcEndpoint.getServer().getEndpoint().getOutInterceptors().add(new LoggingOutInterceptor()); } @After http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/header/ProviderHeaderClientServerTest.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/header/ProviderHeaderClientServerTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/header/ProviderHeaderClientServerTest.java index 4d58918..74aa024 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/header/ProviderHeaderClientServerTest.java +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/header/ProviderHeaderClientServerTest.java @@ -32,10 +32,7 @@ import javax.xml.ws.Endpoint; import javax.xml.ws.Service; import org.apache.cxf.BusFactory; -import org.apache.cxf.interceptor.LoggingInInterceptor; -import org.apache.cxf.interceptor.LoggingOutInterceptor; import org.apache.cxf.jaxws.AbstractJaxWsTest; -import org.apache.cxf.jaxws.EndpointImpl; import org.apache.header_test.rpc.SOAPRPCHeaderService; import org.junit.Before; import org.junit.Test; @@ -48,9 +45,7 @@ public class ProviderHeaderClientServerTest extends AbstractJaxWsTest { TestRPCHeaderProvider implementor = new TestRPCHeaderProvider(); String address = "http://localhost:9104/SoapHeaderRPCContext/SoapHeaderRPCPort"; - EndpointImpl e = (EndpointImpl)Endpoint.publish(address, implementor); - e.getServer().getEndpoint().getInInterceptors().add(new LoggingInInterceptor()); - e.getServer().getEndpoint().getOutInterceptors().add(new LoggingOutInterceptor()); + Endpoint.publish(address, implementor); } @Test http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/logging/SOAPLoggingTest.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/logging/SOAPLoggingTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/logging/SOAPLoggingTest.java new file mode 100644 index 0000000..6028f21 --- /dev/null +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/logging/SOAPLoggingTest.java @@ -0,0 +1,178 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.jaxws.logging; + +import java.net.MalformedURLException; +import java.nio.charset.StandardCharsets; +import java.util.Collections; +import java.util.List; + +import javax.jws.WebService; +import javax.xml.namespace.QName; +import javax.xml.ws.Endpoint; + +import org.apache.cxf.binding.Binding; +import org.apache.cxf.binding.soap.SoapBinding; +import org.apache.cxf.ext.logging.LoggingFeature; +import org.apache.cxf.ext.logging.event.DefaultLogEventMapper; +import org.apache.cxf.ext.logging.event.EventType; +import org.apache.cxf.ext.logging.event.LogEvent; +import org.apache.cxf.feature.Feature; +import org.apache.cxf.jaxws.AbstractJaxWsTest; +import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; +import org.apache.cxf.message.ExchangeImpl; +import org.apache.cxf.message.Message; +import org.apache.cxf.message.MessageImpl; +import org.apache.cxf.service.model.BindingInfo; +import org.apache.cxf.service.model.BindingOperationInfo; +import org.apache.cxf.service.model.OperationInfo; +import org.apache.cxf.service.model.ServiceInfo; + +import org.junit.Assert; +import org.junit.Test; + +public class SOAPLoggingTest extends AbstractJaxWsTest { + + private static final String SERVICE_URI = "http://localhost:5678/test"; + + @WebService(endpointInterface = "org.apache.cxf.jaxws.logging.TestService") + public final class TestServiceImplementation implements TestService { + @Override + public String echo(String msg) { + return msg; + } + } + + + @Test + public void testSoap() { + DefaultLogEventMapper mapper = new DefaultLogEventMapper(); + Message message = new MessageImpl(); + ExchangeImpl exchange = new ExchangeImpl(); + ServiceInfo service = new ServiceInfo(); + BindingInfo info = new BindingInfo(service, "bindingId"); + SoapBinding value = new SoapBinding(info); + exchange.put(Binding.class, value); + OperationInfo opInfo = new OperationInfo(); + opInfo.setName(new QName("http://my", "Operation")); + BindingOperationInfo boi = new BindingOperationInfo(info, opInfo); + exchange.put(BindingOperationInfo.class, boi); + message.setExchange(exchange); + LogEvent event = mapper.map(message); + Assert.assertEquals("{http://my}Operation", event.getOperationName()); + } + @Test + public void testSlf4j() throws MalformedURLException { + TestService serviceImpl = new TestServiceImplementation(); + LoggingFeature loggingFeature = new LoggingFeature(); + loggingFeature.setPrettyLogging(true); + // Setting the limit should omit parts of the body but the result should still be well formed xml + loggingFeature.setLimit(140); + Endpoint ep = Endpoint.publish(SERVICE_URI, serviceImpl, loggingFeature); + TestService client = createTestClient(loggingFeature); + client.echo("test"); + ep.stop(); + } + + @Test + public void testEvents() throws MalformedURLException { + TestService serviceImpl = new TestServiceImplementation(); + LoggingFeature loggingFeature = new LoggingFeature(); + TestEventSender sender = new TestEventSender(); + loggingFeature.setSender(sender); + Endpoint ep = Endpoint.publish(SERVICE_URI, serviceImpl, loggingFeature); + TestService client = createTestClient(loggingFeature); + client.echo("test"); + ep.stop(); + + List<LogEvent> events = sender.getEvents(); + Assert.assertEquals(4, events.size()); + checkRequestOut(events.get(0)); + checkRequestIn(events.get(1)); + checkResponseOut(events.get(2)); + checkResponseIn(events.get(3)); + } + + private void checkRequestOut(LogEvent requestOut) { + Assert.assertEquals(SERVICE_URI, requestOut.getAddress()); + Assert.assertEquals("text/xml", requestOut.getContentType()); + Assert.assertEquals(EventType.REQ_OUT, requestOut.getType()); + Assert.assertEquals(StandardCharsets.UTF_8.name(), requestOut.getEncoding()); + Assert.assertNotNull(requestOut.getExchangeId()); + Assert.assertNotNull(requestOut.getMessageId()); + Assert.assertTrue(requestOut.getPayload().contains("<arg0>test</arg0>")); + Assert.assertEquals("TestServicePort", requestOut.getPortName().getLocalPart()); + Assert.assertEquals("TestService", requestOut.getPortTypeName().getLocalPart()); + Assert.assertEquals("TestServiceService", requestOut.getServiceName().getLocalPart()); + } + + private void checkRequestIn(LogEvent requestIn) { + Assert.assertEquals(SERVICE_URI, requestIn.getAddress()); + Assert.assertTrue(requestIn.getContentType(), requestIn.getContentType().contains("text/xml")); + Assert.assertEquals(EventType.REQ_IN, requestIn.getType()); + Assert.assertEquals(StandardCharsets.UTF_8.name(), requestIn.getEncoding()); + Assert.assertNotNull(requestIn.getExchangeId()); + Assert.assertNotNull(requestIn.getMessageId()); + Assert.assertTrue(requestIn.getPayload().contains("<arg0>test</arg0>")); + Assert.assertEquals("TestServiceImplementationPort", requestIn.getPortName().getLocalPart()); + Assert.assertEquals("TestService", requestIn.getPortTypeName().getLocalPart()); + Assert.assertEquals("TestServiceImplementationService", requestIn.getServiceName().getLocalPart()); + } + + private void checkResponseOut(LogEvent responseOut) { + // Not yet available + Assert.assertNull(responseOut.getAddress()); + Assert.assertEquals("text/xml", responseOut.getContentType()); + Assert.assertEquals(EventType.RESP_OUT, responseOut.getType()); + Assert.assertEquals(StandardCharsets.UTF_8.name(), responseOut.getEncoding()); + Assert.assertNotNull(responseOut.getExchangeId()); + + // Not yet available + Assert.assertNull(responseOut.getHttpMethod()); + Assert.assertNotNull(responseOut.getMessageId()); + Assert.assertTrue(responseOut.getPayload().contains("<return>test</return>")); + Assert.assertEquals("TestServiceImplementationPort", responseOut.getPortName().getLocalPart()); + Assert.assertEquals("TestService", responseOut.getPortTypeName().getLocalPart()); + Assert.assertEquals("TestServiceImplementationService", responseOut.getServiceName().getLocalPart()); + } + + private void checkResponseIn(LogEvent responseIn) { + Assert.assertNull(responseIn.getAddress()); + Assert.assertTrue(responseIn.getContentType(), responseIn.getContentType().contains("text/xml")); + Assert.assertEquals(EventType.RESP_IN, responseIn.getType()); + Assert.assertEquals(StandardCharsets.UTF_8.name(), responseIn.getEncoding()); + Assert.assertNotNull(responseIn.getExchangeId()); + + // Not yet available + Assert.assertNull(responseIn.getHttpMethod()); + Assert.assertNotNull(responseIn.getMessageId()); + Assert.assertTrue(responseIn.getPayload().contains("<return>test</return>")); + Assert.assertEquals("TestServicePort", responseIn.getPortName().getLocalPart()); + Assert.assertEquals("TestService", responseIn.getPortTypeName().getLocalPart()); + Assert.assertEquals("TestServiceService", responseIn.getServiceName().getLocalPart()); + } + + private TestService createTestClient(Feature feature) throws MalformedURLException { + JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); + factory.setAddress(SERVICE_URI); + factory.setFeatures(Collections.singletonList(feature)); + return factory.create(TestService.class); + } + +} http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/logging/TestEventSender.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/logging/TestEventSender.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/logging/TestEventSender.java new file mode 100644 index 0000000..02d69aa --- /dev/null +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/logging/TestEventSender.java @@ -0,0 +1,38 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.jaxws.logging; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.cxf.ext.logging.event.LogEvent; +import org.apache.cxf.ext.logging.event.LogEventSender; + +final class TestEventSender implements LogEventSender { + private final List<LogEvent> events = new ArrayList<>(); + + @Override + public void send(LogEvent event) { + events.add(event); + } + + public List<LogEvent> getEvents() { + return events; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/logging/TestService.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/logging/TestService.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/logging/TestService.java new file mode 100644 index 0000000..66b1806 --- /dev/null +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/logging/TestService.java @@ -0,0 +1,26 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.jaxws.logging; + +import javax.jws.WebService; + +@WebService +public interface TestService { + String echo(String msg); +} http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/SpringBeansTest.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/SpringBeansTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/SpringBeansTest.java index 0fb6352..3bc2bf5 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/SpringBeansTest.java +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/SpringBeansTest.java @@ -42,10 +42,10 @@ import org.apache.cxf.databinding.source.SourceDataBinding; import org.apache.cxf.endpoint.Client; import org.apache.cxf.endpoint.ClientImpl; import org.apache.cxf.endpoint.NullConduitSelector; +import org.apache.cxf.ext.logging.LoggingInInterceptor; +import org.apache.cxf.ext.logging.LoggingOutInterceptor; import org.apache.cxf.frontend.ClientProxy; import org.apache.cxf.interceptor.Interceptor; -import org.apache.cxf.interceptor.LoggingInInterceptor; -import org.apache.cxf.interceptor.LoggingOutInterceptor; import org.apache.cxf.jaxb.JAXBDataBinding; import org.apache.cxf.jaxws.EndpointImpl; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/clients.xml ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/clients.xml b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/clients.xml index f835719..1c8cdb6 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/clients.xml +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/clients.xml @@ -39,11 +39,11 @@ <bean id="saajOut" class="org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor"/> <jaxws:client xmlns:s="http://apache.org/hello_world_soap_http" id="client1" serviceClass="org.apache.hello_world_soap_http.Greeter" address="http://localhost:9000/foo" serviceName="s:SOAPService"> <jaxws:inInterceptors> - <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/> + <bean class="org.apache.cxf.ext.logging.LoggingInInterceptor"/> <ref bean="saajIn"/> </jaxws:inInterceptors> <jaxws:outInterceptors> - <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/> + <bean class="org.apache.cxf.ext.logging.LoggingOutInterceptor"/> <ref bean="saajOut"/> </jaxws:outInterceptors> <jaxws:conduitSelector> @@ -61,7 +61,7 @@ </jaxws:client> <jaxws:client xmlns:s="http://apache.org/hello_world_soap_http" name="{http://apache.org/hello_world_soap_http}GreeterPort" serviceClass="org.apache.hello_world_soap_http.Greeter" serviceName="s:SOAPService" endpointName="s:SoapPort" address="http://localhost:8080/simpleWithAddress" wsdlLocation="wsdl/hello_world.wsdl" createdFromAPI="true"> <jaxws:inInterceptors> - <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/> + <bean class="org.apache.cxf.ext.logging.LoggingInInterceptor"/> </jaxws:inInterceptors> </jaxws:client> <!-- this configures the default bus "cxf" --> http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/endpoints.xml ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/endpoints.xml b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/endpoints.xml index 54b6279..1ec5880 100644 --- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/endpoints.xml +++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/endpoints.xml @@ -65,12 +65,12 @@ <bean id="saajOut" class="org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor"/> <jaxws:endpoint id="epWithInterceptors" implementor="org.apache.cxf.jaxws.service.Hello" address="http://localhost:8080/test1"> <jaxws:inInterceptors> - <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/> + <bean class="org.apache.cxf.ext.logging.LoggingInInterceptor"/> <ref bean="saajIn"/> </jaxws:inInterceptors> <jaxws:outInterceptors> <ref bean="saajOut"/> - <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/> + <bean class="org.apache.cxf.ext.logging.LoggingOutInterceptor"/> </jaxws:outInterceptors> </jaxws:endpoint> <jaxws:endpoint id="epWithDataBinding" implementor="org.apache.cxf.jaxws.service.Hello" address="http://localhost:8080/test2"> http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/frontend/simple/pom.xml ---------------------------------------------------------------------- diff --git a/rt/frontend/simple/pom.xml b/rt/frontend/simple/pom.xml index 89b5214..bb63f82 100644 --- a/rt/frontend/simple/pom.xml +++ b/rt/frontend/simple/pom.xml @@ -96,6 +96,12 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-features-logging</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>xml-resolver</groupId> <artifactId>xml-resolver</artifactId> <scope>test</scope> http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/SpringBeansTest.java ---------------------------------------------------------------------- diff --git a/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/SpringBeansTest.java b/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/SpringBeansTest.java index 40c1493..f72d74a 100644 --- a/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/SpringBeansTest.java +++ b/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/SpringBeansTest.java @@ -29,12 +29,12 @@ import org.apache.cxf.configuration.security.AuthorizationPolicy; import org.apache.cxf.configuration.spring.AbstractFactoryBeanDefinitionParser; import org.apache.cxf.endpoint.Client; import org.apache.cxf.endpoint.NullConduitSelector; +import org.apache.cxf.ext.logging.LoggingInInterceptor; +import org.apache.cxf.ext.logging.LoggingOutInterceptor; import org.apache.cxf.frontend.ClientProxy; import org.apache.cxf.frontend.ClientProxyFactoryBean; import org.apache.cxf.frontend.ServerFactoryBean; import org.apache.cxf.interceptor.Interceptor; -import org.apache.cxf.interceptor.LoggingInInterceptor; -import org.apache.cxf.interceptor.LoggingOutInterceptor; import org.apache.cxf.message.Message; import org.apache.cxf.service.factory.HelloService; import org.apache.cxf.service.factory.HelloServiceImpl; http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/clients.xml ---------------------------------------------------------------------- diff --git a/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/clients.xml b/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/clients.xml index c4a412c..d0ab66d 100644 --- a/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/clients.xml +++ b/rt/frontend/simple/src/test/java/org/apache/cxf/frontend/spring/clients.xml @@ -36,11 +36,11 @@ <soap:soapBinding mtomEnabled="true" version="1.2"/> </simple:binding> <simple:inInterceptors> - <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/> + <bean class="org.apache.cxf.ext.logging.LoggingInInterceptor"/> <ref bean="saajIn"/> </simple:inInterceptors> <simple:outInterceptors> - <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/> + <bean class="org.apache.cxf.ext.logging.LoggingOutInterceptor"/> <ref bean="saajOut"/> </simple:outInterceptors> <simple:conduitSelector> http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/RountripTest.java ---------------------------------------------------------------------- diff --git a/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/RountripTest.java b/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/RountripTest.java index 45d6634..c0f3661 100644 --- a/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/RountripTest.java +++ b/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/RountripTest.java @@ -20,13 +20,9 @@ package org.apache.cxf.service.factory; import javax.xml.namespace.QName; -import org.apache.cxf.endpoint.ClientImpl; import org.apache.cxf.frontend.ClientFactoryBean; -import org.apache.cxf.frontend.ClientProxy; import org.apache.cxf.frontend.ClientProxyFactoryBean; import org.apache.cxf.frontend.ServerFactoryBean; -import org.apache.cxf.interceptor.LoggingInInterceptor; -import org.apache.cxf.interceptor.LoggingOutInterceptor; import org.apache.hello_world_doc_lit.Greeter; import org.apache.hello_world_doc_lit.GreeterImplDoc; import org.junit.Test; @@ -50,14 +46,9 @@ public class RountripTest extends AbstractSimpleFrontendTest { clientBean.setTransportId("http://schemas.xmlsoap.org/soap/http"); clientBean.setServiceClass(HelloService.class); clientBean.setBus(getBus()); - clientBean.getInInterceptors().add(new LoggingInInterceptor()); HelloService client = (HelloService) proxyFactory.create(); - ClientImpl c = (ClientImpl)ClientProxy.getClient(client); - c.getOutInterceptors().add(new LoggingOutInterceptor()); - c.getInInterceptors().add(new LoggingInInterceptor()); - assertEquals("hello", client.sayHello()); assertEquals("hello", client.echo("hello")); } http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/rs/client/pom.xml ---------------------------------------------------------------------- diff --git a/rt/rs/client/pom.xml b/rt/rs/client/pom.xml index 189723c..ec6e4ab 100644 --- a/rt/rs/client/pom.xml +++ b/rt/rs/client/pom.xml @@ -69,6 +69,12 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-features-logging</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/cache/CacheControlClientReaderInterceptor.java ---------------------------------------------------------------------- diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/cache/CacheControlClientReaderInterceptor.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/cache/CacheControlClientReaderInterceptor.java index 6f60397..629cb84 100644 --- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/cache/CacheControlClientReaderInterceptor.java +++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/cache/CacheControlClientReaderInterceptor.java @@ -51,7 +51,7 @@ public class CacheControlClientReaderInterceptor implements ReaderInterceptor { private boolean cacheResponseInputStream; public CacheControlClientReaderInterceptor(final Cache<Key, Entry> cache) { - setCache(cache); + this.cache = cache; } public CacheControlClientReaderInterceptor() { http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/cache/CacheControlClientRequestFilter.java ---------------------------------------------------------------------- diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/cache/CacheControlClientRequestFilter.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/cache/CacheControlClientRequestFilter.java index e3f103d..9542db1 100644 --- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/cache/CacheControlClientRequestFilter.java +++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/cache/CacheControlClientRequestFilter.java @@ -41,7 +41,7 @@ public class CacheControlClientRequestFilter implements ClientRequestFilter { private Cache<Key, Entry> cache; public CacheControlClientRequestFilter(final Cache<Key, Entry> cache) { - setCache(cache); + this.cache = cache; } public CacheControlClientRequestFilter() { http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/logging/RESTLoggingTest.java ---------------------------------------------------------------------- diff --git a/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/logging/RESTLoggingTest.java b/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/logging/RESTLoggingTest.java new file mode 100644 index 0000000..3b10d4c --- /dev/null +++ b/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/logging/RESTLoggingTest.java @@ -0,0 +1,191 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.jaxrs.client.logging; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.util.Collections; +import java.util.List; + +import org.apache.cxf.endpoint.Server; +import org.apache.cxf.ext.logging.AbstractLoggingInterceptor; +import org.apache.cxf.ext.logging.LoggingFeature; +import org.apache.cxf.ext.logging.event.EventType; +import org.apache.cxf.ext.logging.event.LogEvent; +import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; +import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; +import org.apache.cxf.jaxrs.client.WebClient; +import org.apache.cxf.transport.local.LocalTransportFactory; + +import org.junit.Assert; +import org.junit.Test; + +public class RESTLoggingTest { + + private static final String SERVICE_URI = "local://testrest"; + private static final String SERVICE_URI_BINARY = "local://testrestbin"; + + @Test + public void testSlf4j() throws IOException { + LoggingFeature loggingFeature = new LoggingFeature(); + Server server = createService(loggingFeature); + server.start(); + WebClient client = createClient(loggingFeature); + String result = client.get(String.class); + server.destroy(); + Assert.assertEquals("test1", result); + } + + @Test + public void testBinary() throws IOException { + LoggingFeature loggingFeature = new LoggingFeature(); + TestEventSender sender = new TestEventSender(); + loggingFeature.setSender(sender); + Server server = createServiceBinary(loggingFeature); + server.start(); + WebClient client = createClientBinary(loggingFeature); + client.get(InputStream.class).close(); + loggingFeature.setLogBinary(true); + client.get(InputStream.class).close(); + server.destroy(); + + assertLogged(sender.getEvents().get(0)); + assertLogged(sender.getEvents().get(1)); + assertNotLogged(sender.getEvents().get(2)); + assertNotLogged(sender.getEvents().get(3)); + + assertLogged(sender.getEvents().get(4)); + assertLogged(sender.getEvents().get(5)); + assertLogged(sender.getEvents().get(6)); + assertLogged(sender.getEvents().get(7)); + } + + private void assertLogged(LogEvent event) { + Assert.assertNotEquals(AbstractLoggingInterceptor.CONTENT_SUPPRESSED, event.getPayload()); + } + + private void assertNotLogged(LogEvent event) { + Assert.assertEquals(AbstractLoggingInterceptor.CONTENT_SUPPRESSED, event.getPayload()); + } + + private WebClient createClient(LoggingFeature loggingFeature) { + JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); + bean.setAddress(SERVICE_URI); + bean.setFeatures(Collections.singletonList(loggingFeature)); + bean.setTransportId(LocalTransportFactory.TRANSPORT_ID); + return bean.createWebClient().path("test1"); + } + + private Server createService(LoggingFeature loggingFeature) { + JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean(); + factory.setAddress(SERVICE_URI); + factory.setFeatures(Collections.singletonList(loggingFeature)); + factory.setServiceBean(new TestServiceRest()); + factory.setTransportId(LocalTransportFactory.TRANSPORT_ID); + return factory.create(); + } + + private WebClient createClientBinary(LoggingFeature loggingFeature) { + JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); + bean.setAddress(SERVICE_URI_BINARY); + bean.setFeatures(Collections.singletonList(loggingFeature)); + bean.setTransportId(LocalTransportFactory.TRANSPORT_ID); + return bean.createWebClient().path("test1"); + } + + private Server createServiceBinary(LoggingFeature loggingFeature) { + JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean(); + factory.setAddress(SERVICE_URI_BINARY); + factory.setFeatures(Collections.singletonList(loggingFeature)); + factory.setServiceBean(new TestServiceRestBinary()); + factory.setTransportId(LocalTransportFactory.TRANSPORT_ID); + return factory.create(); + } + + @Test + public void testEvents() throws MalformedURLException { + LoggingFeature loggingFeature = new LoggingFeature(); + loggingFeature.setLogBinary(true); + TestEventSender sender = new TestEventSender(); + loggingFeature.setSender(sender); + Server server = createService(loggingFeature); + server.start(); + WebClient client = createClient(loggingFeature); + String result = client.get(String.class); + Assert.assertEquals("test1", result); + server.destroy(); + List<LogEvent> events = sender.getEvents(); + Assert.assertEquals(4, events.size()); + checkRequestOut(events.get(0)); + checkRequestIn(events.get(1)); + checkResponseOut(events.get(2)); + checkResponseIn(events.get(3)); + } + + private void checkRequestOut(LogEvent requestOut) { + Assert.assertEquals(SERVICE_URI + "/test1", requestOut.getAddress()); + Assert.assertNull(requestOut.getContentType()); + Assert.assertEquals(EventType.REQ_OUT, requestOut.getType()); + Assert.assertNull(requestOut.getEncoding()); + Assert.assertNotNull(requestOut.getExchangeId()); + Assert.assertEquals("GET", requestOut.getHttpMethod()); + Assert.assertNotNull(requestOut.getMessageId()); + Assert.assertEquals("", requestOut.getPayload()); + } + + private void checkRequestIn(LogEvent requestIn) { + Assert.assertEquals(SERVICE_URI + "/test1", requestIn.getAddress()); + Assert.assertNull(requestIn.getContentType()); + Assert.assertEquals(EventType.REQ_IN, requestIn.getType()); + Assert.assertNull(requestIn.getEncoding()); + Assert.assertNotNull(requestIn.getExchangeId()); + Assert.assertEquals("GET", requestIn.getHttpMethod()); + Assert.assertNotNull(requestIn.getMessageId()); + } + + private void checkResponseOut(LogEvent responseOut) { + // Not yet available + Assert.assertNull(responseOut.getAddress()); + Assert.assertEquals("application/octet-stream", responseOut.getContentType()); + Assert.assertEquals(EventType.RESP_OUT, responseOut.getType()); + Assert.assertNull(responseOut.getEncoding()); + Assert.assertNotNull(responseOut.getExchangeId()); + + // Not yet available + Assert.assertNull(responseOut.getHttpMethod()); + Assert.assertNotNull(responseOut.getMessageId()); + Assert.assertEquals("test1", responseOut.getPayload()); + } + + private void checkResponseIn(LogEvent responseIn) { + // Not yet available + Assert.assertNull(responseIn.getAddress()); + Assert.assertEquals("application/octet-stream", responseIn.getContentType()); + Assert.assertEquals(EventType.RESP_IN, responseIn.getType()); + Assert.assertNotNull(responseIn.getExchangeId()); + + // Not yet available + Assert.assertNull(responseIn.getHttpMethod()); + Assert.assertNotNull(responseIn.getMessageId()); + Assert.assertEquals("test1", responseIn.getPayload()); + } + + +} http://git-wip-us.apache.org/repos/asf/cxf/blob/e1d95060/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/logging/TestEventSender.java ---------------------------------------------------------------------- diff --git a/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/logging/TestEventSender.java b/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/logging/TestEventSender.java new file mode 100644 index 0000000..95949a9 --- /dev/null +++ b/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/logging/TestEventSender.java @@ -0,0 +1,38 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.jaxrs.client.logging; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.cxf.ext.logging.event.LogEvent; +import org.apache.cxf.ext.logging.event.LogEventSender; + +final class TestEventSender implements LogEventSender { + private final List<LogEvent> events = new ArrayList<>(); + + @Override + public void send(LogEvent event) { + events.add(event); + } + + public List<LogEvent> getEvents() { + return events; + } +} \ No newline at end of file
