Java learning path-Burlap learning, java path-burlap

Source: Internet
Author: User

Java learning path-Burlap learning, java path-burlap

Today, let's learn about Burlap.

Burlap is an XML-based Remote Call technology, but unlike other XML-based remote technologies (such as SOAP or XML-RPC), Burlap's message structure is as simple as possible, no additional external Definition Language (such as WSDL or IDL) is required ).

Burlap and Hessian are the same to a large extent. The only difference is that Hessian messages are binary messages, while Burlap messages are XML messages. (The implementation of Burlap and Hessian code is also very similar)

Next, let's take a look at the implementation of the Code:

 

1. First, create an object class. The Serializable interface is not required here.

package entity;public class Food {    private String name;    private double price;    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public double getPrice() {        return price;    }    public void setPrice(double price) {        this.price = price;    }}

2. Let's define an Interface

package service;import java.util.List;import entity.Food;public interface FoodService {    List<Food> getFoodList();}

 

3. Define a class, implement the interface in step 2, and inherit the BurlapServlet class (here you need to use the jar file of Burlap, you can download http://www.findjar.com/jar/burlap/jars/burlap-2.1.7.jar.html here)

Package service. impl; import java. util. arrayList; import java. util. list; import service. foodService; import com. caucho. burlap. server. burlapServlet; import entity. food; public class FoodServiceImpl extends BurlapServlet implements FoodService {public List <Food> getFoodList () {List <Food> list = new ArrayList <Food> (); food f1 = new Food (); f1.setName ("Pickled Fish"); f1.setPrice (25); Food f2 = new Food (); f2.setName ("sweet and sour fish"); f2.setPrice (23 ); list. add (f1); list. add (f2); return list ;}}

 

4. Now we can configure a servlet in web. xml under the WEB-INF (Hessian can also configure servlet like this)

<servlet>    <servlet-name>food</servlet-name>    <servlet-class>service.impl.FoodServiceImpl</servlet-class></servlet><servlet-mapping>    <servlet-name>food</servlet-name>    <url-pattern>/food</url-pattern></servlet-mapping>

 

5. Let's write the test code and check the result.

Package test; import java. util. list; import service. foodService; import com. caucho. burlap. client. burlapProxyFactory; import entity. food; public class Test {public static void main (String [] args) {String url = "http: // 127.0.0.1: 8080/test/food "; burlapProxyFactory factory = new BurlapProxyFactory (); try {FoodService foodSevice = (FoodService) factory. create (FoodService. class, url); List <Food> foodList = food Sevice. getFoodList (); for (Food food: foodList) {System. out. println (food. getName () + ":" + food. getPrice () + "RMB. ") ;}} Catch (Exception e) {e. printStackTrace ();}}}

 

The console displays the following results:

========= Console ============


Pickled Fish: 25.0 yuan.

Sugar and vinegar fish: 23.0 yuan.


======================================


Next let's take a look at Spring's Integrated Burlap, which is basically the same as Spring's Integrated Hessian.

Spring integrated Burlap

1. Let's define an Interface

package service;import java.util.List;import entity.Food;public interface FoodService {    List<Food> getFoodList();}

 

2. Define a class and implement the interface in step 2

Package service. impl; import java. util. arrayList; import java. util. list; import service. foodService; import entity. food; public class FoodServiceImpl implements FoodService {public List <Food> getFoodList () {List <Food> list = new ArrayList <Food> (); Food f1 = new Food (); f1.setName ("Pickled Fish"); f1.setPrice (25); Food f2 = new Food (); f2.setName ("sweet and sour fish"); f2.setPrice (23); list. add (f1); list. add (f2); return list ;}}

 

3. We can configure SpringMVC required information in web. xml under the WEB-INF.

<context-param>  <param-name>contextConfigLocation</param-name>  <param-value>classpath:applicationContext.xml</param-value></context-param><listener>  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><servlet>  <servlet-name>springMvc</servlet-name>  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  <load-on-startup>1</load-on-startup></servlet><servlet-mapping>  <servlet-name>springMvc</servlet-name>  <url-pattern>/</url-pattern></servlet-mapping>

 

4. Configure bean information for the Service to be exported in applicationContext. xml

<bean id="foodService" class="service.impl.FoodServiceImpl"></bean>
<bean id="FoodService"  class="org.springframework.remoting.caucho.BurlapServiceExporter"  p:serviceInterface="service.FoodService"  p:service-ref="foodService"/>

 

5. Create a WEB-INF file under the springMvc-servlet.xml and configure information

<?xml version="1.0" encoding="UTF-8"?><beans  xmlns="http://www.springframework.org/schema/beans"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:p="http://www.springframework.org/schema/p"  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">  <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">    <property name="mappings">      <props>        <prop key="/foodService">FoodService</prop>      </props>    </property>  </bean></beans>

 

6. Configure and obtain the bean information of the Service in applicationContext. xml of the client program.

<bean id="getFoodService"  class="org.springframework.remoting.caucho.BurlapProxyFactoryBean"  p:serviceInterface="service.FoodService"  p:serviceUrl="http://127.0.0.1:8080/test/foodService"/>

 

7. Now let's write the test code

Package test; import java. util. list; import org. springframework. context. applicationContext; import org. springframework. context. support. classPathXmlApplicationContext; import entity. food; import service. foodService; public class Test {public static void main (String [] args) {ApplicationContext ctx = new ClassPathXmlApplicationContext ("applicationContext. xml "); FoodService foodService = (FoodService) ctx. getB Ean ("getFoodService"); List <Food> foodList = foodService. getFoodList (); for (Food food: foodList) {System. out. println (food. getName () + ":" + food. getPrice () + "RMB. ");}}}

 

Next, deploy the project to Tomcat and start the service. Run the test code

===== Console ========


Pickled Fish: 25.0 yuan.

Sugar and vinegar fish: 23.0 yuan.


==============================

Here we have learned how to integrate Spring with Burlap.


How to Learn java

I don't know how your foundation works! It seems that you have no foundation. If so, I will share with you my own experiences.
At first, I heard about java from my classmates. I started the java electives when I was in the 3rd class, and I didn't take them well. After all, I only had a few weeks of classes. The teacher spoke very quickly, I have not learned anything! After I finished my graduation project, I went to learn java by myself and picked up the book to compile the simplest program for a long time. I almost gave up! I changed the policy.
Step 1: I read the thin book first.
Step 2: Compile the example code in the book and do exercises again. I found myself getting started!
Step 3: Find a subject, make small things, chat software on the LAN, calculator, notepad, and other things. That will make my classmates admire me very much. In fact, it is very easy to get into the door. It is difficult to get started.
Step 4: even if the above j2se is finished, we will learn java web development, jsp, struts, hibenate, and spring through video. In this process, we will exercise our programming skills through projects.
In fact, learning may not have such a strict limit. My method may not be the best, but it may be suitable for me and I will give you a reference.
When you can complete a student achievement management system independently, you apply for a job in the company. As a fresh graduate, your level is already high!
If you think my answer is helpful or helpful to you, please give me extra points. If you have any questions to discuss with me, Baidu, qq, and mobile phones can all help the Group's children who love learning!

JAVA learning path

Linux: the operating system (the same as winXP) has no essential relationship with java, but in the company, it is generally required to use common linux commands.
XML: Data Transmission Format. Learn more about Java Web.
Strut: One of the open-source Java Web frameworks, one of the essential technologies of Java Web

Spring: One of the open-source frameworks of javaweb, one of the essential technologies of javaweb
Hibernate: One of the open-source frameworks of javaweb, one of the essential technologies of javaweb

The above three constitute the most common enterprise-level development framework technology ssh, (each technology name starts with a letter)

SERVLET: One of the basic Java Web technologies, required. This is the foundation of ssh and must be learned well.
Jsp: javaweb display layer, required!
We recommend that you first learn java BASICS (such as interfaces, inheritance, and control statements) and then javaweb, otherwise, Java Web will learn servlet, jsp, and javabean before learning framework technology. In framework technology, I first learned struct2 spring

Java Web can be said to be used as a website, while javase is one of the major functions of java3 (j2s, J2ee, and javase ).
J2ee is enterprise-level development,
Java EE is standard development. j2ee and javase (also called j2se) are basically used for developing desktop applications and websites. However, the former has better functions than the latter.

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.