Search in sources :

Example 1 with GreetMe

use of org.apache.cxf.greeter_control.types.GreetMe in project cxf by apache.

the class WSRMWithWSSecurityPolicyTest method testContextProperty.

@Test
public void testContextProperty() throws Exception {
    try (ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("org/apache/cxf/systest/ws/rm/sec/client-policy.xml")) {
        Bus bus = (Bus) context.getBean("bus");
        BusFactory.setDefaultBus(bus);
        BusFactory.setThreadDefaultBus(bus);
        Greeter greeter = (Greeter) context.getBean("GreeterCombinedClientNoProperty");
        Client client = ClientProxy.getClient(greeter);
        QName operationQName = new QName("http://cxf.apache.org/greeter_control", "greetMe");
        BindingOperationInfo boi = client.getEndpoint().getBinding().getBindingInfo().getOperation(operationQName);
        Map<String, Object> invocationContext = new HashMap<>();
        Map<String, Object> requestContext = new HashMap<>();
        Map<String, Object> responseContext = new HashMap<>();
        invocationContext.put(Client.REQUEST_CONTEXT, requestContext);
        invocationContext.put(Client.RESPONSE_CONTEXT, responseContext);
        requestContext.put(SecurityConstants.USERNAME, "Alice");
        requestContext.put(SecurityConstants.CALLBACK_HANDLER, "org.apache.cxf.systest.ws.rm.sec.UTPasswordCallback");
        requestContext.put(SecurityConstants.ENCRYPT_PROPERTIES, "bob.properties");
        requestContext.put(SecurityConstants.ENCRYPT_USERNAME, "bob");
        requestContext.put(SecurityConstants.SIGNATURE_PROPERTIES, "alice.properties");
        requestContext.put(SecurityConstants.SIGNATURE_USERNAME, "alice");
        RMManager manager = bus.getExtension(RMManager.class);
        boolean empty = manager.getRetransmissionQueue().isEmpty();
        assertTrue("RetransmissionQueue is not empty", empty);
        GreetMe param = new GreetMe();
        param.setRequestType("testContextProperty");
        Object[] answer = client.invoke(boi, new Object[] { param }, invocationContext);
        Assert.assertEquals("TESTCONTEXTPROPERTY", answer[0].toString());
        Thread.sleep(5000);
        empty = manager.getRetransmissionQueue().isEmpty();
        assertTrue("RetransmissionQueue not empty", empty);
    }
}
Also used : GreetMe(org.apache.cxf.greeter_control.types.GreetMe) Bus(org.apache.cxf.Bus) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) RMManager(org.apache.cxf.ws.rm.RMManager) Greeter(org.apache.cxf.greeter_control.Greeter) Client(org.apache.cxf.endpoint.Client) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 QName (javax.xml.namespace.QName)1 Bus (org.apache.cxf.Bus)1 Client (org.apache.cxf.endpoint.Client)1 Greeter (org.apache.cxf.greeter_control.Greeter)1 GreetMe (org.apache.cxf.greeter_control.types.GreetMe)1 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)1 RMManager (org.apache.cxf.ws.rm.RMManager)1 Test (org.junit.Test)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1