Search in sources :

Example 1 with AbstractHTTPDestination

use of org.apache.cxf.transport.http.AbstractHTTPDestination in project cxf by apache.

the class SseHttpTransportFactory method getDestination.

@Override
public Destination getDestination(EndpointInfo endpointInfo, Bus bus) throws IOException {
    if (endpointInfo == null) {
        throw new IllegalArgumentException("EndpointInfo cannot be null");
    }
    // it seems like no better option exists at the moment.
    synchronized (registry) {
        AbstractHTTPDestination d = registry.getDestinationForPath(endpointInfo.getAddress());
        if (d == null) {
            d = factory.createDestination(endpointInfo, bus, registry);
            if (d == null) {
                throw new IOException("No destination available. The CXF SSE transport needs Atmosphere" + " dependencies to be available");
            }
            registry.addDestination(d);
            configure(bus, d);
            d.finalizeConfig();
        }
        return d;
    }
}
Also used : AbstractHTTPDestination(org.apache.cxf.transport.http.AbstractHTTPDestination) IOException(java.io.IOException)

Example 2 with AbstractHTTPDestination

use of org.apache.cxf.transport.http.AbstractHTTPDestination in project jbossws-cxf by jbossws.

the class RequestHandlerImpl method handleHttpRequest.

public void handleHttpRequest(Endpoint ep, HttpServletRequest req, HttpServletResponse res, ServletContext context) throws ServletException, IOException {
    final boolean isGet = "GET".equals(req.getMethod());
    final boolean isGetWithQueryString = isGet && hasQueryString(req);
    if (isGet && !isGetWithQueryString) {
        // reject HTTP GET without query string (only support messages sent w/ POST)
        res.setStatus(405);
        res.setContentType("text/plain");
        Writer out = res.getWriter();
        out.write("HTTP GET not supported");
        out.close();
        return;
    }
    final boolean statisticsEnabled = getServerConfig().isStatisticsEnabled();
    final Long beginTime = statisticsEnabled == true ? initRequestMetrics(ep) : 0;
    final Deployment dep = ep.getService().getDeployment();
    final AbstractHTTPDestination dest = findDestination(req, dep.getAttachment(BusHolder.class).getBus());
    final HttpServletResponseWrapper response = new HttpServletResponseWrapper(res);
    try {
        ServletConfig cfg = (ServletConfig) context.getAttribute(ServletConfig.class.getName());
        if (isGetWithQueryString) {
            final EndpointInfo endpointInfo = dest.getEndpointInfo();
            final boolean autoRewrite = SoapAddressRewriteHelper.isAutoRewriteOn(dep.getAttachment(SOAPAddressRewriteMetadata.class));
            endpointInfo.setProperty(WSDLGetUtils.AUTO_REWRITE_ADDRESS, autoRewrite);
            endpointInfo.setProperty(WSDLGetUtils.AUTO_REWRITE_ADDRESS_ALL, autoRewrite);
        }
        dest.invoke(cfg, context, req, response);
    } catch (IOException e) {
        throw new ServletException(e);
    }
    if (statisticsEnabled && response.getStatus() < 500) {
        processResponseMetrics(ep, beginTime);
    }
    if (statisticsEnabled && response.getStatus() >= 500) {
        processFaultMetrics(ep, beginTime);
    }
}
Also used : ServletException(javax.servlet.ServletException) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) AbstractHTTPDestination(org.apache.cxf.transport.http.AbstractHTTPDestination) HttpServletResponseWrapper(javax.servlet.http.HttpServletResponseWrapper) ServletConfig(javax.servlet.ServletConfig) SOAPAddressRewriteMetadata(org.jboss.wsf.spi.metadata.config.SOAPAddressRewriteMetadata) Deployment(org.jboss.wsf.spi.deployment.Deployment) IOException(java.io.IOException) Writer(java.io.Writer)

Example 3 with AbstractHTTPDestination

use of org.apache.cxf.transport.http.AbstractHTTPDestination in project cxf by apache.

the class CXFNonSpringServlet method destroy.

