Author: mmao
Date: Thu Nov 8 23:48:19 2007
New Revision: 593444
URL: http://svn.apache.org/viewvc?rev=593444&view=rev
Log:
CXF-1186, CXF-1172
* WS-Addressing is working with the API approach
* Complete the system tests
* Logging interceptors more programmatic
Added:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingMessage.java
Modified:
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/addressing/WSAContextUtils.java
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_feature/WSAClientServerTest.java
Modified:
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/addressing/WSAContextUtils.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/addressing/WSAContextUtils.java?rev=593444&r1=593443&r2=593444&view=diff
==============================================================================
---
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/addressing/WSAContextUtils.java
(original)
+++
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/addressing/WSAContextUtils.java
Thu Nov 8 23:48:19 2007
@@ -60,7 +60,7 @@
*/
public static boolean retrieveUsingAddressing(Message message) {
Boolean override = (Boolean)message.get(USING_PROPERTY);
- return override != null && override.booleanValue();
+ return override == null || (override != null &&
override.booleanValue());
}
/**
Modified:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java?rev=593444&r1=593443&r2=593444&view=diff
==============================================================================
---
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java
(original)
+++
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingInInterceptor.java
Thu Nov 8 23:48:19 2007
@@ -37,16 +37,29 @@
public class LoggingInInterceptor extends AbstractPhaseInterceptor<Message> {
private static final Logger LOG =
LogUtils.getL7dLogger(LoggingInInterceptor.class);
+ private final LoggingMessage buffer = new LoggingMessage("Inbound
Message\n----------------------------");
private int limit = 100 * 1024;
+ private boolean enabled;
+
public LoggingInInterceptor() {
super(Phase.RECEIVE);
}
public LoggingInInterceptor(int lim) {
- super(Phase.RECEIVE);
+ this();
limit = lim;
}
+
+ public LoggingInInterceptor(boolean b) {
+ this();
+ this.enabled = b;
+ }
+
+ public LoggingMessage getBuffer() {
+ return this.buffer;
+ }
+
public void setLimit(int lim) {
limit = lim;
}
@@ -56,52 +69,53 @@
}
public void handleMessage(Message message) throws Fault {
+ if (enabled || LOG.isLoggable(Level.INFO)) {
+ logging(message);
+ }
+ }
- if (LOG.isLoggable(Level.INFO)) {
- StringBuilder buffer = new StringBuilder(2048);
-
- buffer.append("Inbound Message\n")
- .append("--------------------------------------");
-
- String encoding = (String)message.get(Message.ENCODING);
- if (encoding != null) {
- buffer.append("\nEncoding: " + encoding);
- }
- Object headers = message.get(Message.PROTOCOL_HEADERS);
- if (headers != null) {
- buffer.append("\nHeaders: " + headers);
- }
+ private void logging(Message message) throws Fault {
+ String encoding = (String)message.get(Message.ENCODING);
+
+ if (encoding != null) {
+ buffer.getEncoding().append(encoding);
+ }
+ Object headers = message.get(Message.PROTOCOL_HEADERS);
+
+ if (headers != null) {
+ buffer.getHeader().append(headers);
+ }
- InputStream is = message.getContent(InputStream.class);
- if (is != null) {
- CachedOutputStream bos = new CachedOutputStream();
- try {
- IOUtils.copy(is, bos);
-
- bos.flush();
- is.close();
-
- message.setContent(InputStream.class,
bos.getInputStream());
- if (bos.getTempFile() != null) {
- //large thing on disk...
- buffer.append("\nMessage (saved to tmp file):\n");
- buffer.append("Filename: " +
bos.getTempFile().getAbsolutePath() + "\n");
- } else {
- buffer.append("\nMessage:\n");
- }
- if (bos.size() > limit) {
- buffer.append("(message truncated to " + limit + "
bytes)\n");
- }
- bos.writeCacheTo(buffer, limit);
-
- bos.close();
- } catch (IOException e) {
- throw new Fault(e);
+ InputStream is = message.getContent(InputStream.class);
+ if (is != null) {
+ CachedOutputStream bos = new CachedOutputStream();
+ try {
+ IOUtils.copy(is, bos);
+
+ bos.flush();
+ is.close();
+
+ message.setContent(InputStream.class, bos.getInputStream());
+ if (bos.getTempFile() != null) {
+ //large thing on disk...
+ buffer.getMessage().append("\nMessage (saved to tmp
file):\n");
+ buffer.getMessage().append("Filename: " +
bos.getTempFile().getAbsolutePath() + "\n");
+ } else {
+ buffer.getMessage().append("\nMessage:\n");
}
+ if (bos.size() > limit) {
+ buffer.getMessage().append("(message truncated to " +
limit + " bytes)\n");
+ }
+ bos.writeCacheTo(buffer.getPayload(), limit);
+
+ bos.close();
+ } catch (IOException e) {
+ throw new Fault(e);
}
- buffer.append("\n--------------------------------------");
+ }
+
+ if (LOG.isLoggable(Level.INFO)) {
LOG.info(buffer.toString());
}
}
-
}
Added:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingMessage.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingMessage.java?rev=593444&view=auto
==============================================================================
---
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingMessage.java
(added)
+++
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingMessage.java
Thu Nov 8 23:48:19 2007
@@ -0,0 +1,67 @@
+/**
+ * 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.interceptor;
+
+public final class LoggingMessage {
+
+ private final String heading;
+
+ private final StringBuilder encoding;
+ private final StringBuilder header;
+ private final StringBuilder message;
+ private final StringBuilder payload;
+
+ public LoggingMessage(String h) {
+ heading = h;
+
+ encoding = new StringBuilder();
+ header = new StringBuilder();
+ message = new StringBuilder();
+ payload = new StringBuilder();
+ }
+
+ public StringBuilder getEncoding() {
+ return encoding;
+ }
+
+ public StringBuilder getHeader() {
+ return header;
+ }
+
+ public StringBuilder getMessage() {
+ return message;
+ }
+
+ public StringBuilder getPayload() {
+ return payload;
+ }
+
+ public String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(heading);
+ buffer.append("\nEncoding: ");
+ buffer.append(encoding);
+ buffer.append("\nHeaders: ");
+ buffer.append(header);
+ buffer.append(message);
+ buffer.append(payload);
+ buffer.append("\n--------------------------------------");
+ return buffer.toString();
+ }
+}
\ No newline at end of file
Modified:
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java?rev=593444&r1=593443&r2=593444&view=diff
==============================================================================
---
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
(original)
+++
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/LoggingOutInterceptor.java
Thu Nov 8 23:48:19 2007
@@ -37,18 +37,24 @@
public class LoggingOutInterceptor extends AbstractPhaseInterceptor {
private static final Logger LOG =
LogUtils.getL7dLogger(LoggingOutInterceptor.class);
+ private final LoggingMessage buffer = new LoggingMessage("Outbound
Message\n---------------------------");
private int limit = 100 * 1024;
+ private boolean enabled;
public LoggingOutInterceptor() {
super(Phase.PRE_STREAM);
addBefore(StaxOutInterceptor.class.getName());
}
public LoggingOutInterceptor(int lim) {
- super(Phase.PRE_STREAM);
- addBefore(StaxOutInterceptor.class.getName());
+ this();
limit = lim;
}
+
+ public LoggingOutInterceptor(boolean b) {
+ this();
+ this.enabled = b;
+ }
public void setLimit(int lim) {
limit = lim;
@@ -58,20 +64,22 @@
return limit;
}
+ public LoggingMessage getBuffer() {
+ return this.buffer;
+ }
public void handleMessage(Message message) throws Fault {
final OutputStream os = message.getContent(OutputStream.class);
if (os == null) {
return;
}
- if (!LOG.isLoggable(Level.INFO)) {
- return;
+
+ if (LOG.isLoggable(Level.INFO) || enabled) {
+ // Write the output while caching it for the log message
+ final CacheAndWriteOutputStream newOut = new
CacheAndWriteOutputStream(os);
+ message.setContent(OutputStream.class, newOut);
+ newOut.registerCallback(new LoggingCallback());
}
-
- // Write the output while caching it for the log message
- final CacheAndWriteOutputStream newOut = new
CacheAndWriteOutputStream(os);
- message.setContent(OutputStream.class, newOut);
- newOut.registerCallback(new LoggingCallback());
}
class LoggingCallback implements CachedOutputStreamCallback {
@@ -81,31 +89,27 @@
}
public void onClose(CachedOutputStream cos) {
-
- StringBuilder buffer = new StringBuilder(2048);
-
if (cos.getTempFile() == null) {
- buffer.append("Outbound Message:\n");
+ //buffer.append("Outbound Message:\n");
if (cos.size() > limit) {
- buffer.append("(message truncated to " + limit + "
bytes)\n");
+ buffer.getMessage().append("(message truncated to " +
limit + " bytes)\n");
}
- buffer.append("--------------------------------------\n");
} else {
- buffer.append("Outbound Message (saved to tmp file):\n");
- buffer.append("Filename: " +
cos.getTempFile().getAbsolutePath() + "\n");
+ buffer.getMessage().append("Outbound Message (saved to tmp
file):\n");
+ buffer.getMessage().append("Filename: " +
cos.getTempFile().getAbsolutePath() + "\n");
if (cos.size() > limit) {
- buffer.append("(message truncated to " + limit + "
bytes)\n");
+ buffer.getMessage().append("(message truncated to " +
limit + " bytes)\n");
}
- buffer.append("--------------------------------------\n");
}
try {
- cos.writeCacheTo(buffer, limit);
+ cos.writeCacheTo(buffer.getPayload(), limit);
} catch (Exception ex) {
//ignore
}
- buffer.append("--------------------------------------\n");
- LOG.info(buffer.toString());
+
+ if (LOG.isLoggable(Level.INFO)) {
+ LOG.info(buffer.toString());
+ }
}
-
}
}
Modified:
incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java?rev=593444&r1=593443&r2=593444&view=diff
==============================================================================
---
incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java
(original)
+++
incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java
Thu Nov 8 23:48:19 2007
@@ -22,7 +22,6 @@
import java.text.MessageFormat;
import java.util.Collection;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -65,14 +64,14 @@
* is used in all chains.
*/
protected final Map<String, String> messageIDs =
- new HashMap<String, String>();
+ new ConcurrentHashMap<String, String>();
/**
* Whether the endpoint supports WS-Addressing.
*/
- private Map<Endpoint, Boolean> usingAddressing = new
ConcurrentHashMap<Endpoint, Boolean>();
- private boolean usingAddressingAdvisory;
+ private final Map<Endpoint, Boolean> usingAddressing = new
ConcurrentHashMap<Endpoint, Boolean>();
+ private boolean usingAddressingAdvisory = true;
private boolean allowDuplicates = true;
@@ -85,7 +84,7 @@
/**
* Indicates if duplicate messageIDs are allowed.
- * @return true iff duplicate messageIDs are allowed
+ * @return true if duplicate messageIDs are allowed
*/
public boolean allowDuplicates() {
return allowDuplicates;
@@ -147,13 +146,17 @@
* @pre message is outbound
*/
private boolean usingAddressing(Message message) {
- boolean ret = false;
+ boolean ret = true;
if (ContextUtils.isRequestor(message)) {
- ret = usingAddressingAdvisory
- || WSAContextUtils.retrieveUsingAddressing(message)
- || hasUsingAddressing(message)
+ if (hasUsingAddressing(message)
|| hasAddressingAssertion(message)
- || hasUsingAddressingAssertion(message);
+ || hasUsingAddressingAssertion(message)) {
+ return true;
+ }
+ if (!usingAddressingAdvisory
+ || !WSAContextUtils.retrieveUsingAddressing(message)) {
+ ret = false;
+ }
} else {
ret = getMAPs(message, false, false) != null;
}
@@ -205,8 +208,7 @@
private boolean hasAddressingAssertion(Message message) {
AssertionInfoMap aim = message.get(AssertionInfoMap.class);
if (null == aim) {
- return false;
-
+ return false;
}
Collection<AssertionInfo> ais =
aim.get(MetadataConstants.ADDRESSING_ASSERTION_QNAME);
if (null == ais || ais.size() == 0) {
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_feature/WSAClientServerTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_feature/WSAClientServerTest.java?rev=593444&r1=593443&r2=593444&view=diff
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_feature/WSAClientServerTest.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/addr_feature/WSAClientServerTest.java
Thu Nov 8 23:48:19 2007
@@ -23,7 +23,12 @@
import javax.xml.namespace.QName;
import javax.xml.ws.soap.AddressingFeature;
+import org.apache.cxf.interceptor.LoggingInInterceptor;
+import org.apache.cxf.interceptor.LoggingOutInterceptor;
+import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.cxf.ws.addressing.WSAddressingFeature;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -31,23 +36,71 @@
private final QName serviceName = new
QName("http://apache.org/cxf/systest/ws/addr_feature/",
"AddNumbersService");
+
+ private LoggingInInterceptor in;
+ private LoggingOutInterceptor out;
+
+ @Before
+ public void setUp() throws Exception {
+ createBus();
+
+ in = new LoggingInInterceptor(true);
+ this.bus.getInInterceptors().add(in);
+ out = new LoggingOutInterceptor(true);
+ this.bus.getOutInterceptors().add(out);
+ }
+
@BeforeClass
public static void startServers() throws Exception {
assertTrue("server did not launch correctly",
launchServer(Server.class));
}
@Test
- public void testDetail() throws Exception {
+ public void testNoWsaFeature() throws Exception {
+ JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
+ factory.setServiceClass(AddNumbersPortType.class);
+ factory.setAddress("http://localhost:9091/jaxws/add");
+ AddNumbersPortType port = (AddNumbersPortType) factory.create();
+
+ assertEquals(3, port.addNumbers(1, 2));
+
+ String expectedOut =
"<Address>http://www.w3.org/2005/08/addressing/anonymous</Address>";
+ String expectedIn = "<RelatesTo
xmlns=\"http://www.w3.org/2005/08/addressing\">";
+
+
assertTrue(out.getBuffer().getPayload().toString().indexOf(expectedOut) == -1);
+ assertTrue(in.getBuffer().getPayload().toString().indexOf(expectedIn)
== -1);
+ }
+
+ @Test
+ public void testCxfWsaFeature() throws Exception {
+ JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
+ factory.setServiceClass(AddNumbersPortType.class);
+ factory.setAddress("http://localhost:9091/jaxws/add");
+ factory.getFeatures().add(new WSAddressingFeature());
+ AddNumbersPortType port = (AddNumbersPortType) factory.create();
+
+ assertEquals(3, port.addNumbers(1, 2));
+
+ String expectedOut =
"<Address>http://www.w3.org/2005/08/addressing/anonymous</Address>";
+ String expectedIn = "<RelatesTo
xmlns=\"http://www.w3.org/2005/08/addressing\">";
+
+
assertTrue(out.getBuffer().getPayload().toString().indexOf(expectedOut) != -1);
+ assertTrue(in.getBuffer().getPayload().toString().indexOf(expectedIn)
!= -1);
+ }
+
+ @Test
+ public void testJaxwsWsaFeature() throws Exception {
AddNumbersPortType port = getPort();
- // JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
- // factory.setServiceClass(AddNumbersPortType.class);
- // factory.setAddress("http://localhost:9090/jaxws/add");
- // factory.getFeatures().add(new WSAddressingFeature());
- // AddNumbersPortType port = (AddNumbersPortType)
factory.create();
assertEquals(3, port.addNumbers(1, 2));
+
+ String expectedOut =
"<Address>http://www.w3.org/2005/08/addressing/anonymous</Address>";
+ String expectedIn = "<RelatesTo
xmlns=\"http://www.w3.org/2005/08/addressing\">";
+
+
assertTrue(out.getBuffer().getPayload().toString().indexOf(expectedOut) != -1);
+ assertTrue(in.getBuffer().getPayload().toString().indexOf(expectedIn)
!= -1);
}
-
+
private AddNumbersPortType getPort() {
URL wsdl = getClass().getResource("/wsdl/add_numbers.wsdl");
assertNotNull("WSDL is null", wsdl);