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

The following examples show how to use org.apache.cxf.ws.addressing.AddressingProperties#setTo() . 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: IntegrationBaseTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected Resource createClient(ReferenceParametersType refParams) {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();

    Map<String, Object> props = factory.getProperties();
    if (props == null) {
        props = new HashMap<>();
    }
    props.put("jaxb.additionalContextClasses",
            ExpressionType.class);
    factory.setProperties(props);

    factory.setBus(bus);
    factory.setServiceClass(Resource.class);
    factory.setAddress(RESOURCE_ADDRESS);
    Resource proxy = (Resource) factory.create();

    // Add reference parameters
    AddressingProperties addrProps = new AddressingProperties();
    EndpointReferenceType endpoint = new EndpointReferenceType();
    endpoint.setReferenceParameters(refParams);
    endpoint.setAddress(ContextUtils.getAttributedURI(RESOURCE_ADDRESS));
    addrProps.setTo(endpoint);
    ((BindingProvider) proxy).getRequestContext().put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES, addrProps);

    return proxy;
}
 
Example 2
Source File: ResourceTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected Resource createClient(ReferenceParametersType refParams) {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setBus(bus);
    factory.setServiceClass(Resource.class);
    factory.setAddress(RESOURCE_LOCAL_ADDRESS);
    Resource proxy = (Resource) factory.create();

    // Add reference parameters
    AddressingProperties addrProps = new AddressingProperties();
    EndpointReferenceType endpoint = new EndpointReferenceType();
    endpoint.setReferenceParameters(refParams);
    endpoint.setAddress(ContextUtils.getAttributedURI(RESOURCE_ADDRESS));
    addrProps.setTo(endpoint);
    ((BindingProvider) proxy).getRequestContext().put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES, addrProps);

    return proxy;
}
 
Example 3
Source File: TestUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected static Resource createResourceClient(EndpointReferenceType ref) {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setServiceClass(Resource.class);
    factory.setAddress(ref.getAddress().getValue());
    Resource proxy = (Resource) factory.create();

    // Add reference parameters
    AddressingProperties addrProps = new AddressingProperties();
    addrProps.setTo(ref);
    ((BindingProvider) proxy).getRequestContext().put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES, addrProps);

    return proxy;
}
 
Example 4
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 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: 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 7
Source File: ServantTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static Message createTestCreateSequenceMessage(Expires expires, OfferType offer) {
        Message message = new MessageImpl();
        Exchange exchange = new ExchangeImpl();
        exchange.setInMessage(message);
//        exchange.setOutMessage(new MessageImpl());

        message.put(Message.REQUESTOR_ROLE, Boolean.FALSE);

        AddressingProperties maps = new AddressingProperties();
        String msgId = "urn:uuid:12345-" + Math.random();
        AttributedURIType id = ContextUtils.getAttributedURI(msgId);
        maps.setMessageID(id);

        maps.setAction(ContextUtils.getAttributedURI(RM10Constants.INSTANCE.getCreateSequenceAction()));
        maps.setTo(ContextUtils.getAttributedURI(SERVICE_URL));

        maps.setReplyTo(RMUtils.createReference(DECOUPLED_URL));

        message.put(JAXWSAConstants.ADDRESSING_PROPERTIES_INBOUND, maps);

        CreateSequenceType cs = new CreateSequenceType();
        cs.setAcksTo(org.apache.cxf.ws.addressing.VersionTransformer
            .convert(RMUtils.createReference(DECOUPLED_URL)));

        cs.setExpires(expires);
        cs.setOffer(offer);

        MessageContentsList contents = new MessageContentsList();
        contents.add(cs);
        message.setContent(List.class, contents);

        RMContextUtils.setProtocolVariation(message, ProtocolVariation.RM10WSA200408);

        return message;
    }
 
Example 8
Source File: ServantTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static Message createTestTerminateSequenceMessage(String sidstr, ProtocolVariation protocol) {
    Message message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    exchange.setInMessage(message);

    message.put(Message.REQUESTOR_ROLE, Boolean.FALSE);

    AddressingProperties maps = new AddressingProperties();
    String msgId = "urn:uuid:12345-" + Math.random();
    AttributedURIType id = ContextUtils.getAttributedURI(msgId);
    maps.setMessageID(id);

    maps.setAction(ContextUtils.getAttributedURI(RM10Constants.INSTANCE.getTerminateSequenceAction()));
    maps.setTo(ContextUtils.getAttributedURI(SERVICE_URL));

    maps.setReplyTo(RMUtils.createReference(DECOUPLED_URL));

    message.put(JAXWSAConstants.ADDRESSING_PROPERTIES_INBOUND, maps);

    TerminateSequenceType ts = new TerminateSequenceType();
    Identifier sid = new Identifier();
    sid.setValue(sidstr);
    ts.setIdentifier(sid);
    Object tst = ProtocolVariation.RM10WSA200408.getWSRMNamespace().equals(protocol.getWSRMNamespace())
        ? ts : ProtocolVariation.RM10WSA200408.getCodec().convertReceivedTerminateSequence(ts);
    MessageContentsList contents = new MessageContentsList();
    contents.add(tst);
    message.setContent(List.class, contents);

    RMContextUtils.setProtocolVariation(message, protocol);

    return message;
}
 
