Refine search
public void handleMessage(Message message) throws Fault { BindingOperationInfo bop = message.getExchange().getBindingOperationInfo(); if (bop != null && !bindingName.equals(bop.getBinding().getName())) { return; } else if (DataSource.class.isAssignableFrom(type)) { MessageContentsList list = (MessageContentsList)message.getContent(List.class); DataSource ds = (DataSource)list.get(0); String ct = ds.getContentType(); if (ct.toLowerCase().contains("multipart/related")) { Message msg = new MessageImpl(); msg.setExchange(message.getExchange()); deser.initializeAttachments(); } catch (IOException ex) { throw new Fault(ex); out = new CachedOutputStream(); message.setContent(OutputStream.class, out); XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(out); if (!(ds instanceof DOMSource)) { try { ds = new DOMSource(StaxUtils.read(ds)); } catch (XMLStreamException e) { throw new Fault(e);
CachedOutputStream csnew = (CachedOutputStream) message.getContent(OutputStream.class); String currentEnvelopeMessage = IOUtils.toString(csnew.getInputStream(), "UTF-8"); csnew.flush(); IOUtils.closeQuietly(csnew); replaceInStream.close(); IOUtils.closeQuietly(replaceInStream); os.flush(); message.setContent(OutputStream.class, os); IOUtils.closeQuietly(os);
private InputStream getInputStream(XMLStreamReader input) throws XMLStreamException, IOException { CachedOutputStream out = new CachedOutputStream(); try { StaxUtils.copy(input, out); return out.getInputStream(); } finally { out.close(); } } public DOMSource read(XMLStreamReader reader) {
private Source handleDispatchProviderCase(Service.Mode mode) { Source source = null; Message message = msgContext.getWrappedMessage(); Source obj = message.getContent(Source.class); if (message instanceof SoapMessage) { try (CachedOutputStream cos = new CachedOutputStream()) { StaxUtils.copy(obj, cos); obj = new StreamSource(cos.getInputStream()); message.setContent(Source.class, new StreamSource(cos.getInputStream())); } catch (Exception e) { throw new Fault(e); source = obj; } else { try (CachedOutputStream cos = new CachedOutputStream()) { StaxUtils.copy(obj, cos); InputStream in = cos.getInputStream(); SOAPMessage msg = initSOAPMessage(in); source = new DOMSource(SAAJUtils.getBody(msg).getFirstChild()); in.close(); } catch (Exception e) { throw new Fault(e);
inMessage.setExchange(new ExchangeImpl()); inMessage.getExchange().put(Bus.class, bus); inMessage.put(Message.DECOUPLED_CHANNEL_MESSAGE, Boolean.TRUE); InputStream in = inMessage.getContent(InputStream.class); if (in != null) { CachedOutputStream cos = new CachedOutputStream(); IOUtils.copy(in, cos); inMessage.setContent(InputStream.class, cos.getInputStream());
/** * Read the entire original input stream and cache it. Useful * if switching threads or doing something where the original * stream may not be valid by the time the next read() occurs */ public void cacheInput() { if (!cached) { CachedOutputStream cache = new CachedOutputStream(); try { InputStream origIn = in; IOUtils.copy(in, cache); if (cache.size() > 0) { in = cache.getInputStream(); } else { in = new ByteArrayInputStream(new byte[0]); } cache.close(); origIn.close(); } catch (IOException e) { //ignore } cached = true; } }
if (isOutbound(message)) { OutputStream outputStream = message.getContent(OutputStream.class); CachedOutputStream cachedOutputStream = new CachedOutputStream(); message.setContent(OutputStream.class, cachedOutputStream); message.getInterceptorChain().doIntercept(message); try { cachedOutputStream.flush(); CachedOutputStream messageStream = (CachedOutputStream) message.getContent(OutputStream.class); String currentEnvelopeMessage = IOUtils.toString(messageStream.getInputStream(), "UTF-8"); currentEnvelopeMessage = currentEnvelopeMessage.replaceAll("ns2:", ""); currentEnvelopeMessage = currentEnvelopeMessage.replaceAll(":ns2", ""); messageStream.flush(); messageStream.close(); InputStream replaceInStream = new ByteArrayInputStream(currentEnvelopeMessage.getBytes(StandardCharsets.UTF_8)); IOUtils.copy(replaceInStream, outputStream); replaceInStream.close(); outputStream.flush(); message.setContent(OutputStream.class, outputStream); outputStream.close(); } catch (Exception e) { e.printStackTrace();
/** * Copied from LoggingInInterceptor * * @param soapMessage */ private void getSoapRequest(Message soapMessage, ExchangeData exchange) { InputStream is = soapMessage.getContent(InputStream.class); if (is != null) { CachedOutputStream bos = new CachedOutputStream(); try { IOUtils.copy(is, bos); bos.flush(); is.close(); soapMessage.setContent(InputStream.class, bos.getInputStream()); StringBuilder builder = new StringBuilder(); bos.writeCacheTo(builder, bos.size()); bos.close(); exchange.setRequest(builder.toString()); exchange.setRequestSize((int)bos.size()); } catch (IOException e) { throw new Fault(e); } } }
private void dispatchDirect(Message message) throws IOException { if (destination.getMessageObserver() == null) { throw new IllegalStateException("Local destination does not have a MessageObserver on address " + destination.getAddress().getAddress().getValue()); } MessageImpl copy = new MessageImpl(); copy.put(IN_CONDUIT, this); copy.setDestination(destination); transportFactory.copy(message, copy); MessageImpl.copyContent(message, copy); OutputStream out = message.getContent(OutputStream.class); out.flush(); out.close(); CachedOutputStream stream = message.get(CachedOutputStream.class); copy.setContent(InputStream.class, stream.getInputStream()); copy.removeContent(CachedOutputStream.class); stream.releaseTempFileHold(); // Create a new incoming exchange and store the original exchange for the response ExchangeImpl ex = new ExchangeImpl(); ex.setInMessage(copy); ex.put(IN_EXCHANGE, message.getExchange()); ex.put(LocalConduit.DIRECT_DISPATCH, true); ex.setDestination(destination); destination.getMessageObserver().onMessage(copy); }
@Override public void onClose(CachedOutputStream wrapper) { InputStream transformedStream = null; try { transformedStream = XSLTUtils.transform(xsltTemplate, wrapper.getInputStream()); IOUtils.copyAndCloseInput(transformedStream, origStream); } catch (IOException e) { throw new Fault("STREAM_COPY", LOG, e, e.getMessage()); } finally { try { origStream.close(); } catch (IOException e) { LOG.warning("Cannot close stream after transformation: " + e.getMessage()); } } } }
public static String getStringFromInputStream(InputStream in) throws Exception { CachedOutputStream bos = new CachedOutputStream(); IOUtils.copy(in, bos); in.close(); bos.close(); return bos.getOut().toString(); }
@Override public void close(Message message) throws IOException { // set the pseudo status code if not set (REVISIT add this method in MessageUtils to be reused elsewhere?) Integer i = (Integer)message.get(Message.RESPONSE_CODE); if (i == null) { int code = ((message.getExchange().isOneWay() && !MessageUtils.isPartialResponse(message)) || MessageUtils.isEmptyPartialResponse(message)) ? 202 : 200; message.put(Message.RESPONSE_CODE, code); } if (Boolean.TRUE.equals(message.getExchange().get(LocalConduit.DIRECT_DISPATCH))) { final Exchange exchange = (Exchange)message.getExchange().get(LocalConduit.IN_EXCHANGE); MessageImpl copy = new MessageImpl(); copy.putAll(message); message.getContent(OutputStream.class).close(); CachedOutputStream stream = message.getContent(CachedOutputStream.class); message.setContent(OutputStream.class, stream); MessageImpl.copyContent(message, copy); copy.setContent(InputStream.class, stream.getInputStream()); stream.releaseTempFileHold(); if (exchange != null && exchange.getInMessage() == null) { exchange.setInMessage(copy); } conduit.getMessageObserver().onMessage(copy); return; } super.close(message); }
CachedOutputStream cos = new CachedOutputStream(); ctx.setOutputStream(cos); ctx.proceed(); JweJsonProducer producer = new JweJsonProducer(sharedProtectedHeaders, cos.getBytes()); String jweContent = producer.encryptWith(providers, perRecipientUnprotectedHeaders); IOUtils.copy(new ByteArrayInputStream(StringUtils.toBytesUTF8(jweContent)), actualOs); actualOs.flush();
/** * @param is * @return * @throws IOException */ public static RewindableInputStream makeRewindable(InputStream is) throws IOException { if (is.markSupported()) { return new RewindableInputStream(is); } CachedOutputStream os = new CachedOutputStream(MEMORY_SIZE_LIMIT); CachedOutputStream.copyStream(is, os, COPY_BLOCK_SIZE); return new RewindableInputStream(os); }
protected void transformXReader(Message message, XMLStreamReader xReader) { CachedOutputStream cachedOS = new CachedOutputStream(); try { StaxUtils.copy(xReader, cachedOS); InputStream transformedIS = XSLTUtils.transform(getXSLTTemplate(), cachedOS.getInputStream()); XMLStreamReader transformedReader = StaxUtils.createXMLStreamReader(transformedIS); message.setContent(XMLStreamReader.class, transformedReader); } catch (XMLStreamException e) { throw new Fault("STAX_COPY", LOG, e, e.getMessage()); } catch (IOException e) { throw new Fault("GET_CACHED_INPUT_STREAM", LOG, e, e.getMessage()); } finally { StaxUtils.close(xReader); try { cachedOS.close(); } catch (IOException e) { LOG.warning("Cannot close stream after transformation: " + e.getMessage()); } } }
private void doFromSoapMessage(Message message, Object sm) { SOAPMessage m = (SOAPMessage)sm; MessageContentsList list = (MessageContentsList)message.getContent(List.class); if (list == null) { list = new MessageContentsList(); message.setContent(List.class, list); } Object o = m; if (StreamSource.class.isAssignableFrom(type)) { try { try (CachedOutputStream out = new CachedOutputStream()) { XMLStreamWriter xsw = StaxUtils.createXMLStreamWriter(out); StaxUtils.copy(new DOMSource(m.getSOAPPart()), xsw); xsw.close(); o = new StreamSource(out.getInputStream()); } } catch (Exception e) { throw new Fault(e); } } else if (SAXSource.class.isAssignableFrom(type)) { o = new StaxSource(new W3CDOMStreamReader(m.getSOAPPart())); } else if (Source.class.isAssignableFrom(type)) { o = new DOMSource(m.getSOAPPart()); } list.set(0, o); }
private void transformOutputStream(Message message) { OutputStream os = message.getContent(OutputStream.class); if (os == null) { return; } if (!(os instanceof CachedOutputStream)) { return; } CachedOutputStream wrapper = (CachedOutputStream)os; InputStream transformedStream = null; try { transformedStream = XSLTUtils.transform(xsltTemplate, wrapper.getInputStream()); IOUtils.copy(transformedStream, origStream); message.setContent(OutputStream.class, origStream); } catch (IOException e) { throw new Fault("STREAM_COPY", LOG, e, e.getMessage()); }finally{ try { wrapper.close(); } catch (IOException e) {} } }
public Object read(QName name, Node input, Class<?> type) { if (SAXSource.class.isAssignableFrom(type)) { XMLStreamReader reader = StaxUtils.createXMLStreamReader((Element)input); return new StaxSource(reader); } else if (StreamSource.class.isAssignableFrom(type)) { try { CachedOutputStream out = new CachedOutputStream(); DOMUtils.writeXml(input, out); InputStream is = out.getInputStream(); out.close(); return new StreamSource(is); } catch (IOException e) { throw new Fault("COULD_NOT_READ_XML_STREAM", LOG, e); } catch (TransformerException e) { throw new Fault("COULD_NOT_READ_XML_STREAM_CAUSED_BY", LOG, e, e.getClass().getCanonicalName(), e.getMessage()); } } return read(input); }
public Object read(QName name, Node input, Class<?> type) { if (SAXSource.class.isAssignableFrom(type)) { XMLStreamReader reader = StaxUtils.createXMLStreamReader((Element)input); return new StaxSource(reader); } else if (StreamSource.class.isAssignableFrom(type)) { try (CachedOutputStream out = new CachedOutputStream()) { StaxUtils.writeTo(input, out); InputStream is = out.getInputStream(); return new StreamSource(is); } catch (IOException e) { throw new Fault("COULD_NOT_READ_XML_STREAM", LOG, e); } catch (XMLStreamException e) { throw new Fault("COULD_NOT_READ_XML_STREAM_CAUSED_BY", LOG, e, e.getClass().getCanonicalName(), e.getMessage()); } } return read(input); }