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;
}
}
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);
}
}
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();
}
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>");
}
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());
}
Aggregations