public void destroy() {
    if (!globalRegistry) {
        for (String path : destinationRegistry.getDestinationsPaths()) {
            // clean up the destination in case the destination itself can
            // no longer access the registry later
            AbstractHTTPDestination dest = destinationRegistry.getDestinationForPath(path);
            synchronized (dest) {
                destinationRegistry.removeDestination(path);
                dest.releaseRegistry();
            }
        }
        destinationRegistry = null;
    }
    destroyBus();
    super.destroy();
}
Also used : AbstractHTTPDestination(org.apache.cxf.transport.http.AbstractHTTPDestination)

Example 4 with AbstractHTTPDestination

use of org.apache.cxf.transport.http.AbstractHTTPDestination in project cxf by apache.

the class FormattedServiceListWriter method writeRESTfulEndpoint.

private void writeRESTfulEndpoint(PrintWriter writer, String basePath, AbstractDestination sd) {
    String absoluteURL = getAbsoluteAddress(basePath, sd);
    if (absoluteURL == null) {
        return;
    }
    absoluteURL = StringEscapeUtils.escapeHtml4(absoluteURL);
    writer.write("<tr><td>");
    writer.write("<span class=\"field\">Endpoint address:</span> " + "<span class=\"value\">" + absoluteURL + "</span>");
    Bus sb = bus;
    if (sd instanceof AbstractHTTPDestination) {
        sb = ((AbstractHTTPDestination) sd).getBus();
    }
    addWadlIfNeeded(absoluteURL, sb, writer);
    addOpenApiIfNeeded(absoluteURL, sb, writer);
    addSwaggerIfNeeded(absoluteURL, sb, writer);
    addAtomLinkIfNeeded(absoluteURL, atomMap, writer);
    writer.write("</td></tr>");
}
Also used : Bus(org.apache.cxf.Bus) AbstractHTTPDestination(org.apache.cxf.transport.http.AbstractHTTPDestination)

Example 5 with AbstractHTTPDestination

use of org.apache.cxf.transport.http.AbstractHTTPDestination in project cxf by apache.

the class ServletControllerTest method testHideServiceListing.

@Test
public void testHideServiceListing() throws Exception {
    req.getPathInfo();
    EasyMock.expectLastCall().andReturn(null);
    registry.getDestinationForPath("", true);
    EasyMock.expectLastCall().andReturn(null).atLeastOnce();
    AbstractHTTPDestination dest = EasyMock.createMock(AbstractHTTPDestination.class);
    registry.checkRestfulRequest("");
    EasyMock.expectLastCall().andReturn(dest).atLeastOnce();
    dest.getBus();
    EasyMock.expectLastCall().andReturn(null).anyTimes();
    dest.getMessageObserver();
    EasyMock.expectLastCall().andReturn(EasyMock.createMock(MessageObserver.class)).atLeastOnce();
    expectServiceListGeneratorNotCalled();
    EasyMock.replay(req, registry, serviceListGenerator, dest);
    TestServletController sc = new TestServletController(registry, serviceListGenerator);
    sc.setHideServiceList(true);
    sc.invoke(req, res);
    assertTrue(sc.invokeDestinationCalled());
}
Also used : AbstractHTTPDestination(org.apache.cxf.transport.http.AbstractHTTPDestination) Test(org.junit.Test)

Aggregations

AbstractHTTPDestination (org.apache.cxf.transport.http.AbstractHTTPDestination)12 IOException (java.io.IOException)4 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)3 ServletException (javax.servlet.ServletException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 Bus (org.apache.cxf.Bus)2 Destination (org.apache.cxf.transport.Destination)2 Writer (java.io.Writer)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ServletConfig (javax.servlet.ServletConfig)1 HttpServletResponseWrapper (javax.servlet.http.HttpServletResponseWrapper)1 ClassLoaderHolder (org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)1 ResourceManager (org.apache.cxf.resource.ResourceManager)1 DestinationRegistry (org.apache.cxf.transport.http.DestinationRegistry)1 Deployment (org.jboss.wsf.spi.deployment.Deployment)1 SOAPAddressRewriteMetadata (org.jboss.wsf.spi.metadata.config.SOAPAddressRewriteMetadata)1 Test (org.junit.Test)1