Example usage for org.springframework.remoting.httpinvoker HttpInvokerProxyFactoryBean getObject

List of usage examples for org.springframework.remoting.httpinvoker HttpInvokerProxyFactoryBean getObject

Introduction

In this page you can find the example usage for org.springframework.remoting.httpinvoker HttpInvokerProxyFactoryBean getObject.

Prototype

@Override
    @Nullable
    public Object getObject() 

Source Link

Usage

From source file:almira.sample.client.ListCatapults.java

/**
 * Main function./*from w w w  . ja va 2  s . c  om*/
 *
 * @param args the serviceUrl as command line argument.
 */
@SuppressWarnings("unchecked")
public static void main(String[] args) {

    if (args.length != 1) {

        printMessage("Usage: java -jar client.jar <serviceUrl>");
        System.exit(1);
    }

    HttpInvokerProxyFactoryBean fb = getFactoryBeanInstance(args[0]);
    executeQuery((ObjectQueryService<Catapult, Long>) fb.getObject());
}

From source file:org.jdal.remoting.httpinvoker.HttpInvokerRemoteReference.java

/**
 * {@inheritDoc}/*from w w w  .  ja v  a  2  s.c o m*/
 */
@Override
public RemoteClient createRemoteClient() {
    HttpInvokerProxyFactoryBean factoryBean = new HttpInvokerProxyFactoryBean();
    factoryBean.setServiceUrl(getServiceUrl());
    factoryBean.setServiceInterface(getServiceInterface());
    factoryBean.setCodebaseUrl(codebaseUrl);
    factoryBean.afterPropertiesSet();

    return (RemoteClient) factoryBean.getObject();
}

From source file:org.apache.servicemix.http.endpoints.SerializedMarshalerTest.java

public void testUsingSpringHttpRemoting() throws Exception {
    final Person person = new PersonImpl("Hunter", "Thompson", 67);

    // Create a consumer endpoint
    HttpConsumerEndpoint ep = new HttpConsumerEndpoint();
    ep.setService(new QName("urn:HttpConsumer", "HttpConsumer"));
    ep.setEndpoint("HttpConsumer");
    ep.setLocationURI("http://localhost:8192/service/");
    ep.setTargetService(new QName("urn:HttpInvoker", "Endpoint"));

    // Configure the SerializedMarshaler and specifiy it on the endpoint
    SerializedMarshaler marshaler = new SerializedMarshaler();
    marshaler.setDefaultMep(MessageExchangeSupport.IN_OUT);
    ep.setMarshaler(marshaler);/*  w w  w.  j a v a  2s .c om*/

    // Add the endpoint to the component and activate it
    HttpComponent component = new HttpComponent();
    component.setEndpoints(new HttpEndpointType[] { ep });
    container.activateComponent(component, "HttpConsumer");

    // Dummy up a component as a receiver and route it to urn:HttpInvoker/Endpoint
    TransformComponentSupport rmiComponent = new TransformComponentSupport() {
        protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out)
                throws MessagingException {
            try {
                // Deserialize rmi invocation
                XStream xstream = new XStream(new DomDriver());
                SourceTransformer st = new SourceTransformer();
                Object rmi = xstream.fromXML(st.toString(in.getContent()));

                DefaultRemoteInvocationExecutor executor = new DefaultRemoteInvocationExecutor();
                Object result = executor.invoke((RemoteInvocation) rmi, person);

                // Convert result to an rmi invocation
                RemoteInvocationResult rmiResult = new RemoteInvocationResult(result);
                out.setContent(new StringSource(xstream.toXML(rmiResult)));
            } catch (Exception e) {
                throw new MessagingException(e);
            }

            return true;
        }
    };
    ActivationSpec asReceiver = new ActivationSpec("rmiComponent", rmiComponent);
    asReceiver.setService(new QName("urn:HttpInvoker", "Endpoint"));
    container.activateComponent(asReceiver);

    // Start the JBI container
    container.start();

    // Set up the Spring bean to call into the URL specified for the consumer endpoint
    HttpInvokerProxyFactoryBean pfb = new HttpInvokerProxyFactoryBean();
    pfb.setServiceInterface(Person.class);
    pfb.setServiceUrl("http://localhost:8192/service/");
    pfb.setHttpInvokerRequestExecutor(new SimpleHttpInvokerRequestExecutor());
    pfb.afterPropertiesSet();

    // Grab the object via the proxy factory bean
    Person test = (Person) pfb.getObject();

    // Test getters
    assertEquals("Hunter", test.getGivenName());
    assertEquals("Thompson", test.getSurName());
    assertEquals(67, test.getAge());

    // Test setters
    test.setGivenName("John");
    test.setSurName("Doe");
    test.setAge(34);

    assertEquals(person.getGivenName(), "John");
    assertEquals(person.getSurName(), "Doe");
    assertEquals(person.getAge(), 34);
}

