Example usage for org.springframework.remoting RemoteAccessException getCause

List of usage examples for org.springframework.remoting RemoteAccessException getCause

Introduction

In this page you can find the example usage for org.springframework.remoting RemoteAccessException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

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

public void testJmsProxyFactoryBeanAndServiceExporterWithJMSException() throws Exception {
    TestBean target = new TestBean("myname", 99);
    final JmsServiceExporter exporter = new JmsServiceExporter();
    exporter.setServiceInterface(ITestBean.class);
    exporter.setService(target);//from   ww w. j  a va  2  s.co m
    configure(exporter);
    subscribeToQueue(exporter, getDestinationName());

    JmsProxyFactoryBean pfb = new JmsProxyFactoryBean();
    pfb.setServiceInterface(ITestBean.class);
    pfb.setServiceUrl("http://myurl");

    pfb.setRequestor(createRequestor(getDestinationName()));
    configure(pfb);
    ITestBean proxy = (ITestBean) pfb.getObject();

    // lets force an exception by closing the session
    closeSession(pfb);
    try {
        proxy.setAge(50);
        fail("Should have thrown RemoteAccessException");
    } catch (RemoteAccessException ex) {
        // expected
        assertTrue(ex.getCause() instanceof JMSException);
    }
}

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

public void testJmsInvokerWithSpecialLocalMethods() throws Exception {
    String serviceUrl = "http://myurl";
    JmsProxyFactoryBean pfb = new JmsProxyFactoryBean();
    pfb.setServiceInterface(ITestBean.class);
    pfb.setServiceUrl(serviceUrl);/*from ww w.j  a va  2s .c  om*/
    pfb.setRequestor(createRequestor(getDestinationName()));
    configure(pfb);

    ITestBean proxy = (ITestBean) pfb.getObject();

    // shouldn't go through to remote service
    assertTrue(proxy.toString().indexOf("JMS invoker") != -1);
    assertTrue(proxy.toString().indexOf(serviceUrl) != -1);
    assertEquals(proxy.hashCode(), proxy.hashCode());
    assertTrue(proxy.equals(proxy));

    // lets force an exception by closing the session
    closeSession(pfb);
    try {
        proxy.setAge(50);
        fail("Should have thrown RemoteAccessException");
    } catch (RemoteAccessException ex) {
        // expected
        assertTrue(ex.getCause() instanceof JMSException);
    }
}

From source file:de.juwimm.cms.util.Communication.java

public SiteValue[] getSites(String userName, String passwd)
        throws InvalidUsernameException, NoSitesException, LocalizedException {
    log.info("Trying to fetching Sites for User " + userName);
    try {//from  w  ww .ja  v  a  2s  .c  o m
        SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);
        RemoteAuthenticationManager remoteAuthenticationService = RemoteServiceLocator.instance()
                .getRemoteAuthenticationService();
        GrantedAuthority[] authorities = remoteAuthenticationService.attemptAuthentication(userName,
                String.valueOf(passwd));
        SecurityContextHolder.getContext().setAuthentication(
                new UsernamePasswordAuthenticationToken(userName, String.valueOf(passwd), authorities));
        log.debug(SecurityContextHolder.getContext().getAuthentication());
    } catch (RemoteAccessException e) {
        if (e.getCause() != null && e.getCause() instanceof SpringSecurityException) {
            log.info("authentication failed: " + e.getMessage());
            throw new InvalidUsernameException();
        }
        LocalizedException ge = new LocalizedException("communication.login.unkwownError", "unknown error", e);
        ge.logThrowException();
        throw ge;
    }

    try {
        ClientServiceSpring cs = getClientService();
        SiteValue[] sites = cs.getSites();
        return sites;
    } catch (Exception e) {
        //       e.printStackTrace();
        throw new NoSitesException("No sites associated?", e);
    }
}