Skip to content
Permalink
Browse files
Reduce some duplicate code between the various HTTP providers
git-svn-id: https://svn.apache.org/repos/asf/cxf/trunk@1544657 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
dkulp committed Nov 22, 2013
1 parent 880377a commit 7521ad685276b02af30a5fa145dbced0b91058fd
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 127 deletions.
@@ -85,7 +85,8 @@ protected void serviceRequest(final HttpServletRequest req, final HttpServletRes
Message inMessage = new MessageImpl();
ExchangeImpl exchange = new ExchangeImpl();
exchange.setInMessage(inMessage);
setupMessage(inMessage, null, req, resp);

setupMessage(inMessage, null, req.getServletContext(), req, resp);

((MessageImpl)inMessage).setDestination(this);

@@ -42,17 +42,13 @@
import org.apache.cxf.configuration.jsse.TLSServerParameters;
import org.apache.cxf.configuration.security.CertificateConstraintsType;
import org.apache.cxf.continuations.ContinuationProvider;
import org.apache.cxf.continuations.SuspendedInvocationException;
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.io.CopyingOutputStream;
import org.apache.cxf.message.ExchangeImpl;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageImpl;
import org.apache.cxf.service.model.EndpointInfo;
import org.apache.cxf.transport.http.AbstractHTTPDestination;
import org.apache.cxf.transport.http.DestinationRegistry;
import org.apache.cxf.transport.http.HTTPSession;
import org.apache.cxf.transport.http_jetty.continuations.JettyContinuationProvider;
import org.apache.cxf.transport.https.CertConstraintsJaxBUtils;
import org.eclipse.jetty.http.Generator;
@@ -248,7 +244,7 @@ protected void doService(ServletContext context,
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
serviceRequest(context, req, resp);
invoke(null, context, req, resp);
} finally {
if (origBus != bus) {
BusFactory.setThreadDefaultBus(origBus);
@@ -258,58 +254,16 @@ protected void doService(ServletContext context,
}
}
}

protected void serviceRequest(final ServletContext context,
protected void invokeComplete(final ServletContext context,
final HttpServletRequest req,
final HttpServletResponse resp)
throws IOException {
final HttpServletResponse resp,
Message m) throws IOException {
resp.flushBuffer();
Request baseRequest = (req instanceof Request)
? (Request)req : getCurrentRequest();

if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Service http request on thread: " + Thread.currentThread());
}
Message inMessage = retrieveFromContinuation(req);

if (inMessage == null) {

inMessage = new MessageImpl();
ExchangeImpl exchange = new ExchangeImpl();
exchange.setInMessage(inMessage);
setupMessage(inMessage, context, req, resp);

((MessageImpl)inMessage).setDestination(this);

exchange.setSession(new HTTPSession(req));
}

try {
incomingObserver.onMessage(inMessage);
resp.flushBuffer();
baseRequest.setHandled(true);
ContinuationProvider p = inMessage.get(ContinuationProvider.class);
if (p != null) {
p.complete();
}
} catch (SuspendedInvocationException ex) {
if (ex.getRuntimeException() != null) {
throw ex.getRuntimeException();
}
//else nothing to do
} catch (Fault ex) {
Throwable cause = ex.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException)cause;
} else {
throw ex;
}
} catch (RuntimeException ex) {
throw ex;
} finally {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Finished servicing http request on thread: " + Thread.currentThread());
}
}
baseRequest.setHandled(true);
super.invokeComplete(context, req, resp, m);
}

