Search in sources :

Example 1 with RelatesToType

use of org.apache.cxf.ws.addressing.RelatesToType in project cxf by apache.

the class MAPCodecTest method isReply.

private boolean isReply(boolean exposedAsNative) {
    boolean isReply = false;
    if (exposedAsNative) {
        isReply = Names.WSA_RELATIONSHIP_REPLY.equals(((RelatesToType) expectedValues[4]).getRelationshipType());
    } else {
        QName relationship = expectedValues[4] instanceof Relationship ? ((Relationship) expectedValues[4]).getRelationshipType() : ((org.apache.cxf.ws.addressing.v200403.Relationship) expectedValues[4]).getRelationshipType();
        isReply = relationship == null || Names.WSA_REPLY_NAME.equalsIgnoreCase(relationship.getLocalPart());
    }
    return isReply;
}
Also used : RelatesToType(org.apache.cxf.ws.addressing.RelatesToType) QName(javax.xml.namespace.QName) Relationship(org.apache.cxf.ws.addressing.v200408.Relationship)

Example 2 with RelatesToType

use of org.apache.cxf.ws.addressing.RelatesToType in project cxf by apache.

the class MAPCodecTest method getMAPs.

private AddressingProperties getMAPs(boolean requestor, boolean outbound, String uri) {
    AddressingProperties maps = new AddressingProperties();
    boolean exposeAsNative = Names.WSA_NAMESPACE_NAME.equals(uri);
    boolean exposeAs200408 = Names200408.WSA_NAMESPACE_NAME.equals(uri);
    boolean exposeAs200403 = Names200403.WSA_NAMESPACE_NAME.equals(uri);
    AttributedURIType id = ContextUtils.getAttributedURI("urn:uuid:12345");
    maps.setMessageID(id);
    AttributedURIType to = ContextUtils.getAttributedURI("foobar");
    EndpointReferenceType toEpr = EndpointReferenceUtils.getEndpointReference(to);
    maps.setTo(toEpr);
    EndpointReferenceType replyTo = new EndpointReferenceType();
    String anonymous = exposeAsNative ? Names.WSA_ANONYMOUS_ADDRESS : exposeAs200408 ? Names200408.WSA_ANONYMOUS_ADDRESS : Names200403.WSA_ANONYMOUS_ADDRESS;
    replyTo.setAddress(ContextUtils.getAttributedURI(anonymous));
    maps.setReplyTo(replyTo);
    EndpointReferenceType from = EndpointReferenceUtils.getEndpointReference("snafu");
    maps.setFrom(from);
    EndpointReferenceType faultTo = new EndpointReferenceType();
    anonymous = exposeAsNative ? Names.WSA_ANONYMOUS_ADDRESS : exposeAs200408 ? Names200408.WSA_ANONYMOUS_ADDRESS : Names200403.WSA_ANONYMOUS_ADDRESS;
    faultTo.setAddress(ContextUtils.getAttributedURI(anonymous));
    maps.setFaultTo(faultTo);
    RelatesToType relatesTo = null;
    if (expectRelatesTo) {
        String correlationID = "urn:uuid:67890";
        relatesTo = new RelatesToType();
        relatesTo.setValue(correlationID);
        maps.setRelatesTo(relatesTo);
        if (nonReplyRelationship == null) {
            correlatedExchange = new ExchangeImpl();
            codec.uncorrelatedExchanges.put(correlationID, correlatedExchange);
        } else {
            relatesTo.setRelationshipType(nonReplyRelationship);
        }
    }
    AttributedURIType action = ContextUtils.getAttributedURI("http://foo/bar/SEI/opRequest");
    maps.setAction(action);
    maps.exposeAs(uri);
    expectedNamespaceURI = uri;
    expectedNames = new QName[] { new QName(uri, Names.WSA_ACTION_NAME), new QName(uri, Names.WSA_MESSAGEID_NAME), new QName(uri, Names.WSA_TO_NAME), new QName(uri, Names.WSA_REPLYTO_NAME), new QName(uri, Names.WSA_RELATESTO_NAME), new QName(uri, Names.WSA_FROM_NAME), new QName(uri, Names.WSA_FAULTTO_NAME) };
    if (exposeAsNative) {
        expectedValues = new Object[] { action, id, to, replyTo, relatesTo, from, faultTo };
    } else if (exposeAs200408) {
        expectedValues = new Object[] { org.apache.cxf.ws.addressing.VersionTransformer.convert(action), org.apache.cxf.ws.addressing.VersionTransformer.convert(id), org.apache.cxf.ws.addressing.VersionTransformer.convert(to), org.apache.cxf.ws.addressing.VersionTransformer.convert(replyTo), org.apache.cxf.ws.addressing.VersionTransformer.convert(relatesTo), org.apache.cxf.ws.addressing.VersionTransformer.convert(from), org.apache.cxf.ws.addressing.VersionTransformer.convert(faultTo) };
        if (!outbound) {
            // conversion from 2004/08 to 2005/08 anonymous address
            // occurs transparently in VersionTransformer
            Names200408.EPR_TYPE.cast(expectedValues[3]).getAddress().setValue(Names.WSA_ANONYMOUS_ADDRESS);
            Names200408.EPR_TYPE.cast(expectedValues[5]).getAddress().setValue(Names.WSA_ANONYMOUS_ADDRESS);
        }
    } else if (exposeAs200403) {
        expectedValues = new Object[] { org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(action), org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(id), org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(to), org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(replyTo), org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(relatesTo), org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(from), org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(faultTo) };
        if (!outbound) {
            // conversion from 2004/03 to 2005/08 anonymous address
            // occurs transparently in VersionTransformer
            Names200403.EPR_TYPE.cast(expectedValues[3]).getAddress().setValue(Names.WSA_ANONYMOUS_ADDRESS);
            Names200403.EPR_TYPE.cast(expectedValues[5]).getAddress().setValue(Names.WSA_ANONYMOUS_ADDRESS);
        }
    } else {
        fail("unexpected namespace URI: " + uri);
    }
    return maps;
}
Also used : RelatesToType(org.apache.cxf.ws.addressing.RelatesToType) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) QName(javax.xml.namespace.QName) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 3 with RelatesToType

