Friday, March 21, 2014

Remote X11 Over SSH

Remote X11 Over SSH

On the remote machine (Linux):
1) Ensure that X11Forwarding is enabled in /etc/ssh/sshd_conf on the remote machine.

On the local machine (Windows):
2) Install Xming.
 3) Add the Linux machine's DNS name(s) and IP address to the C:\Program Files\xming\X0.hosts file. File should containthe IP of the server for which you want X11 forwarding:
   localhost
   192.168.1.25
4) Start Xming on your Windows machine (NOT XLaunch)
5) Install SSH Secure Shell(if it's not already installed) onto your Windows machine.
6) Open ssh client and fill in the “Host Name” box.
7) Ensure the port is correct (probably 22).
8) Under Settings > Tunneling > X11 check the “Tunnel X11 connections” box.
9) If you create a profile then ensure tunneling is enabled on the profile as well.
10) Start the connection.
11) Log into the remote machine as you would do in a normal SSH session.
12) Start the X application from the command line, a window should open on your local machine with the application.
13) Minimize the SSH session, do not close it. If you close it, your X connections will close.
(It's a regular SSH session with putty but with X11 forwarding enabled.)

*The steps are pretty much the same for putty as well. you just need to switch on X11 forwarding in putty.

1) Open putty and fill in the “Host Name” box.
2) Ensure that SSH is checked and that the port is correct (probably 22).
3) Under Category > Connection > SSH > X11 check the “Enable X11 forwarding” box.
4) Click the “Open” button to start the connection.
5) Log into the remote machine as you would do in a normal SSH session.
6) Start the X application from the command line, a window should open on your local machine with the application.
7) Minimize the SSH session, do not close it. If you close it, your X connections will close.
(It's a regular SSH session with putty but with X11 forwarding enabled.)

Wednesday, March 19, 2014

Java.Lang.NoClassDefFoundError : Org/Apache/Commons/Fileupload/FileUploadException





java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileUploadException
 java.lang.Class.getDeclaredConstructors0(Native Method)
 java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
 java.lang.Class.getConstructor0(Unknown Source)
 java.lang.Class.newInstance0(Unknown Source)
 java.lang.Class.newInstance(Unknown Source)
If you see the above error then you can solve the issue by simply adding the below dependency in your pom.xml

<dependency>
  <groupId>commons-fileupload</groupId>
  <artifactId&gtcommons-fileupload</artifactId>
  <version&gt1.3</version>
</dependency>

Primefaces fileUploadListener not working

Add the following dependency in your pom.xml
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3</version>
</dependency>

Add this in your web.xml

<context-param>
  <param-name>primefaces.UPLOADER</param-name>
  <param-value>commons</param-value>
</context-param>

<filter>
  <filter-name>PrimeFaces FileUpload Filter</filter-name>
  <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>

<filter-mapping>
  <filter-name>PrimeFaces FileUpload Filter</filter-name>
  <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>

In h:form it's important to write enctype="multipart/form-data"

ajax="false" for the command button is necessary

Example Using Simple File Upload

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      >
    <h:head>
    <h:outputStylesheet library="css" name="table-style.css"  />
    </h:head>
 
    <h:body>
<h:form enctype="multipart/form-data">
<p:panel>
<p:messages showDetail="true"/>
<p:fileUpload value="#{fileUploadBean.file}" mode="simple" />
<p:commandButton value="Submit" ajax="false" actionListener="#{fileUploadBean.upload}"/>
</p:panel>
</h:form>
</h:body>

</html>

Bean:
package com.malware;

import java.io.Serializable;
import java.util.Map;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

import org.primefaces.context.RequestContext;
import org.primefaces.model.UploadedFile;

@ManagedBean
@SessionScoped
public class FileUploadBean implements Serializable{

private static final long serialVersionUID = 3998498873477818990L;

private UploadedFile file;

public void init(){
}
    public UploadedFile getFile() {
        return file;
    }

    public void setFile(UploadedFile file) {
        this.file = file;
    }
 
    public void upload() {
        if(file != null) {        
            FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Successfully Uploaded File " , file.getFileName());
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }
    }
}

Wednesday, March 12, 2014

Java.Lang.NoSuchMethodError: Org.Objectweb.Asm.ClassWriter


If you see this error while deploying application with hibernate :

SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'sessionFactory' defined in ServletContext resource 
[/WEB-INF/classes/config/database/spring/HibernateSessionFactory.xml]: 
Invocation of init method failed; nested exception is 
 
Caused by: org.hibernate.HibernateException: 
Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
 ...
 ...
Caused by: java.lang.reflect.InvocationTargetException
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
 ...
Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(I)V
 at net.sf.cglib.core.DebuggingClassWriter.<init>(DebuggingClassWriter.java:47)
 ...
The error can be resolved as follows :

The ASM package is needed by the cglib package, which is part of the Hibernate libraries. If we remove that package, Jersey will work correctly, but Hibernate will stop working. To solve this conflict use cglib-nodep.jar instead of cglib.jar and keep ASM version 3.x with Jersey. cglib-nodep.jar includes some ASM classes demanded by cglib.jar, changing the package name to avoid any class conflict.

If you are using maven then change
<dependency> <groupId>cglib</groupId> <artifactId&gtcglib</artifactId> <version&gt2.2</version> </dependency>
to
<dependency> <groupId>cglib</groupId> <artifactId&gtcglib-nodep</artifactId> <version&gt2.2</version> </dependency>

Tuesday, March 11, 2014

Using to_date function oracle

The to_date function can be used to compare dates :
Usage can be as follows

select
from message 
where message_text like '%888309%' 
and message_received >= to_date('20131119', 'yyyymmdd');

The date format can be changed according to needs.

How to remove dead EPR JBOSS

To remove dead EPR go to 
C:\Vineet\JBoss\jboss-soa-p-5.2\jboss-as\server\sao\deployers\esb.deployer\jbossesb-properties.xml

add the following to transports 



Fix the error ORA-28002: the password will expire within 7 days

ORA-28002: the password will expire within 7 days
Cause: The user's account is about to about to expire and the password needs 
to be changed.
Action: Change the password or contact the database administrator.

Reference: Oracle Documentation 

Solutions:

1) Simply change the password to avoid it temporary

  [oracle@lnxsvr ~]$ sqlplus scott/tiger

  SQL*Plus: Release 11.2.0.1.0 Production on Wed Jun 20 14:08:01 2012

  Copyright (c) 1982, 2009, Oracle.  All rights reserved.

  ERROR:
  ORA-28002: the password will expire within 7 days

  Connected to:
  Oracle Database 11g Release 11.2.0.1.0 - 64bit Production

  SQL> PASSWORD
  Changing password for SCOTT
  Old password:
  New password:
  Retype new password:
  Password changed