protected OutputStream flushHeaders(Message outMessage, boolean getStream) throws IOException {
@@ -664,6 +664,7 @@ private void setUpDoService(boolean setRedirectURL,
EasyMock.expect(request.getHeader("Accept")).andReturn("*/*");
EasyMock.expect(request.getContentType()).andReturn("text/xml charset=utf8").times(2);
EasyMock.expect(request.getAttribute("org.eclipse.jetty.ajax.Continuation")).andReturn(null);
EasyMock.expect(request.getAttribute("http.service.redirection")).andReturn(null).anyTimes();

HttpFields httpFields = new HttpFields();
httpFields.add("content-type", "text/xml");
@@ -36,16 +36,11 @@
import org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.continuations.ContinuationProvider;
import org.apache.cxf.continuations.SuspendedInvocationException;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.ExchangeImpl;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageImpl;
import org.apache.cxf.service.model.EndpointInfo;
import org.apache.cxf.transport.http.AbstractHTTPDestination;
import org.apache.cxf.transport.http.DestinationRegistry;
import org.apache.cxf.transport.http.HTTPSession;

public class NettyHttpDestination extends AbstractHTTPDestination {

@@ -176,7 +171,7 @@ protected void doService(ServletContext context,
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
serviceRequest(context, req, resp);
invoke(null, context, req, resp);
} finally {
if (origBus != bus) {
BusFactory.setThreadDefaultBus(origBus);
@@ -186,59 +181,15 @@ protected void doService(ServletContext context,
}
}
}

protected void serviceRequest(final ServletContext context,
final HttpServletRequest req,
final HttpServletResponse resp)
throws IOException {

if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Service http request on thread: " + Thread.currentThread());
}
Message inMessage = retrieveFromContinuation(req);

if (inMessage == null) {

ExchangeImpl exchange = new ExchangeImpl();
inMessage = new MessageImpl();
exchange.setInMessage(inMessage);
setupMessage(inMessage, context, req, resp);

((MessageImpl) inMessage).setDestination(this);

exchange.setSession(new HTTPSession(req));
}

try {
incomingObserver.onMessage(inMessage);

resp.flushBuffer();
ContinuationProvider p = inMessage.get(ContinuationProvider.class);
if (p != null) {
p.complete();
}
} catch (SuspendedInvocationException ex) {
if (ex.getRuntimeException() != null) {
throw ex.getRuntimeException();
}
//else nothing to do
} catch (Fault ex) {
Throwable cause = ex.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
} else {
throw ex;
}
} catch (RuntimeException ex) {
throw ex;
} finally {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Finished servicing http request on thread: " + Thread.currentThread());
}
}

protected void invokeComplete(final ServletContext context,
final HttpServletRequest req,
final HttpServletResponse resp,
Message m) throws IOException {
resp.flushBuffer();
super.invokeComplete(context, req, resp, m);
}


public ServerEngine getEngine() {
return engine;
}
@@ -661,6 +661,7 @@ private void setUpDoService(boolean setRedirectURL,
EasyMock.expect(request.getHeader("Accept")).andReturn("*/*");
EasyMock.expect(request.getContentType()).andReturn("text/xml charset=utf8").times(2);
EasyMock.expect(request.getAttribute("org.eclipse.jetty.ajax.Continuation")).andReturn(null);
EasyMock.expect(request.getAttribute("http.service.redirection")).andReturn(null).anyTimes();

List<String> contentType = new ArrayList<String>();
contentType.add("text/xml");
@@ -212,7 +212,7 @@ protected final boolean isOneWay(Message message) {
return ex == null ? false : ex.isOneWay();
}

public void invoke(final ServletConfig config,
public void invoke(final ServletConfig config,
final ServletContext context,
final HttpServletRequest req,
final HttpServletResponse resp) throws IOException {
@@ -238,31 +238,42 @@ public void invoke(final ServletConfig config,

try {
incomingObserver.onMessage(inMessage);
ContinuationProvider p = inMessage.get(ContinuationProvider.class);
if (p != null) {
p.complete();
}
invokeComplete(context, req, resp, inMessage);
} catch (SuspendedInvocationException ex) {
if (ex.getRuntimeException() != null) {
throw ex.getRuntimeException();
}
//else nothing to do, just finishing the processing
} catch (Fault ex) {
Throwable cause = ex.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException)cause;
} else {
throw ex;
}
} catch (RuntimeException ex) {
throw ex;
} finally {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Finished servicing http request on thread: " + Thread.currentThread());
}
}
}

protected void invokeComplete(final ServletContext context,
final HttpServletRequest req,
final HttpServletResponse resp,
Message m) throws IOException {
ContinuationProvider p = m.get(ContinuationProvider.class);
if (p != null) {
p.complete();
}


}

private void copyKnownRequestAttributes(HttpServletRequest request, Message message) {
message.put(SERVICE_REDIRECTION, request.getAttribute(SERVICE_REDIRECTION));
}

protected void setupMessage(Message inMessage,
final ServletContext context,
final HttpServletRequest req,
final HttpServletResponse resp) throws IOException {
setupMessage(inMessage, null, context, req, resp);
}


protected void setupMessage(final Message inMessage,
final ServletConfig config,
final ServletContext context,

0 comments on commit 7521ad6

Please sign in to comment.