I did not know anything about web cross-service push data before, and I studied it today. In fact, some things, when they do not understand the full feel like a day foreign objects. But after a little bit of understanding, it's very interesting. It's fun to gossip every day. The following simple instance 10 minutes configures message pushes across Web services.
first, the called End of the web. XML Configuration
<!--Hellohessian--<servlet> <servlet-name>HelloHessian</servlet-name> <servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class><!--Hessian-&L T;init-param> <param-name>home-api</param-name> <param-value>com.css.webservices.push Data. acceptmailservice</param-value><!--Your interface-</init-param> <init-param> <p Aram-name>home-class</param-name> <param-value>com.css.webservices.pushdata.acceptmail</ param-value><!--Your interface implementation class-</init-param> </servlet> <servlet-mapping> < Servlet-name>hellohessian</servlet-name> <url-pattern>/HelloHessian</url-pattern> </ Servlet-mapping>
Second, the called End
Here we define an interface and an implementation class for an interface
Third, the called End Interface
Public interface Acceptmailservice {
/** * * 远端调用接口 * @param text 描述类信息 * */public void acceptMailFromWeb(String text);}
Iv. called-end Interface Implementation class
public class Acceptmail implements Acceptmailservice {
@Overridepublic void acceptMailFromWeb(String text) { System.err.println("我这边接收到你推送的描述类信息为:"+text);}
}
V. Call END
Copy the above two files to the calling end. Copied together with the package where the file resides. That is, the implementation class that defines the interface and interface of the same callee with the same name as the same package as the content.
Six, the call end, start to push the data
You know, we've already configured the call-side server with the receiving server.
Start pushing data below:
The caller defines the method and pushes the data into the push, pushing it directly.
String url = "Http://xx.xx.xxx.xxx:8080/20180816/HelloHessian";
String text = "Hello, Hello,hello, I am going to give you the server to push the data." Did you get my message? ";
Hessianproxyfactory factory = new Hessianproxyfactory ();
Acceptmailservice Acceptmail;
try {
Acceptmail = (acceptmailservice) factory.create (Acceptmailservice.class, url.tostring ());
Acceptmail.acceptmailfromweb (text);
} catch (Malformedurlexception e) {
E.printstacktrace ();
}
Seven, the demonstration:
Start the service at the same time as both the caller and the callee.
Then execute the push data method
You'll see that in the console at the end of the call.
Push success.
Imagine, we will string text = "Hello, Hello,hello, I am going to give you the server to push the data." Did you get my message? ";
Push the content, instead of the binary encoding of the file stream, you can directly push files (pictures, music, Word documents, etc.).
Well, these things will be discussed later, the author is going to eat chicken.
Configure a simple cross-Web service message push with HESSIAN10 minutes