SoapFault fault = new SoapFault("unable to process request", SoapFault.FAULT_CODE_SERVER); Element detail = fault.getOrCreateDetail(); Document detailPayload = getYourDetailHere(); detail.appendChild(detail.getOwnerDocument().importNode(detailPayload.getDocumentElement(), true)); Message outMessage = exchange.getOut(); outMessage.setHeader(org.apache.cxf.message.Message.RESPONSE_CODE, new Integer(500)); outMessage.setFault(true); outMessage.setBody(fault);
private void checkResult(String id, Exchange exchange, Person result) { if (result == null){ exchange.getOut().setFault(true); exchange.getOut().setBody(new PersonException(String.format(ERR_PERSON_X_NOT_FOUND, id), id)); }else{ exchange.getOut().setBody(result); } }
public void process(Exchange exchange) throws Exception { if (error) { throw new RuntimeException("failed"); } else { exchange.getOut().setBody("failed"); exchange.getOut().setFault(true); } }
@Override public void process(Exchange exchange) throws Exception { logger.trace("Setting fault for exchange arriving from endpoint {}", (exchange.getFromEndpoint() != null ? exchange.getFromEndpoint().getEndpointUri() : "unknown")); exchange.getIn().setFault(true); exchange.getIn().setBody(getValue()); new ContentTypeTestResource("application/xml").process(exchange); }
@Override public boolean process(Exchange exchange, AsyncCallback callback) { final RpcRequest request = module.unmarshalRequest(exchange.getIn().getBody(String.class)); final CompletableFuture<RpcResponse> future = module.execute(request); future.whenComplete((res, ex) -> { try { final RpcResponse response; if (ex != null) { // An exception occurred, store the exception in a new response LOG.warn("An error occured while executing a call in {}.", module.getId(), ex); response = module.createResponseWithException(ex); } else { // No exception occurred, use the given response response = res; } try { exchange.getOut().setBody(module.marshalResponse(response), String.class); postProcess(exchange); } catch (Throwable t) { LOG.error("Marshalling a response in RPC module {} failed.", module, t); exchange.setException(t); exchange.getOut().setFault(true); } } finally { callback.done(false); } }); return false; }
@Override public boolean process(Exchange exchange, AsyncCallback callback) { final RpcRequest request = module.unmarshalRequest(exchange.getIn().getBody(String.class)); final CompletableFuture<RpcResponse> future = module.execute(request); future.whenComplete((res, ex) -> { try { final RpcResponse response; if (ex != null) { // An exception occurred, store the exception in a new response LOG.warn("An error occured while executing a call in {}.", module.getId(), ex); response = module.createResponseWithException(ex); } else { // No exception occurred, use the given response response = res; } try { exchange.getOut().setBody(module.marshalResponse(response), String.class); postProcess(exchange); } catch (Throwable t) { LOG.error("Marshalling a response in RPC module {} failed.", module, t); exchange.setException(t); exchange.getOut().setFault(true); } } finally { callback.done(false); } }); return false; }
outMessage.setFault(true);
@Override public void handleFault(final Exchange exchange) { final Object content = exchange.getMessage().getContent(); if (content instanceof Throwable) { _camelExchange.setException((Throwable) content); return; } try { Message camelMsg = compose(exchange); camelMsg.setFault(true); } catch (Exception e) { _camelExchange.setException(e); } }
private void processReponse(MessageExchange messageExchange, Exchange exchange) throws MessagingException { if (messageExchange.getStatus() == ExchangeStatus.ERROR) { exchange.setException(messageExchange.getError()); } else if (messageExchange.getStatus() == ExchangeStatus.ACTIVE) { // first copy the exchange headers binding.copyPropertiesFromJbiToCamel(messageExchange, exchange); // then copy the out/fault message if (messageExchange.getFault() != null) { binding.copyFromJbiToCamel(messageExchange.getMessage("fault"), exchange.getOut()); exchange.getOut().setBody(new FaultException("Fault occured for " + exchange.getPattern() + " exchange", messageExchange, messageExchange.getFault())); exchange.getOut().setFault(true); } else if (messageExchange.getMessage("out") != null) { binding.copyFromJbiToCamel(messageExchange.getMessage("out"), exchange.getOut()); } done(messageExchange); } }
@Override public void handleFault(final Exchange exchange) { final Object content = exchange.getMessage().getContent(); if (content instanceof Throwable) { try { // SWITCHYARD-2906 - Transfer exchange properties/message headers first mapContext(exchange, ExchangeMapper.getCamelMessage(_camelExchange, ExchangePhase.OUT)); } catch (Exception e) { SwitchYardCamelComponentLogger.ROOT_LOGGER.failedToMapSwitchYardContextPropertiesToCamel(e); } _camelExchange.setException((Throwable) content); return; } try { Message camelMsg = compose(exchange); camelMsg.setFault(true); } catch (Exception e) { _camelExchange.setException(e); } }
log.debug("Transfer fault on OUT message: {}", isFault); if (isFault) { exchange.getOut().setFault(true);