org.apache.camel.InvalidPayloadException Java Examples
The following examples show how to use
org.apache.camel.InvalidPayloadException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QuteTestBase.java From camel-quarkus with Apache License 2.0 | 5 votes |
/** * Asserts that the given exchange has an OUT message of the given body value * * @param exchange the exchange which should have an OUT message * @param expected the expected value of the OUT message * @throws InvalidPayloadException is thrown if the payload is not the expected class type */ protected static void assertOutMessageBodyEquals(Exchange exchange, Object expected) throws InvalidPayloadException { Assertions.assertNotNull(exchange, "Should have a response exchange!"); Object actual; if (expected == null) { actual = exchange.getMessage().getMandatoryBody(); Assertions.assertEquals(expected, actual, "output body of: " + exchange); } else { actual = exchange.getMessage().getMandatoryBody(expected.getClass()); } Assertions.assertEquals(expected, actual, "output body of: " + exchange); }
Example #2
Source File: RequestSoapPayloadConverter.java From syndesis with Apache License 2.0 | 5 votes |
@Override protected void convertMessage(final Message in) { try { final Source body = bodyAsSource(in); // extract body as stream, and headers as elements in single DOM final XMLEventReader bodyReader = XML_INPUT_FACTORY.createXMLEventReader(body); final SoapPayloadReaderFilter payloadFilter = new SoapPayloadReaderFilter(soapVersion); final XMLEventReader eventReader = XML_INPUT_FACTORY.createFilteredReader(bodyReader, payloadFilter); // all the work is done in the filter, so we ignore the event writer output try (OutputStream bos = new ByteArrayOutputStream()) { XMLEventWriter target = XML_OUTPUT_FACTORY.createXMLEventWriter(bos); target.add(eventReader); } // convert filtered parts to CxfPayload final CxfPayload<Source> cxfPayload = payloadFilter.getCxfPayload(); // add existing SOAP headers final List<?> existingHeaders = (List<?>) in.getHeader(Header.HEADER_LIST); if (existingHeaders != null) { final List<Source> headers = cxfPayload.getHeaders(); for (Object header : existingHeaders) { if (header instanceof Source) { headers.add((Source) header); } else { // wrap dom node headers.add(new DOMSource((Node)header)); } } } in.setBody(cxfPayload); } catch (XMLStreamException | InvalidPayloadException | IOException e) { throw new RuntimeCamelException("Error creating SOAP message from request message: " + e.getMessage(), e); } }
Example #3
Source File: ResponseSoapPayloadConverter.java From syndesis with Apache License 2.0 | 5 votes |
@Override protected void convertMessage(Message in) { try { // get SOAP QNames from CxfPayload headers final SoapMessage soapMessage = in.getHeader("CamelCxfMessage", SoapMessage.class); final SoapVersion soapVersion = soapMessage.getVersion(); // get CxfPayload body final CxfPayload<?> cxfPayload = in.getMandatoryBody(CxfPayload.class); final List<?> headers = cxfPayload.getHeaders(); final List<Source> body = cxfPayload.getBodySources(); final OutputStream outputStream = newOutputStream(in, cxfPayload); final XMLStreamWriter writer = newXmlStreamWriter(outputStream); // serialize headers and body into an envelope writeStartEnvelopeAndHeaders(soapVersion, headers, writer); if (body != null && !body.isEmpty()) { writeBody(writer, body, soapVersion); } writer.writeEndDocument(); final InputStream inputStream = getInputStream(outputStream, writer); // set the input stream as the Camel message body in.setBody(inputStream); } catch (InvalidPayloadException | XMLStreamException | IOException e) { throw new RuntimeCamelException("Error parsing CXF Payload: " + e.getMessage(), e); } }
Example #4
Source File: AbstractFaultSoapPayloadConverter.java From syndesis with Apache License 2.0 | 5 votes |
@Override public void process(Exchange exchange) { final Exception exception = (Exception) exchange.getProperty(Exchange.EXCEPTION_CAUGHT); if (exception instanceof SoapFault) { SoapFault soapFault = (SoapFault) exception; final Message in = exchange.getIn(); // get SOAP QNames from CxfPayload headers final SoapMessage soapMessage = in.getHeader("CamelCxfMessage", SoapMessage.class); final SoapVersion soapVersion = soapMessage.getVersion(); try { // get CxfPayload body final CxfPayload<?> cxfPayload = in.getMandatoryBody(CxfPayload.class); final OutputStream outputStream = newOutputStream(in, cxfPayload); final XMLStreamWriter writer = newXmlStreamWriter(outputStream); handleFault(writer, soapFault, soapVersion); writer.writeEndDocument(); final InputStream inputStream = getInputStream(outputStream, writer); // set the input stream as the Camel message body in.setBody(inputStream); } catch (InvalidPayloadException | XMLStreamException | IOException e) { throw new RuntimeCamelException("Error parsing CXF Payload: " + e.getMessage(), e); } } }
Example #5
Source File: RequestSoapPayloadConverter.java From syndesis with Apache License 2.0 | 4 votes |
static Source bodyAsSource(final Message in) throws InvalidPayloadException { return new StreamSource(in.getMandatoryBody(InputStream.class)); }