001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.systest.ws.addressing;
019:
020: import java.lang.reflect.UndeclaredThrowableException;
021: import java.net.SocketException;
022: import org.apache.cxf.message.Message;
023: import org.apache.cxf.phase.AbstractPhaseInterceptor;
024: import org.apache.cxf.phase.Phase;
025: import org.apache.cxf.systest.ws.util.ConnectionHelper;
026: import org.apache.hello_world_soap_http.BadRecordLitFault;
027: import org.junit.Test;
028:
029: /**
030: * Tests the addition of WS-Addressing Message Addressing Properties.
031: */
032: public class MAPTest extends MAPTestBase {
033:
034: private static final String CONFIG;
035: static {
036: CONFIG = "org/apache/cxf/systest/ws/addressing/cxf"
037: + (("HP-UX".equals(System.getProperty("os.name")) || "Windows XP"
038: .equals(System.getProperty("os.name"))) ? "-hpux"
039: : "") + ".xml";
040: }
041:
042: public String getConfigFileName() {
043: return CONFIG;
044: }
045:
046: @Test
047: public void foo() {
048:
049: }
050:
051: @Test
052: public void testUsingKeepAliveConnection() throws Exception {
053: if (!"HP-UX".equals(System.getProperty("os.name"))) {
054: return;
055: }
056: int n = 100;
057: for (int i = 0; i < n; i++) {
058: greeter.greetMeOneWay("oneway on keep-alive connection");
059: }
060: for (int i = 0; i < n; i++) {
061: assertNotNull(greeter
062: .greetMe("twoway on keep-alive connection"));
063: }
064: for (int i = 0; i < 0; i++) {
065: try {
066: greeter.testDocLitFault("BadRecordLitFault");
067: fail("expected fault from service");
068: } catch (BadRecordLitFault brlf) {
069: //checkVerification();
070: } catch (UndeclaredThrowableException ex) {
071: throw (Exception) ex.getCause();
072: }
073: }
074: }
075:
076: /**
077: * On HP-UX, the server seems to close the connection by the time the
078: * thread servicing the requests terminates and therefore possibly before
079: * the client has had a chance to read the response (the client throws
080: * a SocketException: Broken pipe). This may be a bug
081: * in Jetty or in the HP-UX JDK. It can be worked around by
082: * adding a sleep to the end of method handle in
083: * org.apache.cxf.transport.http_jetty.JettyHTTPHandler or,
084: * preferrably, by ensuring the client uses keep alive
085: * connections.
086: */
087: @Test
088: public void testDelayReadingPartialResponse() throws Exception {
089: if (!"HP-UX".equals(System.getProperty("os.name"))) {
090: return;
091: }
092:
093: assertTrue(ConnectionHelper.isKeepAliveConnection(greeter));
094: ConnectionHelper.setKeepAliveConnection(greeter, false);
095:
096: class DelayInterceptor extends
097: AbstractPhaseInterceptor<Message> {
098: long delay = 100L;
099:
100: DelayInterceptor() {
101: super (Phase.RECEIVE);
102: }
103:
104: public void handleMessage(Message msg) {
105: try {
106: Thread.sleep(delay);
107: } catch (Exception ex) {
108: // ignore
109: } finally {
110: if (delay < 1000L) {
111: delay += 100L;
112: }
113: }
114: }
115: }
116: DelayInterceptor interceptor = new DelayInterceptor();
117: staticBus.getInInterceptors().add(interceptor);
118:
119: int n = 100;
120: try {
121: for (int i = 0; i < n; i++) {
122: greeter.greetMeOneWay("delay reading partial reponse");
123: }
124: fail("Expected SocketException not thrown");
125: } catch (Exception ex) {
126: Throwable t = ex.getCause();
127: while (null != t.getCause()) {
128: t = t.getCause();
129: }
130: assertTrue("Unexpected exception type: "
131: + t.getClass().getName(),
132: t instanceof SocketException);
133: } finally {
134: // need to reset to Keep-Alive for subsequenct tests
135: // (all tests are using the same conduit selector, and
136: // thus the same conduit)
137: ConnectionHelper.setKeepAliveConnection(greeter, true);
138: staticBus.getInInterceptors().remove(interceptor);
139: }
140: }
141: }
|