use of org.apache.cxf.ws.rm.v200502.CreateSequenceResponseType 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.ws.rm.v200502.CreateSequenceResponseType in project cxf by apache.
the class VersionTransformer method convert.
/**
* Convert 200502 wsrm:CreateSequenceResponseType with 200408 WS-Addressing namespace to internal form.
*
* @param exposed (may be <code>null</code>)
* @return converted (<code>null</code> if exposed is <code>null</code>)
*/
public static CreateSequenceResponseType convert(org.apache.cxf.ws.rm.v200502.CreateSequenceResponseType exposed) {
if (exposed == null) {
return null;
}
CreateSequenceResponseType internal = new CreateSequenceResponseType();
internal.setAccept(convert(exposed.getAccept()));
internal.setExpires(convert(exposed.getExpires()));
internal.setIdentifier(convert(exposed.getIdentifier()));
addAll(exposed.getAny(), internal.getAny());
putAll(exposed.getOtherAttributes(), internal.getOtherAttributes());
return internal;
}
use of org.apache.cxf.ws.rm.v200502.CreateSequenceResponseType in project cxf by apache.
the class Servant method createSequence.
Object createSequence(Message message) {
LOG.fine("Creating sequence");
final ProtocolVariation protocol = RMContextUtils.getProtocolVariation(message);
AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, false);
Message outMessage = message.getExchange().getOutMessage();
if (null != outMessage) {
RMContextUtils.storeMAPs(maps, outMessage, false, false);
}
EncoderDecoder codec = protocol.getCodec();
CreateSequenceType create = codec.convertReceivedCreateSequence(getParameter(message));
Destination destination = reliableEndpoint.getDestination();
CreateSequenceResponseType createResponse = new CreateSequenceResponseType();
createResponse.setIdentifier(destination.generateSequenceIdentifier());
DestinationPolicyType dp = reliableEndpoint.getManager().getDestinationPolicy();
if (dp.getMaxSequences() > 0 && destination.getProcessingSequenceCount() >= dp.getMaxSequences()) {
throw new RuntimeException("Sequence creation refused");
}
Duration supportedDuration = dp.getSequenceExpiration();
if (null == supportedDuration) {
supportedDuration = DatatypeFactory.PT0S;
}
Expires ex = create.getExpires();
if (null != ex) {
Duration effectiveDuration = ex.getValue();
// PT0S represents 0 second and the shortest duration but in ws-rm, considered the longest
if (DatatypeFactory.PT0S.equals(effectiveDuration) || (!DatatypeFactory.PT0S.equals(supportedDuration) && supportedDuration.isShorterThan(effectiveDuration))) {
effectiveDuration = supportedDuration;
}
ex = new Expires();
ex.setValue(effectiveDuration);
createResponse.setExpires(ex);
}
OfferType offer = create.getOffer();
if (null != offer) {
AcceptType accept = new AcceptType();
if (dp.isAcceptOffers()) {
Source source = reliableEndpoint.getSource();
LOG.fine("Accepting inbound sequence offer");
// AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, false);
accept.setAcksTo(RMUtils.createReference(maps.getTo().getValue()));
SourceSequence seq = new SourceSequence(offer.getIdentifier(), null, createResponse.getIdentifier(), protocol);
seq.setExpires(offer.getExpires());
seq.setTarget(create.getAcksTo());
source.addSequence(seq);
source.setCurrent(createResponse.getIdentifier(), seq);
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Making offered sequence the current sequence for responses to " + createResponse.getIdentifier().getValue());
}
} else {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Refusing inbound sequence offer");
}
accept.setAcksTo(RMUtils.createNoneReference());
}
createResponse.setAccept(accept);
}
DestinationSequence seq = new DestinationSequence(createResponse.getIdentifier(), create.getAcksTo(), destination, protocol);
seq.setCorrelationID(maps.getMessageID().getValue());
destination.addSequence(seq);
LOG.fine("returning " + createResponse);
return codec.convertToSend(createResponse);
}
use of org.apache.cxf.ws.rm.v200502.CreateSequenceResponseType in project cxf by apache.
the class RMManagerTest method testGetNewSequence.
@Test
public void testGetNewSequence() throws NoSuchMethodException, SequenceFault, RMException {
Method m = RMManager.class.getDeclaredMethod("getSource", new Class[] { Message.class });
manager = control.createMock(RMManager.class, new Method[] { m });
Message message = control.createMock(Message.class);
Exchange exchange = control.createMock(Exchange.class);
EasyMock.expect(message.getContextualPropertyKeys()).andReturn(new HashSet<>()).anyTimes();
EasyMock.expect(message.getExchange()).andReturn(exchange).anyTimes();
EasyMock.expect(exchange.getOutMessage()).andReturn(message).anyTimes();
EasyMock.expect(exchange.getInMessage()).andReturn(null).anyTimes();
EasyMock.expect(exchange.getOutFaultMessage()).andReturn(null).anyTimes();
Conduit conduit = control.createMock(Conduit.class);
EasyMock.expect(exchange.getConduit(message)).andReturn(conduit).anyTimes();
Identifier inSid = control.createMock(Identifier.class);
AddressingProperties maps = control.createMock(AddressingProperties.class);
Source source = control.createMock(Source.class);
EasyMock.expect(manager.getSource(message)).andReturn(source);
EasyMock.expect(source.getCurrent(inSid)).andReturn(null);
AttributedURIType uri = control.createMock(AttributedURIType.class);
EasyMock.expect(maps.getTo()).andReturn(uri);
EasyMock.expect(uri.getValue()).andReturn("http://localhost:9001/TestPort");
EndpointReferenceType epr = RMUtils.createNoneReference();
EasyMock.expect(maps.getReplyTo()).andReturn(epr);
RMEndpoint rme = control.createMock(RMEndpoint.class);
EasyMock.expect(source.getReliableEndpoint()).andReturn(rme).times(2);
Proxy proxy = control.createMock(Proxy.class);
EasyMock.expect(rme.getProxy()).andReturn(proxy);
CreateSequenceResponseType createResponse = control.createMock(CreateSequenceResponseType.class);
proxy.createSequence(EasyMock.isA(EndpointReferenceType.class), (RelatesToType) EasyMock.isNull(), EasyMock.eq(false), EasyMock.isA(ProtocolVariation.class), EasyMock.isA(Exchange.class), // NOPMD
CastUtils.cast(EasyMock.isA(HashMap.class), String.class, Object.class));
EasyMock.expectLastCall().andReturn(createResponse);
Servant servant = control.createMock(Servant.class);
EasyMock.expect(rme.getServant()).andReturn(servant);
servant.createSequenceResponse(createResponse, ProtocolVariation.RM10WSA200408);
EasyMock.expectLastCall();
SourceSequence sseq = control.createMock(SourceSequence.class);
EasyMock.expect(source.awaitCurrent(inSid)).andReturn(sseq);
sseq.setTarget(EasyMock.isA(EndpointReferenceType.class));
EasyMock.expectLastCall();
control.replay();
assertSame(sseq, manager.getSequence(inSid, message, maps));
control.verify();
}
use of org.apache.cxf.ws.rm.v200502.CreateSequenceResponseType in project cxf by apache.
the class ServantTest method verifyCreateSequenceDefault.
private void verifyCreateSequenceDefault(Servant servant, RMManager manager) throws SequenceFault {
DestinationPolicyType dp = RMMANGER_FACTORY.createDestinationPolicyType();
AcksPolicyType ap = RMMANGER_FACTORY.createAcksPolicyType();
dp.setAcksPolicy(ap);
manager.setDestinationPolicy(dp);
Expires expires = new Expires();
expires.setValue(DatatypeFactory.createDuration("P0Y0M0DT0H0M0.0S"));
Message message = createTestCreateSequenceMessage(expires, null);
CreateSequenceResponseType csr = (CreateSequenceResponseType) servant.createSequence(message);
Expires expires2 = csr.getExpires();
assertNotNull(expires2);
assertEquals(DatatypeFactory.PT0S, expires2.getValue());
}
Aggregations