1 package org.objectweb.celtix.bus.ws.rm; 2 3 import java.io.IOException ; 4 import java.util.logging.Level ; 5 import java.util.logging.Logger ; 6 7 import javax.xml.datatype.Duration ; 8 9 import org.objectweb.celtix.bus.configuration.wsrm.DestinationPolicyType; 10 import org.objectweb.celtix.bus.ws.addressing.VersionTransformer; 11 import org.objectweb.celtix.common.logging.LogUtils; 12 import org.objectweb.celtix.ws.addressing.AddressingProperties; 13 import org.objectweb.celtix.ws.addressing.v200408.AttributedURI; 14 import org.objectweb.celtix.ws.rm.AcceptType; 15 import org.objectweb.celtix.ws.rm.CreateSequenceResponseType; 16 import org.objectweb.celtix.ws.rm.CreateSequenceType; 17 import org.objectweb.celtix.ws.rm.Expires; 18 import org.objectweb.celtix.ws.rm.Identifier; 19 import org.objectweb.celtix.ws.rm.OfferType; 20 import org.objectweb.celtix.ws.rm.wsdl.SequenceFault; 21 22 public class RMServant { 23 24 private static final Logger LOG = LogUtils.getL7dLogger(RMServant.class); 25 26 private Identifier unattachedIdentifier; 28 29 public RMServant() { 30 } 31 32 38 public CreateSequenceResponseType createSequence(RMDestination destination, 39 CreateSequenceType cs, 40 AddressingProperties maps) 41 throws SequenceFault { 42 43 CreateSequenceResponseType csr = RMUtils.getWSRMFactory().createCreateSequenceResponseType(); 44 csr.setIdentifier(destination.generateSequenceIdentifier()); 45 46 DestinationPolicyType dp = destination.getDestinationPolicies(); 47 Duration supportedDuration = dp.getSequenceExpiration(); 48 if (null == supportedDuration) { 49 supportedDuration = SourceSequence.PT0S; 50 } 51 Expires ex = cs.getExpires(); 52 LOG.info("supported duration: " + supportedDuration); 53 54 if (null != ex || supportedDuration.isShorterThan(SourceSequence.PT0S)) { 55 Duration effectiveDuration = supportedDuration; 56 if (null != ex && supportedDuration.isLongerThan(ex.getValue())) { 57 effectiveDuration = supportedDuration; 58 } 59 ex = RMUtils.getWSRMFactory().createExpires(); 60 ex.setValue(effectiveDuration); 61 csr.setExpires(ex); 62 } 63 64 OfferType offer = cs.getOffer(); 65 if (null != offer) { 66 AcceptType accept = RMUtils.getWSRMFactory().createAcceptType(); 67 if (dp.isAcceptOffers()) { 68 RMSource source = destination.getHandler().getSource(); 69 LOG.fine("Accepting inbound sequence offer"); 70 AttributedURI to = VersionTransformer.convert(maps.getTo()); 71 accept.setAcksTo(RMUtils.createReference(to.getValue())); 72 SourceSequence seq = new SourceSequence(offer.getIdentifier(), 73 null, 74 csr.getIdentifier()); 75 seq.setExpires(offer.getExpires()); 76 seq.setTarget(VersionTransformer.convert(cs.getAcksTo())); 77 source.addSequence(seq); 78 source.setCurrent(csr.getIdentifier(), seq); 79 LOG.fine("Making offered sequence the current sequence for responses to " 80 + csr.getIdentifier().getValue()); 81 } else { 82 LOG.fine("Refusing inbound sequence offer"); 83 accept.setAcksTo(RMUtils.createReference(Names.WSA_NONE_ADDRESS)); 84 } 85 csr.setAccept(accept); 86 } 87 88 DestinationSequence seq = new DestinationSequence(csr.getIdentifier(), cs.getAcksTo(), destination); 89 seq.setCorrelationID(maps.getMessageID().getValue()); 90 destination.addSequence(seq); 91 92 return csr; 93 } 94 95 public void createSequenceResponse(RMSource source, 96 CreateSequenceResponseType csr, 97 Identifier offeredId) { 98 SourceSequence seq = new SourceSequence(csr.getIdentifier()); 101 seq.setExpires(csr.getExpires()); 102 source.addSequence(seq); 103 104 source.setCurrent(clearUnattachedIdentifier(), seq); 108 109 if (null != offeredId) { 113 assert null != csr.getAccept(); 114 RMDestination dest = source.getHandler().getDestination(); 115 String address = csr.getAccept().getAcksTo().getAddress().getValue(); 116 if (!RMUtils.getAddressingConstants().getNoneURI().equals(address)) { 117 DestinationSequence ds = 118 new DestinationSequence(offeredId, csr.getAccept().getAcksTo(), dest); 119 dest.addSequence(ds); 120 } 121 } 122 } 123 124 134 public void terminateSequence(RMDestination destination, Identifier sid) 135 throws SequenceFault { 136 139 DestinationSequence terminatedSeq = destination.getSequence(sid); 140 if (null == terminatedSeq) { 141 LOG.severe("No such sequence."); 142 return; 143 } 144 145 destination.removeSequence(terminatedSeq); 146 147 150 for (SourceSequence outboundSeq : destination.getHandler().getSource().getAllSequences()) { 151 if (outboundSeq.offeredBy(sid) && !outboundSeq.isLastMessage()) { 152 153 156 RMProxy proxy = destination.getHandler().getProxy(); 157 try { 158 proxy.lastMessage(outboundSeq); 159 } catch (IOException ex) { 160 LOG.log(Level.SEVERE, "Could not terminate correlated sequence.", ex); 161 } 162 163 164 break; 165 } 166 } 167 168 169 } 170 171 protected Identifier clearUnattachedIdentifier() { 172 Identifier ret = unattachedIdentifier; 173 unattachedIdentifier = null; 174 return ret; 175 } 176 177 protected void setUnattachedIdentifier(Identifier i) { 178 unattachedIdentifier = i; 179 } 180 } 181 | Popular Tags |