Explore osgi web application development tool equinox: Environment Settings

Source: Internet
Author: User
Tags apache tomcat

[51cto] in the previous "Hello, osgi" Series
Medium,
We have laid the foundation for understanding how the osgi service platform works. In the last few articles, we will learn how to apply osgi pluggable and component-based development models to the Web
Application. You will create an osgi Application Based on bundle, which can be a static resource, Servlet, or JSP
Provides server services. In addition, you can also learn some practical experience: in Web applications, the Equinox framework is easy to use.
Osgi modularization, version management, and dynamic services.

51cto editing recommendations:
Osgi introduction and Practice

This series has introduced osgi development concepts and demonstrated how to use Equinox to create a simple hello World application, eclipse osgi
Container and implementation. In addition, we have introduced spring DM (Spring dynamic model), which allows you to easily create spring applications and deploy them in
In the osgi container.

In the last section, we will answer the following questions that many developers are asking:I like osgi, but how can I use it to create Web applications?

In this section, you will see that the osgi development model greatly simplifies the process of writing truly pluggable, modularized, and componentized server applications. The development exercise will be based on osgi
Reference the implementation of equinox (this is the case in this series ). However, this time we will use equinox on the server side.
). Open
At the beginning, we will discuss the option sequence for deploying osgi Web applications (jetty or tomcat in this example), and then a short guide to configure the Web
Application development environment. Then, we will develop a simple hello World osgi web application and deploy it in different ways.

Use server-side equinox for application development

There are two ways to use server-side Equinox to develop osgi Web applications: You can embed lightweight servlet containers (such as jetty)
In the osgi container, or embed the osgi container into a web application, and then deploy the program in the servlet container (such as Apache Tomcat.

Now, the good news is that the process for developing osgi Web applications is the same regardless of the method you choose. Therefore, it is best to set the Servlet
The container is embedded into your osgi container. Once the application is ready, you can restart and package it for deployment. Now you can learn how
The container is embedded into your osgi container. But the first step is to set up the development environment.

Equinox: Rise of equinox

The server-side equinox project is developing rapidly. There is a tendency to add popular MVC frameworks (such
Support for Apache struts and spring web frameworks, as well as popular Object-link Ing tools (such as Hibernate. Rich Ajax
The platform is another Eclipse project that allows you to use Ajax applications with server-side equinox.

Set Development Environment

In the application development exercises in this section, we will embed a lightweight servlet container into the osgi Suite (or plug-in, that is,
Plug-in ). Once this plug-in is installed in the osgi container, it will listen to HTTP
Request. When receiving a request, it will check whether any installed plug-in can process the request. If yes, it will forward the control to the corresponding plug-in to generate a response. Once a response is generated
Yes, the osgi container will forward it to the customer.

Server-side equinox simplifies osgi-based Web by providing several pre-fabricated plug-ins (embedding servlet containers into osgi plug-ins)
Application development. The following plug-ins contain an embedded servlet container:

Org. Eclipse. Equinox. http: A very small plug-in that runs footprint and is suitable for environments with limited resources.

Org. Eclipse. Equinox. http. jetty: Uses jetty as the underlying engine to provide 2.4
.

In this section, we embed the jetty plug-in into Eclipse IDE to configure the osgi web application development environment. (If your ide
Not started yet. You should start it first ).

1. Set the jettyhttp-anon.psf

Download to your computer.

2. Right-click package explorer and choose import> Team Project.
Set, and then click Next ).

3. In the import a team project set dialog box, Click Browse and select
Jettyhttp-anon.psf file, 1 shown.


 

Figure 1. Import plug-in

Click Finish to start the import process. This step may take several minutes, depending on the speed of your Internet connection, because eclipse will
Dev.eclipse.org the CVS library downloads the required project files.

4. Once the import is complete, you can see that some suites have been imported into your workspace:

1. javax. servlet v2_4
2. org. Apache. commons. Logging v1_0_4
3. org. Eclipse. Equinox. http. Jetty
4. org. Eclipse. Equinox. http. Registry
5. org. Eclipse. Equinox. http. servlet
6. org. mortbay. jetty v5_000011

Your development environment is ready. The next step is to execute your suite in the Equinox osgi framework. If you forget how to perform the operation, refer to Section 1 of this series.

Verify your settings

If you have executed the suite in the Equinox osgi framework, you will see the osgi> prompt in the console view. You should be able
The console displays the information generated by the jetty servlet container, which is similar to list 1 below.

List 1. jetty information in the osgi Console

1. osgi> May 21,200 8 12:28:06 org. mortbay. http. httpserver dostart
2. Info: Version jetty/5.1.x
3. May 21,200 8 12:28:07 org. mortbay. util. Container start
4. Info: started org. mortbay. Jetty. servlet. servlethandler @ f47bf5
5. May 21,200 8 12:28:07 org. mortbay. util. Container start
6. Info: started httpcontext [/,/]
7. May 21,200 8 12:28:07 org. mortbay. http. socketlistener start
8. Info: started socketlistener on 0.0.0.0: 80
9. May 21,200 8 12:28:07 org. mortbay. util. Container start
10. Info: started org. mortbay. http. httpserver @ 1f6df4c

You can see info: started org. mortbay. http. httpserver @ 1f6df4c.
And then proceed to the next step.

Enterhttp://localhost/

To verify
You can divide it into jetty servers. You should be able to see the error page, as shown in List 2.

List 2. jetty error message

1. HTTP Error: 404
2. proxyservlet :/
3. requesturi =/
4. powered by Jetty ://

Because jetty cannot find the requested resource, you will receive Error 404. If you cannot find a hosted plug-in to process the current request, Jetty osgi
The plug-in does not provide any default index page on the server side. As an alternative, it will throw this 404 error page.

If your settings match my story, you can start the first exercise in the next article: using server-side Equinox to develop osgi-based Web
Application. Stay tuned!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.