Search in sources :

Example 11 with SequenceType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType in project cxf by apache.

the class EncoderDecoder11Impl method decodeSequenceType.

public SequenceType decodeSequenceType(Element elem) throws JAXBException {
    Unmarshaller unmarshaller = getContext().createUnmarshaller();
    JAXBElement<SequenceType> jaxbElement = unmarshaller.unmarshal(elem, SequenceType.class);
    return jaxbElement.getValue();
}
Also used : CreateSequenceType(org.apache.cxf.ws.rm.v200702.CreateSequenceType) TerminateSequenceType(org.apache.cxf.ws.rm.v200702.TerminateSequenceType) CloseSequenceType(org.apache.cxf.ws.rm.v200702.CloseSequenceType) SequenceType(org.apache.cxf.ws.rm.v200702.SequenceType) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 12 with SequenceType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType in project cxf by apache.

the class RedeliveryQueueImpl method getRedeliveryStatuses.

public Map<Long, RetryStatus> getRedeliveryStatuses(DestinationSequence seq) {
    Map<Long, RetryStatus> cp = new HashMap<>();
    List<RedeliverCandidate> sequenceCandidates = getSequenceCandidates(seq);
    if (null != sequenceCandidates) {
        for (int i = 0; i < sequenceCandidates.size(); i++) {
            RedeliverCandidate candidate = sequenceCandidates.get(i);
            RMProperties properties = RMContextUtils.retrieveRMProperties(candidate.getMessage(), false);
            SequenceType st = properties.getSequence();
            cp.put(st.getMessageNumber(), candidate);
        }
    }
    return cp;
}
Also used : HashMap(java.util.HashMap) SequenceType(org.apache.cxf.ws.rm.v200702.SequenceType) RetryStatus(org.apache.cxf.ws.rm.RetryStatus) Endpoint(org.apache.cxf.endpoint.Endpoint) RMProperties(org.apache.cxf.ws.rm.RMProperties)

Example 13 with SequenceType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType in project cxf by apache.

the class RedeliveryQueueImpl method purgeDelivered.

protected void purgeDelivered(RedeliverCandidate candidate) {
    RMProperties rmps = RMContextUtils.retrieveRMProperties(candidate.getMessage(), false);
    SequenceType st = rmps.getSequence();
    Identifier sid = st.getIdentifier();
    String key = sid.getValue();
    synchronized (this) {
        List<RedeliverCandidate> sequenceCandidates = getSequenceCandidates(key);
        if (null != sequenceCandidates) {
            // TODO use a constant op instead of this inefficient linear op
            sequenceCandidates.remove(candidate);
            undeliveredCount--;
        }
        if (sequenceCandidates.isEmpty()) {
            candidates.remove(sid.getValue());
        }
    }
    LOG.fine("Purged delivered message.");
}
Also used : Identifier(org.apache.cxf.ws.rm.v200702.Identifier) SequenceType(org.apache.cxf.ws.rm.v200702.SequenceType) RMProperties(org.apache.cxf.ws.rm.RMProperties)

Example 14 with SequenceType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType in project cxf by apache.

the class RedeliveryQueueImpl method cacheUndelivered.

/**
 * Accepts a new resend candidate.
 *
 * @param ctx the message context.
 * @return ResendCandidate
 */
protected RedeliverCandidate cacheUndelivered(Message message) {
    RMProperties rmps = RMContextUtils.retrieveRMProperties(message, false);
    SequenceType st = rmps.getSequence();
    Identifier sid = st.getIdentifier();
    String key = sid.getValue();
    RedeliverCandidate candidate = null;
    synchronized (this) {
        List<RedeliverCandidate> sequenceCandidates = getSequenceCandidates(key);
        if (null == sequenceCandidates) {
            sequenceCandidates = new ArrayList<>();
            candidates.put(key, sequenceCandidates);
        }
        candidate = getRedeliverCandidate(st, sequenceCandidates);
        if (candidate == null) {
            candidate = new RedeliverCandidate(message);
            if (isSequenceSuspended(key)) {
                candidate.suspend();
            }
            sequenceCandidates.add(candidate);
            undeliveredCount++;
        }
    }
    LOG.fine("Cached undelivered message.");
    return candidate;
}
Also used : Identifier(org.apache.cxf.ws.rm.v200702.Identifier) SequenceType(org.apache.cxf.ws.rm.v200702.SequenceType) RMProperties(org.apache.cxf.ws.rm.RMProperties)

