use of org.apache.axis.AxisFault in project Lucee by lucee.
the class RPCServer method convertExceptionToAxisFault.
/**
* turn any Exception into an AxisFault, log it, set the response
* status code according to what the specifications say and
* return a response message for posting. This will be the response
* message passed in if non-null; one generated from the fault otherwise.
*
* @param exception what went wrong
* @param responseMsg what response we have (if any)
* @return a response message to send to the user
*/
private Message convertExceptionToAxisFault(Exception exception, Message responseMsg) {
logException(exception);
if (responseMsg == null) {
AxisFault fault = AxisFault.makeFault(exception);
processAxisFault(fault);
responseMsg = new Message(fault);
}
return responseMsg;
}
use of org.apache.axis.AxisFault in project Lucee by lucee.
the class RPCServer method doPost.
/**
* Process a POST to the servlet by handing it off to the Axis Engine.
* Here is where SOAP messages are received
* @param req posted request
* @param res respose
* @throws ServletException trouble
* @throws IOException different trouble
*/
public void doPost(HttpServletRequest req, HttpServletResponse res, Component component) throws ServletException, IOException {
long t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0;
String soapAction = null;
MessageContext msgContext = null;
Message responseMsg = null;
String contentType = null;
InputStream is = null;
try {
AxisEngine engine = getEngine();
if (engine == null) {
// !!! should return a SOAP fault...
ServletException se = new ServletException(Messages.getMessage("noEngine00"));
log.debug("No Engine!", se);
throw se;
}
// provide performance boost.
res.setBufferSize(1024 * 8);
/**
* get message context w/ various properties set
*/
msgContext = createMessageContext(engine, req, res, component);
ComponentController.set(msgContext);
// ? where it would also be picked up for 'doGet()' ?
if (securityProvider != null) {
if (isDebug) {
log.debug("securityProvider:" + securityProvider);
}
msgContext.setProperty(MessageContext.SECURITY_PROVIDER, securityProvider);
}
is = req.getInputStream();
Message requestMsg = new Message(is, false, req.getHeader(HTTPConstants.HEADER_CONTENT_TYPE), req.getHeader(HTTPConstants.HEADER_CONTENT_LOCATION));
// Transfer HTTP headers to MIME headers for request message.
MimeHeaders requestMimeHeaders = requestMsg.getMimeHeaders();
for (Enumeration e = req.getHeaderNames(); e.hasMoreElements(); ) {
String headerName = (String) e.nextElement();
for (Enumeration f = req.getHeaders(headerName); f.hasMoreElements(); ) {
String headerValue = (String) f.nextElement();
requestMimeHeaders.addHeader(headerName, headerValue);
}
}
if (isDebug) {
log.debug("Request Message:" + requestMsg);
/* Set the request(incoming) message field in the context */
/**
*******************************************************
*/
}
msgContext.setRequestMessage(requestMsg);
String url = HttpUtils.getRequestURL(req).toString().toLowerCase();
msgContext.setProperty(MessageContext.TRANS_URL, url);
// put character encoding of request to message context
// in order to reuse it during the whole process.
String requestEncoding;
try {
requestEncoding = (String) requestMsg.getProperty(SOAPMessage.CHARACTER_SET_ENCODING);
if (requestEncoding != null) {
msgContext.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, requestEncoding);
}
} catch (SOAPException e1) {
}
try {
/**
* Save the SOAPAction header in the MessageContext bag.
* This will be used to tell the Axis Engine which service
* is being invoked. This will save us the trouble of
* having to parse the Request message - although we will
* need to double-check later on that the SOAPAction header
* does in fact match the URI in the body.
*/
// (is this last stmt true??? (I don't think so - Glen))
/**
*****************************************************
*/
soapAction = getSoapAction(req);
if (soapAction != null) {
msgContext.setUseSOAPAction(true);
msgContext.setSOAPActionURI(soapAction);
}
// Create a Session wrapper for the HTTP session.
// These can/should be pooled at some point.
// (Sam is Watching! :-)
msgContext.setSession(new AxisHttpSession(req));
if (log.isDebugEnabled()) {
t1 = System.currentTimeMillis();
}
/**
**************************
*/
if (isDebug) {
log.debug("Invoking Axis Engine.");
// here we run the message by the engine
}
engine.invoke(msgContext);
if (isDebug) {
log.debug("Return from Axis Engine.");
}
if (log.isDebugEnabled())
t2 = System.currentTimeMillis();
responseMsg = msgContext.getResponseMessage();
// We used to throw exceptions on null response messages.
// They are actually OK in certain situations (asynchronous
// services), so fall through here and return an ACCEPTED
// status code below. Might want to install a configurable
// error check for this later.
} catch (AxisFault fault) {
// log and sanitize
processAxisFault(fault);
configureResponseFromAxisFault(res, fault);
responseMsg = msgContext.getResponseMessage();
if (responseMsg == null) {
responseMsg = new Message(fault);
((org.apache.axis.SOAPPart) responseMsg.getSOAPPart()).getMessage().setMessageContext(msgContext);
}
} catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
if (t instanceof InvocationTargetException)
t = ((InvocationTargetException) t).getTargetException();
// Exception
if (t instanceof Exception) {
Exception e = (Exception) t;
// other exceptions are internal trouble
responseMsg = msgContext.getResponseMessage();
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
responseMsg = convertExceptionToAxisFault(e, responseMsg);
((org.apache.axis.SOAPPart) responseMsg.getSOAPPart()).getMessage().setMessageContext(msgContext);
} else // throwable
{
logException(t);
// other exceptions are internal trouble
responseMsg = msgContext.getResponseMessage();
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
responseMsg = new Message(new AxisFault(t.toString(), t));
((org.apache.axis.SOAPPart) responseMsg.getSOAPPart()).getMessage().setMessageContext(msgContext);
}
}
} catch (AxisFault fault) {
processAxisFault(fault);
configureResponseFromAxisFault(res, fault);
responseMsg = msgContext.getResponseMessage();
if (responseMsg == null) {
responseMsg = new Message(fault);
((org.apache.axis.SOAPPart) responseMsg.getSOAPPart()).getMessage().setMessageContext(msgContext);
}
} finally {
IOUtil.closeEL(is);
}
if (log.isDebugEnabled()) {
t3 = System.currentTimeMillis();
}
/**
********************************
*/
if (responseMsg != null) {
// Transfer MIME headers to HTTP headers for response message.
MimeHeaders responseMimeHeaders = responseMsg.getMimeHeaders();
for (Iterator i = responseMimeHeaders.getAllHeaders(); i.hasNext(); ) {
MimeHeader responseMimeHeader = (MimeHeader) i.next();
res.addHeader(responseMimeHeader.getName(), responseMimeHeader.getValue());
}
// synchronize the character encoding of request and response
String responseEncoding = (String) msgContext.getProperty(SOAPMessage.CHARACTER_SET_ENCODING);
if (responseEncoding != null) {
try {
responseMsg.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, responseEncoding);
} catch (SOAPException e) {
}
}
// determine content type from message response
contentType = responseMsg.getContentType(msgContext.getSOAPConstants());
sendResponse(contentType, res, responseMsg);
} else {
// No content, so just indicate accepted
res.setStatus(202);
}
if (isDebug) {
log.debug("Response sent.");
log.debug("Exit: doPost()");
}
if (log.isDebugEnabled()) {
t4 = System.currentTimeMillis();
log.debug("axisServlet.doPost: " + soapAction + " pre=" + (t1 - t0) + " invoke=" + (t2 - t1) + " post=" + (t3 - t2) + " send=" + (t4 - t3) + " " + msgContext.getTargetService() + "." + ((msgContext.getOperation() == null) ? "" : msgContext.getOperation().getName()));
}
}
use of org.apache.axis.AxisFault in project Lucee by lucee.
the class RPCServer method getSoapAction.
/**
* Extract the SOAPAction header.
* if SOAPAction is null then we'll we be forced to scan the body for it.
* if SOAPAction is "" then use the URL
* @param req incoming request
* @return the action
* @throws AxisFault
*/
private String getSoapAction(HttpServletRequest req) throws AxisFault {
String soapAction = req.getHeader(HTTPConstants.HEADER_SOAP_ACTION);
if (soapAction == null) {
String contentType = req.getHeader(HTTPConstants.HEADER_CONTENT_TYPE);
if (contentType != null) {
int index = contentType.indexOf("action");
if (index != -1) {
soapAction = contentType.substring(index + 7);
}
}
}
if (isDebug) {
log.debug("HEADER_SOAP_ACTION:" + soapAction);
/**
* Technically, if we don't find this header, we should probably fault.
* It's required in the SOAP HTTP binding.
*/
}
if (soapAction == null) {
AxisFault af = new AxisFault("Client.NoSOAPAction", Messages.getMessage("noHeader00", "SOAPAction"), null, null);
exceptionLog.error(Messages.getMessage("genFault00"), af);
throw af;
}
// we strip them if they are present
if (soapAction.startsWith("\"") && soapAction.endsWith("\"") && soapAction.length() >= 2) {
int end = soapAction.length() - 1;
soapAction = soapAction.substring(1, end);
}
if (soapAction.length() == 0) {
// Is this right?
soapAction = req.getContextPath();
}
return soapAction;
}
use of org.apache.axis.AxisFault in project tomee by apache.
the class AxisWsContainer method doService.
protected void doService(final HttpRequest req, final HttpResponse res) throws Exception {
final org.apache.axis.MessageContext messageContext = new org.apache.axis.MessageContext(null);
req.setAttribute(WsConstants.MESSAGE_CONTEXT, messageContext);
messageContext.setClassLoader(classLoader);
Message responseMessage;
String contentType = req.getHeader(HTTPConstants.HEADER_CONTENT_TYPE);
final String contentLocation = req.getHeader(HTTPConstants.HEADER_CONTENT_LOCATION);
final InputStream inputStream = req.getInputStream();
final Message requestMessage = new Message(inputStream, false, contentType, contentLocation);
messageContext.setRequestMessage(requestMessage);
messageContext.setProperty(HTTPConstants.MC_HTTP_SERVLETPATHINFO, req.getURI().getPath());
messageContext.setProperty(org.apache.axis.MessageContext.TRANS_URL, req.getURI().toString());
messageContext.setService(service);
messageContext.setProperty(REQUEST, req);
messageContext.setProperty(RESPONSE, res);
messageContext.setProperty(AxisEngine.PROP_DISABLE_PRETTY_XML, Boolean.TRUE);
final ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
try {
try {
final String characterEncoding = (String) requestMessage.getProperty(SOAPMessage.CHARACTER_SET_ENCODING);
if (characterEncoding != null) {
messageContext.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, characterEncoding);
} else {
messageContext.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, "UTF-8");
}
final String soapAction = req.getHeader(HTTPConstants.HEADER_SOAP_ACTION);
if (soapAction != null) {
messageContext.setUseSOAPAction(true);
messageContext.setSOAPActionURI(soapAction);
}
final SOAPEnvelope env = requestMessage.getSOAPEnvelope();
if (env != null && env.getSOAPConstants() != null) {
messageContext.setSOAPConstants(env.getSOAPConstants());
}
final SOAPService service = messageContext.getService();
Thread.currentThread().setContextClassLoader(classLoader);
service.invoke(messageContext);
responseMessage = messageContext.getResponseMessage();
} catch (final AxisFault fault) {
if (req.getMethod().equals(HttpRequest.Method.GET.name()) && req.getParameters().isEmpty()) {
String serviceName = req.getURI().getRawPath();
serviceName = serviceName.substring(serviceName.lastIndexOf("/") + 1);
printServiceInfo(res, serviceName);
return;
} else {
responseMessage = handleFault(fault, res, messageContext);
}
} catch (final Exception e) {
responseMessage = handleException(messageContext, res, e);
}
// TODO investigate and fix operation == null!
if (messageContext.getOperation() != null) {
if (messageContext.getOperation().getMep() == OperationType.ONE_WAY) {
// No content, so just indicate accepted
res.setStatus(HttpServletResponse.SC_ACCEPTED);
return;
} else if (responseMessage == null) {
responseMessage = handleException(messageContext, null, new ServerRuntimeException("No response for non-one-way operation"));
}
} else if (responseMessage == null) {
res.setStatus(HttpServletResponse.SC_ACCEPTED);
return;
}
try {
final SOAPConstants soapConstants = messageContext.getSOAPConstants();
final String contentType1 = responseMessage.getContentType(soapConstants);
res.setContentType(contentType1);
// Transfer MIME headers to HTTP headers for response message.
final MimeHeaders responseMimeHeaders = responseMessage.getMimeHeaders();
for (final Iterator i = responseMimeHeaders.getAllHeaders(); i.hasNext(); ) {
final MimeHeader responseMimeHeader = (MimeHeader) i.next();
res.setHeader(responseMimeHeader.getName(), responseMimeHeader.getValue());
}
// TODO discuss this with dims.
// // synchronize the character encoding of request and response
// String responseEncoding = (String) messageContext.getProperty(
// SOAPMessage.CHARACTER_SET_ENCODING);
// if (responseEncoding != null) {
// try {
// responseMessage.setProperty(SOAPMessage.CHARACTER_SET_ENCODING,
// responseEncoding);
// } catch (SOAPException e) {
// log.info(Messages.getMessage("exception00"), e);
// }
// }
// determine content type from message response
contentType = responseMessage.getContentType(messageContext.getSOAPConstants());
responseMessage.writeTo(res.getOutputStream());
} catch (final Exception e) {
LOGGER.warning(Messages.getMessage("exception00"), e);
}
} finally {
Thread.currentThread().setContextClassLoader(oldClassLoader);
}
}
use of org.apache.axis.AxisFault in project tomee by apache.
the class AxisWsContainer method handleException.
private Message handleException(final MessageContext context, final HttpResponse res, final Exception e) {
Message responseMessage;
// other exceptions are internal trouble
responseMessage = context.getResponseMessage();
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
Message responseMsg = responseMessage;
LOGGER.warning(Messages.getMessage("exception00"), e);
if (responseMsg == null) {
final AxisFault fault = AxisFault.makeFault(e);
// log the fault
final Element runtimeException = fault.lookupFaultDetail(Constants.QNAME_FAULTDETAIL_RUNTIMEEXCEPTION);
if (runtimeException != null) {
LOGGER.debug(Messages.getMessage("axisFault00"), fault);
// strip runtime details
fault.removeFaultDetail(Constants.QNAME_FAULTDETAIL_RUNTIMEEXCEPTION);
}
responseMsg = new Message(fault);
}
responseMessage = responseMsg;
final SOAPPart soapPart = (SOAPPart) responseMessage.getSOAPPart();
soapPart.getMessage().setMessageContext(context);
return responseMessage;
}
Aggregations