From source file:org.geoserver.geofence.servicetest.MainTest.java

public void instantiateAndRunSpringRemoting() {
    HttpInvokerProxyFactoryBean httpInvokerProxyFactoryBean = new HttpInvokerProxyFactoryBean();
    httpInvokerProxyFactoryBean.setServiceInterface(org.geoserver.geofence.services.RuleReaderService.class);
    httpInvokerProxyFactoryBean.setServiceUrl("http://localhost:9191/geofence/remoting/RuleReader");
    httpInvokerProxyFactoryBean.afterPropertiesSet();
    RuleReaderService rrs = (RuleReaderService) httpInvokerProxyFactoryBean.getObject();

    RuleFilter filter1 = new RuleFilter(SpecialFilterType.DEFAULT, true).setUser("pippo").setInstance("gs1")
            .setService("WMS");
    AccessInfo accessInfo = rrs.getAccessInfo(filter1);
    LOGGER.info(accessInfo);// w w w.j av a2s  . c om

    RuleFilter filter2 = new RuleFilter(SpecialFilterType.DEFAULT, true).setUser("pippo").setInstance("gs1")
            .setService("WCS");
    AccessInfo accessInfo2 = rrs.getAccessInfo(filter2);
    LOGGER.info(accessInfo2);
}

From source file:it.geosolutions.geofence.servicetest.MainTest.java

public void instantiateAndRunSpringRemoting() {
    HttpInvokerProxyFactoryBean httpInvokerProxyFactoryBean = new HttpInvokerProxyFactoryBean();
    httpInvokerProxyFactoryBean.setServiceInterface(it.geosolutions.geofence.services.RuleReaderService.class);
    httpInvokerProxyFactoryBean.setServiceUrl("http://localhost:9191/geofence/remoting/RuleReader");
    httpInvokerProxyFactoryBean.afterPropertiesSet();
    RuleReaderService rrs = (RuleReaderService) httpInvokerProxyFactoryBean.getObject();

    RuleFilter filter1 = new RuleFilter(SpecialFilterType.DEFAULT, true).setUser("pippo").setInstance("gs1")
            .setService("WMS");
    AccessInfo accessInfo = rrs.getAccessInfo(filter1);
    LOGGER.info(accessInfo);//from  www.ja  va2s .  c o  m

    RuleFilter filter2 = new RuleFilter(SpecialFilterType.DEFAULT, true).setUser("pippo").setInstance("gs1")
            .setService("WCS");
    AccessInfo accessInfo2 = rrs.getAccessInfo(filter2);
    LOGGER.info(accessInfo2);
}

From source file:de.scoopgmbh.copper.monitoring.client.context.ApplicationContext.java

