use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class RMCaptureInInterceptor method handle.
@Override
protected void handle(Message message) throws SequenceFault, RMException {
// Non application messages temp files are released (cos.releaseTempFileHold()) in RMInInterceptor
if (!isGET(message) && !MessageUtils.getContextualBoolean(message, Message.ROBUST_ONEWAY, false) && (getManager().getStore() != null || (getManager().getDestinationPolicy() != null && getManager().getDestinationPolicy().getRetryPolicy() != null))) {
message.getInterceptorChain().add(new RMCaptureInEnd());
XMLStreamReader reader = message.getContent(XMLStreamReader.class);
if (null != reader) {
CachedOutputStream saved = new CachedOutputStream();
// REVISIT check factory for READER
try {
StaxUtils.copy(reader, saved);
saved.flush();
saved.holdTempFile();
reader.close();
LOG.fine("Create new XMLStreamReader");
InputStream is = saved.getInputStream();
// keep References to clean-up tmp files in RMDeliveryInterceptor
setCloseable(message, saved, is);
XMLStreamReader newReader = StaxUtils.createXMLStreamReader(is);
StaxUtils.configureReader(reader, message);
message.setContent(XMLStreamReader.class, newReader);
LOG.fine("Capturing the original RM message");
message.put(RMMessageConstants.SAVED_CONTENT, saved);
} catch (XMLStreamException | IOException e) {
throw new Fault(e);
}
} else {
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("No message found for redeliver", LOG, Collections.<String>emptyList());
RMException ex = new RMException(msg);
throw new Fault(ex);
}
}
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class RMTxStore method storeMessage.
// helpers
protected void storeMessage(Connection con, Identifier sid, RMMessage msg, boolean outbound) throws IOException, SQLException {
String id = sid.getValue();
long nr = msg.getMessageNumber();
String to = msg.getTo();
String contentType = msg.getContentType();
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "Storing {0} message number {1} for sequence {2}, to = {3}", new Object[] { outbound ? "outbound" : "inbound", nr, id, to });
}
PreparedStatement stmt = null;
try (CachedOutputStream cos = msg.getContent()) {
try (InputStream msgin = cos.getInputStream()) {
stmt = getStatement(con, outbound ? CREATE_OUTBOUND_MESSAGE_STMT_STR : CREATE_INBOUND_MESSAGE_STMT_STR);
stmt.setString(1, id);
stmt.setLong(2, nr);
stmt.setString(3, to);
stmt.setLong(4, msg.getCreatedTime());
stmt.setBinaryStream(5, msgin);
stmt.setString(6, contentType);
stmt.execute();
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "Successfully stored {0} message number {1} for sequence {2}", new Object[] { outbound ? "outbound" : "inbound", nr, id });
}
} finally {
releaseResources(stmt, null);
}
}
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class RewindableInputStream method makeRewindable.
/**
* @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);
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class RMInInterceptor method handle.
protected void handle(Message message) throws SequenceFault, RMException {
LOG.entering(getClass().getName(), "handleMessage");
boolean isServer = RMContextUtils.isServerSide(message);
LOG.fine("isServerSide: " + isServer);
RMProperties rmps = RMContextUtils.retrieveRMProperties(message, false);
// message addressing properties may be null, e.g. in case of a runtime fault
// on the server side
final AddressingProperties maps = ContextUtils.retrieveMAPs(message, false, false, false);
if (null == maps) {
// if wsrmp:RMAssertion and addressing is optional
if (isServer && !isRMPolicyEnabled(message)) {
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("WSA_REQUIRED_EXC", LOG);
LOG.log(Level.INFO, msg.toString());
throw new RMException(msg);
}
return;
}
String action = null;
if (null != maps.getAction()) {
action = maps.getAction().getValue();
}
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Action: " + action);
}
// RM does not apply to WS-Trust messages, as used by WS-SecureConversation
if (action != null && action.contains("/RST/SCT") && (action.startsWith(STSUtils.WST_NS_05_02) || action.startsWith(STSUtils.WST_NS_05_12))) {
return;
}
Object originalRequestor = message.get(RMMessageConstants.ORIGINAL_REQUESTOR_ROLE);
if (null != originalRequestor) {
LOG.fine("Restoring original requestor role to: " + originalRequestor);
message.put(Message.REQUESTOR_ROLE, originalRequestor);
}
// get the wsa and wsrm namespaces from the message
String rmUri = rmps.getNamespaceURI();
String addrUri = maps.getNamespaceURI();
ProtocolVariation protocol = ProtocolVariation.findVariant(rmUri, addrUri);
if (null == protocol && !MessageUtils.isFault(message)) {
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("WSRM_REQUIRED_EXC", LOG, rmUri, addrUri);
LOG.log(Level.INFO, msg.toString());
throw new RMException(msg);
}
RMContextUtils.setProtocolVariation(message, protocol);
boolean isApplicationMessage = !RMContextUtils.isRMProtocolMessage(action);
LOG.fine("isApplicationMessage: " + isApplicationMessage);
// for application AND out of band messages
RMEndpoint rme = getManager().getReliableEndpoint(message);
Destination destination = getManager().getDestination(message);
assertReliability(message);
if (isApplicationMessage) {
if (null != rmps) {
processAcknowledgments(rme, rmps, protocol);
processAcknowledgmentRequests(destination, message);
processSequence(destination, message);
processDeliveryAssurance(rmps);
}
if (ContextUtils.retrieveDeferredUncorrelatedMessageAbort(message)) {
LOG.info("deferred uncorrelated message abort");
message.getInterceptorChain().abort();
} else {
rme.receivedApplicationMessage();
}
} else {
// in case message is not an application message, release SAVED_CONTENT
// otherwise tmp files will not be closed
CachedOutputStream cos = (CachedOutputStream) message.get(RMMessageConstants.SAVED_CONTENT);
if (null != cos) {
cos.releaseTempFileHold();
}
rme.receivedControlMessage();
if (RM10Constants.SEQUENCE_ACKNOWLEDGMENT_ACTION.equals(action) || RM11Constants.SEQUENCE_ACKNOWLEDGMENT_ACTION.equals(action)) {
processAcknowledgments(rme, rmps, protocol);
} else if (RM10Constants.CLOSE_SEQUENCE_ACTION.equals(action)) {
// RM10 out-of-band CloseSequence/lastMessage is a special case; RM11 needs no special handling
processSequence(destination, message);
} else if ((RM10Constants.CREATE_SEQUENCE_ACTION.equals(action) || RM11Constants.CREATE_SEQUENCE_ACTION.equals(action)) && !isServer) {
LOG.fine("Processing inbound CreateSequence on client side.");
Servant servant = rme.getServant();
Object csr = servant.createSequence(message);
Proxy proxy = rme.getProxy();
proxy.createSequenceResponse(csr, protocol);
return;
}
}
}
use of org.apache.cxf.io.CachedOutputStream in project cxf by apache.
the class RMTxStoreTestBase method testCreateDeleteMessages.
@Test
public void testCreateDeleteMessages() throws IOException, SQLException {
RMMessage msg1 = control.createMock(RMMessage.class);
RMMessage msg2 = control.createMock(RMMessage.class);
Identifier sid1 = new Identifier();
sid1.setValue("sequence1");
EasyMock.expect(msg1.getMessageNumber()).andReturn(ONE).anyTimes();
EasyMock.expect(msg2.getMessageNumber()).andReturn(ONE).anyTimes();
byte[] bytes = new byte[89];
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
CachedOutputStream cos = new CachedOutputStream();
IOUtils.copy(bais, cos);
cos.flush();
bais.close();
EasyMock.expect(msg1.getContent()).andReturn(cos).anyTimes();
EasyMock.expect(msg2.getContent()).andReturn(cos).anyTimes();
EasyMock.expect(msg1.getContentType()).andReturn("text/xml").times(1);
control.replay();
Connection con = getConnection();
try {
store.beginTransaction();
store.storeMessage(con, sid1, msg1, true);
store.storeMessage(con, sid1, msg2, false);
store.commit(con);
} finally {
releaseConnection(con);
}
control.verify();
control.reset();
EasyMock.expect(msg1.getMessageNumber()).andReturn(ONE);
EasyMock.expect(msg1.getContent()).andReturn(cos);
control.replay();
con = getConnection();
try {
store.beginTransaction();
store.storeMessage(con, sid1, msg1, true);
} catch (SQLException ex) {
assertEquals("23505", ex.getSQLState());
store.abort(con);
} finally {
releaseConnection(con);
}
control.verify();
control.reset();
EasyMock.expect(msg1.getMessageNumber()).andReturn(TEN).anyTimes();
EasyMock.expect(msg2.getMessageNumber()).andReturn(TEN).anyTimes();
EasyMock.expect(msg1.getContent()).andReturn(cos).anyTimes();
EasyMock.expect(msg2.getContent()).andReturn(cos).anyTimes();
control.replay();
con = getConnection();
try {
store.beginTransaction();
store.storeMessage(con, sid1, msg1, true);
store.storeMessage(con, sid1, msg2, false);
store.commit(con);
} finally {
releaseConnection(con);
}
control.verify();
Collection<Long> messageNrs = Arrays.asList(ZERO, TEN, ONE, TEN);
store.removeMessages(sid1, messageNrs, true);
store.removeMessages(sid1, messageNrs, false);
Identifier sid2 = new Identifier();
sid1.setValue("sequence2");
store.removeMessages(sid2, messageNrs, true);
}
Aggregations