How to fix the error ORA-01691: unable to extend lob segment

For the error like this 
org.jboss.soa.esb.services.persistence.MessageStoreException: java.sql.SQLException: ORA-01691: unable to extend lob segment
SAO.SYS_LOB0000049247C00003$$ by 1024 in tablespace SYSTEM

        at org.jboss.internal.soa.esb.persistence.format.db.DBMessageStoreImpl.addMessage(DBMessageStoreImpl.java:100)
        at org.jboss.soa.esb.actions.MessagePersister.process(MessagePersister.java:72)
        at org.jboss.soa.esb.listeners.message.ActionProcessingPipeline.processPipeline(ActionProcessingPipeline.java:649)
        at org.jboss.soa.esb.listeners.message.ActionProcessingPipeline.processPipeline(ActionProcessingPipeline.java:603)
        at org.jboss.soa.esb.listeners.message.ActionProcessingPipeline.process(ActionProcessingPipeline.java:433)
        at org.jboss.soa.esb.listeners.message.MessageAwareListener$TransactionalRunner.run(MessageAwareListener.java:550)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
        at java.lang.Thread.run(Thread.java:662)
Caused by: java.sql.SQLException: ORA-01691: unable to extend lob segment SAO.SYS_LOB0000049247C00003$$ by 1024 in tablespace
SYSTEM

Following these steps
SQL> select * from dba_tablespace_usage_metrics order by used_percent desc;

use the file location from the below SQL to the ALTER database
SQL> select dbms_metadata.get_ddl('TABLESPACE','SYSTEM') from dual;

SQL> ALTER DATABASE
  2  DATAFILE '/u01/app/oracle/oradata/XE/system.dbf'
  3  RESIZE 256M;
  
SQL> select * from dba_tablespace_usage_metrics order by used_percent desc;

Tuesday, March 4, 2014

GWT Setup Steps

For setting up the GWT in your local environment the following things are required.
  • Download and install JDK 1.7. The GWT tutorial say you can use 1.6 or higher. For me it did the app Engine did not work with 1.6 and required 1.7.
  • Download Eclipse Kepler 4.3 or higher.
  • Install the Google plugin in eclipse using the software update feature in the Eclipse
  • You can create a sample project after all the installation is done. To create a Web Application, select File > New > Web Application Project from the Eclipse menu.
  • In the New Web Application Project wizard, enter a name for your project “MyWebApp” and a java package name, e.g., “com.mycompany.mywebapp”. If you installed the Google App Engine SDK, the wizard gives you the option to use App Engine as well. For now, uncheck this option and click Finish.
  • The wizard creates a directory structure for the project, including a src/ directory for Java source files, and a war/ directory for compiled classes and other files for the application, libraries, configuration files, static files such as images and CSS, and other data files. The wizard also creates a servlet source file and two configuration files.
  • To run the Project go to Run As >  Web Application. The Development mode will give a URL on which the application is running. ( For the first time the browser will prompt you to add a GWT plugin. Install the plugin).
  • You can double click the link to start on the default browser. Or you can right click and click on Open With to choose the browser which you want to use to open the link.
  • If you get an error message as below then follow these steps
o    Right click on your web project -> Run as -> Run configurations.
o    Select 'Server' and 'GWT' tabs respectively and check on 'Automatically select an unused port'
o    Clear Cache from your Chrome browser (do the same on Firefox if you are using Firefox, remember the GWT plugin is not available on the latest Firefox versions, 3-10 I believe).
o    Run and hopefully enjoy.