Monthly Archives: January 2016

Get ContentType for URL in java

content-type
To determine content type for certain URL you can use next:

package org.test;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

public class ContentType {

    public static void main(String[] args) throws IOException {
        getContentType("http://google.com");
        getContentType("http://www.orimi.com/pdf-test.pdf");
    }

    private static void getContentType(String uri) throws IOException {
        URL url = new URL(uri);
        HttpURLConnection connection = (HttpURLConnection)  url.openConnection();
        connection.setRequestMethod("HEAD");
        connection.connect();

        System.out.println(connection.getContentType() + ": " 
          + connection.getResponseCode() + " -> " + uri);
    }
}

The result:

text/html; charset=windows-1251: 200 -> http://google.com
application/pdf: 200 -> http://www.orimi.com/pdf-test.pdf

So, as you see to get content type it is need to send small HEAD request!
Thanx to http://stackoverflow.com/a/5802223

Xrdp configuration to connect existing session

xrdp
The RDP protocol is very convenient to manage windows and linux servers. But if you use Xrdp as terminal server, you may notice new session always creates when connection established.

The CentOS (RedHat) rdp server implementation is more useful, because can connect to existing session by default. But Ubuntu (Debian) always creates new session if you configure it as “port=-1” setting in xrdp.ini file:

[xrdp2]
name=test-name
...
port=-1

But if you set port to certain value, connection problem occurs.
To fix the problem I recommend to create two different xrdp configurations in xrdp.ini file:

[xrdp1]
name=existing-session
lib=libvnc.so
username=ask
password=ask
ip=127.0.0.1
port=5910

[xrdp2]
name=new-session
lib=libvnc.so
username=ask
password=ask
ip=127.0.0.1
port=-1

So, for the first connection you have to use “new-session” configuration, and the next one will be used “existing-session” configuration by default.
Make sure, you are connecting to 5910 port (in my case).