Saturday, 1 December 2018

XML Processing via Java - JAXB

Unmarshal is a process reading from XML to Java
Marshal is a process writing into XML from Java

image.png

Wednesday, 4 July 2018

GenericDaoImpl


@Repository

@Transactional(readOnly = true)

@SuppressWarnings({ "unchecked", "serial" })

public abstract class GenericDaoImpl<E, ID extends Serializable> extends

HibernateTemplate implements GenericDao<E, ID> {

protected Class<E> entityClass;
public GenericDaoImpl() {

setEntityClass(); 

}

public E findById(ID id, boolean lock) {

return (E) super.get(entityClass, id);

}

public E findById(ID id) {

return findById(id, false);

}

public List<E> findAll() throws Exception {

return this.loadAll(entityClass);

}

public List<E> findByCriteria(DetachedCriteria criteria, int startIndex,

int maxResults) {

return (List<E>) super.findByCriteria(criteria, startIndex, maxResults);

}

@Autowired

@Qualifier("hibernateSessionFactory")

public void setSessionFactory(SessionFactory hibernateSessionFactory) {

super.setSessionFactory(hibernateSessionFactory);



}

protected void setEntityClass() {

entityClass = (Class<E>) ((ParameterizedType) getClass()

.getGenericSuperclass()).getActualTypeArguments()[0];

}



@Transactional(readOnly = false, propagation = Propagation.REQUIRED)

public E makePersistent(E entity) {

this.checkWriteOperationAllowed(getSession());

this.saveOrUpdate(entity);

return entity;

}



@Transactional(readOnly = false, propagation = Propagation.REQUIRED)

public void deleteEntity(E entity) {

this.checkWriteOperationAllowed(getSession());

this.delete(entity);

}



@Transactional(readOnly = false, propagation = Propagation.REQUIRED)

public void deleteAllEntities(Collection<E> entities) {



for (E entity : entities) {

this.checkWriteOperationAllowed(getSession());

this.delete(entity);

}

}

@Override

public Session getSession() {
Session session = getSessionFactory().getCurrentSession();

session.setFlushMode(FlushMode.COMMIT);

return session;

}

}

Session factory configuration in spring

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">

<property name="jndiName" value="jdbc/TEST" />

</bean>



<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">

<property name="dataSource" ref="dataSource"></property>

<property name="packagesToScan" value="com.test.model"></property>

<property name="hibernateProperties">

<props>

<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>

<prop key="hibernate.show_sql">false</prop>

<prop key="hibernate.bytecode.use_reflection_optimizer">false</prop>

<prop key="hibernate.search.autoregister_listeners">false</prop>

<prop key="hibernate.connection.release_mode">after_transaction</prop>

<prop key="hibernate.transaction.auto_close_session">false</prop>

</props>

</property>

</bean>




<bean id="transactionManager"

class="org.springframework.orm.hibernate5.HibernateTransactionManager">

<property name="sessionFactory" ref="hibernateSessionFactory"></property>

</bean>




<tx:annotation-driven transaction-manager="transactionManager"/>

Model listener

Model listeners were designed to perform lightweight actions in response to a create, remove, or update attempt on an entity’s database table or a mapping table

Model listeners are not called when fetching records from the database

Monday, 3 July 2017

import data from file to mongodb collection

import data from file to mongodb collection :


Saturday, 22 August 2015

Debug enabling on Servers

WEBLOGIC Server : folder path : /user_projects/domains/base_domain/bin/setDomainEnv.sh

JAVA_OPTIONS="${JAVA_OPTIONS} ${JAVA_PROPERTIES} -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=25801,server=y,suspend=n 
  .........." 

JBOSS Server : folder path : bin/standalone-conf.bat

"%JAVA%" -agentlib:jdwp=transport=dt_socket,address=25801,server=y,suspend=n %JAVA_OPTS% ^
"-Dorg.jboss.boot.log.file=%JBOSS_LOG_DIR%\boot.log" ^
"-Dlogging.configuration=file:%JBOSS_CONFIG_DIR%/logging.properties" ^
    -jar "%JBOSS_HOME%\jboss-modules.jar" ^
    -mp "%JBOSS_MODULEPATH%" ^
    -jaxpmodule "javax.xml.jaxp-provider" ^
     org.jboss.as.standalone ^
    -Djboss.home.dir="%JBOSS_HOME%" ^
     %*



TOMCAT Server : folder path : bin/catalina.bat

%_EXECJAVA% -agentlib:jdwp=transport=dt_socket,address=25801,server=y,suspend=n %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%

Liferay 6.x cstom plugin or out of box web services consumption via Java program

