public void sendFault(MessageExchange exchange, Fault fault, HttpServletRequest request, HttpServletResponse response) throws Exception { addResponseHeaders(exchange, request, response); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); XMLStreamReader reader = transformer.toXMLStreamReader(fault.getContent()); OutputStream encodingStream = getResponseEncodingStream(request.getHeader(HttpHeaders.ACCEPT_ENCODING), response.getOutputStream()); XMLStreamWriter writer = transformer.getOutputFactory().createXMLStreamWriter(encodingStream); XMLStreamHelper.copy(reader, writer); writer.close(); encodingStream.close(); }
@Converter public Source convertFaultExceptionToSource(FaultException e) { return e.getFault().getContent(); }
public Fault toFaultType(javax.jbi.messaging.Fault jbiFlt, Collection<Fault> faults) throws MessageTranslationException { Element el = parse(jbiFlt.getContent()); QName elQname = new QName(el.getNamespaceURI(),el.getLocalName()); for (Fault f : faults) { if (f.getMessage() == null || f.getMessage().getParts().size() != 1) continue; javax.wsdl.Part pdef = (Part) f.getMessage().getParts().values().iterator().next(); if (pdef.getElementName() == null) continue; if (pdef.getElementName().equals(elQname)) return f; } return null; }
/** * @param logger * the logger * @param httpResponse * the HTTP response * @param fault * the JBI fault * @throws TransformerException * if an unrecoverable error occurs during the course of the * transformation */ public static final void sendHTTPErrorResponse(final Logger logger, final HttpServletResponse httpResponse, final Fault fault) throws TransformerException { final Source source = fault.getContent(); final String errorMessage; if (source == null) { errorMessage = "The fault content is empty"; } else { errorMessage = SourceHelper.toString(source); } sendHTTPErrorResponse(logger, httpResponse, HttpStatus.INTERNAL_SERVER_ERROR_500, errorMessage); }
@Override protected void processInOnly(MessageExchange exchange, NormalizedMessage in) throws Exception { NormalizedMessage out = exchange.createMessage(); Fault fault = exchange.createFault(); this.startValidation(exchange, in, out, fault); if (fault.getContent() != null) { throw new RuntimeException(sourceTransformer.contentToString(fault)); } }
@Override protected void processInOut(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws Exception { Fault fault = exchange.createFault(); this.startValidation(exchange, in, out, fault); if (fault.getContent() != null) { exchange.setFault(fault); } }
public void onJBIMessage(Exchange exchange) throws PEtALSCDKException { // Simply log Fault Fault fault = exchange.getFault(); try { listener.getLogger().log( Level.INFO, "JMS BC receive a Fault from an other component : \n" + SourceUtil.createString(fault.getContent())); } catch (PEtALSCDKException e) { throw new PEtALSCDKException("Error logging fault received on JMS BC", e); } } }
/** * Retrieve the right {@code OnJBIResponseTransformation} for the the given JBI fault. * * @param fault * The JBI fault * @param onJBIResponseTransformation * A holder in which the right {@code OnJBIResponseTransformation} will be put. * @param outgoingXmlPayload * A holder in which the XML payload to transform will be put. * @throws OnJBIResponseTransformationException * Unexpected case that should not occur, or system error */ private void lookForJBITransformationAsFault(final Fault fault, final Holder<OnJBIResponseTransformation> onJBIResponseTransformation, final Holder<Source> outgoingXmlPayload) throws OnJBIResponseTransformationException, TransformerException { outgoingXmlPayload.value = fault.getContent(); if (outgoingXmlPayload.value != null) { if (this.logger.isLoggable(Level.FINE)) { this.logger.fine("Fault received: " + SourceHelper.toString(outgoingXmlPayload.value)); } onJBIResponseTransformation.value = this.lookForJBIFaultTransformation(outgoingXmlPayload.value); } else { throw new OnJBIResponseTransformationException("JBI fault content is null", HttpStatus.INTERNAL_SERVER_ERROR_500); } }
Element srcel = parse(jbiFlt.getContent()); Node n = srcel.getFirstChild(); while (n != null) {
private static Node getFaultMessage(MessageExchange mex) throws TransformerConfigurationException { Source s = null; if (mex.getFault() != null) { Fault f = mex.getFault(); if (f != null) { s = f.getContent(); } } if (s == null) { return null; } Transformer t = null; try { t = TransformerPool.get().retrieve(); DOMResult dr = new DOMResult(); t.transform(s, dr); return dr.getNode(); } catch (TransformerConfigurationException ex) { return null; } catch (TransformerException ex) { return null; } finally { if (t != null) { TransformerPool.get().relinquish(t); } } }
public void sendFault(MessageExchange exchange, Fault fault, HttpServletRequest request, HttpServletResponse response) throws Exception { addResponseHeaders(exchange, request, response); // the content type is specific to this marshaler, depending of the used SOAP version if (soapVersion.equals("1.1")) { response.setContentType("text/xml"); } else { response.setContentType("application/soap+xml"); } response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); Message in = (Message) request.getAttribute(Message.class.getName()); Message msg = binding.createMessage(in); OutputStream encodingStream = getResponseEncodingStream(request.getHeader(HttpHeaders.CONTENT_ENCODING), response.getOutputStream()); msg.setContent(OutputStream.class, encodingStream); msg.setContent(MessageExchange.class, exchange); msg.setContent(NormalizedMessage.class, fault); msg.put(SoapVersion.class, in.get(SoapVersion.class)); msg.put(JbiConstants.USE_JBI_WRAPPER, useJbiWrapper); InterceptorChain phase = getChain(Phase.ServerOutFault); QName code = (QName) fault.getProperty("org.apache.servicemix.soap.fault.code"); String reason = (String) fault.getProperty("org.apache.servicemix.soap.fault.reason"); SoapFault soapFault = new SoapFault(code, reason, null, null, fault.getContent()); msg.setContent(Exception.class, soapFault); phase.doIntercept(msg); encodingStream.close(); }
final Source faultSource = fault.getContent(); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final Result result = new StreamResult(baos);
public Message createFault(MessageExchange exchange, Fault fault, Session session, JmsContext context) throws Exception { org.apache.servicemix.soap.api.Message in = ((Context) context).msg; org.apache.servicemix.soap.api.Message msg = binding.createMessage(in); ByteArrayOutputStream baos = new ByteArrayOutputStream(); msg.setContent(OutputStream.class, baos); msg.setContent(MessageExchange.class, exchange); msg.setContent(NormalizedMessage.class, fault); msg.put(SoapVersion.class, in.get(SoapVersion.class)); msg.put(JbiConstants.USE_JBI_WRAPPER, useJbiWrapper); InterceptorChain phase = getChain(Phase.ServerOutFault); QName code = (QName) fault.getProperty("org.apache.servicemix.soap.fault.code"); String reason = (String) fault.getProperty("org.apache.servicemix.soap.fault.reason"); SoapFault soapFault = new SoapFault(code, reason, null, null, fault.getContent()); msg.setContent(Exception.class, soapFault); phase.doIntercept(msg); return session.createTextMessage(baos.toString()); }
protected void assertExchangeWorked(MessageExchange me) throws Exception { if (me.getStatus() == ExchangeStatus.ERROR) { if (me.getError() != null) { throw me.getError(); } else { fail("Received ERROR status"); } } else if (me.getFault() != null) { fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent())); } }
.getContent()); f.setDetail(details); .getContent());
state.messageType = "fault"; if (showMessageContent) { if (fault.getContent() != null) { state.content = createString(fault.getContent()); } catch (Exception e) { state.content = "<monitoring-error>Error occured "
public Message createFault(MessageExchange exchange, Fault fault, Session session, JmsContext context) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PhaseInterceptorChain chain = new PhaseInterceptorChain(); chain.add(new AttachmentsOutInterceptor()); chain.add(new StaxOutInterceptor()); chain.add(new BodyOutInterceptor()); org.apache.servicemix.soap.api.Message msg = new MessageImpl(); msg.setContent(Source.class, fault.getContent()); msg.setContent(OutputStream.class, baos); for (String attId : (Set<String>) fault.getAttachmentNames()) { msg. getAttachments().put(attId, fault.getAttachment(attId)); } chain.doIntercept(msg); TextMessage text = session.createTextMessage(baos.toString()); if (msg.get(org.apache.servicemix.soap.api.Message.CONTENT_TYPE) != null) { text.setStringProperty(CONTENT_TYPE_PROPERTY, (String) msg.get(org.apache.servicemix.soap.api.Message.CONTENT_TYPE)); } text.setBooleanProperty(FAULT_JMS_PROPERTY, true); if (isCopyProperties()) { copyPropertiesFromNM(fault, text); } return text; }
throw xchng.getError(); content = ((InOut)xchng).getFault().getContent(); normalizedMessageProps = ((InOut)xchng).getFault().getPropertyNames();
private void processFault(MessageExchange exchange, HttpServletRequest request, HttpServletResponse response) throws Exception { SoapFault fault = new SoapFault( (QName) exchange.getFault().getProperty(JBIMarshaler.SOAP_FAULT_CODE), (QName) exchange.getFault().getProperty(JBIMarshaler.SOAP_FAULT_SUBCODE), (String) exchange.getFault().getProperty(JBIMarshaler.SOAP_FAULT_REASON), (URI) exchange.getFault().getProperty(JBIMarshaler.SOAP_FAULT_NODE), (URI) exchange.getFault().getProperty(JBIMarshaler.SOAP_FAULT_ROLE), exchange.getFault().getContent()); sendFault(fault, request, response); }
protected Message fromNMSResponse(MessageExchange exchange, Context ctx, Session session) throws Exception { Message response = null; if (exchange.getStatus() == ExchangeStatus.ERROR) { // marshal error Exception e = exchange.getError(); if (e == null) { e = new Exception("Unkown error"); } response = endpoint.getMarshaler().toJMS(e, session); } else if (exchange.getStatus() == ExchangeStatus.ACTIVE) { // check for fault Fault jbiFault = exchange.getFault(); if (jbiFault != null) { // convert fault to SOAP message SoapFault fault = new SoapFault(SoapFault.RECEIVER, null, null, null, jbiFault.getContent()); SoapMessage soapFault = soapHelper.onFault(ctx, fault); Map headers = (Map) jbiFault.getProperty(JbiConstants.PROTOCOL_HEADERS); response = endpoint.getMarshaler().toJMS(soapFault, headers, session); } else { NormalizedMessage outMsg = exchange.getMessage("out"); if (outMsg != null) { SoapMessage out = soapHelper.onReply(ctx, outMsg); Map headers = (Map) outMsg.getProperty(JbiConstants.PROTOCOL_HEADERS); response = endpoint.getMarshaler().toJMS(out, headers, session); } } } return response; }