Search in sources :

Example 51 with HTTPClientPolicy

use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.

the class HTTPConduitTest method testHandleResponseOnWorkqueueAllowCurrentThread.

@Test
public void testHandleResponseOnWorkqueueAllowCurrentThread() throws Exception {
    Message m = getNewMessage();
    Exchange exchange = new ExchangeImpl();
    Bus bus = new ExtensionManagerBus();
    exchange.put(Bus.class, bus);
    EndpointInfo endpointInfo = new EndpointInfo();
    Endpoint endpoint = new EndpointImpl(null, null, endpointInfo);
    exchange.put(Endpoint.class, endpoint);
    m.setExchange(exchange);
    HTTPClientPolicy policy = new HTTPClientPolicy();
    policy.setAsyncExecuteTimeoutRejection(true);
    m.put(HTTPClientPolicy.class, policy);
    exchange.put(Executor.class, new Executor() {

        @Override
        public void execute(Runnable command) {
            // forces us to use current thread
            throw new RejectedExecutionException("expected");
        }
    });
    HTTPConduit conduit = new MockHTTPConduit(bus, endpointInfo, policy);
    OutputStream os = conduit.createOutputStream(m, false, false, 0);
    assertTrue(os instanceof WrappedOutputStream);
    WrappedOutputStream wos = (WrappedOutputStream) os;
    try {
        wos.handleResponseOnWorkqueue(true, false);
        assertEquals(Thread.currentThread(), m.get(Thread.class));
        try {
            wos.handleResponseOnWorkqueue(false, false);
            fail("Expected RejectedExecutionException not thrown");
        } catch (RejectedExecutionException ex) {
            assertEquals("expected", ex.getMessage());
        }
    } catch (Exception ex) {
        throw ex;
    }
}
Also used : Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) Message(org.apache.cxf.message.Message) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) WrappedOutputStream(org.apache.cxf.transport.http.HTTPConduit.WrappedOutputStream) OutputStream(java.io.OutputStream) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Executor(java.util.concurrent.Executor) Endpoint(org.apache.cxf.endpoint.Endpoint) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) WrappedOutputStream(org.apache.cxf.transport.http.HTTPConduit.WrappedOutputStream) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 52 with HTTPClientPolicy

use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.

the class PolicyUtilsTest method testAssertClientPolicy.

void testAssertClientPolicy(boolean outbound) {
    Message message = control.createMock(Message.class);
    HTTPClientPolicy ep = new HTTPClientPolicy();
    HTTPClientPolicy cmp = new HTTPClientPolicy();
    cmp.setConnectionTimeout(60000L);
    HTTPClientPolicy icmp = new HTTPClientPolicy();
    icmp.setAllowChunking(false);
    AssertionInfo eai = getClientPolicyAssertionInfo(ep);
    AssertionInfo cmai = getClientPolicyAssertionInfo(cmp);
    AssertionInfo icmai = getClientPolicyAssertionInfo(icmp);
    AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(Collections.EMPTY_LIST, PolicyAssertion.class));
    Collection<AssertionInfo> ais = new ArrayList<>();
    ais.add(eai);
    ais.add(cmai);
    ais.add(icmai);
    aim.put(new ClientPolicyCalculator().getDataClassName(), ais);
    EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
    Exchange ex = control.createMock(Exchange.class);
    EasyMock.expect(message.getExchange()).andReturn(ex).atLeastOnce();
    EasyMock.expect(ex.getOutMessage()).andReturn(outbound ? message : null).atLeastOnce();
    if (!outbound) {
        EasyMock.expect(ex.getOutFaultMessage()).andReturn(null).atLeastOnce();
    }
    control.replay();
    PolicyDataEngine pde = new PolicyDataEngineImpl(null);
    pde.assertMessage(message, ep, new ClientPolicyCalculator());
    assertTrue(eai.isAsserted());
    assertTrue(cmai.isAsserted());
    assertTrue(icmai.isAsserted());
    control.verify();
}
Also used : Exchange(org.apache.cxf.message.Exchange) PolicyAssertion(org.apache.cxf.ws.policy.PolicyAssertion) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) Message(org.apache.cxf.message.Message) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) ArrayList(java.util.ArrayList) PolicyDataEngine(org.apache.cxf.policy.PolicyDataEngine) PolicyDataEngineImpl(org.apache.cxf.ws.policy.PolicyDataEngineImpl) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap) ClientPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator)

Example 53 with HTTPClientPolicy

use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.

the class HTTPClientAssertionBuilderTest method testHTTPCLientPolicyAssertionEqual.