protected void connect(final String serverAdressParam, final String user, final String password) {
    boolean secureConnect = StringUtils.hasText(user) && StringUtils.hasText(password);
    String serverAdress = serverAdressParam;
    if (!serverAdress.endsWith("/")) {
        serverAdress = serverAdress + "/";
    }/* w  w w . j  ava 2s .co m*/

    final LoginService loginService;
    final CommonsHttpInvokerRequestExecutor httpInvokerRequestExecutor = new CommonsHttpInvokerRequestExecutor();
    DefaultHttpMethodRetryHandler retryHandler = new DefaultHttpMethodRetryHandler(10, false);
    httpInvokerRequestExecutor.getHttpClient().getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            retryHandler);
    httpInvokerRequestExecutor.getHttpClient().getParams().setSoTimeout(1000 * 60 * 5);
    {
        HttpInvokerProxyFactoryBean httpInvokerProxyFactoryBean = new HttpInvokerProxyFactoryBean();
        httpInvokerProxyFactoryBean.setServiceUrl(serverAdress + "copperMonitoringService");
        httpInvokerProxyFactoryBean.setServiceInterface(LoginService.class);
        httpInvokerProxyFactoryBean.setServiceUrl(serverAdress + "loginService");
        httpInvokerProxyFactoryBean.afterPropertiesSet();
        httpInvokerProxyFactoryBean.setHttpInvokerRequestExecutor(httpInvokerRequestExecutor);
        loginService = (LoginService) httpInvokerProxyFactoryBean.getObject();
    }

    final String sessionId;
    if (secureConnect) {
        try {
            sessionId = loginService.doLogin(user, password);
        } catch (RemoteException e) {
            throw new RuntimeException(e);
        }
    } else {
        sessionId = "";
    }

    if (sessionId == null) {
        getIssueReporterSingleton().reportWarning("Invalid user/password", null, new Runnable() {
            @Override
            public void run() {
                createLoginForm().show();
            }
        });
    } else {
        HttpInvokerProxyFactoryBean httpInvokerProxyFactoryBean = new HttpInvokerProxyFactoryBean();
        httpInvokerProxyFactoryBean.setServiceUrl(serverAdress + "copperMonitoringService");
        httpInvokerProxyFactoryBean.setServiceInterface(CopperMonitoringService.class);
        RemoteInvocationFactory remoteInvocationFactory = secureConnect
                ? new SecureRemoteInvocationFactory(sessionId)
                : new DefaultRemoteInvocationFactory();
        httpInvokerProxyFactoryBean.setRemoteInvocationFactory(remoteInvocationFactory);
        httpInvokerProxyFactoryBean.setHttpInvokerRequestExecutor(httpInvokerRequestExecutor);
        httpInvokerProxyFactoryBean.afterPropertiesSet();
        final CopperMonitoringService copperMonitoringService = (CopperMonitoringService) httpInvokerProxyFactoryBean
                .getObject();

        final String serverAdressFinal = serverAdress;
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                setGuiCopperDataProvider(copperMonitoringService, serverAdressFinal, sessionId);
            }
        });
    }
}

From source file:org.copperengine.monitoring.client.context.ApplicationContext.java

