@Override public Object unmarshal(final Exchange exchange, final InputStream stream) throws Exception { try (final InputStreamReader isr = new InputStreamReader(stream, IOHelper.getCharsetName(exchange)); final BufferedReader reader = IOHelper.buffered(isr)) { if (unmarshalGenericType == null) { return gson.fromJson(reader, unmarshalType); } else { return gson.fromJson(reader, unmarshalGenericType); } } }
private NonXmlFilterReader createNonXmlFilterReader(Exchange exchange, InputStream stream) throws UnsupportedEncodingException { return new NonXmlFilterReader(new InputStreamReader(stream, IOHelper.getCharsetName(exchange))); }
@Override public void marshal(final Exchange exchange, final Object graph, final OutputStream stream) throws Exception { try (final OutputStreamWriter osw = new OutputStreamWriter(stream, IOHelper.getCharsetName(exchange)); final BufferedWriter writer = IOHelper.buffered(osw)) { gson.toJson(graph, writer); } if (contentTypeHeader) { if (exchange.hasOut()) { exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "application/json"); } else { exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/json"); } } }
@Converter public static String soapMessageToString(final SOAPMessage soapMessage, Exchange exchange) throws SOAPException, IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); soapMessage.writeTo(baos); return baos.toString(IOHelper.getCharsetName(exchange)); }
@Converter public static Payload toPayload(String str, Exchange ex) throws UnsupportedEncodingException { return toPayload(str.getBytes(IOHelper.getCharsetName(ex))); }
protected void setupClientMatrix(WebClient client, Exchange exchange) throws Exception { org.apache.cxf.message.Message cxfMessage = (org.apache.cxf.message.Message) exchange.getIn().getHeader("CamelCxfMessage"); if (cxfMessage != null) { String requestURL = (String)cxfMessage.get("org.apache.cxf.request.uri"); String matrixParam = null; int matrixStart = requestURL.indexOf(";"); int matrixEnd = requestURL.indexOf("?") > -1 ? requestURL.indexOf("?") : requestURL.length(); Map<String, String> maps = null; if (requestURL != null && matrixStart > 0) { matrixParam = requestURL.substring(matrixStart + 1, matrixEnd); if (matrixParam != null) { maps = getMatrixParametersFromMatrixString(matrixParam, IOHelper.getCharsetName(exchange)); } } if (maps != null) { for (Map.Entry<String, String> entry : maps.entrySet()) { client.matrix(entry.getKey(), entry.getValue()); LOG.debug("Matrix param " + entry.getKey() + " :: " + entry.getValue()); } } } }
public Object unmarshal(Exchange exchange, InputStream inputStream) throws IOException { CSVParser parser = new CSVParser(new InputStreamReader(inputStream, IOHelper.getCharsetName(exchange)), format); try { return asList(parser.iterator(), converter); } finally { IOHelper.close(parser); } }
return IOHelper.getCharsetName(exchange, false);
@SuppressWarnings("unchecked") protected void setupClientQueryAndHeaders(WebClient client, Exchange exchange) throws Exception { Message inMessage = exchange.getIn(); CxfRsEndpoint cxfRsEndpoint = (CxfRsEndpoint) getEndpoint(); // check if there is a query map in the message header Map<String, String> maps = inMessage.getHeader(CxfConstants.CAMEL_CXF_RS_QUERY_MAP, Map.class); if (maps == null) { // Get the map from HTTP_QUERY header String queryString = inMessage.getHeader(Exchange.HTTP_QUERY, String.class); if (queryString != null) { maps = getQueryParametersFromQueryString(queryString, IOHelper.getCharsetName(exchange)); } } if (maps == null) { maps = cxfRsEndpoint.getParameters(); } if (maps != null) { for (Map.Entry<String, String> entry : maps.entrySet()) { client.query(entry.getKey(), entry.getValue()); } } setupClientHeaders(client, exchange); }
/** * Marshals the given object into the given stream. * * @param exchange Exchange (used for access to type conversion) * @param object Body to marshal * @param outputStream Output stream of the CSV * @throws NoTypeConversionAvailableException if the body cannot be converted * @throws IOException if we cannot write into the given stream */ public void marshal(Exchange exchange, Object object, OutputStream outputStream) throws NoTypeConversionAvailableException, IOException { CSVPrinter printer = new CSVPrinter(new OutputStreamWriter(outputStream, IOHelper.getCharsetName(exchange)), format); try { Iterator it = ObjectHelper.createIterator(object); while (it.hasNext()) { Object child = it.next(); printer.printRecord(getRecordValues(exchange, child)); } } finally { IOHelper.close(printer); } }
/** * {@inheritDoc} */ @Override public void marshal(Exchange exchange, Object body, OutputStream stream) throws Exception { if (writerSettings == null) { synchronized (writerSettingsToken) { if (writerSettings == null) { writerSettings = createAndConfigureWriterSettings(); marshaller = new Marshaller<>(headers, headers == null); } } } Writer writer = new OutputStreamWriter(stream, getCharsetName(exchange)); try { marshaller.marshal(exchange, body, createWriter(writer, writerSettings)); } finally { writer.close(); } }
InputStreamReader in = new InputStreamReader(inputStream, IOHelper.getCharsetName(exchange));
String charset = IOHelper.getCharsetName(exchange, true);
@Override public Object unmarshal(Exchange exchange, InputStream inputStream) throws IOException { Reader reader = null; try { reader = new InputStreamReader(inputStream, IOHelper.getCharsetName(exchange)); CSVParser parser = new CSVParser(reader, format); CsvIterator answer = new CsvIterator(parser, converter); // add to UoW so we can close the iterator so it can release any resources exchange.addOnCompletion(new CsvUnmarshalOnCompletion(answer)); return answer; } catch (Exception e) { IOHelper.close(reader); throw e; } } }
/** * {@inheritDoc} */ @Override public Object unmarshal(Exchange exchange, InputStream stream) throws Exception { if (parserSettings == null) { synchronized (parserSettingsToken) { if (parserSettings == null) { parserSettings = new ThreadLocal<CPS>() { @Override protected CPS initialValue() { return createAndConfigureParserSettings(); } }; unmarshaller = new Unmarshaller<>(lazyLoad, asMap); } } } HeaderRowProcessor headerRowProcessor = new HeaderRowProcessor(); CPS settings = parserSettings.get(); settings.setProcessor(headerRowProcessor); P parser = createParser(settings); // univocity-parsers is responsible for closing the reader, even in case of error Reader reader = new InputStreamReader(stream, getCharsetName(exchange)); return unmarshaller.unmarshal(reader, parser, headerRowProcessor); }
in = new InputStreamReader(inputStream, IOHelper.getCharsetName(exchange));
InputStreamReader in = new InputStreamReader(inputStream, IOHelper.getCharsetName(exchange));
} else if (value instanceof InputStream) { if (needFiltering(exchange)) { xmlReader = staxConverter.createXMLStreamReader(new NonXmlFilterReader(new InputStreamReader((InputStream)value, IOHelper.getCharsetName(exchange)))); } else { xmlReader = staxConverter.createXMLStreamReader((InputStream)value, exchange);
String charset = IOHelper.getCharsetName(exchange, false); answer = new StringRequestEntity((String) data, contentType, charset);
mimeMessage.setSubject(subject, IOHelper.getCharsetName(exchange, false));