Archive for the ‘Web’ Category

Essentials of Java web stack

March 15, 2017 Leave a comment

Jetty 8

1. start.jar is a launcher. Use –help command-line key to list available command-line options.
2. Launcher can start server in the same process (by default), or, if –exec command-line arg is present, as a separate process (if, for example, you need different JVM settings)
3. Launcher is controlled via command-line keys, and by start.ini file from current dir. There is a special command-line key –ini allowing to either specify a different ini file, or to specify a configuration content which is expected from such file
4. Server is customizable. You can specify which modules will be loaded. These are called OPTIONS, and are read from OPTIONS section of start.ini (or specified in –ini command line arg). Example:

java -jar start.jar --ini OPTIONS=Server,websocket etc\jetty.xml

5. To get a list of available modules use –list-options command-line key. It will show which jar files are used by each module.
6. Information produced by –list-options is calculated based on start.config script file which is packed inside start.jar. You can take a look by using –list-config command line key to understand module dependencies. You can override this config file by using –config command line key to completelly change server’s behaviour, but this is rarely needed.
7. There are some modules which just aggregate several other modules. Very good aggregate module is Server, which includes HTTP server, servlet container and deployer
8. Modules may be explicitly configured by XML config scripts which are usually stored in etc/ dir. Application of such configs specified in start.ini
9. To configure Jetty logging, customize existing configuration script etc/jetty-logging.xml, and don’t forget to add it to start.ini
10. Web applications are deployed to webapps dir
11. If you’ve included “resources” module, then directory resources/ is added to classpath (by default start.config script). You can put config files for your application there
12. One of usages of resouces/ dir is for applications which use log4j. If you put file in resources/ dir, then log4j will discover that file and will configure itself based on that file

Jetty 9

1. start.jar is a launcher. Use –help command-line key to list available command-line options
2. Launcher can start server in the same process (by default), or, if –exec command-line arg is present, as a separate process (if, for example, you need different JVM settings)
2. Launcher is controlled via command-line keys, and by start.ini file from current dir. File start.ini is just a set of same keys as for command-line
3. Server is customizable. You can specify which modules will be loaded via –module key. Example:

java -jar start.jar --module=http,deploy

4. To get a list of available modules use –list-modules command-line key. It will show which jar files are used by each module, and will show module dependencies.
5. Information provided by –list-modules is calculated based on module descriptors stored in modules/ directory as .mod files.
6. Each module has a corresponding config in etc/ directory. To check which config corresponds to which module you can use output of –list-modules (property XML) or by looking into .mod file. Configs are implicitly executed if corresponding module is included.
7. Minimal set of modules for working servlet container with auto-deployment support is server,http,deploy.
8. Web applications are deployed to webapps dir (will work in deploy module is enabled)
9. Recommended way to start Jetty 9 is to create a separate base directory for each running instance, which will contain configs, webapps and logs for this instance. This is called jetty.base
10. When running Jetty 9 this instance base dir should be current dir, and path to start.jar should be fully specified:

java -jar path/to/jetty/installation/start.jar

11. You can manually place start.ini into instance base dir, and create sub-dirs log, webapps. But there is a better way: from empty instance base dir run start.jar via full path and use command-line key –add-to-start. Example:

java -jar path/to/jetty/installation/start.jar --add-to-start=http,server,deploy

This will create config files from templates, and all necessary dirs.
12. If you’ve included “resources” module, then directory resources/ is added to classpath. You can put config files for your application there

Difference between Jetty 9 and Jetty 8

1. In Jetty 9, a start.ini file is just a set of command-line keys, so you can live without it. In Jetty 8 value of OPTIONS could be specified only in ini file, so you could live without it if you have specified –ini command-line key had to override this
2. Instead of defining OPTIONS in single config script, each module has it’s own descriptor.

Servlets basics

1. Web applications are packed into .war files (similar to .jar files). Applications contain static files and dynamic logic.
2. Jetty deployer maps content of web app to URL path corresponding to name of .war file. For example, application example.war to URL http://host:80/example/ . It’s called servet URL context path.
2. All dynamic logic should be placed in WEB-INF/ dir inside a .war file. In this dir there should be a classes/ sub-dir for .class files, lib/ sub-dir for .jar files, and web.xml descriptor of web app
3. Descriptor file web.xml describes servlets (they have name and main class) and mappings from url patterns to servlets.
4. Mappings from URL patterns to servlets is done relative from web application URL context path. For example, if in web.xml servlet mainServlet is mapped to URL pattern /main for web application superapp.war,
then such servlet will handle HTTP requests for URL http://host:80/superapp/main
5. Jetty comes with several built-in servlets: DefaultServlet which serves static files, and JSP servlet which handles .jsp files. You can use them in your application.
6. By default, these servlets are already used in your application. This happens because for module “deploy” it’s config script “etc/jetty-deploy.xml” defines property “jetty.deploy.defaultsDescriptorPath” with value “etc/webdefault.xml”.
This webdefault.xml is pre-pended to your web.xml. To switch it off, override property in your config files, for example in start.ini
7. in etc/webdefault.xml servlet DefaultServlet is mapped to “/”
7. Use Maven with war packaging, maven-war-plugin at build stage, maven profiles to specify which content should be included in .war file

Spring MVC

