use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class JMSContinuationTest method setUp.
@Before
public void setUp() {
m = new MessageImpl();
Exchange exchange = new ExchangeImpl();
m.setExchange(exchange);
m.setInterceptorChain(EasyMock.createMock(InterceptorChain.class));
exchange.setInMessage(m);
b = BusFactory.getDefaultBus();
observer = EasyMock.createMock(MessageObserver.class);
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class JMSContinuationProviderTest method testGetNewContinuation.
@Test
public void testGetNewContinuation() {
Message m = new MessageImpl();
m.setExchange(new ExchangeImpl());
Counter counter = EasyMock.createMock(Counter.class);
JMSContinuationProvider provider = new JMSContinuationProvider(bus, m, null, counter);
Continuation cw = provider.getContinuation();
assertTrue(cw.isNew());
assertSame(cw, m.get(JMSContinuation.class));
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class RMManager method getSequence.
public SourceSequence getSequence(Identifier inSeqId, Message message, AddressingProperties maps) throws RMException {
Source source = getSource(message);
SourceSequence seq = source.getCurrent(inSeqId);
RMConfiguration config = getEffectiveConfiguration(message);
if (null == seq || seq.isExpired()) {
// TODO: better error handling
final EndpointReferenceType to;
boolean isServer = RMContextUtils.isServerSide(message);
EndpointReferenceType acksTo;
RelatesToType relatesTo = null;
if (isServer) {
AddressingProperties inMaps = RMContextUtils.retrieveMAPs(message, false, false);
inMaps.exposeAs(config.getAddressingNamespace());
acksTo = RMUtils.createReference(inMaps.getTo().getValue());
to = inMaps.getReplyTo();
source.getReliableEndpoint().getServant().setUnattachedIdentifier(inSeqId);
relatesTo = (new org.apache.cxf.ws.addressing.ObjectFactory()).createRelatesToType();
Destination destination = getDestination(message);
DestinationSequence inSeq = inSeqId == null ? null : destination.getSequence(inSeqId);
relatesTo.setValue(inSeq != null ? inSeq.getCorrelationID() : null);
} else {
to = RMUtils.createReference(maps.getTo().getValue());
acksTo = maps.getReplyTo();
if (RMUtils.getAddressingConstants().getNoneURI().equals(acksTo.getAddress().getValue())) {
Endpoint ei = message.getExchange().getEndpoint();
org.apache.cxf.transport.Destination dest = ei == null ? null : ei.getEndpointInfo().getProperty(MAPAggregator.DECOUPLED_DESTINATION, org.apache.cxf.transport.Destination.class);
if (null == dest) {
acksTo = RMUtils.createAnonymousReference();
} else {
acksTo = dest.getAddress();
}
}
}
if (ContextUtils.isGenericAddress(to)) {
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("CREATE_SEQ_ANON_TARGET", LOG, to != null && to.getAddress() != null ? to.getAddress().getValue() : null);
LOG.log(Level.INFO, msg.toString());
throw new RMException(msg);
}
Proxy proxy = source.getReliableEndpoint().getProxy();
ProtocolVariation protocol = config.getProtocolVariation();
Exchange exchange = new ExchangeImpl();
Map<String, Object> context = new HashMap<>(16);
for (String key : message.getContextualPropertyKeys()) {
// copy other properties?
if (key.startsWith("ws-security") || key.startsWith("security.")) {
context.put(key, message.getContextualProperty(key));
}
}
CreateSequenceResponseType createResponse = proxy.createSequence(acksTo, relatesTo, isServer, protocol, exchange, context);
if (!isServer) {
Servant servant = source.getReliableEndpoint().getServant();
servant.createSequenceResponse(createResponse, protocol);
// propagate security properties to application endpoint, in case we're using WS-SecureConversation
Exchange appex = message.getExchange();
if (appex.get(SecurityConstants.TOKEN) == null) {
appex.put(SecurityConstants.TOKEN, exchange.get(SecurityConstants.TOKEN));
appex.put(SecurityConstants.TOKEN_ID, exchange.get(SecurityConstants.TOKEN_ID));
}
}
seq = source.awaitCurrent(inSeqId);
seq.setTarget(to);
}
return seq;
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class RMManager method recoverDestinationSequence.
private void recoverDestinationSequence(Endpoint endpoint, Conduit conduit, Destination d, DestinationSequence ds) {
// always recover the sequence
d.addSequence(ds, false);
Collection<RMMessage> ms = store.getMessages(ds.getIdentifier(), false);
if (null == ms || ms.isEmpty()) {
return;
}
LOG.log(Level.FINE, "Number of messages in sequence: {0}", ms.size());
for (RMMessage m : ms) {
Message message = new MessageImpl();
Exchange exchange = new ExchangeImpl();
message.setExchange(exchange);
if (null != conduit) {
exchange.setConduit(conduit);
}
exchange.put(Endpoint.class, endpoint);
exchange.put(Service.class, endpoint.getService());
if (endpoint.getEndpointInfo().getService() != null) {
exchange.put(ServiceInfo.class, endpoint.getEndpointInfo().getService());
exchange.put(InterfaceInfo.class, endpoint.getEndpointInfo().getService().getInterface());
}
exchange.put(Binding.class, endpoint.getBinding());
exchange.put(BindingInfo.class, endpoint.getEndpointInfo().getBinding());
exchange.put(Bus.class, bus);
SequenceType st = new SequenceType();
st.setIdentifier(ds.getIdentifier());
st.setMessageNumber(m.getMessageNumber());
RMProperties rmps = new RMProperties();
rmps.setSequence(st);
rmps.setCreatedTime(m.getCreatedTime());
RMContextUtils.storeRMProperties(message, rmps, false);
try {
// RMMessage is stored in a serialized way, therefore
// RMMessage content must be splitted into soap root message
// and attachments
PersistenceUtils.decodeRMContent(m, message);
redeliveryQueue.addUndelivered(message);
// add acknowledged undelivered message
ds.addDeliveringMessageNumber(m.getMessageNumber());
} catch (IOException e) {
LOG.log(Level.SEVERE, "Error reading persisted message data", e);
}
}
// if no messages are recovered and the sequence has been already terminated, remove the sequence
if (ds.isTerminated() && ds.allAcknowledgedMessagesDelivered()) {
d.removeSequence(ds);
store.removeDestinationSequence(ds.getIdentifier());
}
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class WSS4JInOutTest method testCustomProcessor.
@Test
public void testCustomProcessor() throws Exception {
Document doc = readDocument("wsse-request-clean.xml");
WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();
SoapMessage msg = getSoapMessageForDom(doc);
msg.put(ConfigurationConstants.ACTION, ConfigurationConstants.SIGNATURE);
msg.put(ConfigurationConstants.SIG_PROP_FILE, "outsecurity.properties");
msg.put(ConfigurationConstants.USER, "myalias");
msg.put("password", "myAliasPassword");
handler.handleMessage(msg);
SOAPMessage saajMsg = msg.getContent(SOAPMessage.class);
doc = saajMsg.getSOAPPart();
assertValid("//wsse:Security", doc);
assertValid("//wsse:Security/ds:Signature", doc);
byte[] docbytes = getMessageBytes(doc);
StaxUtils.read(new ByteArrayInputStream(docbytes));
final Map<String, Object> properties = new HashMap<>();
properties.put(WSS4JInInterceptor.PROCESSOR_MAP, createCustomProcessorMap());
WSS4JInInterceptor inHandler = new WSS4JInInterceptor(properties);
SoapMessage inmsg = new SoapMessage(new MessageImpl());
Exchange ex = new ExchangeImpl();
ex.setInMessage(inmsg);
inmsg.setContent(SOAPMessage.class, saajMsg);
inHandler.setProperty(ConfigurationConstants.ACTION, WSHandlerConstants.NO_SECURITY);
inHandler.handleMessage(inmsg);
List<WSHandlerResult> results = getResults(inmsg);
assertTrue(results != null && results.size() == 1);
List<WSSecurityEngineResult> signatureResults = results.get(0).getActionResults().get(WSConstants.SIGN);
assertTrue(signatureResults == null || signatureResults.isEmpty());
}
Aggregations