Search in sources :

Example 11 with HTTPServerPolicy

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

the class UndertowHTTPDestinationTest method setUpDestination.

private UndertowHTTPDestination setUpDestination(boolean contextMatchOnStem, boolean mockedBus) throws Exception {
    policy = new HTTPServerPolicy();
    address = getEPR("bar/foo");
    transportFactory = new HTTPTransportFactory();
    final ConduitInitiator ci = new ConduitInitiator() {

        public Conduit getConduit(EndpointInfo targetInfo, Bus b) throws IOException {
            return decoupledBackChannel;
        }

        public Conduit getConduit(EndpointInfo localInfo, EndpointReferenceType target, Bus b) throws IOException {
            return decoupledBackChannel;
        }

        public List<String> getTransportIds() {
            return null;
        }

        public Set<String> getUriPrefixes() {
            return new HashSet<>(Collections.singletonList("http"));
        }
    };
    ConduitInitiatorManager mgr = new ConduitInitiatorManager() {

        public void deregisterConduitInitiator(String name) {
        }

        public ConduitInitiator getConduitInitiator(String name) throws BusException {
            return null;
        }

        public ConduitInitiator getConduitInitiatorForUri(String uri) {
            return ci;
        }

        public void registerConduitInitiator(String name, ConduitInitiator factory) {
        }
    };
    if (!mockedBus) {
        bus = new ExtensionManagerBus();
        bus.setExtension(mgr, ConduitInitiatorManager.class);
    } else {
        bus = EasyMock.createMock(Bus.class);
        bus.getExtension(EndpointResolverRegistry.class);
        EasyMock.expectLastCall().andReturn(null);
        bus.getExtension(ContinuationProviderFactory.class);
        EasyMock.expectLastCall().andReturn(null).anyTimes();
        bus.getExtension(PolicyDataEngine.class);
        EasyMock.expectLastCall().andReturn(null).anyTimes();
        bus.hasExtensionByName("org.apache.cxf.ws.policy.PolicyEngine");
        EasyMock.expectLastCall().andReturn(false);
        bus.getExtension(ClassLoader.class);
        EasyMock.expectLastCall().andReturn(this.getClass().getClassLoader());
        EasyMock.replay(bus);
    }
    engine = EasyMock.createNiceMock(UndertowHTTPServerEngine.class);
    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.setName(new QName("bla", "Service"));
    endpointInfo = new EndpointInfo(serviceInfo, "");
    endpointInfo.setName(new QName("bla", "Port"));
    endpointInfo.setAddress(NOWHERE + "bar/foo");
    endpointInfo.addExtensor(policy);
    engine.addServant(EasyMock.eq(new URL(NOWHERE + "bar/foo")), EasyMock.isA(UndertowHTTPHandler.class));
    EasyMock.expectLastCall();
    engine.getContinuationsEnabled();
    EasyMock.expectLastCall().andReturn(true);
    EasyMock.replay(engine);
    UndertowHTTPDestination dest = new EasyMockUndertowHTTPDestination(bus, transportFactory.getRegistry(), endpointInfo, null, engine);
    dest.retrieveEngine();
    policy = dest.getServer();
    observer = new MessageObserver() {

        public void onMessage(Message m) {
            inMessage = m;
            threadDefaultBus = BusFactory.getThreadDefaultBus();
        }
    };
    dest.setMessageObserver(observer);
    return dest;
}
Also used : Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) QName(javax.xml.namespace.QName) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) HttpString(io.undertow.util.HttpString) URL(java.net.URL) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) ConduitInitiatorManager(org.apache.cxf.transport.ConduitInitiatorManager) ConduitInitiator(org.apache.cxf.transport.ConduitInitiator) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) HashSet(java.util.HashSet)

Example 12 with HTTPServerPolicy

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

the class AbstractHTTPDestination method calcServerPolicyInternal.

private synchronized HTTPServerPolicy calcServerPolicyInternal(Message m) {
    HTTPServerPolicy sp = serverPolicy;
    if (!serverPolicyCalced) {
        PolicyDataEngine pde = bus.getExtension(PolicyDataEngine.class);
        if (pde != null) {
            sp = pde.getServerEndpointPolicy(m, endpointInfo, this, new ServerPolicyCalculator());
        }
        if (null == sp) {
            sp = endpointInfo.getTraversedExtensor(new HTTPServerPolicy(), HTTPServerPolicy.class);
        }
        serverPolicy = sp;
        serverPolicyCalced = true;
    }
    return sp;
}
Also used : HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) PolicyDataEngine(org.apache.cxf.policy.PolicyDataEngine) ServerPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator)

Example 13 with HTTPServerPolicy

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

the class PolicyLoggingInterceptor method handleMessage.