Example 15 with SequenceType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType in project cxf by apache.

the class RetransmissionQueueImpl method doResend.

private void doResend(SoapMessage message) {
    InputStream is = null;
    try {
        // initialize copied interceptor chain for message
        PhaseInterceptorChain retransmitChain = manager.getRetransmitChain(message);
        ProtocolVariation protocol = RMContextUtils.getProtocolVariation(message);
        Endpoint endpoint = manager.getReliableEndpoint(message).getEndpoint(protocol);
        PhaseChainCache cache = new PhaseChainCache();
        boolean after = true;
        if (retransmitChain == null) {
            // no saved retransmit chain, so construct one from scratch (won't work for WS-Security on server, so
            // need to fix)
            retransmitChain = buildRetransmitChain(endpoint, cache);
            after = false;
        }
        message.setInterceptorChain(retransmitChain);
        // clear flag for SOAP out interceptor so envelope will be written
        message.remove(SoapOutInterceptor.WROTE_ENVELOPE_START);
        // discard all saved content
        Set<Class<?>> formats = message.getContentFormats();
        List<CachedOutputStreamCallback> callbacks = null;
        for (Class<?> clas : formats) {
            Object content = message.getContent(clas);
            if (content != null) {
                LOG.info("Removing " + clas.getName() + " content of actual type " + content.getClass().getName());
                message.removeContent(clas);
                if (clas == OutputStream.class && content instanceof WriteOnCloseOutputStream) {
                    callbacks = ((WriteOnCloseOutputStream) content).getCallbacks();
                }
            }
        }
        // read SOAP headers from saved input stream
        CachedOutputStream cos = (CachedOutputStream) message.get(RMMessageConstants.SAVED_CONTENT);
        // CachedOutputStream is hold until delivering was successful
        cos.holdTempFile();
        // instance is needed to close input stream later on
        is = cos.getInputStream();
        XMLStreamReader reader = StaxUtils.createXMLStreamReader(is, StandardCharsets.UTF_8.name());
        message.getHeaders().clear();
        if (reader.getEventType() != XMLStreamConstants.START_ELEMENT && reader.nextTag() != XMLStreamConstants.START_ELEMENT) {
            throw new IllegalStateException("No document found");
        }
        readHeaders(reader, message);
        int event;
        while ((event = reader.nextTag()) != XMLStreamConstants.START_ELEMENT) {
            if (event == XMLStreamConstants.END_ELEMENT) {
                throw new IllegalStateException("No body content present");
            }
        }
        // set message addressing properties
        AddressingProperties maps = MAPCodec.getInstance(message.getExchange().getBus()).unmarshalMAPs(message);
        RMContextUtils.storeMAPs(maps, message, true, MessageUtils.isRequestor(message));
        AttributedURIType to = null;
        if (null != maps) {
            to = maps.getTo();
        }
        if (null == to) {
            LOG.log(Level.SEVERE, "NO_ADDRESS_FOR_RESEND_MSG");
            return;
        }
        if (RMUtils.getAddressingConstants().getAnonymousURI().equals(to.getValue())) {
            LOG.log(Level.FINE, "Cannot resend to anonymous target");
            return;
        }
        // initialize conduit for new message
        Conduit c = message.getExchange().getConduit(message);
        if (c == null) {
            c = buildConduit(message, endpoint, to);
        }
        c.prepare(message);
        // replace standard message marshaling with copy from saved stream
        ListIterator<Interceptor<? extends Message>> iterator = retransmitChain.getIterator();
        while (iterator.hasNext()) {
            Interceptor<? extends Message> incept = iterator.next();
            // remove JAX-WS interceptors which handle message modes and such
            if (incept.getClass().getName().startsWith("org.apache.cxf.jaxws.interceptors")) {
                retransmitChain.remove(incept);
            } else if (incept instanceof PhaseInterceptor && (((PhaseInterceptor<?>) incept).getPhase() == Phase.MARSHAL)) {
                // remove any interceptors from the marshal phase
                retransmitChain.remove(incept);
            }
        }
        retransmitChain.add(new CopyOutInterceptor(reader));
        // restore callbacks on output stream
        if (callbacks != null) {
            OutputStream os = message.getContent(OutputStream.class);
            if (os != null) {
                WriteOnCloseOutputStream woc;
                if (os instanceof WriteOnCloseOutputStream) {
                    woc = (WriteOnCloseOutputStream) os;
                } else {
                    woc = new WriteOnCloseOutputStream(os);
                    message.setContent(OutputStream.class, woc);
                }
                for (CachedOutputStreamCallback cb : callbacks) {
                    woc.registerCallback(cb);
                }
            }
        }
        // send the message
        message.put(RMMessageConstants.RM_RETRANSMISSION, Boolean.TRUE);
        if (after) {
            retransmitChain.doInterceptStartingAfter(message, RMCaptureOutInterceptor.class.getName());
        } else {
            retransmitChain.doIntercept(message);
        }
        if (LOG.isLoggable(Level.INFO)) {
            RMProperties rmps = RMContextUtils.retrieveRMProperties(message, true);
            SequenceType seq = rmps.getSequence();
            LOG.log(Level.INFO, "Retransmitted message " + seq.getMessageNumber() + " in sequence " + seq.getIdentifier().getValue());
            rmps = new RMProperties();
        }
    } catch (Exception ex) {
        LOG.log(Level.SEVERE, "RESEND_FAILED_MSG", ex);
    } finally {
        // make sure to always close InputStreams of the CachedOutputStream to avoid leaving temp files undeleted
        if (null != is) {
            try {
                is.close();
            } catch (IOException e) {
            // Ignore
            }
        }
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) PartialXMLStreamReader(org.apache.cxf.staxutils.PartialXMLStreamReader) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) Message(org.apache.cxf.message.Message) WriteOnCloseOutputStream(org.apache.cxf.io.WriteOnCloseOutputStream) CachedOutputStreamCallback(org.apache.cxf.io.CachedOutputStreamCallback) PhaseInterceptor(org.apache.cxf.phase.PhaseInterceptor) WriteOnCloseOutputStream(org.apache.cxf.io.WriteOnCloseOutputStream) OutputStream(java.io.OutputStream) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) SequenceType(org.apache.cxf.ws.rm.v200702.SequenceType) RMCaptureOutInterceptor(org.apache.cxf.ws.rm.RMCaptureOutInterceptor) PhaseChainCache(org.apache.cxf.phase.PhaseChainCache) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) RMEndpoint(org.apache.cxf.ws.rm.RMEndpoint) Endpoint(org.apache.cxf.endpoint.Endpoint) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) RMCaptureOutInterceptor(org.apache.cxf.ws.rm.RMCaptureOutInterceptor) AbstractOutDatabindingInterceptor(org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) PhaseInterceptor(org.apache.cxf.phase.PhaseInterceptor) SoapOutInterceptor(org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor) RMProperties(org.apache.cxf.ws.rm.RMProperties) ProtocolVariation(org.apache.cxf.ws.rm.ProtocolVariation) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) InputStream(java.io.InputStream) IOException(java.io.IOException) RMEndpoint(org.apache.cxf.ws.rm.RMEndpoint) Endpoint(org.apache.cxf.endpoint.Endpoint) XMLStreamException(javax.xml.stream.XMLStreamException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException) RMException(org.apache.cxf.ws.rm.RMException) Conduit(org.apache.cxf.transport.Conduit)

Aggregations

SequenceType (org.apache.cxf.ws.rm.v200702.SequenceType)33 CloseSequenceType (org.apache.cxf.ws.rm.v200702.CloseSequenceType)12 RMProperties (org.apache.cxf.ws.rm.RMProperties)11 CreateSequenceType (org.apache.cxf.ws.rm.v200702.CreateSequenceType)11 TerminateSequenceType (org.apache.cxf.ws.rm.v200702.TerminateSequenceType)11 Message (org.apache.cxf.message.Message)8 Identifier (org.apache.cxf.ws.rm.v200702.Identifier)7 SequenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType)6 IOException (java.io.IOException)6 Unmarshaller (javax.xml.bind.Unmarshaller)5 AckRequestedType (org.apache.cxf.ws.rm.v200702.AckRequestedType)5 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)4 Endpoint (org.apache.cxf.endpoint.Endpoint)4 Exchange (org.apache.cxf.message.Exchange)4 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)4 SequenceAcknowledgement (org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement)4 Test (org.junit.Test)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 SystemException (com.evolveum.midpoint.util.exception.SystemException)3 File (java.io.File)3