use of org.apache.cxf.ws.addressing.RelatesToType 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
        EndpointReferenceType to = null;
        boolean isServer = RMContextUtils.isServerSide(message);
        EndpointReferenceType acksTo = null;
        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 4 with RelatesToType

use of org.apache.cxf.ws.addressing.RelatesToType in project cxf by apache.

the class ProxyTest method testCreateSequence.

@SuppressWarnings("unchecked")
private void testCreateSequence(boolean isServer) throws NoSuchMethodException, RMException {
    Method m = Proxy.class.getDeclaredMethod("invoke", new Class[] { OperationInfo.class, ProtocolVariation.class, Object[].class, Map.class, Exchange.class });
    Proxy proxy = EasyMock.createMockBuilder(Proxy.class).addMockedMethod(m).createMock(control);
    proxy.setReliableEndpoint(rme);
    RMManager manager = control.createMock(RMManager.class);
    EasyMock.expect(rme.getManager()).andReturn(manager).anyTimes();
    SourcePolicyType sp = control.createMock(SourcePolicyType.class);
    EasyMock.expect(manager.getSourcePolicy()).andReturn(sp).anyTimes();
    EasyMock.expect(sp.getAcksTo()).andReturn(null).anyTimes();
    Duration d = DatatypeFactory.createDuration("PT12H");
    EasyMock.expect(sp.getSequenceExpiration()).andReturn(d).anyTimes();
    EasyMock.expect(sp.isIncludeOffer()).andReturn(Boolean.TRUE).anyTimes();
    Duration dOffered = DatatypeFactory.createDuration("PT24H");
    EasyMock.expect(sp.getOfferedSequenceExpiration()).andReturn(dOffered).anyTimes();
    Source source = control.createMock(Source.class);
    EasyMock.expect(rme.getSource()).andReturn(source).anyTimes();
    Identifier offeredId = control.createMock(Identifier.class);
    EasyMock.expect(source.generateSequenceIdentifier()).andReturn(offeredId).anyTimes();
    Endpoint endpoint = control.createMock(Endpoint.class);
    EasyMock.expect(rme.getEndpoint(ProtocolVariation.RM10WSA200408)).andReturn(endpoint).anyTimes();
    EndpointInfo epi = control.createMock(EndpointInfo.class);
    EasyMock.expect(endpoint.getEndpointInfo()).andReturn(epi).anyTimes();
    ServiceInfo si = control.createMock(ServiceInfo.class);
    EasyMock.expect(epi.getService()).andReturn(si).anyTimes();
    InterfaceInfo ii = control.createMock(InterfaceInfo.class);
    EasyMock.expect(si.getInterface()).andReturn(ii).anyTimes();
    OperationInfo oi = control.createMock(OperationInfo.class);
    org.apache.cxf.ws.rm.v200502.CreateSequenceResponseType csr = null;
    if (isServer) {
        EasyMock.expect(ii.getOperation(RM10Constants.CREATE_SEQUENCE_ONEWAY_QNAME)).andReturn(oi).anyTimes();
        Endpoint ae = control.createMock(Endpoint.class);
        EasyMock.expect(rme.getApplicationEndpoint()).andReturn(ae).anyTimes();
        EasyMock.expect(ae.getExecutor()).andReturn(SynchronousExecutor.getInstance()).anyTimes();
    } else {
        EasyMock.expect(ii.getOperation(RM10Constants.CREATE_SEQUENCE_QNAME)).andReturn(oi).anyTimes();
        csr = new org.apache.cxf.ws.rm.v200502.CreateSequenceResponseType();
    }
    ExchangeImpl exchange = new ExchangeImpl();
    EasyMock.expect(proxy.invoke(EasyMock.same(oi), EasyMock.isA(ProtocolVariation.class), EasyMock.isA(Object[].class), EasyMock.isA(Map.class), EasyMock.isA(Exchange.class))).andReturn(csr).anyTimes();
    EndpointReferenceType defaultAcksTo = control.createMock(EndpointReferenceType.class);
    AttributedURIType aut = control.createMock(AttributedURIType.class);
    EasyMock.expect(aut.getValue()).andReturn("here").anyTimes();
    EasyMock.expect(defaultAcksTo.getAddress()).andReturn(aut).anyTimes();
    RelatesToType relatesTo = control.createMock(RelatesToType.class);
    control.replay();
    Map<String, Object> context = new HashMap<>();
    if (isServer) {
        assertNull(proxy.createSequence(defaultAcksTo, relatesTo, isServer, ProtocolVariation.RM10WSA200408, exchange, context));
    } else {
        assertNotNull(proxy.createSequence(defaultAcksTo, relatesTo, isServer, ProtocolVariation.RM10WSA200408, exchange, context));
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) HashMap(java.util.HashMap) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) Duration(javax.xml.datatype.Duration) Method(java.lang.reflect.Method) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) RelatesToType(org.apache.cxf.ws.addressing.RelatesToType) Identifier(org.apache.cxf.ws.rm.v200702.Identifier) Endpoint(org.apache.cxf.endpoint.Endpoint) SourcePolicyType(org.apache.cxf.ws.rm.manager.SourcePolicyType) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Aggregations

RelatesToType (org.apache.cxf.ws.addressing.RelatesToType)4 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)3 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)3 HashMap (java.util.HashMap)2 QName (javax.xml.namespace.QName)2 Endpoint (org.apache.cxf.endpoint.Endpoint)2 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)2 AttributedURIType (org.apache.cxf.ws.addressing.AttributedURIType)2 Method (java.lang.reflect.Method)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Duration (javax.xml.datatype.Duration)1 Exchange (org.apache.cxf.message.Exchange)1 Message (org.apache.cxf.message.Message)1 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)1 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)1 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)1 OperationInfo (org.apache.cxf.service.model.OperationInfo)1 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)1 Relationship (org.apache.cxf.ws.addressing.v200408.Relationship)1 SourcePolicyType (org.apache.cxf.ws.rm.manager.SourcePolicyType)1