Example usage for org.springframework.remoting.support RemoteInvocation addAttribute

List of usage examples for org.springframework.remoting.support RemoteInvocation addAttribute

Introduction

In this page you can find the example usage for org.springframework.remoting.support RemoteInvocation addAttribute.

Prototype

public void addAttribute(String key, Serializable value) throws IllegalStateException 

Source Link

Document

Add an additional invocation attribute.

Usage

From source file:org.logicblaze.lingo.jms.JmsRemotingTest.java

public void testJmsProxyFactoryBeanAndServiceExporterWithInvocationAttributes() throws Exception {
    TestBean target = new TestBean("myname", 99);
    final JmsServiceExporter exporter = new JmsServiceExporter();
    exporter.setServiceInterface(ITestBean.class);
    exporter.setService(target);//from w w w  . ja v  a  2  s  . c  o m
    exporter.setRemoteInvocationExecutor(new DefaultRemoteInvocationExecutor() {
        public Object invoke(RemoteInvocation invocation, Object targetObject)
                throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
            assertNotNull(invocation.getAttributes());
            assertEquals(1, invocation.getAttributes().size());
            assertEquals("myValue", invocation.getAttributes().get("myKey"));
            assertEquals("myValue", invocation.getAttribute("myKey"));
            return super.invoke(invocation, targetObject);
        }
    });
    configure(exporter);
    subscribeToQueue(exporter, getDestinationName());

    JmsProxyFactoryBean pfb = new JmsProxyFactoryBean();
    pfb.setServiceInterface(ITestBean.class);
    pfb.setServiceUrl("http://myurl");
    pfb.setRequestor(createRequestor(getDestinationName()));
    pfb.setRemoteInvocationFactory(new LingoRemoteInvocationFactory(strategy) {
        public RemoteInvocation createRemoteInvocation(MethodInvocation methodInvocation) {
            RemoteInvocation invocation = super.createRemoteInvocation(methodInvocation);
            invocation.addAttribute("myKey", "myValue");
            try {
                invocation.addAttribute("myKey", "myValue");
                fail("Should have thrown IllegalStateException");
            } catch (IllegalStateException ex) {
                // expected: already defined
            }
            assertNotNull(invocation.getAttributes());
            assertEquals(1, invocation.getAttributes().size());
            assertEquals("myValue", invocation.getAttributes().get("myKey"));
            assertEquals("myValue", invocation.getAttribute("myKey"));
            return invocation;
        }
    });
    configure(pfb);

    ITestBean proxy = (ITestBean) pfb.getObject();
    assertEquals("myname", proxy.getName());
    assertEquals(99, proxy.getAge());
}