Java Code Examples for org.apache.cxf.ws.addressing.AddressingProperties#exposeAs()

The following examples show how to use org.apache.cxf.ws.addressing.AddressingProperties#exposeAs() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WSDiscoveryClient.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void addAddressing(BindingProvider p, boolean addSeq, String action) {
    AddressingProperties addrProperties = new AddressingProperties();
    if (action != null) {
        AttributedURIType act = new AttributedURIType();
        act.setValue(action);
        addrProperties.setAction(act);
    }
    if (adHoc) {
        EndpointReferenceType to = new EndpointReferenceType();
        addrProperties.exposeAs(version.getAddressingNamespace());
        AttributedURIType epr = new AttributedURIType();
        epr.setValue(version.getToAddress());
        to.setAddress(epr);
        addrProperties.setTo(to);

        if (addSeq) {
            AppSequenceType s = new AppSequenceType();
            s.setInstanceId(instanceId);
            s.setMessageNumber(msgId.getAndIncrement());
            JAXBElement<AppSequenceType> seq = new ObjectFactory().createAppSequence(s);
            Header h = new Header(seq.getName(),
                                  seq,
                                  new JAXBDataBinding(getJAXBContext()));
            List<Header> headers = new ArrayList<>();
            headers.add(h);
            p.getRequestContext()
                .put(Header.HEADER_LIST, headers);
        }
    } else {
        addrProperties.exposeAs(version.getAddressingNamespace());
    }
    p.getRequestContext().put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES, addrProperties);
}
 
Example 2
Source File: WSDiscoveryServiceImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void updateOutputAction(String append) {
    AddressingProperties p = ContextUtils.retrieveMAPs(PhaseInterceptorChain.getCurrentMessage(),
                                                       false, false);
    AddressingProperties pout = new AddressingProperties();
    AttributedURIType action = new AttributedURIType();
    action.setValue(p.getAction().getValue() + append);
    pout.exposeAs(p.getNamespaceURI());
    pout.setAction(action);
    ContextUtils.storeMAPs(pout, PhaseInterceptorChain.getCurrentMessage(), true);

}
 
Example 3
Source File: InternalContextUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Construct and store MAPs for partial response.
 *
 * @param partialResponse the partial response message
 * @param namespaceURI the current namespace URI
 */
private static void ensurePartialResponseMAPs(Message partialResponse,
                                             String namespaceURI) {
    // ensure there is a MAPs instance available for the outbound
    // partial response that contains appropriate To and ReplyTo
    // properties (i.e. anonymous & none respectively)
    AddressingProperties maps = new AddressingProperties();
    maps.setTo(EndpointReferenceUtils.getAnonymousEndpointReference());
    maps.setReplyTo(ContextUtils.WSA_OBJECT_FACTORY.createEndpointReferenceType());
    maps.getReplyTo().setAddress(ContextUtils.getAttributedURI(Names.WSA_NONE_ADDRESS));
    maps.setAction(ContextUtils.getAttributedURI(""));
    maps.exposeAs(namespaceURI);
    ContextUtils.storeMAPs(maps, partialResponse, true, true, false);
}
 
Example 4
Source File: MAPAggregatorImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void setupNamespace(AddressingProperties maps, Message message) {
    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    if (null == aim) {
        String ns = (String)message.getContextualProperty(MAPAggregator.ADDRESSING_NAMESPACE);
        if (ns != null) {
            maps.exposeAs(ns);
        }
        return;
    }
    Collection<AssertionInfo> aic = aim.getAssertionInfo(MetadataConstants.USING_ADDRESSING_2004_QNAME);
    if (aic != null && !aic.isEmpty()) {
        maps.exposeAs(Names200408.WSA_NAMESPACE_NAME);
    }
}
 
Example 5
Source File: InternalContextUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Construct and store MAPs for partial response.
 *
 * @param partialResponse the partial response message
 * @param namespaceURI the current namespace URI
 */
private static void ensurePartialResponseMAPs(Message partialResponse,
                                             String namespaceURI) {
    // ensure there is a MAPs instance available for the outbound
    // partial response that contains appropriate To and ReplyTo
    // properties (i.e. anonymous & none respectively)
    AddressingProperties maps = new AddressingProperties();
    maps.setTo(EndpointReferenceUtils.getAnonymousEndpointReference());
    maps.setReplyTo(ContextUtils.WSA_OBJECT_FACTORY.createEndpointReferenceType());
    maps.getReplyTo().setAddress(ContextUtils.getAttributedURI(Names.WSA_NONE_ADDRESS));
    maps.setAction(ContextUtils.getAttributedURI(""));
    maps.exposeAs(namespaceURI);
    ContextUtils.storeMAPs(maps, partialResponse, true, true, false);
}
 
Example 6
Source File: RetransmissionQueueImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * @param m the unacked message
 */
protected ResendCandidate(Message m) {
    message = m;
    retries = 0;
    RMConfiguration cfg = manager.getEffectiveConfiguration(message);
    long baseRetransmissionInterval =
        cfg.getBaseRetransmissionInterval().longValue();
    backoff = cfg.isExponentialBackoff()  ? RetransmissionQueue.DEFAULT_EXPONENTIAL_BACKOFF : 1;
    next = new Date(System.currentTimeMillis() + baseRetransmissionInterval);
    nextInterval = baseRetransmissionInterval * backoff;
    RetryPolicyType rmrp = null != manager.getSourcePolicy()
        ? manager.getSourcePolicy().getRetryPolicy() : null;
    maxRetries = null != rmrp ? rmrp.getMaxRetries() : -1;

    AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, true);
    AttributedURIType to = null;
    if (null != maps) {
        to = maps.getTo();
        maps.exposeAs(cfg.getAddressingNamespace());
    }
    if (to != null  && RMUtils.getAddressingConstants().getAnonymousURI().equals(to.getValue())) {
        LOG.log(Level.INFO, "Cannot resend to anonymous target.  Not scheduling a resend.");
        return;
    }
    RMProperties rmprops = RMContextUtils.retrieveRMProperties(message, true);
    if (null != rmprops) {
        number = rmprops.getSequence().getMessageNumber();
    }
    if (null != manager.getTimer() && maxRetries != 0) {
        schedule();
    }
}
 
Example 7
Source File: MAPCodecTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 8
Source File: RMManager.java    From cxf with Apache License 2.0 4 votes vote down vote up
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;
}