use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class MediatorInInterceptor method selectEndpoint.
@Override
protected Endpoint selectEndpoint(Message message, Set<Endpoint> eps) {
InputStream is = message.getContent(InputStream.class);
if (is == null) {
return null;
}
// cache the input stream
CachedOutputStream bos = new CachedOutputStream(4096);
try {
IOUtils.copy(is, bos);
is.close();
message.setContent(InputStream.class, bos.getInputStream());
String encoding = (String) message.get(Message.ENCODING);
XMLStreamReader xsr;
XMLInputFactory factory = StaxInInterceptor.getXMLInputFactory(message);
if (factory == null) {
xsr = StaxUtils.createXMLStreamReader(bos.getInputStream(), encoding);
} else {
synchronized (factory) {
xsr = factory.createXMLStreamReader(bos.getInputStream(), encoding);
}
}
// move to the soap body
while (true) {
xsr.nextTag();
if ("Body".equals(xsr.getName().getLocalPart())) {
break;
}
}
xsr.nextTag();
if (!xsr.isStartElement()) {
return null;
}
String methodName = xsr.getName().getLocalPart();
// to the new version of service on endpoint "local://localhost:9027/SoapContext/version2/SoapPort"
for (Endpoint ep : eps) {
if (methodName.indexOf("sayHi") != -1) {
if ("2".equals(ep.get("version"))) {
return ep;
}
} else if ("1".equals(ep.get("version"))) {
return ep;
}
}
bos.close();
} catch (Exception e) {
throw new Fault(e);
}
return null;
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class LocalConduit method dispatchDirect.
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);
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class Destination method processingComplete.
void processingComplete(Message message) {
SequenceType sequenceType = RMContextUtils.retrieveRMProperties(message, false).getSequence();
if (null == sequenceType) {
return;
}
DestinationSequence seq = getSequence(sequenceType.getIdentifier());
if (null != seq) {
long mn = sequenceType.getMessageNumber().longValue();
seq.processingComplete(mn);
seq.purgeAcknowledged(mn);
// remove acknowledged undelivered message
seq.removeDeliveringMessageNumber(mn);
if (seq.isTerminated() && seq.allAcknowledgedMessagesDelivered()) {
removeSequence(seq);
}
}
CachedOutputStream saved = (CachedOutputStream) message.remove(RMMessageConstants.SAVED_CONTENT);
if (saved != null) {
saved.releaseTempFileHold();
try {
saved.close();
} catch (IOException e) {
// ignore
}
}
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class PersistenceUtils method decodeRMContent.
public static void decodeRMContent(RMMessage rmmsg, Message msg) throws IOException {
String contentType = rmmsg.getContentType();
final CachedOutputStream cos = rmmsg.getContent();
if ((null != contentType) && contentType.startsWith("multipart/related")) {
final InputStream is = cos.getInputStream();
msg.put(Message.CONTENT_TYPE, contentType);
msg.setContent(InputStream.class, is);
AttachmentDeserializer ad = new AttachmentDeserializer(msg);
ad.initializeAttachments();
// create new cos with soap envelope only
CachedOutputStream cosSoap = new CachedOutputStream();
IOUtils.copy(msg.getContent(InputStream.class), cosSoap);
cosSoap.flush();
msg.put(RMMessageConstants.SAVED_CONTENT, cosSoap);
// REVISIT -- At the moment references must be hold for retransmission
// and the final cleanup of the CachedOutputStream.
msg.put(RMMessageConstants.ATTACHMENTS_CLOSEABLE, new Closeable() {
@Override
public void close() throws IOException {
try {
is.close();
} catch (IOException e) {
// Ignore
}
try {
cos.close();
} catch (IOException e) {
// Ignore
}
}
});
} else {
msg.put(RMMessageConstants.SAVED_CONTENT, cos);
}
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class RMTxStore method getMessages.
public Collection<RMMessage> getMessages(Identifier sid, boolean outbound) {
Connection con = verifyConnection();
PreparedStatement stmt = null;
SQLException conex = null;
Collection<RMMessage> msgs = new ArrayList<>();
ResultSet res = null;
try {
stmt = getStatement(con, outbound ? SELECT_OUTBOUND_MESSAGES_STMT_STR : SELECT_INBOUND_MESSAGES_STMT_STR);
stmt.setString(1, sid.getValue());
res = stmt.executeQuery();
while (res.next()) {
long mn = res.getLong(1);
String to = res.getString(2);
long ct = res.getLong(3);
Blob blob = res.getBlob(4);
String contentType = res.getString(5);
RMMessage msg = new RMMessage();
msg.setMessageNumber(mn);
msg.setTo(to);
msg.setCreatedTime(ct);
CachedOutputStream cos = new CachedOutputStream();
IOUtils.copyAndCloseInput(blob.getBinaryStream(), cos);
cos.flush();
msg.setContent(cos);
msg.setContentType(contentType);
msgs.add(msg);
}
} catch (SQLException ex) {
conex = ex;
LOG.log(Level.WARNING, new Message(outbound ? "SELECT_OUTBOUND_MSGS_FAILED_MSG" : "SELECT_INBOUND_MSGS_FAILED_MSG", LOG).toString(), ex);
} catch (IOException e) {
abort(con);
throw new RMStoreException(e);
} finally {
releaseResources(stmt, res);
updateConnectionState(con, conex);
}
return msgs;
}
Aggregations