Java Code Examples for org.apache.cxf.ws.addressing.EndpointReferenceType#setReferenceParameters()

The following examples show how to use org.apache.cxf.ws.addressing.EndpointReferenceType#setReferenceParameters() . 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: SubscriptionManagerImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void grantSubscriptionManagerReference(SubscriptionTicket ticket,
                                                 SubscriptionTicketGrantingResponse response) {
    EndpointReferenceType subscriptionManagerReference = new EndpointReferenceType();
    subscriptionManagerReference.setAddress(getSubscriptionManagerAddress());
    // generate a ID for this subscription
    UUID uuid = UUID.randomUUID();
    JAXBElement<String> idqn
        = new JAXBElement<>(new QName(subscriptionIdNamespace, subscriptionIdElementName),
                String.class,
                uuid.toString());
    subscriptionManagerReference.setReferenceParameters(new ReferenceParametersType());
    subscriptionManagerReference.getReferenceParameters().getAny().add(idqn);
    ticket.setUuid(uuid);
    response.setSubscriptionManagerReference(subscriptionManagerReference);
    response.setUUID(uuid);
}
 
Example 4
Source File: AbstractMultiplexDestination.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * Builds an new endpoint reference using the current target reference as a template.
 * The supplied id is endcoded using a reference parameter.
 * This requires the ws-a interceptors to propagate the reference parameters
 * on subsequent invokes using the returned reference.
 * @param id the id to encode in the new reference
 * @return the new reference with the id encoded as a reference parameter
 * @see org.apache.cxf.transport.MultiplexDestination#getAddressWithId(java.lang.String)

 */
public EndpointReferenceType getAddressWithId(String id) {
    EndpointReferenceType epr = EndpointReferenceUtils.duplicate(
        EndpointReferenceUtils.mint(reference, bus));
    ReferenceParametersType newParams = new org.apache.cxf.ws.addressing.ObjectFactory()
        .createReferenceParametersType();

    ReferenceParametersType existingParams = epr.getReferenceParameters();
    if (null != existingParams) {
        newParams.getAny().addAll(existingParams.getAny());
    }

    newParams.getAny().add(new JAXBElement<String>(MULTIPLEX_ID_QNAME, String.class, id));
    epr.setReferenceParameters(newParams);
    return epr;
}
 
Example 5
Source File: MAPTestBase.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    //super.setUp();

    if (staticBus == null) {
        SpringBusFactory bf = new SpringBusFactory();
        staticBus = bf.createBus(getConfigFileName());
        BusFactory.setDefaultBus(staticBus);
    }

    messageIDs.clear();
    mapVerifier = new MAPVerifier();
    headerVerifier = new HeaderVerifier();
    Interceptor<?>[] interceptors = {mapVerifier, headerVerifier};
    addInterceptors(staticBus.getInInterceptors(), interceptors);
    addInterceptors(staticBus.getOutInterceptors(), interceptors);
    addInterceptors(staticBus.getOutFaultInterceptors(), interceptors);
    addInterceptors(staticBus.getInFaultInterceptors(), interceptors);

    EndpointReferenceType target =
        EndpointReferenceUtils.getEndpointReference(getAddress());
    ReferenceParametersType params =
        ContextUtils.WSA_OBJECT_FACTORY.createReferenceParametersType();
    JAXBElement<String> param =
         new JAXBElement<>(CUSTOMER_NAME, String.class, CUSTOMER_KEY);
    params.getAny().add(param);
    target.setReferenceParameters(params);
    greeter = createGreeter(target);
    mapVerifier.verificationCache = this;
    headerVerifier.verificationCache = this;
}
 
