Search in sources :

Example 6 with AbstractHTTPDestination

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

the class HttpUtils method getEndpointAddress.

public static String getEndpointAddress(Message m) {
    String address;
    Destination d = m.getExchange().getDestination();
    if (d != null) {
        if (d instanceof AbstractHTTPDestination) {
            EndpointInfo ei = ((AbstractHTTPDestination) d).getEndpointInfo();
            HttpServletRequest request = (HttpServletRequest) m.get(AbstractHTTPDestination.HTTP_REQUEST);
            Object property = request != null ? request.getAttribute("org.apache.cxf.transport.endpoint.address") : null;
            address = property != null ? property.toString() : ei.getAddress();
        } else {
            address = m.containsKey(Message.BASE_PATH) ? (String) m.get(Message.BASE_PATH) : d.getAddress().getAddress().getValue();
        }
    } else {
        address = (String) m.get(Message.ENDPOINT_ADDRESS);
    }
    if (address.startsWith("http") && address.endsWith("//")) {
        address = address.substring(0, address.length() - 1);
    }
    return address;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Destination(org.apache.cxf.transport.Destination) AbstractHTTPDestination(org.apache.cxf.transport.http.AbstractHTTPDestination) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) AbstractHTTPDestination(org.apache.cxf.transport.http.AbstractHTTPDestination)

Example 7 with AbstractHTTPDestination

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

the class NettyHttpTransportFactory method getDestination.

public Destination getDestination(EndpointInfo endpointInfo, Bus bus) throws IOException {
    if (endpointInfo == null) {
        throw new IllegalArgumentException("EndpointInfo cannot be null");
    }
    synchronized (registry) {
        AbstractHTTPDestination d = registry.getDestinationForPath(endpointInfo.getAddress());
        if (d == null) {
            d = factory.createDestination(endpointInfo, bus, registry);
            registry.addDestination(d);
            configure(bus, d);
            d.finalizeConfig();
        }
        return d;
    }
}
Also used : AbstractHTTPDestination(org.apache.cxf.transport.http.AbstractHTTPDestination)

Example 8 with AbstractHTTPDestination

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

the class ServletController method invoke.

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;
}
Also used : ServletException(javax.servlet.ServletException) Bus(org.apache.cxf.Bus) AbstractHTTPDestination(org.apache.cxf.transport.http.AbstractHTTPDestination) ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder) ResourceManager(org.apache.cxf.resource.ResourceManager) IOException(java.io.IOException)

Example 9 with AbstractHTTPDestination

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

the class HttpUtils method getEndpointAddress.

public static String getEndpointAddress(Message m) {
    String address;
    Destination d = m.getExchange().getDestination();
    if (d != null) {
        if (d instanceof AbstractHTTPDestination) {
            EndpointInfo ei = ((AbstractHTTPDestination) d).getEndpointInfo();
            HttpServletRequest request = (HttpServletRequest) m.get(AbstractHTTPDestination.HTTP_REQUEST);
            Object property = request != null ? request.getAttribute("org.apache.cxf.transport.endpoint.address") : null;
            address = property != null ? property.toString() : ei.getAddress();
        } else {
            address = m.containsKey(Message.BASE_PATH) ? (String) m.get(Message.BASE_PATH) : d.getAddress().getAddress().getValue();
        }
    } else {
        address = (String) m.get(Message.ENDPOINT_ADDRESS);
    }
    if (address.startsWith("http") && address.endsWith("//")) {
        address = address.substring(0, address.length() - 1);
    }
    return address;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Destination(org.apache.cxf.transport.Destination) AbstractHTTPDestination(org.apache.cxf.transport.http.AbstractHTTPDestination) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) AbstractHTTPDestination(org.apache.cxf.transport.http.AbstractHTTPDestination)

Example 10 with AbstractHTTPDestination

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

the class WebSocketTransportFactory method getDestination.

/**
 * {@inheritDoc}
 */
public Destination getDestination(EndpointInfo endpointInfo, Bus bus) throws IOException {
    if (endpointInfo == null) {
        throw new IllegalArgumentException("EndpointInfo cannot be null");
    }
    synchronized (registry) {
        AbstractHTTPDestination d = registry.getDestinationForPath(endpointInfo.getAddress());
        if (d == null) {
            d = factory.createDestination(endpointInfo, bus, registry);
            if (d == null) {
                String error = "No destination available. The CXF websocket transport needs either the " + "Jetty WebSocket or Atmosphere dependencies to be available";
                throw new IOException(error);
            }
            registry.addDestination(d);
            configure(bus, d);
            d.finalizeConfig();
        }
        return d;
    }
}
Also used : AbstractHTTPDestination(org.apache.cxf.transport.http.AbstractHTTPDestination) IOException(java.io.IOException)

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