Tuesday, April 7, 2015

How to enable SSH X11 forwarding in Linux?

How to enable SSH X11 forwarding in Linux?

The  X11 forwarding from putty using Xming was not working, the DISPLAY variable is not set(echo $DISPLAY) after opening the remote server session in putty(X11 forwarding is enabled in putty and also the display is specified as localhost:0.0)

The actual issue is the X11 forwarding was not enabled in remote linux server.

The following steps can be followed to enable the X11 forwarding in linux server.

Login to linux server through putty

vi /etc/ssh/sshd_config

Enable the following flags

AllowAgentForwarding yes
AllowTcpForwarding yes
X11Forwarding yes

Execute the following commands

service sshd restart

yum -y update xauth
yum -y install xauth

Now you will be able to perform X11 forwarding.



Tuesday, February 10, 2015

Expected a string but was BEGIN_ARRAY at line 1 column - Gson

Expected a string but was BEGIN_ARRAY at line 1 column 

I was receiving "Expected a string but was BEGIN_ARRAY at line 1 column" error while deserializing the json string to java object using Gson.

Model class:

public class EmailGroup{
private String type;
private String id;
private String name;
private String permissions;

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPermissions() {
return permissions;
}
public void setPermissions(String permissions) {
this.permissions = permissions;
}
}

JSON Response:

{"emailGroup":{"type":"EmailGroup","id":"1","depth":"minimal","description":"","name":"sample","permissions":[2,5,4,3]}}

Gson gson = new Gson();
EmailGroup obj = gson.fromJson(jsonstring, EmailGroup.class)

The root cause of the exception is the permissions attribute defined in the model class is of type String but the type of permissions in the jsonstring is List.

To fix the issue convert the type of permissions in the model class to List<String>(type string will change based on the type of the list entries)

public class EmailGroup{
private String type;
private String id;
private String name;
private List<String> permissions;

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<String> getPermissions() {
return permissions;
}
public void setPermissions(List<String> permissions) {
this.permissions = permissions;
}
}