Required class path dependencies are :


  1. portal-client
  2. axis
  3. axis-jaxrpc
  4. commons-logging
  5. commons-discovery
  6. wsdl4j

Java code:

public class CompetencyRemoteAuth {

                static final Logger LOGGER = LoggerFactory
                                                .getLogger(CompetencyRemoteAuth.class);

                static final String LIFERAY_USER_NAME = "satya.kolliboina@gmail.com";
                static final String LIFERAY_USER_PASSWORD = "test1";

                static final String USER_SERVICE = "Portal_UserService";
                static final String COMPANY_SERVICE = "Portal_CompanyService";
                static final String Competency_AUTHENTICATION_SERVICE = "Plugin_Competency_CompetencyAuthenticationService";
                static final String Competency_REGISTRATION_SERVICE = "Plugin_Competency_RegistrationService";

                /**
                * @param args
                */
                public static void main(String[] args) {
                                try {
                                                System.out.println("UserEmail: " + args[0] + "...user pwd:"+args[1]);
                                                URL CompetencyAuthenticationServiceEndPoint = _getURL(args[0],args[1], Competency_AUTHENTICATION_SERVICE);
                                             
                                                System.out.println("Try lookup CompetencyAuthentication Service by End Point: "         + CompetencyAuthenticationServiceEndPoint + "...");
                                             
                                                URL companyServiceEndPoint = _getURL(args[0],args[1], COMPANY_SERVICE);
                                             
                                                System.out.println("Try lookup company Service by End Point: "               + CompetencyAuthenticationServiceEndPoint + "...");
                                             
                                                CompetencyAuthenticationServiceSoapServiceLocator CompetencyAuthenticationLocator = new CompetencyAuthenticationServiceSoapServiceLocator();
                                                CompetencyAuthenticationServiceSoap CompetencyAuthenticationService = CompetencyAuthenticationLocator.getPlugin_Competency_CompetencyAuthenticationService(CompetencyAuthenticationServiceEndPoint);
                                                                             
                                                ((Plugin_Competency_CompetencyAuthenticationServiceSoapBindingStub) competencyAuthenticationService)
                                                .setUsername(args[0]);
                                                ((Plugin_Competency_CompetencyAuthenticationServiceSoapBindingStub) competencyAuthenticationService)
                                                .setPassword(args[1]);
             
                                             
                                                CompanyServiceSoapServiceLocator locatorCompany = new CompanyServiceSoapServiceLocator();
                                                CompanyServiceSoap companyService = locatorCompany.getPortal_CompanyService(companyServiceEndPoint);
                                                CompanySoap companySoap = companyService.getCompanyByVirtualHost("localhost");

                                                System.out.println("Get UserID" + "...");
                                                long userId = 0;
                                             
                                             
                                                userId = CompetencyAuthenticationService.CompetencyAuthentication(args[0], args[1], args[2]);
                                                System.out.println("UserId for user named " + args[0]   + " is " + userId);

                                             

                                } catch (RemoteException re) {
                                                LOGGER.error(re.getClass().getCanonicalName()
                                                                                + re.getMessage());
                                } catch (ServiceException se) {
                                                LOGGER.error(se.getClass().getCanonicalName()
                                                                                + se.getMessage());
                                }
                }
             
                /**
                * Get the URL Liferay SOAP Service
                *
                 * @param remoteUser
                * @param password
                * @param serviceName
                * @return
                */
                private static URL _getURL(String remoteUser, String password, String serviceName) {
//http://localhost:9090/CompetencyAuthentication-portlet/api/axis/Plugin_Competency_CompetencyAuthenticationService?wsdl
                                final String LIFERAY_PROTOCOL = "http://";
                                final String LIFERAY_TCP_PORT = "9090";
                                final String LIFERAY_FQDN = "127.0.0.1";
                                String LIFERAY_AXIS_PATH = "";
                             
                                try {
                                                if(serviceName.split("_")[0].equalsIgnoreCase("Plugin")){
                                                                LIFERAY_AXIS_PATH = "/CompetencyMobility-portlet/api/secure/axis/";
                                                }else{
                                                                LIFERAY_AXIS_PATH = "/api/secure/axis/";
                                                }
                                                return new URL(LIFERAY_PROTOCOL
                                                                                + URLEncoder.encode(remoteUser, "UTF-8") + ":"
                                                                                + URLEncoder.encode(password, "UTF-8") + "@" + LIFERAY_FQDN
                                                                                + ":" + LIFERAY_TCP_PORT + LIFERAY_AXIS_PATH + serviceName);
                                } catch (Exception e) {
                                                LOGGER.error(e.getMessage());
                                                e.printStackTrace();
                                                return null;
                                }
                }
}