Example 6
Source File: NotificationTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void withReferenceParameters() throws Exception {
    NotificatorService service = createNotificatorService();
    Subscribe subscribe = new Subscribe();
    ExpirationType exp = new ExpirationType();
    exp.setValue(
            DurationAndDateUtil.convertToXMLString(DurationAndDateUtil.parseDurationOrTimestamp("PT0S")));
    subscribe.setExpires(exp);

    EndpointReferenceType eventSinkERT = new EndpointReferenceType();

    JAXBElement<String> idqn
        = new JAXBElement<>(new QName("http://www.example.org", "MyReferenceParameter"),
            String.class,
            "380");
    JAXBElement<String> idqn2
        = new JAXBElement<>(new QName("http://www.example.org", "MyReferenceParameter2"),
            String.class,
            "381");
    eventSinkERT.setReferenceParameters(new ReferenceParametersType());
    eventSinkERT.getReferenceParameters().getAny().add(idqn);
    eventSinkERT.getReferenceParameters().getAny().add(idqn2);
    AttributedURIType eventSinkAddr = new AttributedURIType();
    String url = TestUtil.generateRandomURLWithHttpTransport(NOTIFICATION_TEST_PORT);
    eventSinkAddr.setValue(url);
    eventSinkERT.setAddress(eventSinkAddr);
    subscribe.setDelivery(new DeliveryType());
    subscribe.getDelivery().getContent().add(new ObjectFactory().createNotifyTo(eventSinkERT));

    eventSourceClient.subscribeOp(subscribe);

    Server eventSinkServer = createEventSinkWithReferenceParametersAssertion(url,
            eventSinkERT.getReferenceParameters());
    TestingEventSinkImpl.RECEIVED_FIRES.set(0);
    service.start();
    Emitter emitter = new EmitterImpl(service);
    emitter.dispatch(new FireEvent("Canada", 8));
    for (int i = 0; i < 10; i++) {
        if (TestingEventSinkImpl.RECEIVED_FIRES.get() == 1) {
            break;
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
    eventSinkServer.stop();
    int received = TestingEventSinkImpl.RECEIVED_FIRES.get();
    if (received != 1) {
        Assert.fail("TestingEventSinkImpl should have received 1 events but received "
                + received);
    }
}
 
Example 7
Source File: SubscriptionEndTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void doTest() throws IOException {
    NotificatorService service = createNotificatorService();
    service.start();

    Subscribe subscribe = new Subscribe();

    EndpointReferenceType eventSinkERT = new EndpointReferenceType();
    AttributedURIType eventSinkAddr = new AttributedURIType();
    String eventSinkURL = TestUtil.generateRandomURLWithLocalTransport();
    eventSinkAddr.setValue(eventSinkURL);
    eventSinkERT.setAddress(eventSinkAddr);
    subscribe.setDelivery(new DeliveryType());
    subscribe.getDelivery().getContent().add(new ObjectFactory().createNotifyTo(eventSinkERT));

    JAXBElement<String> idqn
        = new JAXBElement<>(new QName("http://www.example.org", "MyReferenceParameter"),
            String.class,
            "380");
    ReferenceParametersType myParams = new ReferenceParametersType();
    myParams.getAny().add(idqn);
    eventSinkERT.setReferenceParameters(myParams);

    EndpointReferenceType endToERT = new EndpointReferenceType();
    AttributedURIType endToAddr = new AttributedURIType();
    String endToURL = TestUtil.generateRandomURLWithLocalTransport();
    endToAddr.setValue(endToURL);
    endToERT.setAddress(endToAddr);
    subscribe.setEndTo(endToERT);

    SubscribeResponse response = eventSourceClient.subscribeOp(subscribe);
    Element referenceParams = (Element)response.getSubscriptionManager()
            .getReferenceParameters().getAny().get(0);

    Server endToEndpoint = createEndToEndpointWithReferenceParametersAssertion(endToURL, myParams);

    TestingEndToEndpointImpl.RECEIVED_ENDS.set(0);

    SingletonSubscriptionManagerContainer.getInstance()
            .subscriptionEnd(UUID.fromString(referenceParams.getTextContent()), "Sorry, "
                    + "but we don't like you anymore",
                    SubscriptionEndStatus.SOURCE_CANCELLING);

    for (int i = 0; i < 10; i++) {
        if (TestingEndToEndpointImpl.RECEIVED_ENDS.get() == 1) {
            break;
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
    endToEndpoint.stop();
    if (TestingEndToEndpointImpl.RECEIVED_ENDS.get() != 1) {
        Assert.fail("TestingEndToEndpointImpl should have received 1 subscription end notification but received "
                + TestingEndToEndpointImpl.RECEIVED_ENDS.get());
    }
}