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

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

Introduction

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

Prototype

JibxMarshaller

Source Link

Usage

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

/**
 * Constructor//  w  ww.  ja v a  2  s  .  co 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());

}