Monday Nov 16, 2009

Java Store application cleanup

I assume that most of the people in the Java community have already noticed that the Java team at Sun has released a beta version of the Java Store. Lots of details about the launch can be read here. If you are a consumer that uses the store, you have several options of installing and uninstalling the applications that you've installed from the store. I'll focus on the more obscure ways of uninstalling apps on Windows:

  • end user - launch the store, open the My Apps menu and uninstall at will
  • advanced user - launch the Start | Control Panel | Programs | Uninstall a program | look for the application by name, select it and choose Uninstall from the menu of the Windows application
  • developer - Open the Java Control Panel (Start | Control Panel | Choose Classic View | Java | General | Settings; here you either choose to delete all files or follow the path (e.g. C:\\Users\\<username>\\AppData\\LocalLow\\Sun\\Java\\Deployment\\cache) to where the apps are installed and give it your best shot. I really don't recommend doing this
  • hacker - javaws -uninstall <jnlp app name>; note that if you just call javaws -uninstall it will uninstall all Java Web Start apps from your system

Sunday Feb 17, 2008

What are the web servers that power the internet?

So how can you tell what server is being used to run a website? Here is a simple Java program that can help one figure out the kind of server that serves a particular website.

package whataretheyrunning;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/\*\*
 \*
 \* @author octav
 \*/
public class SnoopURL {

    String URLString = null;

    public SnoopURL(String URLString) {
        this.URLString = URLString;
    }

    public void snoop() {
        try {
            // build URL
            URL url = new URL(URLString);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();

            conn.setRequestMethod("GET";);
            conn.setDoOutput(true);

            // start talking
            conn.connect();

            // int length = conn.getContentLength();
            // System.out.println(" \*\*\*\* the length of the content is " + length + " for URL " + URLString);

            System.out.println(" \*\*\*\* Server type is:  " + conn.getHeaderField("Server";) + "\\n\\n";);

            // get more information
            Map map = conn.getHeaderFields();
            for (int i = 0; i < map.size(); i++) {
                System.out.println(" \*\*\*\* " + conn.getHeaderField(i));
            }

            // cleanup
            conn.disconnect();
        } catch (MalformedURLException ex) {
            Logger.getLogger(SnoopURL.class.getName()).log(Level.SEVERE, null, ex);
        } catch (java.io.IOException ioe) {
            ioe.printStackTrace();
        } finally {
            // do whatever cleanup ...
        }
    }

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
    }

    @Override
    public String toString() {
        return super.toString();
    }
}

The output of this program is something like this:

\*\*\*\* Server type is: Sun-Java-System-Web-Server/6.1

\*\*\*\* HTTP/1.1 200 OK
\*\*\*\* Sun-Java-System-Web-Server/6.1
\*\*\*\* Mon, 18 Feb 2008 04:46:48 GMT
\*\*\*\* text/html;charset=UTF-8
\*\*\*\* policyref="http://www.sun.com/p3p/Sun_P3P_Policy.xml", CP="CAO DSP COR CUR ADMa DEVa TAIa PSAa PSDa CONi TELi OUR SAMi PUBi IND PHY ONL PUR COM NAV INT DEM CNT STA POL PRE GOV"
\*\*\*\* Servlet/2.4,JSP/2.0
\*\*\*\* chunked
\*\*\*\* Starload=star-fep5; Path=/
 

Now let's look at some popular websites.

Sun's www.sun.com is using the old Web Enterprise server, version 6.1 (the same is true for java.sun.com). The site the publishes this blog: blogs.sun.com is powered by Sun-Java-System-Web-Server/7.0 (a newer version of the same web server). Google seems to use their own version: gws. Yahoo does not tell you (returns null). Microsoft eats their own dog food: Microsoft-IIS/7.0. Nice. IBM runs something called: IBM_HTTP_Server (I bet is Apache's web server).



 

Wednesday Oct 31, 2007

Centering components in a (visual) web form

One of the typical requirements for a web application developer is to build a secure, identity enabled web application. NetBeans supports this usecase either by employing the bundled JavaServer Faces components, or a combination of JSP & HTML. On the backend the user can either use container based authentication, a database or some custom authentication mechanism.

Let's explore what one would have to do to build the a login page in NetBeans. In order to speed up the development, one can choose the visual application features (File | New Project | web | ... "Next" in the first page of the wizard | check the "Visual JSF" option and voila you have a page and a palette full of useful components that you can just drag and drop them in the form (page).

Further my requirement will be to center the group of components in the page. This turned out to be a little tricky so here are some steps that one can follow to work around this NetBeans shortcoming:

1. Select the page in the designer and in the property pane switch to Flow Layout
2. Remove style attribute.
3. In the JSP view of the page, use  <center> and <br> tags to adjust layout.

This works at both design time and run time. Here is an example of the a form that uses a couple of labels, textfields and button to submit the form.

<webuijsf:form binding="#{Page1.form1}" id="form1">
                       <center>
                           <webuijsf:label binding="#{Page1.label1}" id="label1"  text="Label"/>
                           <webuijsf:textField binding="#{Page1.textField1}" id="textField1" />
                           <br/>
                           <br/>
                           <br/>
                           <webuijsf:label binding="#{Page1.label2}" id="label2"  text="Label"/>
                           <webuijsf:textField binding="#{Page1.textField2}" id="textField2" />
                           <br/>
                           <br/>
                           <br/>
                           <webuijsf:button binding="#{Page1.button1}" id="button1"  text="Button"/>
                       </center>
                       <br/>
                   </webuijsf:form>

Many thanks to Jayashri for helping me work out a solution.

Perhaps in a the next installment I'll talk more about authentication and how to deploy on an https port using the Glassfish application server.

Monday Oct 22, 2007

NetBeans ships version 6 beta 2

NetBeans ships beta 2 of the upcoming 6.0 release, today (10/22/07). New NetBeans users may want to start on the docs page, while current users could just download the bits to get the latest bug fixes. If you are new to Java start here, you'll see a variety of online courses - all using NetBeans. Also, I highly recommend subscribing to the mailing lists (NetBeans has developers around the world: St Petersburg - Russia, Prague - Czech Republic, and the US, you'll likely be able to get help around the clock).
About

octav

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today