1. Spring comes with servlet called org.springframework.web.servlet.DispatcherServlet. You can have different servlets of this class under several names
2. This servlet will create Spring application content based on XML file. It will search for Spring context descriptor XML file, depending on servlet name, with pattern -context.xml
3. Like with any Spring XML context, you can either specify beans, including controller beans, directly via tags, or via  and
3. To enable MVC annotations like @Controller etc use
4. If you have mapped DispatcherServlet to “/”, but still want static files to be served, use in your context XML following tag: . It will make static requests to be forwarded
from DispatcherServlet to container’s DefaultServlet (if it is included in your web.xml either explicitly or implicitly by Jetty, see above)
5. If your Spring context supports several profiles, then you can specify which Spring profiles are active using web.xml to set context param “”
6. Log examples to see how your RequestHandlerMappings work:

INFO RequestMappingHandlerMapping:534 - Mapped "{[/rest/query],methods=[GET]}" onto public org.springframework.http.ResponseEntity<java.lang.String>
INFO RequestMappingHandlerMapping:534 - Mapped "{[/proxy/**]}" onto public org.springframework.http.ResponseEntity<java.lang.String> com.GenericPurposeProxyController.processRequest(jav

For default servlet handler:

INFO SimpleUrlHandlerMapping:341 - Mapped URL path [/**] onto handler 'org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#0'


Categories: Java, Web Tags: , ,

WebCMS: first try

June 13, 2007 Leave a comment

In my recent article I’ve told about WebCMS, a software to buld dynamic web-sities without knowledge of HTML and web-programming. That article were just theory, impression made from reading other articles. Now I have my own experience, which I whould like to share.

When I decided to place some local web-site on my desktop, I was very naive and forgot that running a server is a completelly different story than using standalone software. To be able to play with web, first one needs a web server. I’ve downloaded Apache and installed it. This server is very good, with control window accessable from bottom-right corner, configuration from single text file accessible from “start” menu, and logs also accessible from “start” menu. Next step was to install PHP, because most WebCMS systems written in it. Another required software is DBMS, so I’ve downloaded and installed MySQL. With back-end prepared, at last I could install WebCMS itself.

I’ve decided to start with Drupal, which got best reviews from articles I’ve read. I’ve downloaded version 5.1, unpacked and placed in separate directory under web server’s root. Then I’ve entered path to that directory in browser’s addres line, and got “database not found” error message. Not very helpfull, because database was there. I’m coder, so I’ve quickly checked source code (which is very good) and found that “mysql_open” function is not available. Finally I understood the reason, started PHP installer again and added MySQL support, which is disabled by default. That first problem was enough for me to read documentation, which I usually skip. Document is not very helpfull, so I’ve quickly abandoned it. However, after upgrading PHP with MySQL support and restarting Apache everything was fine, and I was able to got on administration home page.

Well, my initial expectations about “beginner-friendly” were proved false. For beginners Drupal is a mystery. I’ve tried help from web site, but it’s very bad: information is organized in horrible way, and it’s just a mess between help pages for different versions of Drupal. So, I’ve returned back to learn-by-trial approach.

After about 2 hours I’ve finally got it, and Drupal appeared much more easier. It has sities, each site is a collection of “nodes”. This weird word corresponds to “web page” just because Drupal has content type named “page”. Each page has central part and sidebars. Central part contains main content, and sidebars contain menues and other “boxes”, that’s how sites are built.

Drupal is modular, so I was able to download stuff from their site and plug it into my existing site. First thing I did was getting more “themes”, to play with them. Most themes are crap, but some are really nice.

Drupal is complex and hard to learn for beginner. But modular design and extensibility make it attactive for me. Out-of-box it has static pages, persistent “blocks” on sides of each page, blogs, “front page” which aggregates latest updates from other pages. So I’m planning to invest some time to learn it more and to use it internally. For long time I was web programmer, but now I’m administrator, and I really like it!

Categories: Web

WebCMS: web publishing done right

June 6, 2007 Leave a comment

Some time ago I was a “Web programmer”. This means that I was making a programs which operated with users through web browser. Even before that I’ve made several sites using raw HTML. HTML is good. You can edit it with simplest text editor and with powerfull editors like FrontPage, DreamWeaver or HomeSite. And, very important, it’s very easy to generate from code. Yes, HTML has it’s limitations, and it’s not a universal UI, but for presending information it is good, and now it is becoming a very widespread UI, because of zero-installation and platform independence.

For a long time I didn’t use HTML, because I’m developing system software, with no UI at all. But now I want to establish small Web site, mostly with static rarely edited content. In single word, if somebody asks me what I will do with this site, I’ll answer “publishing”. From my previous experience first approach whould be writing whole site in static HTML. But now I’m arrogant and lazy, and don’t want to write HTML by hands. WYSIWUG editors also is not an option: for me it’s easier to edit HTML then to learn how to change page’s look using those bloated and non-intuitive tools. So I’ve started to look for solution which will allow me to consentrate on content. First idea about tools which allow editing static web content was blogging software, so I’ve opened Wikipedia and typed “blog”. Following links led me to more general-purpose software genre called “Web content management systems”.

Reading all available info I undestood that finally Web done it right. People who make content should not take a burden to learn HTML, software should do everything for them. And tools for editing content should also be web-based. WebCMS allow versioning, workflow, and also provide extensibility so they could be enchanced and integrated with custom dynamic parts of Web site. It seems that at time I’ve stopped doing web programming those systems were uncapable, but now they become powerfull enought to be useful.

So, I’ve decided to pick a WebCMS and try. Now the question: where to start ? Looking at sities like CMS matrix made me panic, because there are so many of them. Obviously I want free CMS. Digging different sities, forums, message boards and “review” pages give me several candidates: Joomla, Drupal, Lenya, Plone and WordPress. So now I’m having fun evaluating them personally. Expect some impressions very soon.

For somebody interested in topic, here is a very good presentation describing WebCMS.

Categories: Technology, Web