@Test
public void testHTTPCLientPolicyAssertionEqual() throws Exception {
    HTTPClientAssertionBuilder ab = new HTTPClientAssertionBuilder();
    JaxbAssertion<HTTPClientPolicy> a = ab.buildAssertion();
    a.setData(new HTTPClientPolicy());
    assertTrue(a.equal(a));
    JaxbAssertion<HTTPClientPolicy> b = ab.buildAssertion();
    b.setData(new HTTPClientPolicy());
    assertTrue(a.equal(b));
    HTTPClientPolicy pa = new HTTPClientPolicy();
    a.setData(pa);
    assertTrue(a.equal(a));
    HTTPClientPolicy pb = new HTTPClientPolicy();
    b.setData(pb);
    assertTrue(a.equal(b));
    pa.setDecoupledEndpoint("http://localhost:9999/decoupled_endpoint");
    assertFalse(a.equal(b));
}
Also used : HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) Test(org.junit.Test)

Example 54 with HTTPClientPolicy

use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.

the class ClientPolicyCalculatorTest method testEqualClientPolicies.

@Test
public void testEqualClientPolicies() {
    ClientPolicyCalculator calc = new ClientPolicyCalculator();
    HTTPClientPolicy p1 = new HTTPClientPolicy();
    assertTrue(calc.equals(p1, p1));
    HTTPClientPolicy p2 = new HTTPClientPolicy();
    assertTrue(calc.equals(p1, p2));
    p1.setDecoupledEndpoint("http://localhost:8080/decoupled");
    assertFalse(calc.equals(p1, p2));
    p2.setDecoupledEndpoint("http://localhost:8080/decoupled");
    assertTrue(calc.equals(p1, p2));
    p1.setReceiveTimeout(10000L);
    assertFalse(calc.equals(p1, p2));
}
Also used : HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) ClientPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator) Test(org.junit.Test)

Example 55 with HTTPClientPolicy

use of org.apache.cxf.transports.http.configuration.HTTPClientPolicy in project cxf by apache.

the class ClientPolicyCalculatorTest method testIntersectClientPolicies.

@Test
public void testIntersectClientPolicies() {
    ThreadLocalRandom random = ThreadLocalRandom.current();
    ClientPolicyCalculator calc = new ClientPolicyCalculator();
    HTTPClientPolicy p1 = new HTTPClientPolicy();
    HTTPClientPolicy p2 = new HTTPClientPolicy();
    p1.setBrowserType("browser");
    HTTPClientPolicy p = calc.intersect(p1, p2);
    assertEquals("browser", p.getBrowserType());
    p1.setBrowserType(null);
    long connectionRequestTimeout = random.nextLong(0, 10000);
    p1.setConnectionRequestTimeout(connectionRequestTimeout);
    p = calc.intersect(p1, p2);
    assertEquals(connectionRequestTimeout, p.getConnectionRequestTimeout());
    long receiveTimeout = random.nextLong(0, 10000);
    p1.setReceiveTimeout(receiveTimeout);
    p = calc.intersect(p1, p2);
    assertEquals(receiveTimeout, p.getReceiveTimeout());
    long connectionTimeout = random.nextLong(0, 10000);
    p1.setConnectionTimeout(connectionTimeout);
    p = calc.intersect(p1, p2);
    assertEquals(connectionTimeout, p.getConnectionTimeout());
    p1.setAllowChunking(false);
    p2.setAllowChunking(false);
    p = calc.intersect(p1, p2);
    assertFalse(p.isAllowChunking());
}
Also used : HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ClientPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator) Test(org.junit.Test)

Aggregations

HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)78 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)53 Client (org.apache.cxf.endpoint.Client)31 Test (org.junit.Test)27 URL (java.net.URL)12 Bus (org.apache.cxf.Bus)10 IOException (java.io.IOException)8 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)8 WebClient (org.apache.cxf.jaxrs.client.WebClient)7 ClientPolicyCalculator (org.apache.cxf.transport.http.policy.impl.ClientPolicyCalculator)7 QName (javax.xml.namespace.QName)6 ProxyAuthorizationPolicy (org.apache.cxf.configuration.security.ProxyAuthorizationPolicy)6 ClientConfiguration (org.apache.cxf.jaxrs.client.ClientConfiguration)6 TLSClientParameters (org.apache.cxf.configuration.jsse.TLSClientParameters)5 Greeter (org.apache.hello_world.Greeter)5 SOAPService (org.apache.hello_world.services.SOAPService)5 Map (java.util.Map)4 BindingProvider (javax.xml.ws.BindingProvider)4 Endpoint (org.apache.cxf.endpoint.Endpoint)4 HashMap (java.util.HashMap)3