Search in sources :

Example 86 with ExchangeImpl

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);
}
Also used : Exchange(org.apache.cxf.message.Exchange) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) MessageObserver(org.apache.cxf.transport.MessageObserver) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Before(org.junit.Before)

Example 87 with ExchangeImpl

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));
}
Also used : Continuation(org.apache.cxf.continuations.Continuation) Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 88 with ExchangeImpl

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;
}
Also used : EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) Message(org.apache.cxf.message.Message) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Endpoint(org.apache.cxf.endpoint.Endpoint) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) CreateSequenceResponseType(org.apache.cxf.ws.rm.v200702.CreateSequenceResponseType) Exchange(org.apache.cxf.message.Exchange) RelatesToType(org.apache.cxf.ws.addressing.RelatesToType) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 89 with ExchangeImpl

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());
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) Message(org.apache.cxf.message.Message) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) CloseSequenceType(org.apache.cxf.ws.rm.v200702.CloseSequenceType) SequenceType(org.apache.cxf.ws.rm.v200702.SequenceType) IOException(java.io.IOException) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 90 with ExchangeImpl

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());
}
Also used : HashMap(java.util.HashMap) Document(org.w3c.dom.Document) SOAPMessage(javax.xml.soap.SOAPMessage) WSHandlerResult(org.apache.wss4j.dom.handler.WSHandlerResult) WSSecurityEngineResult(org.apache.wss4j.dom.engine.WSSecurityEngineResult) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) Exchange(org.apache.cxf.message.Exchange) ByteArrayInputStream(java.io.ByteArrayInputStream) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Aggregations

ExchangeImpl (org.apache.cxf.message.ExchangeImpl)227 MessageImpl (org.apache.cxf.message.MessageImpl)189 Message (org.apache.cxf.message.Message)166 Exchange (org.apache.cxf.message.Exchange)159 Test (org.junit.Test)107 Endpoint (org.apache.cxf.endpoint.Endpoint)42 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)30 ByteArrayInputStream (java.io.ByteArrayInputStream)28 QName (javax.xml.namespace.QName)23 Bus (org.apache.cxf.Bus)23 HashMap (java.util.HashMap)22 List (java.util.List)22 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)20 SOAPMessage (javax.xml.soap.SOAPMessage)16 LogEvent (org.apache.cxf.ext.logging.event.LogEvent)16 ArrayList (java.util.ArrayList)15 IOException (java.io.IOException)14 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)14 Conduit (org.apache.cxf.transport.Conduit)14