List of usage examples for org.springframework.remoting.support RemoteInvocation getAttribute
@Nullable
public Serializable getAttribute(String key)
From source file:org.logicblaze.lingo.jms.JmsRemotingTest.java
public void testJmsProxyFactoryBeanAndServiceExporterWithCustomInvocationObject() throws Exception { TestBean target = new TestBean("myname", 99); final JmsServiceExporter exporter = new JmsServiceExporter(); exporter.setServiceInterface(ITestBean.class); exporter.setService(target);/*w w w . j av a 2 s .co m*/ exporter.setRemoteInvocationExecutor(new DefaultRemoteInvocationExecutor() { public Object invoke(RemoteInvocation invocation, Object targetObject) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { assertNull(invocation.getAttributes()); assertNull(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); assertNull(invocation.getAttributes()); assertNull(invocation.getAttribute("myKey")); return invocation; } }); configure(pfb); ITestBean proxy = (ITestBean) pfb.getObject(); assertEquals("myname", proxy.getName()); assertEquals(99, proxy.getAge()); }
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()); }
From source file:org.jsecurity.spring.remoting.SecureRemoteInvocationExecutor.java
@SuppressWarnings({ "unchecked" }) public Object invoke(RemoteInvocation invocation, Object targetObject) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { try {/*from w w w . j ava 2 s . c o m*/ PrincipalCollection principals = null; boolean authenticated = false; InetAddress inetAddress = getInetAddress(invocation, targetObject); Session session = null; Serializable sessionId = invocation.getAttribute(SecureRemoteInvocationFactory.SESSION_ID_KEY); if (sessionId != null) { session = securityManager.getSession(sessionId); principals = getPrincipals(invocation, targetObject, session); authenticated = isAuthenticated(invocation, targetObject, session, principals); } else { if (log.isWarnEnabled()) { log.warn("RemoteInvocation object did not contain a JSecurity Session id under " + "attribute name [" + SecureRemoteInvocationFactory.SESSION_ID_KEY + "]. A Session will not " + "be available to the method. Ensure that clients are using a " + "SecureRemoteInvocationFactory to prevent this problem."); } } Subject subject = new DelegatingSubject(principals, authenticated, inetAddress, session, securityManager); ThreadContext.bind(securityManager); ThreadContext.bind(subject); return super.invoke(invocation, targetObject); } catch (NoSuchMethodException nsme) { throw nsme; } catch (IllegalAccessException iae) { throw iae; } catch (InvocationTargetException ite) { throw ite; } catch (Throwable t) { throw new InvocationTargetException(t); } finally { ThreadContext.clear(); } }