com.hiperium.commons.client.soap.AuthenticationSOAPTest.java Source code

Java tutorial

Introduction

Here is the source code for com.hiperium.commons.client.soap.AuthenticationSOAPTest.java

Source

/**
 * Open Source Solutions Corp.
 * Product: Hiperium
 * Created: 12-Mar-2011 - 00:00:00
 * 
 * 
 * The contents of this file are copyrighted by Open Source Solutions Corp. 
 * and it is protected by the license: "GPL V3." You can find a copy of this 
 * license at: http://www.aldebaran-solutions.com
 * 
 * Copyright 2011 Open Source Solutions Corp. All rights reserved.
 * 
 */
package com.hiperium.commons.client.soap;

import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.hiperium.client.soap.authentication.AuthenticationObjectFactory;
import com.hiperium.client.soap.authentication.HomeSelectionWSInterface;
import com.hiperium.client.soap.authentication.HomeSelectionWSService;
import com.hiperium.client.soap.authentication.UserAuthenticationWSInterface;
import com.hiperium.client.soap.authentication.UserAuthenticationWSService;
import com.hiperium.client.soap.common.ClientHandlerResolver;
import com.hiperium.client.soap.general.GeneralObjectFactory;
import com.hiperium.client.soap.general.MenuWSInterface;
import com.hiperium.client.soap.general.MenuWSService;
import com.hiperium.commons.CommonsUtil;
import com.hiperium.commons.dto.HomeSelectionDTO;
import com.hiperium.commons.dto.SelectionDTO;
import com.hiperium.commons.dto.UserCredentialDTO;
import com.hiperium.commons.log.HiperiumLogger;
import com.hiperium.commons.soap.InformationException_Exception;

/**
 * @author Andres Solorzano
 *
 */
public class AuthenticationSOAPTest {

    /** The property LOGGER. */
    private static final HiperiumLogger LOGGER = HiperiumLogger.getLogger(AuthenticationSOAPTest.class);

    /** The property CLIENT_APPLICATION_TOKEN used to encrypt service messages. */
    private static final String CLIENT_APPLICATION_TOKEN = "abc123def";

    /**
     * This class test the services using the generated JAXWS service client classes.
     * 
     * @param args
     */
    public static void main(String[] args) {
        UserCredentialDTO credentialsDTO = new UserCredentialDTO("andres_solorzano85@hotmail.com", "andres123");
        UserAuthenticationWSService authenticationWS = new UserAuthenticationWSService();
        UserAuthenticationWSInterface authenticationSEI = authenticationWS.getUserAuthenticationWSPort();
        try {
            String sessionId = authenticationSEI.userAuthentication(credentialsDTO);
            LOGGER.debug(sessionId);

            if (StringUtils.isBlank(sessionId)) {
                LOGGER.error("No session identifier was obtained from the Service.");
            } else {
                HomeSelectionWSService homeSelectionWS = new HomeSelectionWSService();
                homeSelectionWS.setHandlerResolver(new ClientHandlerResolver(credentialsDTO.getEmail(),
                        CLIENT_APPLICATION_TOKEN, AuthenticationObjectFactory._SelectHome_QNAME));
                HomeSelectionWSInterface homeSelectionSEI = homeSelectionWS.getHomeSelectionWSPort();
                CommonsUtil.mantainSessionProperty(homeSelectionSEI, sessionId);

                // Get the associated homes to the user in the actual session
                List<SelectionDTO> homeSelectionList = homeSelectionSEI.findHomeByUserId();
                for (SelectionDTO dto : homeSelectionList) {
                    LOGGER.debug("HOME: " + dto);
                }

                // Get the associated profiles to the home in the actual session
                List<SelectionDTO> profileSelectionList = homeSelectionSEI.findProfileByHomeId(1L);
                for (SelectionDTO dto : profileSelectionList) {
                    LOGGER.debug("PROFILE: " + dto);
                }

                // Select a home and a profile associated to the user in that home
                HomeSelectionDTO homeSelectionDTO = new HomeSelectionDTO(1L, 1L);
                String response = homeSelectionSEI.selectHome(homeSelectionDTO);
                LOGGER.debug("HOME SELECTION: " + response);

                // Logout to the actual session.
                MenuWSService menuWS = new MenuWSService();
                menuWS.setHandlerResolver(new ClientHandlerResolver(credentialsDTO.getEmail(),
                        CLIENT_APPLICATION_TOKEN, GeneralObjectFactory._EndSession_QNAME));
                MenuWSInterface menuSEI = menuWS.getMenuWSPort();
                CommonsUtil.mantainSessionProperty(menuSEI, sessionId);
                response = menuSEI.endSession();
                LOGGER.debug("MENU END SESSION: " + response);
            }
        } catch (InformationException_Exception e) {
            LOGGER.error(e.getMessage(), e);
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
        }

    }
}