Example 9
Source File: ServantTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static Message createTestCloseSequenceMessage(String sidstr) {
    Message message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    exchange.setInMessage(message);

    message.put(Message.REQUESTOR_ROLE, Boolean.FALSE);

    AddressingProperties maps = new AddressingProperties();
    String msgId = "urn:uuid:12345-" + Math.random();
    AttributedURIType id = ContextUtils.getAttributedURI(msgId);
    maps.setMessageID(id);

    maps.setAction(ContextUtils.getAttributedURI(RM10Constants.INSTANCE.getTerminateSequenceAction()));
    maps.setTo(ContextUtils.getAttributedURI(SERVICE_URL));

    maps.setReplyTo(RMUtils.createReference(DECOUPLED_URL));

    message.put(JAXWSAConstants.ADDRESSING_PROPERTIES_INBOUND, maps);

    CloseSequenceType cs = new CloseSequenceType();
    org.apache.cxf.ws.rm.v200702.Identifier sid = new  org.apache.cxf.ws.rm.v200702.Identifier();
    sid.setValue(sidstr);
    cs.setIdentifier(sid);
    MessageContentsList contents = new MessageContentsList();
    contents.add(cs);
    message.setContent(List.class, contents);

    RMContextUtils.setProtocolVariation(message, ProtocolVariation.RM11WSA200508);

    return message;
}
 
Example 10
Source File: RMOutInterceptorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private AddressingProperties createMAPs(String action, String to, String replyTo) {
    AddressingProperties maps = new AddressingProperties();
    AttributedURIType actionuri = new AttributedURIType();
    actionuri.setValue(action);
    maps.setAction(actionuri);
    maps.setTo(RMUtils.createReference(to));
    EndpointReferenceType epr = RMUtils.createReference(replyTo);
    maps.setReplyTo(epr);
    return maps;

}
 
Example 11
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 12
Source File: RMManager.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void recoverSourceSequence(Endpoint endpoint, Conduit conduit, Source s,
                                   SourceSequence ss) {
    Collection<RMMessage> ms = store.getMessages(ss.getIdentifier(), true);
    if (null == ms || ms.isEmpty()) {
        store.removeSourceSequence(ss.getIdentifier());
        return;
    }
    LOG.log(Level.FINE, "Number of messages in sequence: {0}", ms.size());
    // only recover the sequence if there are pending messages
    s.addSequence(ss, false);
    // choosing an arbitrary valid source sequence as the current source sequence
    if (s.getAssociatedSequence(null) == null && !ss.isExpired() && !ss.isLastMessage()) {
        s.setCurrent(ss);
    }
    //make sure this is associated with the offering id
    s.setCurrent(ss.getOfferingSequenceIdentifier(), ss);
    for (RMMessage m : ms) {

        Message message = new MessageImpl();
        Exchange exchange = new ExchangeImpl();
        message.setExchange(exchange);
        exchange.setOutMessage(message);
        if (null != conduit) {
            exchange.setConduit(conduit);
            message.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
        }
        exchange.put(Endpoint.class, endpoint);
        exchange.put(Service.class, endpoint.getService());
        exchange.put(Binding.class, endpoint.getBinding());
        exchange.put(Bus.class, bus);

        SequenceType st = new SequenceType();
        st.setIdentifier(ss.getIdentifier());
        st.setMessageNumber(m.getMessageNumber());
        RMProperties rmps = new RMProperties();
        rmps.setSequence(st);
        rmps.setCreatedTime(m.getCreatedTime());
        rmps.exposeAs(ss.getProtocol().getWSRMNamespace());
        if (ss.isLastMessage() && ss.getCurrentMessageNr() == m.getMessageNumber()) {
            CloseSequenceType close = new CloseSequenceType();
            close.setIdentifier(ss.getIdentifier());
            rmps.setCloseSequence(close);
        }
        RMContextUtils.storeRMProperties(message, rmps, true);
        if (null == conduit) {
            String to = m.getTo();
            AddressingProperties maps = new AddressingProperties();
            maps.setTo(RMUtils.createReference(to));
            RMContextUtils.storeMAPs(maps, message, true, 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);
            RMContextUtils.setProtocolVariation(message, ss.getProtocol());
            retransmissionQueue.addUnacknowledged(message);
        } catch (IOException e) {
            LOG.log(Level.SEVERE, "Error reading persisted message data", e);
        }
    }
}