Author: andreasmyth Date: Tue Nov 7 03:12:10 2006 New Revision: 472063 URL: http://svn.apache.org/viewvc?view=rev&rev=472063 Log: [JIRA CXF-140] Implemented verifiers for RM system test. Refactored test to use Control interface so that tests can run against differently configure server endpoints. Removed printlns.
Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/ControlImpl.java - copied, changed from r471745, incubator/cxf/tags/celtix/pre_apache/systests/src/test/java/org/objectweb/celtix/systest/ws/rm/ControlImpl.java incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/InMessageRecorder.java (with props) incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/JaxwsInterceptorRemover.java (with props) incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/MessageFlow.java - copied, changed from r471795, incubator/cxf/tags/celtix/pre_apache/systests/src/test/java/org/objectweb/celtix/systest/ws/rm/MessageFlow.java incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/OutMessageRecorder.java (with props) incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/anonymous.xml - copied, changed from r471709, incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/cxf.xml Removed: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/cxf.xml Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/Phase.java incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/GreeterImpl.java incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/Server.java Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/Phase.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/Phase.java?view=diff&rev=472063&r1=472062&r2=472063 ============================================================================== --- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/Phase.java (original) +++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/Phase.java Tue Nov 7 03:12:10 2006 @@ -34,7 +34,7 @@ public static final String PREPARE_SEND = "prepare-send"; public static final String PRE_STREAM = "pre-stream"; public static final String USER_STREAM = "user-stream"; - public static final String POST_STREAM = "port-stream"; + public static final String POST_STREAM = "post-stream"; public static final String WRITE = "write"; public static final String SEND = "send"; Copied: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/ControlImpl.java (from r471745, incubator/cxf/tags/celtix/pre_apache/systests/src/test/java/org/objectweb/celtix/systest/ws/rm/ControlImpl.java) URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/ControlImpl.java?view=diff&rev=472063&p1=incubator/cxf/tags/celtix/pre_apache/systests/src/test/java/org/objectweb/celtix/systest/ws/rm/ControlImpl.java&r1=471745&p2=incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/ControlImpl.java&r2=472063 ============================================================================== --- incubator/cxf/tags/celtix/pre_apache/systests/src/test/java/org/objectweb/celtix/systest/ws/rm/ControlImpl.java (original) +++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/ControlImpl.java Tue Nov 7 03:12:10 2006 @@ -1,52 +1,61 @@ -package org.objectweb.celtix.systest.ws.rm; +/** + * 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.systest.ws.rm; -import java.net.URL; import java.util.concurrent.Future; import java.util.logging.Logger; import javax.jws.WebService; -import javax.xml.namespace.QName; import javax.xml.ws.AsyncHandler; import javax.xml.ws.Endpoint; import javax.xml.ws.Response; -import org.objectweb.celtix.Bus; -import org.objectweb.celtix.BusException; -import org.objectweb.celtix.greeter_control.Control; -import org.objectweb.celtix.greeter_control.types.StartGreeterResponse; -import org.objectweb.celtix.greeter_control.types.StopGreeterResponse; +import org.apache.cxf.Bus; +import org.apache.cxf.bus.spring.SpringBusFactory; +import org.apache.cxf.greeter_control.Control; +import org.apache.cxf.greeter_control.types.StartGreeterResponse; +import org.apache.cxf.greeter_control.types.StopGreeterResponse; @WebService(serviceName = "ControlService", portName = "ControlPort", - endpointInterface = "org.objectweb.celtix.greeter_control.Control", - targetNamespace = "http://celtix.objectweb.org/greeter_control") + endpointInterface = "org.apache.cxf.greeter_control.Control", + targetNamespace = "http://cxf.apache.org/greeter_control") public class ControlImpl implements Control { private static final Logger LOG = Logger.getLogger(ControlImpl.class.getName()); - private static QName serviceName = new QName("http://celtix.objectweb.org/greeter_control", - "GreeterService"); private Endpoint endpoint; private Bus greeterBus; - public boolean startGreeter(String configuration) { + public boolean startGreeter(String cfgResource) { - if (!(null == configuration || "".equals(configuration))) { - setConfigFileProperty(configuration); - } - - try { - greeterBus = Bus.init(); - } catch (BusException ex) { - return false; - } - - TestConfigurator tc = new TestConfigurator(greeterBus.getConfigurationBuilder()); - tc.configureServer(serviceName); + SpringBusFactory bf = new SpringBusFactory(); + greeterBus = bf.createBus(cfgResource); + bf.setDefaultBus(greeterBus); + LOG.info("Initialised bus with cfg file resource: " + cfgResource); GreeterImpl implementor = new GreeterImpl(); String address = "http://localhost:9020/SoapContext/GreeterPort"; endpoint = Endpoint.publish(address, implementor); + LOG.info("Published greeter endpoint."); return true; } @@ -61,25 +70,11 @@ } endpoint = null; if (null != greeterBus) { - try { - greeterBus.shutdown(true); - } catch (BusException ex) { - return false; - } + greeterBus.shutdown(true); } return true; } - public static void setConfigFileProperty(String cfgName) { - URL url = ControlImpl.class.getResource(cfgName + ".xml"); - if (null == url) { - LOG.severe("cannot find test resource " + cfgName + ".xml"); - return; - } - String configFileName = url.toString(); - System.setProperty("celtix.config.file", configFileName); - } - public Future<?> startGreeterAsync(String requestType, AsyncHandler<StartGreeterResponse> asyncHandler) { // never called return null; Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/GreeterImpl.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/GreeterImpl.java?view=diff&rev=472063&r1=472062&r2=472063 ============================================================================== --- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/GreeterImpl.java (original) +++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/GreeterImpl.java Tue Nov 7 03:12:10 2006 @@ -20,6 +20,7 @@ package org.apache.cxf.systest.ws.rm; import java.util.concurrent.Future; +import java.util.logging.Logger; import javax.jws.WebService; import javax.xml.ws.AsyncHandler; @@ -41,11 +42,12 @@ targetNamespace = "http://cxf.apache.org/greeter_control") public class GreeterImpl implements Greeter { + private static final Logger LOG = Logger.getLogger(GreeterImpl.class.getName()); public String greetMe(String arg0) { - System.out.println("Executing operation greetMe with parameter: " + arg0); + LOG.fine("Executing operation greetMe with parameter: " + arg0); String result = arg0.toUpperCase(); - System.out.println("returning: " + result); + LOG.fine("returning: " + result); return result; } @@ -60,11 +62,11 @@ } public void greetMeOneWay(String arg0) { - System.out.println("Executing operation greetMeOneWay with parameter: " + arg0); + LOG.fine("Executing operation greetMeOneWay with parameter: " + arg0); } public void pingMe() throws PingMeFault { - System.out.println("Executing operation pingMe"); + LOG.fine("Executing operation pingMe"); } public Response<PingMeResponse> pingMeAsync() { Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/InMessageRecorder.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/InMessageRecorder.java?view=auto&rev=472063 ============================================================================== --- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/InMessageRecorder.java (added) +++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/InMessageRecorder.java Tue Nov 7 03:12:10 2006 @@ -0,0 +1,71 @@ +/** + * 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.systest.ws.rm; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.soap.MessageFactory; +import javax.xml.soap.SOAPMessage; + +import org.apache.cxf.helpers.IOUtils; +import org.apache.cxf.interceptor.Fault; +import org.apache.cxf.message.Message; +import org.apache.cxf.phase.AbstractPhaseInterceptor; +import org.apache.cxf.phase.Phase; + +public class InMessageRecorder extends AbstractPhaseInterceptor<Message> { + + private List<SOAPMessage> inbound; + + public InMessageRecorder() { + inbound = new ArrayList<SOAPMessage>(); + setPhase(Phase.RECEIVE); + } + + public void handleMessage(Message message) throws Fault { + InputStream is = message.getContent(InputStream.class); + + if (is == null) { + return; + } + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + try { + IOUtils.copy(is, bos); + is.close(); + bos.close(); + MessageFactory mf = MessageFactory.newInstance(); + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + SOAPMessage sm = mf.createMessage(null, bis); + inbound.add(sm); + bis = new ByteArrayInputStream(bos.toByteArray()); + message.setContent(InputStream.class, bis); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + protected List<SOAPMessage> getInboundMessages() { + return inbound; + } +} Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/InMessageRecorder.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/InMessageRecorder.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/JaxwsInterceptorRemover.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/JaxwsInterceptorRemover.java?view=auto&rev=472063 ============================================================================== --- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/JaxwsInterceptorRemover.java (added) +++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/JaxwsInterceptorRemover.java Tue Nov 7 03:12:10 2006 @@ -0,0 +1,79 @@ +/** + * 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.systest.ws.rm; + +import java.util.Collections; +import java.util.ListIterator; +import java.util.Set; + + +import org.apache.cxf.interceptor.Fault; +import org.apache.cxf.interceptor.InterceptorChain; +import org.apache.cxf.jaxws.handler.LogicalHandlerInterceptor; +import org.apache.cxf.jaxws.handler.StreamHandlerInterceptor; +import org.apache.cxf.jaxws.handler.soap.SOAPHandlerInterceptor; +import org.apache.cxf.message.Message; +import org.apache.cxf.phase.AbstractPhaseInterceptor; +import org.apache.cxf.phase.Phase; +import org.apache.cxf.phase.PhaseInterceptor; + + +/** + * + */ +public class JaxwsInterceptorRemover extends AbstractPhaseInterceptor { + + private Set<String> before = Collections.singleton(LogicalHandlerInterceptor.class.getName()); + + public JaxwsInterceptorRemover() { + setPhase(Phase.PRE_LOGICAL); + } + + public void handleMessage(Message message) throws Fault { + + // remove the JAXWS handler interceptors + InterceptorChain chain = message.getInterceptorChain(); + ListIterator it = chain.getIterator(); + while (it.hasNext()) { + PhaseInterceptor pi = (PhaseInterceptor)it.next(); + if (LogicalHandlerInterceptor.class.getName().equals(pi.getId())) { + chain.remove(pi); + break; + } + } + it = chain.getIterator(); + while (it.hasNext()) { + PhaseInterceptor pi = (PhaseInterceptor)it.next(); + if (SOAPHandlerInterceptor.class.getName().equals(pi.getId())) { + chain.remove(pi); + break; + } + } + it = chain.getIterator(); + while (it.hasNext()) { + PhaseInterceptor pi = (PhaseInterceptor)it.next(); + if (StreamHandlerInterceptor.class.getName().equals(pi.getId())) { + chain.remove(pi); + break; + } + } + } + +} Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/JaxwsInterceptorRemover.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/JaxwsInterceptorRemover.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Copied: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/MessageFlow.java (from r471795, incubator/cxf/tags/celtix/pre_apache/systests/src/test/java/org/objectweb/celtix/systest/ws/rm/MessageFlow.java) URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/MessageFlow.java?view=diff&rev=472063&p1=incubator/cxf/tags/celtix/pre_apache/systests/src/test/java/org/objectweb/celtix/systest/ws/rm/MessageFlow.java&r1=471795&p2=incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/MessageFlow.java&r2=472063 ============================================================================== --- incubator/cxf/tags/celtix/pre_apache/systests/src/test/java/org/objectweb/celtix/systest/ws/rm/MessageFlow.java (original) +++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/MessageFlow.java Tue Nov 7 03:12:10 2006 @@ -1,4 +1,23 @@ -package org.objectweb.celtix.systest.ws.rm; +/** + * 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.systest.ws.rm; import java.io.ByteArrayOutputStream; import java.util.Iterator; @@ -11,50 +30,38 @@ import javax.xml.soap.SOAPHeader; import javax.xml.soap.SOAPHeaderElement; import javax.xml.soap.SOAPMessage; -import javax.xml.ws.handler.LogicalMessageContext; import junit.framework.Assert; -import org.objectweb.celtix.ws.addressing.AddressingProperties; -import org.objectweb.celtix.ws.addressing.ContextUtils; -import org.objectweb.celtix.ws.rm.Names; -import org.objectweb.celtix.ws.rm.RMContextUtils; -import org.objectweb.celtix.ws.rm.RMProperties; -import org.objectweb.celtix.ws.rm.SequenceAcknowledgement; -import org.objectweb.celtix.ws.rm.SequenceType; +import org.apache.cxf.ws.rm.RMConstants; public class MessageFlow extends Assert { private List<SOAPMessage> outboundMessages; - private List<LogicalMessageContext> inboundContexts; + private List<SOAPMessage> inboundMessages; - public MessageFlow(List<SOAPMessage> o, List<LogicalMessageContext> i) { + public MessageFlow(List<SOAPMessage> o, List<SOAPMessage> i) { outboundMessages = o; - inboundContexts = i; + inboundMessages = i; } public List<SOAPMessage> getOutboundMessages() { return outboundMessages; } - public List<LogicalMessageContext> getInboundContexts() { - return inboundContexts; - } - - public void clear() { - getOutboundMessages().clear(); - getInboundContexts().clear(); + public List<SOAPMessage> getInboundMessages() { + return inboundMessages; } public void verifyActions(String[] expectedActions, boolean outbound) throws Exception { - assertEquals(expectedActions.length, outbound ? outboundMessages.size() : inboundContexts.size()); + assertEquals(expectedActions.length, outbound ? outboundMessages.size() : inboundMessages.size()); for (int i = 0; i < expectedActions.length; i++) { - String action = outbound ? getAction(outboundMessages.get(i)) : getAction(inboundContexts.get(i)); + String action = outbound ? getAction(outboundMessages.get(i)) : getAction(inboundMessages.get(i)); if (null == expectedActions[i]) { assertNull((outbound ? "Outbound " : "Inbound") + " message " + i + " has unexpected action: " + action, action); @@ -68,12 +75,12 @@ public boolean checkActions(String[] expectedActions, boolean outbound) throws Exception { - if (expectedActions.length != (outbound ? outboundMessages.size() : inboundContexts.size())) { + if (expectedActions.length != (outbound ? outboundMessages.size() : inboundMessages.size())) { return false; } for (int i = 0; i < expectedActions.length; i++) { - String action = outbound ? getAction(outboundMessages.get(i)) : getAction(inboundContexts.get(i)); + String action = outbound ? getAction(outboundMessages.get(i)) : getAction(inboundMessages.get(i)); if (null == expectedActions[i]) { if (action != null) { return false; @@ -91,10 +98,10 @@ int expectedCount, boolean outbound, boolean exact) throws Exception { - int messageCount = outbound ? outboundMessages.size() : inboundContexts.size(); + int messageCount = outbound ? outboundMessages.size() : inboundMessages.size(); int count = 0; for (int i = 0; i < messageCount; i++) { - String action = outbound ? getAction(outboundMessages.get(i)) : getAction(inboundContexts.get(i)); + String action = outbound ? getAction(outboundMessages.get(i)) : getAction(inboundMessages.get(i)); if (null == expectedAction) { if (action == null) { count++; @@ -125,7 +132,7 @@ boolean exact) throws Exception { int actualMessageCount = - outbound ? outboundMessages.size() : inboundContexts.size(); + outbound ? outboundMessages.size() : inboundMessages.size(); if (exact) { assertEquals(expectedMessageNumbers.length, actualMessageCount); } else { @@ -134,38 +141,25 @@ if (exact) { for (int i = 0; i < expectedMessageNumbers.length; i++) { - if (outbound) { - SOAPElement se = getSequence(outboundMessages.get(i)); - if (null == expectedMessageNumbers[i]) { - assertNull("Outbound message " + i + " contains unexpected message number ", se); - } else { - assertEquals("Outbound message " + i + " does not contain expected message number " - + expectedMessageNumbers[i], expectedMessageNumbers[i], - getMessageNumber(se)); - } + SOAPElement se = outbound ? getSequence(outboundMessages.get(i)) + : getSequence(inboundMessages.get(i)); + if (null == expectedMessageNumbers[i]) { + assertNull((outbound ? "Outbound" : "Inbound") + " message " + i + + " contains unexpected message number ", se); } else { - SequenceType s = getSequence(inboundContexts.get(i)); - String messageNumber = null == s ? null : s.getMessageNumber().toString(); - if (null == expectedMessageNumbers[i]) { - assertNull("Inbound message " + i + " contains unexpected message number ", - messageNumber); - } else { - assertEquals("Inbound message " + i + " does not contain expected message number " - + expectedMessageNumbers[i], expectedMessageNumbers[i], messageNumber); - } + assertEquals((outbound ? "Outbound" : "Inbound") + " message " + i + + " does not contain expected message number " + + expectedMessageNumbers[i], expectedMessageNumbers[i], + getMessageNumber(se)); } } } else { boolean[] matches = new boolean[expectedMessageNumbers.length]; for (int i = 0; i < actualMessageCount; i++) { String messageNumber = null; - if (outbound) { - SOAPElement se = getSequence(outboundMessages.get(i)); - messageNumber = null == se ? null : getMessageNumber(se); - } else { - SequenceType s = getSequence(inboundContexts.get(i)); - messageNumber = null == s ? null : s.getMessageNumber().toString(); - } + SOAPElement se = outbound ? getSequence(outboundMessages.get(i)) + : getSequence(inboundMessages.get(i)); + messageNumber = null == se ? null : getMessageNumber(se); for (int j = 0; j < expectedMessageNumbers.length; j++) { if (messageNumber == null) { if (expectedMessageNumbers[j] == null && !matches[j]) { @@ -197,7 +191,7 @@ boolean exact) throws Exception { int actualMessageCount = - outbound ? outboundMessages.size() : inboundContexts.size(); + outbound ? outboundMessages.size() : inboundMessages.size(); if (exact) { assertEquals(expectedLastMessages.length, actualMessageCount); } else { @@ -206,13 +200,9 @@ for (int i = 0; i < expectedLastMessages.length; i++) { boolean lastMessage; - if (outbound) { - SOAPElement se = getSequence(outboundMessages.get(i)); - lastMessage = null == se ? false : getLastMessage(se); - } else { - SequenceType s = getSequence(inboundContexts.get(i)); - lastMessage = null == s ? false : null != s.getLastMessage(); - } + SOAPElement se = outbound ? getSequence(outboundMessages.get(i)) + : getSequence(inboundMessages.get(i)); + lastMessage = null == se ? false : getLastMessage(se); assertEquals("Outbound message " + i + (expectedLastMessages[i] ? " does not contain expected last message element." : " contains last message element."), @@ -223,11 +213,11 @@ public void verifyAcknowledgements(boolean[] expectedAcks, boolean outbound) throws Exception { assertEquals(expectedAcks.length, outbound ? outboundMessages.size() - : inboundContexts.size()); + : inboundMessages.size()); for (int i = 0; i < expectedAcks.length; i++) { boolean ack = outbound ? (null != getAcknowledgment(outboundMessages.get(i))) - : (null != getAcknowledgment(inboundContexts.get(i))); + : (null != getAcknowledgment(inboundMessages.get(i))); if (expectedAcks[i]) { assertTrue((outbound ? "Outbound" : "Inbound") + " message " + i @@ -244,11 +234,11 @@ boolean exact) throws Exception { int actualMessageCount = - outbound ? outboundMessages.size() : inboundContexts.size(); + outbound ? outboundMessages.size() : inboundMessages.size(); int ackCount = 0; for (int i = 0; i < actualMessageCount; i++) { boolean ack = outbound ? (null != getAcknowledgment(outboundMessages.get(i))) - : (null != getAcknowledgment(inboundContexts.get(i))); + : (null != getAcknowledgment(inboundMessages.get(i))); if (ack) { ackCount++; } @@ -264,9 +254,10 @@ } - public void verifyAckRequestedOutbound() throws Exception { + public void verifyAckRequestedOutbound(boolean outbound) throws Exception { boolean found = false; - for (SOAPMessage m : outboundMessages) { + List<SOAPMessage> messages = outbound ? outboundMessages : inboundMessages; + for (SOAPMessage m : messages) { SOAPElement se = getAckRequested(m); if (se != null) { found = true; @@ -275,21 +266,7 @@ } assertTrue("expected AckRequested", found); } - - public void verifyAckRequestedInbound(List<LogicalMessageContext> contexts) throws Exception { - boolean found = false; - for (LogicalMessageContext context : contexts) { - RMProperties rmps = RMContextUtils.retrieveRMProperties(context, false); - if (null != rmps - && rmps.getAcksRequested() != null - && rmps.getAcksRequested().size() > 0) { - found = true; - break; - } - } - assertTrue("expected AckRequested", found); - } - + protected String getAction(SOAPMessage msg) throws Exception { SOAPEnvelope env = msg.getSOAPPart().getEnvelope(); SOAPHeader header = env.getHeader(); @@ -298,24 +275,16 @@ SOAPHeaderElement headerElement = (SOAPHeaderElement)headerElements.next(); Name headerName = headerElement.getElementName(); String localName = headerName.getLocalName(); - if ((headerName.getURI().equals(org.objectweb.celtix.ws.addressing.Names.WSA_NAMESPACE_NAME) - || headerName.getURI().equals(org.objectweb.celtix.ws.addressing.VersionTransformer + if ((headerName.getURI().equals(org.apache.cxf.ws.addressing.Names.WSA_NAMESPACE_NAME) + || headerName.getURI().equals(org.apache.cxf.ws.addressing.VersionTransformer .Names200408.WSA_NAMESPACE_NAME)) - && localName.equals(org.objectweb.celtix.ws.addressing.Names.WSA_ACTION_NAME)) { + && localName.equals(org.apache.cxf.ws.addressing.Names.WSA_ACTION_NAME)) { return headerElement.getTextContent(); } } return null; } - protected String getAction(LogicalMessageContext context) { - AddressingProperties maps = ContextUtils.retrieveMAPs(context, false, false); - if (null != maps && null != maps.getAction()) { - return maps.getAction().getValue(); - } - return null; - } - protected SOAPElement getSequence(SOAPMessage msg) throws Exception { SOAPEnvelope env = msg.getSOAPPart().getEnvelope(); SOAPHeader header = env.getHeader(); @@ -324,8 +293,8 @@ SOAPHeaderElement headerElement = (SOAPHeaderElement)headerElements.next(); Name headerName = headerElement.getElementName(); String localName = headerName.getLocalName(); - if (headerName.getURI().equals(Names.WSRM_NAMESPACE_NAME) - && localName.equals(Names.WSRM_SEQUENCE_NAME)) { + if (headerName.getURI().equals(RMConstants.WSRM_NAMESPACE_NAME) + && localName.equals(RMConstants.WSRM_SEQUENCE_NAME)) { return headerElement; } } @@ -334,18 +303,13 @@ public String getMessageNumber(SOAPElement elem) throws Exception { SOAPElement se = (SOAPElement)elem.getChildElements( - new QName(Names.WSRM_NAMESPACE_NAME, + new QName(RMConstants.WSRM_NAMESPACE_NAME, "MessageNumber")).next(); return se.getTextContent(); } - protected SequenceType getSequence(LogicalMessageContext context) { - RMProperties rmps = RMContextUtils.retrieveRMProperties(context, false); - return rmps == null ? null : rmps.getSequence(); - } - private boolean getLastMessage(SOAPElement elem) throws Exception { - return elem.getChildElements(new QName(Names.WSRM_NAMESPACE_NAME, "LastMessage")).hasNext(); + return elem.getChildElements(new QName(RMConstants.WSRM_NAMESPACE_NAME, "LastMessage")).hasNext(); } protected SOAPElement getAcknowledgment(SOAPMessage msg) throws Exception { @@ -356,22 +320,14 @@ SOAPHeaderElement headerElement = (SOAPHeaderElement)headerElements.next(); Name headerName = headerElement.getElementName(); String localName = headerName.getLocalName(); - if (headerName.getURI().equals(Names.WSRM_NAMESPACE_NAME) - && localName.equals(Names.WSRM_SEQUENCE_ACK_NAME)) { + if (headerName.getURI().equals(RMConstants.WSRM_NAMESPACE_NAME) + && localName.equals(RMConstants.WSRM_SEQUENCE_ACK_NAME)) { return (SOAPElement)header.getChildElements().next(); } } return null; } - protected SequenceAcknowledgement getAcknowledgment(LogicalMessageContext context) { - RMProperties rmps = RMContextUtils.retrieveRMProperties(context, false); - if (null != rmps && null != rmps.getAcks() && rmps.getAcks().size() > 0) { - return rmps.getAcks().iterator().next(); - } - return null; - } - private SOAPElement getAckRequested(SOAPMessage msg) throws Exception { SOAPEnvelope env = msg.getSOAPPart().getEnvelope(); SOAPHeader header = env.getHeader(); @@ -380,8 +336,8 @@ SOAPHeaderElement headerElement = (SOAPHeaderElement)headerElements.next(); Name headerName = headerElement.getElementName(); String localName = headerName.getLocalName(); - if (headerName.getURI().equals(Names.WSRM_NAMESPACE_NAME) - && localName.equals(Names.WSRM_ACK_REQUESTED_NAME)) { + if (headerName.getURI().equals(RMConstants.WSRM_NAMESPACE_NAME) + && localName.equals(RMConstants.WSRM_ACK_REQUESTED_NAME)) { return (SOAPElement)header.getChildElements().next(); } } @@ -403,10 +359,10 @@ } } else { if (exact) { - assertEquals("Unexpected number of inbound messages", nExpected, inboundContexts.size()); + assertEquals("Unexpected number of inbound messages", nExpected, inboundMessages.size()); } else { - assertTrue("Unexpected number of inbound messages: " + inboundContexts.size(), - nExpected <= inboundContexts.size()); + assertTrue("Unexpected number of inbound messages: " + inboundMessages.size(), + nExpected <= inboundMessages.size()); } } } @@ -418,7 +374,7 @@ public void verifyMessages(int nExpected, boolean outbound, int interval, int attempts, boolean exact) { for (int i = 0; i < attempts; i++) { if ((outbound && outboundMessages.size() < nExpected) - || (!outbound && inboundContexts.size() < nExpected)) { + || (!outbound && inboundMessages.size() < nExpected)) { try { Thread.sleep(interval); } catch (InterruptedException ex) { @@ -432,17 +388,17 @@ } public void purgePartialResponses() throws Exception { - for (int i = inboundContexts.size() - 1; i >= 0; i--) { - if (isPartialResponse(inboundContexts.get(i))) { - inboundContexts.remove(i); + for (int i = inboundMessages.size() - 1; i >= 0; i--) { + if (isPartialResponse(inboundMessages.get(i))) { + inboundMessages.remove(i); } } } public void verifyPartialResponses(int nExpected) throws Exception { int npr = 0; - for (int i = 0; i < inboundContexts.size(); i++) { - if (isPartialResponse(inboundContexts.get(i))) { + for (int i = 0; i < inboundMessages.size(); i++) { + if (isPartialResponse(inboundMessages.get(i))) { npr++; } } @@ -450,13 +406,13 @@ nExpected, npr); } - public boolean isPartialResponse(LogicalMessageContext ctx) throws Exception { - return null == getAction(ctx) && emptyBody(ctx); + public boolean isPartialResponse(SOAPMessage msg) throws Exception { + // return null == getAction(ctx) && emptyBody(msg); + return false; } - public boolean emptyBody(LogicalMessageContext ctx) throws Exception { - return !((SOAPMessage)ctx.get("org.objectweb.celtix.bindings.soap.message")) - .getSOAPPart().getEnvelope().getBody().hasChildNodes(); + public boolean emptyBody(SOAPMessage msg) throws Exception { + return !msg.getSOAPPart().getEnvelope().getBody().hasChildNodes(); } private String outboundDump() { Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/OutMessageRecorder.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/OutMessageRecorder.java?view=auto&rev=472063 ============================================================================== --- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/OutMessageRecorder.java (added) +++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/OutMessageRecorder.java Tue Nov 7 03:12:10 2006 @@ -0,0 +1,142 @@ +/** + * 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.systest.ws.rm; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +import javax.xml.soap.MessageFactory; +import javax.xml.soap.SOAPMessage; + +import org.apache.cxf.interceptor.Fault; +import org.apache.cxf.interceptor.StaxOutInterceptor; +//import org.apache.cxf.io.AbstractCachedOutputStream; +import org.apache.cxf.message.Message; +import org.apache.cxf.phase.AbstractPhaseInterceptor; +import org.apache.cxf.phase.Phase; + + +/** + * + */ +public class OutMessageRecorder extends AbstractPhaseInterceptor { + + private List<SOAPMessage> outbound; + private Set<String> before = Collections.singleton(StaxOutInterceptor.class.getName()); + + public OutMessageRecorder() { + outbound = new ArrayList<SOAPMessage>(); + //setPhase(Phase.POST_STREAM); + setPhase(Phase.PRE_PROTOCOL); + } + + public void handleMessage(Message message) throws Fault { + OutputStream os = message.getContent(OutputStream.class); + if (null == os) { + return; + } + ForkOutputStream fos = new ForkOutputStream(os); + message.setContent(OutputStream.class, fos); + + /* + if (os instanceof AbstractCachedOutputStream) { + try { + String s = ((AbstractCachedOutputStream)os).toString(); + MessageFactory mf = MessageFactory.newInstance(); + ByteArrayInputStream bis = new ByteArrayInputStream(s.getBytes()); + SOAPMessage sm = mf.createMessage(null, bis); + outbound.add(sm); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + */ + } + + @Override + public Set<String> getBefore() { + return before; + } + + protected List<SOAPMessage> getOutboundMessages() { + return outbound; + } + + /** + * Output stream that multicasts its data to several underlying output streams. + */ + class ForkOutputStream extends OutputStream { + + final OutputStream original; + final ByteArrayOutputStream bos; + + public ForkOutputStream(OutputStream o) { + original = o; + bos = new ByteArrayOutputStream(); + } + + @Override + public void close() throws IOException { + bos.close(); + try { + MessageFactory mf = MessageFactory.newInstance(); + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + SOAPMessage sm = mf.createMessage(null, bis); + outbound.add(sm); + } catch (Exception ex) { + ex.printStackTrace(); + } + original.close(); + } + + @Override + public void flush() throws IOException { + bos.flush(); + original.flush(); + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + bos.write(b, off, len); + original.write(b, off, len); + } + + @Override + public void write(byte[] b) throws IOException { + bos.write(b); + original.write(b); + } + + @Override + public void write(int b) throws IOException { + bos.write(b); + original.write(b); + } + + + } + +} Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/OutMessageRecorder.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/OutMessageRecorder.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java?view=diff&rev=472063&r1=472062&r2=472063 ============================================================================== --- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java (original) +++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java Tue Nov 7 03:12:10 2006 @@ -19,16 +19,20 @@ package org.apache.cxf.systest.ws.rm; +import java.util.logging.Logger; import junit.framework.Test; import junit.framework.TestSuite; import org.apache.cxf.Bus; import org.apache.cxf.bus.spring.SpringBusFactory; +import org.apache.cxf.greeter_control.Control; +import org.apache.cxf.greeter_control.ControlService; import org.apache.cxf.greeter_control.Greeter; import org.apache.cxf.greeter_control.GreeterService; import org.apache.cxf.systest.common.ClientServerSetupBase; import org.apache.cxf.systest.common.ClientServerTestBase; +import org.apache.cxf.ws.rm.RMConstants; /** @@ -37,7 +41,19 @@ */ public class SequenceTest extends ClientServerTestBase { + private static final Logger LOG = Logger.getLogger(SequenceTest.class.getName()); + private static final String APP_NAMESPACE = "http://celtix.objectweb.org/greeter_control"; + private static final String GREETMEONEWAY_ACTION = APP_NAMESPACE + "/types/Greeter/greetMeOneWay"; + //private static final String GREETME_ACTION = APP_NAMESPACE + "/types/Greeter/greetMe"; + //private static final String GREETME_RESPONSE_ACTION = GREETME_ACTION + "Response"; + + private Control control; + private Bus greeterBus; private Greeter greeter; + private String currentCfgResource; + private MessageFlow mf; + + private boolean doTestOnewayAnonymousAcks = true; public static void main(String[] args) { junit.textui.TestRunner.run(SequenceTest.class); @@ -47,45 +63,89 @@ TestSuite suite = new TestSuite(SequenceTest.class); return new ClientServerSetupBase(suite) { public void startServers() throws Exception { - // special case handling for WS-Addressing system test to avoid - // UUID related issue when server is run as separate process - // via maven on Win2k - /* - boolean inProcess = "Windows 2000".equals(System.getProperty("os.name")); - assertTrue("server did not launch correctly", - launchServer(Server.class, inProcess)); - */ assertTrue("server did not launch correctly", launchServer(Server.class)); } public void setUp() throws Exception { startServers(); - System.out.println("Started server"); + LOG.fine("Started server"); SpringBusFactory bf = new SpringBusFactory(); - Bus bus = bf.createBus("org/apache/cxf/systest/ws/rm/cxf.xml"); + Bus bus = bf.createBus(); bf.setDefaultBus(bus); setBus(bus); - System.out.println("Created client bus"); + LOG.fine("Created client bus"); } }; } public void setUp() throws Exception { super.setUp(); - GreeterService service = new GreeterService(); - System.out.println("Created GreeterService"); - greeter = service.getGreeterPort(); - System.out.println("Created Greeter"); + ControlService service = new ControlService(); + LOG.fine("Created ControlService"); + control = service.getControlPort(); + LOG.fine("Created Control"); } public void tearDown() { + if (null != greeter) { + assertTrue("Failed to stop greeter", control.stopGreeter()); + greeterBus.shutdown(true); + } } - //--Tests + // --- tests --- - public void testOneway() { - System.out.println("Invoking greetMeOneWay ..."); - greeter.greetMeOneWay("cxf"); + public void testOnewayAnonymousAcks() throws Exception { + if (!doTestOnewayAnonymousAcks) { + return; + } + setupGreeter("org/apache/cxf/systest/ws/rm/anonymous.xml"); + + greeter.greetMeOneWay("once"); + greeter.greetMeOneWay("twice"); + greeter.greetMeOneWay("thrice"); + + // three application messages plus createSequence + + mf.verifyMessages(4, true); + String[] expectedActions = new String[] {RMConstants.getCreateSequenceAction(), GREETMEONEWAY_ACTION, + GREETMEONEWAY_ACTION, GREETMEONEWAY_ACTION}; + expectedActions = new String[] {RMConstants.getCreateSequenceAction(), "", "", ""}; + mf.verifyActions(expectedActions, true); + mf.verifyMessageNumbers(new String[] {null, "1", "2", "3"}, true); + + // createSequenceResponse plus ? partial responses + // partial responses not sent! + mf.verifyMessages(1, false); + expectedActions = new String[] {RMConstants.getCreateSequenceResponseAction()}; + mf.verifyActions(expectedActions, false); + mf.verifyMessageNumbers(new String[] {null}, false); + mf.verifyAcknowledgements(new boolean[] {false}, false); + } + + // --- test utilities --- + + private void setupGreeter(String cfgResource) { + + SpringBusFactory bf = new SpringBusFactory(); + greeterBus = bf.createBus(cfgResource); + bf.setDefaultBus(greeterBus); + + OutMessageRecorder outRecorder = new OutMessageRecorder(); + greeterBus.getOutInterceptors().add(new JaxwsInterceptorRemover()); + greeterBus.getOutInterceptors().add(outRecorder); + InMessageRecorder inRecorder = new InMessageRecorder(); + greeterBus.getInInterceptors().add(inRecorder); + currentCfgResource = cfgResource; + + assertTrue("Failed to start greeter", control.startGreeter(cfgResource)); + + GreeterService service = new GreeterService(); + greeter = service.getGreeterPort(); + + mf = new MessageFlow(outRecorder.getOutboundMessages(), inRecorder.getInboundMessages()); + + } } Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/Server.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/Server.java?view=diff&rev=472063&r1=472062&r2=472063 ============================================================================== --- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/Server.java (original) +++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/Server.java Tue Nov 7 03:12:10 2006 @@ -28,16 +28,16 @@ public class Server extends TestServerBase { - private static final String ADDRESS = "http://localhost:9020/SoapContext/GreeterPort"; + private static final String ADDRESS = "http://localhost:9001/SoapContext/ControlPort"; protected void run() { SpringBusFactory factory = new SpringBusFactory(); - Bus bus = factory.createBus("org/apache/cxf/systest/ws/rm/cxf.xml"); + Bus bus = factory.createBus(); factory.setDefaultBus(bus); setBus(bus); - GreeterImpl implementor = new GreeterImpl(); + ControlImpl implementor = new ControlImpl(); Endpoint.publish(ADDRESS, implementor); } Copied: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/anonymous.xml (from r471709, incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/cxf.xml) URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/anonymous.xml?view=diff&rev=472063&p1=incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/cxf.xml&r1=471709&p2=incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/anonymous.xml&r2=472063 ============================================================================== --- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/cxf.xml (original) +++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/anonymous.xml Tue Nov 7 03:12:10 2006 @@ -33,8 +33,10 @@ </bean> --> - + <!-- <bean id="logOutgoing" class="org.apache.cxf.interceptor.LoggingOutInterceptor"/> + --> + <bean id="logOutgoing" class="org.apache.cxf.systest.ws.rm.OutMessageRecorder"/> <bean id="logIncoming" class="org.apache.cxf.interceptor.LoggingInInterceptor"/> <bean id="mapAggregator" class="org.apache.cxf.ws.addressing.MAPAggregator"/> <bean id="mapCodec" class="org.apache.cxf.ws.addressing.soap.MAPCodec"/> @@ -52,6 +54,8 @@ <property name="inInterceptors"> <list> <ref bean="logIncoming"/> + <!-- + --> <ref bean="mapAggregator"/> <ref bean="mapCodec"/> <ref bean="rmLogicalIn"/> @@ -61,6 +65,8 @@ <property name="inFaultInterceptors"> <list> <ref bean="logIncoming"/> + <!-- + --> <ref bean="mapAggregator"/> <ref bean="mapCodec"/> <ref bean="rmLogicalIn"/>