Java Code Examples for org.apache.cxf.transport.http.AbstractHTTPDestination#getMessageObserver()

The following examples show how to use org.apache.cxf.transport.http.AbstractHTTPDestination#getMessageObserver() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServletControllerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 2
Source File: ServletController.java    From cxf with Apache License 2.0 4 votes vote down vote up
public boolean invoke(HttpServletRequest request, HttpServletResponse res, boolean returnErrors)
    throws ServletException {
    try {
        String pathInfo = request.getPathInfo() == null ? "" : request.getPathInfo();
        AbstractHTTPDestination d = destinationRegistry.getDestinationForPath(pathInfo, true);

        if (d == null) {
            if (!isHideServiceList && (request.getRequestURI().endsWith(serviceListRelativePath)
                || request.getRequestURI().endsWith(serviceListRelativePath + "/")
                || StringUtils.isEmpty(pathInfo)
                || "/".equals(pathInfo))) {
                if (isAuthServiceListPage) {
                    setAuthServiceListPageAttribute(request);
                }
                setBaseURLAttribute(request);
                serviceListGenerator.service(request, res);
            } else {
                d = destinationRegistry.checkRestfulRequest(pathInfo);
                if (d == null || d.getMessageObserver() == null) {
                    if (returnErrors) {
                        LOG.warning("Can't find the request for "
                            + request.getRequestURL() + "'s Observer ");
                        generateNotFound(request, res);
                    }
                    return false;
                }
            }
        }
        if (d != null && d.getMessageObserver() != null) {
            Bus bus = d.getBus();
            ClassLoaderHolder orig = null;
            try {
                if (bus != null) {
                    ClassLoader loader = bus.getExtension(ClassLoader.class);
                    if (loader == null) {
                        ResourceManager manager = bus.getExtension(ResourceManager.class);
                        if (manager != null) {
                            loader = manager.resolveResource("", ClassLoader.class);
                        }
                    }
                    if (loader != null) {
                        //need to set the context classloader to the loader of the bundle
                        orig = ClassLoaderUtils.setThreadContextClassloader(loader);
                    }
                }
                updateDestination(request, d);
                invokeDestination(request, res, d);
            } finally {
                if (orig != null) {
                    orig.reset();
                }
            }
        }
    } catch (IOException e) {
        throw new ServletException(e);
    }
    return true;
}