Java remote Hessian call example

Source: Internet
Author: User

<Servlet> <servlet-Name> hessianservice </servlet-Name> <! -- Note that this is provided by Hessian --> <servlet-class> com. caucho. hessian. server. hessianservlet </servlet-class> <init-param> <param-Name> service-class </param-Name> <! -- Class called after instantiation --> <param-value> guilinsoft. ddsx. API. wdpfimpl </param-value> </init-param> <load-on-startup> 1 </load-on-startup> </servlet> <servlet-mapping> <Servlet -Name> hessianservice </servlet-Name> <URL-pattern>/hessianservice </url-pattern> </servlet-mapping>

Thanks.


The project needs to monitor the current status of the device in real time, and the server is remotely and so, and the powerful Hessian is found online. Haha, I always thought it was a session extension .. khan looked at its official website, a little dizzy, mainly because its configuration file was not clear, and then he found an instance shared by aliyunyou in oschina. oh, too .. if the call is successful, record it.

Simulate two projects, demo (server), client (client)

Greetingapi is the interface, while greetingservlet is the implementation of the interface... the name is not good ..

package example;  public interface GreetingAPI {   public String hello(); public String ok(); public String no();}package example;    public class GreetingServlet  implements GreetingAPI {   private static final long serialVersionUID = 1L; private String _greeting="Hello,would!";    public String hello() {  return _greeting; } public String ok(){  return "this is greetingServlet method ok!!"; }   public void set_greeting(String greeting) {  _greeting = greeting; } public String no() {  return "this is greetingServlet method NO!!"; }  }

Note that the package name must be the same as that of the server. Otherwise, an exception cannot be found in the instance. The content of greetingapi. Java is consistent with that of the server.

package example;  import java.net.MalformedURLException;  import com.caucho.hessian.client.HessianProxyFactory;import com.jzero.util.MPrint;      public class test {   public static void main(String[] args) {  String url="http://localhost:8080/Demo/hessianService";  HessianProxyFactory factory=new HessianProxyFactory();  try {   GreetingAPI api=(GreetingAPI) factory.create(url);   MPrint.print(api.hello());   MPrint.print(api.ok());   MPrint.print(api.no());  } catch (MalformedURLException e) {   // TODO Auto-generated catch block   e.printStackTrace();  } catch (ClassNotFoundException e) {   // TODO Auto-generated catch block   e.printStackTrace();  } }}

------- [Program debugging and printing data: Hello, wocould !] -------------- [Program debugging and printing data: This is greetingservlet method OK !!] -------------- [Program debugging and printing data: This is greetingservlet method no !!] -------


Source: Java remote Hessian call example

----------- Advertisement Area

Casual beans, it information, it news, BT download, HD download, Movie Download, single-host game download, game download, e-book download, and e-book PDF download

Related Article

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.