HttpServletRequest req,
HttpServletResponse resp) throws IOException {
if (context == null) {
context = servletContext;
}
Request baseRequest = (req instanceof Request)
? (Request)req : HttpConnection.getCurrentConnection().getRequest();
if (!"HEAD".equals(req.getMethod())) {
//bug in Jetty with persistent connections that if a HEAD is
//sent, a _head flag is never reset
HttpConnection c = baseRequest.getConnection();
if (c != null) {
c.getGenerator().setHead(false);
}
}
if (getServer().isSetRedirectURL()) {
resp.sendRedirect(getServer().getRedirectURL());
resp.flushBuffer();
baseRequest.setHandled(true);
return;
}
QueryHandlerRegistry queryHandlerRegistry = bus.getExtension(QueryHandlerRegistry.class);
if (null != req.getQueryString() && queryHandlerRegistry != null) {
String reqAddr = req.getRequestURL().toString();
String requestURL = reqAddr + "?" + req.getQueryString();
String pathInfo = req.getPathInfo();
for (QueryHandler qh : queryHandlerRegistry.getHandlers()) {
boolean recognized =
qh instanceof StemMatchingQueryHandler
? ((StemMatchingQueryHandler)qh).isRecognizedQuery(requestURL,
pathInfo,
endpointInfo,
contextMatchOnExact())
: qh.isRecognizedQuery(requestURL, pathInfo, endpointInfo);
if (recognized) {
//replace the endpointInfo address with request url only for get wsdl
String errorMsg = null;
CachedOutputStream out = new CachedOutputStream();
try {
synchronized (endpointInfo) {
String oldAddress = updateEndpointAddress(reqAddr);
resp.setContentType(qh.getResponseContentType(requestURL, pathInfo));
try {
qh.writeResponse(requestURL, pathInfo, endpointInfo, out);
} catch (Exception ex) {
LOG.log(Level.WARNING, "writeResponse failed: ", ex);
errorMsg = ex.getMessage();
}
endpointInfo.setAddress(oldAddress);
}
if (errorMsg != null) {
resp.sendError(500, errorMsg);
} else {
out.writeCacheTo(resp.getOutputStream());
resp.getOutputStream().flush();
}
} finally {
out.close();
}
baseRequest.setHandled(true);
return;
}
}
}