public void handleMessage(Message message) throws Fault {
    EndpointInfo ei = message.getExchange().getEndpoint().getEndpointInfo();
    BindingOperationInfo boi = message.getExchange().getBindingOperationInfo();
    LOG.fine("Getting effective server request policy for endpoint " + ei + " and binding operation " + boi);
    EffectivePolicy ep = bus.getExtension(PolicyEngine.class).getEffectiveServerRequestPolicy(ei, boi, message);
    for (Iterator<List<Assertion>> it = ep.getPolicy().getAlternatives(); it.hasNext(); ) {
        Collection<Assertion> as = it.next();
        LOG.fine("Checking alternative with " + as.size() + " assertions.");
        for (Assertion a : as) {
            LOG.fine("Assertion: " + a.getClass().getName());
            HTTPServerPolicy p = (JaxbAssertion.cast(a, HTTPServerPolicy.class)).getData();
            LOG.fine("server policy: " + ServerPolicyCalculator.toString(p));
        }
    }
}
Also used : EffectivePolicy(org.apache.cxf.ws.policy.EffectivePolicy) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) JaxbAssertion(org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion) Assertion(org.apache.neethi.Assertion) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) List(java.util.List)

Example 14 with HTTPServerPolicy

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

the class PolicyUtilsTest method testAssertServerPolicy.

void testAssertServerPolicy(boolean outbound) {
    Message message = control.createMock(Message.class);
    HTTPServerPolicy ep = new HTTPServerPolicy();
    HTTPServerPolicy mp = new HTTPServerPolicy();
    HTTPServerPolicy cmp = new HTTPServerPolicy();
    cmp.setReceiveTimeout(60000L);
    HTTPServerPolicy icmp = new HTTPServerPolicy();
    icmp.setSuppressClientSendErrors(true);
    AssertionInfo eai = getServerPolicyAssertionInfo(ep);
    AssertionInfo mai = getServerPolicyAssertionInfo(mp);
    AssertionInfo cmai = getServerPolicyAssertionInfo(cmp);
    AssertionInfo icmai = getServerPolicyAssertionInfo(icmp);
    Collection<AssertionInfo> ais = new ArrayList<>();
    ais.add(eai);
    ais.add(mai);
    ais.add(cmai);
    ais.add(icmai);
    AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(Collections.EMPTY_LIST, PolicyAssertion.class));
    aim.put(new ServerPolicyCalculator().getDataClassName(), ais);
    EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim).atLeastOnce();
    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();
    new PolicyDataEngineImpl(null).assertMessage(message, ep, new ServerPolicyCalculator());
    assertTrue(eai.isAsserted());
    assertTrue(mai.isAsserted());
    assertTrue(outbound ? cmai.isAsserted() : !cmai.isAsserted());
    assertTrue(outbound ? icmai.isAsserted() : !icmai.isAsserted());
    control.verify();
}
Also used : Exchange(org.apache.cxf.message.Exchange) PolicyAssertion(org.apache.cxf.ws.policy.PolicyAssertion) HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) Message(org.apache.cxf.message.Message) ArrayList(java.util.ArrayList) ServerPolicyCalculator(org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator) PolicyDataEngineImpl(org.apache.cxf.ws.policy.PolicyDataEngineImpl) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 15 with HTTPServerPolicy

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

the class UndertowHTTPDestination method doService.

protected void doService(ServletContext context, HttpServletRequest req, HttpServletResponse resp) throws IOException {
    if (context == null) {
        context = servletContext;
    }
    HTTPServerPolicy sp = getServer();
    if (sp.isSetRedirectURL()) {
        resp.sendRedirect(sp.getRedirectURL());
        resp.flushBuffer();
        return;
    }
    ClassLoaderHolder origLoader = null;
    Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
    try {
        if (loader != null) {
            origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
        }
        invoke(null, context, req, resp);
    } finally {
        if (origBus != bus) {
            BusFactory.setThreadDefaultBus(origBus);
        }
        if (origLoader != null) {
            origLoader.reset();
        }
    }
}
Also used : Bus(org.apache.cxf.Bus) HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)

Aggregations

HTTPServerPolicy (org.apache.cxf.transports.http.configuration.HTTPServerPolicy)17 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)7 Test (org.junit.Test)7 QName (javax.xml.namespace.QName)6 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)6 HTTPTransportFactory (org.apache.cxf.transport.http.HTTPTransportFactory)6 Bus (org.apache.cxf.Bus)5 ServerPolicyCalculator (org.apache.cxf.transport.http.policy.impl.ServerPolicyCalculator)5 ExtensionManagerBus (org.apache.cxf.bus.extension.ExtensionManagerBus)4 Message (org.apache.cxf.message.Message)4 URL (java.net.URL)3 HashSet (java.util.HashSet)3 ConduitInitiator (org.apache.cxf.transport.ConduitInitiator)3 ConduitInitiatorManager (org.apache.cxf.transport.ConduitInitiatorManager)3 MessageObserver (org.apache.cxf.transport.MessageObserver)3 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)3 ClassLoaderHolder (org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)2 HttpString (io.undertow.util.HttpString)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1