protected void connect(final String serverAddressParam, final String user, final String password) {
    boolean secureConnect = StringUtils.hasText(user) && StringUtils.hasText(password);
    String serverAddress = serverAddressParam;
    if (!serverAddress.endsWith("/")) {
        serverAddress = serverAddress + "/";
    }//from   w w w .  j a  v a2 s . co m

    final LoginService loginService;
    final CommonsHttpInvokerRequestExecutor httpInvokerRequestExecutor = new CommonsHttpInvokerRequestExecutor();
    DefaultHttpMethodRetryHandler retryHandler = new DefaultHttpMethodRetryHandler(10, false);
    httpInvokerRequestExecutor.getHttpClient().getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
            retryHandler);
    httpInvokerRequestExecutor.getHttpClient().getParams().setSoTimeout(1000 * 60 * 5);
    {
        HttpInvokerProxyFactoryBean httpInvokerProxyFactoryBean = new HttpInvokerProxyFactoryBean();
        httpInvokerProxyFactoryBean.setServiceUrl(serverAddress + "copperMonitoringService");
        httpInvokerProxyFactoryBean.setServiceInterface(LoginService.class);
        httpInvokerProxyFactoryBean.setServiceUrl(serverAddress + "loginService");
        httpInvokerProxyFactoryBean.afterPropertiesSet();
        httpInvokerProxyFactoryBean.setHttpInvokerRequestExecutor(httpInvokerRequestExecutor);
        loginService = (LoginService) httpInvokerProxyFactoryBean.getObject();
    }

    final String sessionId;
    if (secureConnect) {
        try {
            sessionId = loginService.doLogin(user, password);
        } catch (RemoteException e) {
            throw new RuntimeException(e);
        }
    } else {
        sessionId = "";
    }

    if (sessionId == null) {
        getIssueReporterSingleton().reportWarning("Invalid user/password", null, new Runnable() {
            @Override
            public void run() {
                createLoginForm().show();
            }
        });
    } else {
        HttpInvokerProxyFactoryBean httpInvokerProxyFactoryBean = new HttpInvokerProxyFactoryBean();
        httpInvokerProxyFactoryBean.setServiceUrl(serverAddress + "copperMonitoringService");
        httpInvokerProxyFactoryBean.setServiceInterface(CopperMonitoringService.class);
        RemoteInvocationFactory remoteInvocationFactory = secureConnect
                ? new SecureRemoteInvocationFactory(sessionId)
                : new DefaultRemoteInvocationFactory();
        httpInvokerProxyFactoryBean.setRemoteInvocationFactory(remoteInvocationFactory);
        httpInvokerProxyFactoryBean.setHttpInvokerRequestExecutor(httpInvokerRequestExecutor);
        httpInvokerProxyFactoryBean.afterPropertiesSet();
        final CopperMonitoringService copperMonitoringService = (CopperMonitoringService) httpInvokerProxyFactoryBean
                .getObject();

        final String serverAddressFinal = serverAddress;
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                setGuiCopperDataProvider(copperMonitoringService, serverAddressFinal, sessionId);
            }
        });
    }
}

From source file:org.kuali.rice.kew.config.ThinClientResourceLoader.java

protected Object getServiceProxy(Class serviceInterface, String endpointParam, String secureEndpointParam) {
    HttpInvokerProxyFactoryBean proxyFactory = new HttpInvokerProxyFactoryBean();
    String serviceUrl = ConfigContext.getCurrentContextConfig().getProperty(endpointParam);
    if (StringUtils.isEmpty(serviceUrl)) {
        throw new IllegalArgumentException(
                "The " + endpointParam + " configuration parameter was not defined but is required.");
    }//from   w w  w  .  j  a v  a2s .  co  m
    proxyFactory.setServiceUrl(serviceUrl);
    proxyFactory.setServiceInterface(serviceInterface);
    String secureProp = ConfigContext.getCurrentContextConfig().getProperty(secureEndpointParam);
    Boolean secureIt = null;
    secureIt = secureProp == null || Boolean.valueOf(secureProp);
    KSBHttpInvokerRequestExecutor executor = new KSBHttpInvokerRequestExecutor(getHttpClient());
    executor.setSecure(secureIt);
    proxyFactory.setHttpInvokerRequestExecutor(executor);
    proxyFactory.afterPropertiesSet();
    return proxyFactory.getObject();
}

From source file:org.openflamingo.web.viz.VizController.java

/**
 * Remote File System Service .//from   w ww . j  a va 2s .c o m
 *
 * @return Remote Workflow Engine Service
 */
private FileSystemService getFileSystemService(String url) {
    HttpInvokerProxyFactoryBean factoryBean = new HttpInvokerProxyFactoryBean();
    factoryBean.setServiceUrl(url);
    factoryBean.setServiceInterface(FileSystemService.class);
    HttpComponentsHttpInvokerRequestExecutor httpInvokerRequestExecutor = new HttpComponentsHttpInvokerRequestExecutor();
    factoryBean.setHttpInvokerRequestExecutor(httpInvokerRequestExecutor);
    factoryBean.afterPropertiesSet();
    return (FileSystemService) factoryBean.getObject();
}