Example usage for org.springframework.oxm.jibx JibxMarshaller afterPropertiesSet

List of usage examples for org.springframework.oxm.jibx JibxMarshaller afterPropertiesSet

Introduction

In this page you can find the example usage for org.springframework.oxm.jibx JibxMarshaller afterPropertiesSet.

Prototype

@Override
    public void afterPropertiesSet() throws JiBXException 

Source Link

Usage

From source file:eu.europeana.uim.sugarcrmclient.plugin.SugarCRMServiceImpl.java

/**
 * Constructor/*from   www.  j a va  2s.c  o m*/
 */
public SugarCRMServiceImpl() {
    this.pollingListeners = new LinkedHashMap<String, PollingListener>();

    BlockingInitializer initializer = new BlockingInitializer() {
        @Override
        public void initializeInternal() {
            MessageFactory mf = null;
            try {
                mf = MessageFactory.newInstance();
            } catch (SOAPException e1) {
                e1.printStackTrace();
            }

            ExtendedSaajSoapMessageFactory mfactory = new ExtendedSaajSoapMessageFactory(mf);
            WebServiceTemplate webServiceTemplate = new WebServiceTemplate(mfactory);

            JibxMarshaller marshaller = new JibxMarshaller();

            marshaller.setStandalone(true);
            marshaller.setTargetClass(eu.europeana.uim.sugarcrmclient.jibxbindings.Login.class);
            marshaller.setTargetClass(eu.europeana.uim.sugarcrmclient.jibxbindings.GetEntries.class);
            marshaller.setEncoding("UTF-8");
            marshaller.setTargetPackage("eu.europeana.uim.sugarcrmclient.jibxbindings");

            try {
                marshaller.afterPropertiesSet();
            } catch (JiBXException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            System.out.println(
                    marshaller.supports(eu.europeana.uim.sugarcrmclient.jibxbindings.GetEntries.class));
            System.out.println(marshaller.supports(eu.europeana.uim.sugarcrmclient.jibxbindings.Login.class));

            webServiceTemplate.setMarshaller(marshaller);
            webServiceTemplate.setUnmarshaller(marshaller);

            sugarwsClient = new SugarWsClientImpl();
            String userName = PropertyReader.getProperty(UimConfigurationProperty.SUGARCRM_USERNAME);
            String password = PropertyReader.getProperty(UimConfigurationProperty.SUGARCRM_PASSWORD);
            String uri = PropertyReader.getProperty(UimConfigurationProperty.SUGARCRM_HOST);
            webServiceTemplate.setDefaultUri(uri);
            sugarwsClient.setUsername(userName);
            sugarwsClient.setPassword(password);
            sugarwsClient.setWebServiceTemplate(webServiceTemplate);

            try {
                sugarwsClient.setSessionID(
                        sugarwsClient.login(ClientUtils.createStandardLoginObject(userName, password)));
            } catch (JIXBLoginFailureException e) {
                sugarwsClient.setSessionID("-1");
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }

            System.out.println("Done");
        }

    };
    initializer.initialize(SugarWsClientImpl.class.getClassLoader());

}