Saturday, November 17, 2007

Community Server for Testing (CST)

Now that I have come so far, what with four servers running concurrently (see previous posts), I thought, why not do something to help those newbies (like me, formerly) out there, who want to test different web applications/services at little or no cost?

For that, I plan to setup my PC as a community server for testing. I might keep it free, or charge peanuts for its use, just enough to cover the additional load in my electricity bill every month, owing to my PC's increased uptime.

I'll have the four servers running. Developers can upload their service on the required server and test it remotely. Simple, na?

Additionally, it can also be used a resource base. I can theoretically provide unlimited downloads to people, as their 'download' will actually be an 'upload' for my server. And MTNL (my ISP) doesn't charge me for uploading :P . Now thats what I call amazing !!

My Brilliant Brain ! (Hey, thats just an upcoming series on National Geographic Channel. What did you think, I am talking about myself???........Well, maybe you weren't entirely wrong either.........)

IIS external accesibility issue resolved

For those of you trying to figure out why IIS asks for username and password when you try to access it from Firefox, or a remote server, here's the solution:

  1. Go to Control Panel > Administrative Tools > Internet Information Services > (local computer) > Default website
  2. Right click and select Properties
  3. Under Directory Security tab > Anonymous access and authentication protocol section > click on the Edit button
  4. Check (select) Anonymous access (that is, enable it)
  5. Leave other things unchanged
  6. Click OK all the way out.
  7. Restart your server
  8. Done !

Update: Port manipulations fot Tomcat & IIS

I guess, I never rest. So here's plugging two holes in my previous post, the port manipulations for Apache Tomcat & Microsoft IIS. Here goes:

Apache Tomcat:

  1. Go to C:\Program Files\Apache Software Foundation\Tomcat 6.0\conf
  2. Open server.xml in Dreamweaver or Notepad
  3. Change Connector port="7777" (for example, from the original 8080 or 80) where protocol="HTTP/1.1"
  4. Be careful of the latter part. There are multiple 'connector' tags in the whole XML document, but you must change only the right one.
  5. Save the file and restart the server.
  6. Confirm at localhost:7777
Windows IIS
  1. Go to Control Panel > Administrative Tools > Internet Information Services > (local computer name) > Default website.
  2. Right click and select Properties.
  3. Under the Website tab > Web Identification section > TCP Port > type 6666
  4. (You can type any port number you wish, as usual)
  5. Restart the server (software)
Thats it!

Multiple Concurrent Servers - A reality !!

When I wrote my last post, I really wasn't sure if I would be able to run multiple servers on my system concurrently. I made three attempts between my last post, and about 19:30. And those attempts all resulted in failure. But as they say, "When things seem evermore difficult, you are really close to solving the problem". And solve I did.

How? No Googling, for a change !! Just plain common sense (of a techie, ofcourse) (jeez, i m getting vain)

So here's the change you make to your router settings that I already mentioned in my previous post. Under Virtual Server, change the Local port from 8080 (or whatever else) to 0 (zero) A zero number means forward all requests. Do not forget to Save and Reboot.

Then, set the different listening ports for your multitude of servers. I havnt figured out a way of changing Tomcat's port, so I let it remain 8080. I thought it safe to keep IIS on the default (80) port. But I changed the Java Application Server and Apache HTTP as follows:

For Sun Java:
  1. Go to localhost:4848 (or whatever administrator port u've set up)
  2. Login with the administrative username and password (which you must have noted down)
  3. Go to Configuration > HTTP Service > HTTP Listeners > http-listener-1 > Listener port.
  4. Enter a random port address between 1025 to 65535. I prefer 5282 (JAVA on ur mobile phone keypad) as it is easy to remember
  5. Save and Logout.
For Apache HTTP:
  1. Go to C:\Program Files\Apache Software Foundation\Apache 2.2\conf\httpd.conf (or whatever is the equivalent conf directory on your system)
  2. You can open the file with notepad
  3. Look for the text Listen
  4. Change the number after that (should be 8080, or 80, before you make the changes) to any number of your choice (between 1025 and 65535)
  5. I chose 9393, just like that
  6. Save the file and close.
Restart your PC and your router. Once everything is up, start all your servers. In this case:
  1. http://localhost/
  2. http://localhost:8080/
  3. http://localhost:5282/
  4. http://localhost:9393/
Thats it. Go to your friend's place (it would be wiser to just call him up, and do the needful). Retrieve your IP address, for example, 59.182.147.56. Ask someone to type the following in simultaneously open browser tabs (or windows, in case the jerk of a friend still uses IE6, not Firefox):
  1. http://59.182.147.56/
  2. http://59.182.147.56:8080/
  3. http://59.182.147.56:5282/
  4. http://59.182.147.56:9393/
If all works fine, your jerk...oops...i mean friend, should get the default pages (or the index, in case you've put something there) for each of those servers.

Whew. Finally, I achieved what I set out to achieve. Now I can R.I.P. May god bless my soul. I don't think I'll be posting anytime soon. Cya until then.

Multiple Concurrent Servers?

I never stop at solving a problem. I go further and find a new problem. Having setup a 'Server @ home', what I want to do next is to have multiple servers running simultaneously. To begin with, atleast IIS and Tomcat. It will require some fiddling with the settings I mentioned in my previous post. Not sure what to do, but will do so nevertheless.

Updates soon.....ciao

Server @ home - Tutorial

Here's how you go about setting up a remotely accessible home-server:

Note that this manual pertains to my home setup only, which is:
  1. Windows XP SP1
  2. MTNL TriBand (Mumbai, INDIA)
  3. UTSTarcom router UT-300R2U
So here's how you go about:

You will need to make the changes in your router setup. No changes are required to be made to your PC setup. The router setup is done via a browser, using a fixed IP address. To figure it out:
  1. Run command prompt
  2. Type ipconfig
  3. Type the address of the Default Gateway in your browser
  4. Type in the username and password (admin, admin) in my case
  5. Go to Advanced tab
  6. Click on Virtual Server
  7. In Private IP, type the IP address as mentioned in your 'ipconfig' result
  8. Select protocol TCP
  9. Select local port 8080 (in case of Tomcat)
  10. Destination port: any port.
  11. Next, go to Filters.
  12. In Oubound filter, add any source IP, any destination IP, any source port, any destination port, any protocol, action Aceept.
  13. Do the same settings in inbound filter.
  14. Go to Tools > Misc and click on Save and reboot.
  15. Restart your PC
You are done with the setup. Now, to access your PC remotely, go to a friend's place (or any other damn PC outside your home; something that doesn't use your router). You will need your home PC running (not even on standby). Tomcat must also be running. You must have the IP address of the home PC (Found in Status under your router admin panel (thru the browser))

Now simply type the address, followed by the port number in your friend's browser. It should look something like: 59.182.27.28:8080

If you see Tomcat's welcome page, you've been succesful!!

Server @ home

Having solved the JSP/Servlet problem, a new one arose. The problem of plenty, as I would like to call it.

By now, I know too much. Or more correctly, too many technologies. To fuel my hunger for knowledge, I had ended up downloading all the servers of the world (or so I think). Now, I had the following:
  1. Microsoft IIS 5.0
  2. Apache HTTP Server 2.2.4
  3. Apache Tomcat 6.13
  4. Java EE Server 5 Update 3
  5. PHP Engine 5.2.2
My current default test site http://csi-tcet.org is hoster by Brinkster, which is a big fan of Billu (Bill Gates). So it provides only ASP and .net hosting (atleast under the Windows hosting scheme). That leaves me with a big bottleneck. Where do I test my products? Ofcourse, localhost is always an option. But it doesn't come anywhere close to the feel of a remote server. So, in principle, what I needed was a multi-protocol (so to say) remote server at my command.

And the only solution I saw, is t make my own PC as a remote server. I knew that PCs behin firewalls cannot be accessed. Googling revealed that what I needed to do was port forwarding. More googling brought up a site http://www.portforwarding.com A really useful resource. Looked up my model number, did a few things. Also looking up other tech forums, finally managed to get this thing done as well.

Now, I have my very own remotely accesible web-server at home!! How did I do it? Read the next post....

JSP Servlets - Explanation

Now that I've posted a full-fledged tutorial, I guess there's some explanation that needs to be done. If you are new to servlets (or Java/JSP, for that matter), please look up resources on the net. A good place to start would be http://java.sun.com/ So now, for those familiar with servlets and their use, here goes...

After having developed test websites in ASP for years, i had finally hit a road-block. The road-block was that even after separating the 'processing logic', from the display related stuff, I was still stuck with having to put everything in an HTML page. I saw the solution in servlets.

So, on 15th November 2007, I finally took the big leap, and made the switch to JSP. I started up a new project, SAMS - Standard APIs for Mobile Services. I vowed not to touch ASP, no matter what.

It wasn't easy. I had developed a certain comfort level with ASP, kind of a relationship.. Now I had to start over again with some'one' else. But start I did. It began with the most frequently used include directive. The next major hurdle I wanted to cross was database connectivity. I managed to set the JDBC:ODBC things straight after a few Google searches. JSP, for now, was done. It was up and running, and that was sufficient for me.

Now, it was time for me to move on. And I saw 'servlets' as the next step. I got a sample servlet file, and tried hard to compile it in JCreator, which would keep giving errors of library not found. Googled hard again, but to no avail. Then somehting struck me.....it might require Java EE. Looked that up, and found out that my guess was right.

Downloading EE was quite a decision. I don't have unlimited downloads on my plan. 1GB a month. That's it. I was at the middle of the month, with 485 GB (nearly half) used up. EE would add another 90 MB. After deliberating a bit, I reckoned it would be money well invested. SO I went forth and downlaoded EE.

Tomcat was set up previously. EE was installed. I had everything running. My servlet was supposed to work. But it didnt. My servlet had compiled alright. But i didnt know where to put the class file. Googled again. Googled hard. Found the configurations to be made to the web.xml file. Did them, and voila, finally, it was running!!!

I had spent a good 4 hours researching and implementing my first servlet. It was 12:30 a.m. of 16th Nov 2007. Was tired already, but though of documenting everything. Wasn't blogging then. So composed a mail to myself.

That mal is what has been posted as the previous blog. Hope that it will be useful to a lot of newbies out there.

Cheers!

JSP Servlets Tutorial

How to create and run a servlet?

You will require to have these Java components before you can run a servlet:
  1. Java Runtime Environment (JRE)
  2. Java software Development Kit (JDK)
  3. Java Enterprise Edition Software Development Kit (Java EE SDK)
These 3 can be downloaded as a complete package, or individually also. To download the complete package (recommended)
  1. Go to: "http://java.sun.com/javaee/downloads/index.jsp " and click on "Download with JDK button"
  2. Accept agreement by clicking on the radio button
  3. Under the header "Windows platfform" click on the file name to download
  4. You can save the setup file to a folder of your choice
  5. Once download completes, click on the file and run it. Proceed with the installation with all default options and settings
  6. Restart the PC
Besides that, you will also need the Apache Tomcat JSP Server, which can be setup as follows:
  1. Go to "http://tomcat.apache.org/"
  2. In the left column, under the "Download" heading, click on the link to the latest version
  3. Once on th downloads page, search for the heading "Binary Distributions"
  4. Click on "Windows Service Installer" to save the file
  5. You can save the setup file in a folder of your choice
  6. Once download completes, click on the file and run it. Proceed with the installation with all default options and settings
  7. Restart the PC
Assuming you have downloaded and setup all the tools, here's what you need to do to get your first servlet running
  1. Write a HelloServlet.java file (see attached)
  2. Save it to the JDK bin directory (In this case: "C:\Program Files\Java\jdk1.5.0_06\bin")
  3. Start Menu> Run > Type "cmd" (without quotes) in the box. MS-DOS Command prompt will open
  4. Change directory to JDK bin using the command (cd C:\Program Files\Java\jdk1.5.0_06\bin )
  5. Compile the HelloServlet.java file using 'javac' (command: javac HelloWorld.java)
  6. Your servlet will be compiled (if no errors are present) and put in the same bin directory
  7. Go to Windows Explorer (My Computer)
  8. Copy HelloServlet.class file FROM "C:\Program Files\Java\jdk1.5.0_06\bin" TO "C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ROOT\WEB-INF\classes"
  9. Add servlet info (copy from attached file "add_to_web_inf") to the web.xml file (final file with added code attached) located in web-inf
  10. Stop the "Default Server" of Java EE SDK by right-clicking on the "Java EE 5 SDK" icon in system tray (besides the clock at right-bottom)
  11. Manually start the Tomcat server by going to "C:\Program Files\Apache Software Foundation\Tomcat 6.0\bin" and clicking on "tomcat"
  12. Let the DOS window remain open throughout your session. If server starts successfully, it wil show INFO:server startup in 2748ms (example)
  13. Execute the servlet by typing the path "http://localhost:8080/sams/HelloServlet" in your browser
  14. Note: Do not add any extension to the servlet name in the path
---------
HelloServlet.java

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

/**
* The simplest possible servlet.
*/

public class HelloServlet extends HttpServlet {

public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/plain");
PrintWriter out = response.getWriter();

out.println("Servlet invoked! ");
out.println(new Date());
}
}

-------------------------

Hello World

What else do u expect from a techie? This is the way we are supposed to greet the rest of the world, right?