Search in sources :

Example 16 with HTTPServerPolicy

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

the class UndertowHTTPDestinationTest method testServerPolicyInServiceModel.

@Test
public void testServerPolicyInServiceModel() throws Exception {
    policy = new HTTPServerPolicy();
    address = getEPR("bar/foo");
    bus = BusFactory.getDefaultBus(true);
    transportFactory = new HTTPTransportFactory();
    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.setName(new QName("bla", "Service"));
    endpointInfo = new EndpointInfo(serviceInfo, "");
    endpointInfo.setName(new QName("bla", "Port"));
    endpointInfo.addExtensor(policy);
    engine = EasyMock.createMock(UndertowHTTPServerEngine.class);
    EasyMock.replay();
    endpointInfo.setAddress(NOWHERE + "bar/foo");
    UndertowHTTPDestination dest = new EasyMockUndertowHTTPDestination(bus, transportFactory.getRegistry(), endpointInfo, null, engine);
    assertEquals(policy, dest.getServer());
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) QName(javax.xml.namespace.QName) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) Test(org.junit.Test)

Example 17 with HTTPServerPolicy

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

the class AbstractHTTPDestination method flushHeaders.

protected OutputStream flushHeaders(Message outMessage, boolean getStream) throws IOException {
    if (isResponseRedirected(outMessage)) {
        return null;
    }
    cacheInput(outMessage);
    HTTPServerPolicy sp = calcServerPolicy(outMessage);
    if (sp != null) {
        new Headers(outMessage).setFromServerPolicy(sp);
    }
    OutputStream responseStream = null;
    boolean oneWay = isOneWay(outMessage);
    HttpServletResponse response = getHttpResponseFromMessage(outMessage);
    int responseCode = getReponseCodeFromMessage(outMessage);
    if (responseCode >= 300) {
        String ec = (String) outMessage.get(Message.ERROR_MESSAGE);
        if (!StringUtils.isEmpty(ec)) {
            response.sendError(responseCode, ec);
            return null;
        }
    }
    response.setStatus(responseCode);
    new Headers(outMessage).copyToResponse(response);
    outMessage.put(RESPONSE_HEADERS_COPIED, "true");
    if (hasNoResponseContent(outMessage)) {
        response.setContentLength(0);
        response.flushBuffer();
        closeResponseOutputStream(response);
    } else if (!getStream) {
        closeResponseOutputStream(response);
    } else {
        responseStream = response.getOutputStream();
    }
    if (oneWay) {
        outMessage.remove(HTTP_RESPONSE);
    }
    return responseStream;
}
Also used : HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) CopyingOutputStream(org.apache.cxf.io.CopyingOutputStream) OutputStream(java.io.OutputStream) AbstractWrappedOutputStream(org.apache.cxf.io.AbstractWrappedOutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse)

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