A Hessian usage summary written in Baidu space last year on. Today, I transferred it
The company was prepared to open some API interfaces for agents to use due to business needs. After taking some time to understand the technology over the weekend, the company decided to use Hessian of caucho.com (Hessian is convenient and efficient)
Test Environment
- Window XP
- JDK 1.6
- Resin3.1.9
- Spring2.0.8
- Hessian-3.0.20.jar (this version should correspond with spring, do not blindly pursue the latest version, I am because of this, I do not know whether it is good or bad problems eat n more bitter)
- HessianPHP-1.0.5-RC2
- Apache2.2
- Php5.3.0
The test on the Java Server and customer service was successful at the beginning, but several problems occurred when php5.3 was used as the client to access Java.
PHP code
- Include_once
'../Dist/Hessian. php'
;
- Include_once
'../Dist/hessianclient. php'
;
- Hessian: mapremotetype ('com. hisupplier. showroom. WebService. queryparams'
,
'Queryparams'
);
- Hessian: mapremotetype ('com. hisupplier. showroom. WebService. listresult'
,
'Listresult'
);
- Hessian: mapremotetype ('com. hisupplier. showroom. entity. product'
,
'Product'
);
- Hessian: mapremotetype ('com. hisupplier. commons. Page. page'
,
'Page'
);
- Try {
- $ Params
=
New
Queryparams (114 );
- $ URL
=
Http://guiyou.jiaming.com/webService"
;
- $ Proxy
=
New
Hessianclient (
$ URL
);
- Echo
"<Br>"
;
- Print_r ($ proxy
-> Hello (
$ Params
));
- Echo
"<Br>"
;
- Print_r ($ proxy
-> Getproduct (
$ Params
));
- Echo
"<Br>"
;
- Print_r ($ proxy
-> Getlist (
$ Params
));
// The terrible problem lies here.
- } Catch (httperror $ ex
){
- ...
- }
Include_once '.. /Dist/Hessian. PHP '; include_once '.. /Dist/hessianclient. PHP '; Hessian: mapremotetype ('com. hisupplier. showroom. webService. queryparams ', 'queryparams'); Hessian: mapremotetype ('com. hisupplier. showroom. webService. listresult ', 'listresult'); Hessian: mapremotetype ('com. hisupplier. showroom. entity. product ', 'product'); Hessian: mapremotetype ('com. hisupplier. commons. page. page ', 'page'); try {$ Params = new queryparams (114); $ url = "http://guiyou.jiaming.com/webService"; $ proxy = new hessianclient ($ URL ); echo "<br>"; print_r ($ proxy-> Hello ($ Params); echo "<br>"; print_r ($ proxy-> getproduct ($ Params )); echo "<br>"; print_r ($ proxy-> getlist ($ Params); // The Problem Is that} catch (httperror $ ex ){...}
Java code
- Public
Interface
Showroomapi {
- String Hello (queryparams Params );
- Listresult <product> getlist (queryparams Params );
- Product getproduct (queryparams Params );
- }
public interface ShowroomAPI { String hello(QueryParams params); ListResult<Product> getList(QueryParams params); Product getProduct(QueryParams params);}
1st questions
Because php5.2.x comes with the datetime class, it conflicts with hessianphp.
Solution:
Change datetime. php to hessiandatetime. php, and datetime to hessiandatetime.
2nd questions
PHP warning: Date (): it is not safe to rely on the system's timezone
Settings. you are * required * to use the date. timezone setting or
Date_default_timezone_set () function. In case you used any of those
Methods and you are still getting this warning, you most likely
Misspelled the timezone identifier. We selected 'utc' for '8. 0/No DST'
Instead in G: // PHP // hessianphp // Dist // Hessian. php on line 74
Solution:
Change the date () method to date_default_timezone_set ()
3rd questions
PHP code
- Exception: Hessian parser, malformed reply: expected R code: 2 exception
'Hessianerror'
With message
'Hessian parser, malformed reply: Expected R'
In E:/workspace/PHP-test/Dist/protocol. php: 339 stack trace:
- #0 E:/workspace/PHP-test/Dist/hessianclient. php (215): hessianparser-> parsereply ()
- #1 E:/workspace/PHP-test/Dist/filter. php (159): hessianproxy-> executecall ('getlist'
, Array)
- #2 E:/workspace/PHP-test/Dist/filter. php (73): proxyfilter-> execute (Object (hessianproxy), object (filterchain ))
- #3 E:/workspace/PHP-test/Dist/filter. php (191): filterchain-> dofilter (Object (hessianproxy ))
- #4 E:/workspace/PHP-test/Dist/filter. php (73): phperrorreportingfilter-> execute (Object (hessianproxy), object (filterchain ))
- #5 E:/workspace/PHP-test/Dist/hessianclient. php (182): filterchain-> dofilter (Object (hessianproxy ))
- #6 E:/workspace/PHP-test/Dist/hessianclient5.php (94): hessianproxy-> call ('getlist'
, Array)
- #7 [internal function
]: Hessianclient->__ call (
'Getlist'
, Array)
- #8 E:/workspace/PHP-test/tests/test. php (23): hessianclient-> getlist (Object (queryparams ))
- #9 {main}
Exception: Hessian Parser, Malformed reply: expected r Code: 2 exception 'HessianError' with message 'Hessian Parser, Malformed reply: expected r' in E:/workspace/php-test/dist/Protocol.php:339 Stack trace: #0 E:/workspace/php-test/dist/HessianClient.php(215): HessianParser->parseReply() #1 E:/workspace/php-test/dist/Filter.php(159): HessianProxy->executeCall('getList', Array) #2 E:/workspace/php-test/dist/Filter.php(73): ProxyFilter->execute(Object(HessianProxy), Object(FilterChain)) #3 E:/workspace/php-test/dist/Filter.php(191): FilterChain->doFilter(Object(HessianProxy)) #4 E:/workspace/php-test/dist/Filter.php(73): PHPErrorReportingFilter->execute(Object(HessianProxy), Object(FilterChain)) #5 E:/workspace/php-test/dist/HessianClient.php(182): FilterChain->doFilter(Object(HessianProxy)) #6 E:/workspace/php-test/dist/HessianClient5.php(94): HessianProxy->call('getList', Array) #7 [internal function]: HessianClient->__call('getList', Array) #8 E:/workspace/php-test/tests/test.php(23): HessianClient->getList(Object(QueryParams)) #9 {main}
Google and Baidu haven't found any related articles for a long time. After that, they reduced Apache and PHP to 2.0 and 5.1 respectively. Finally, they gave up trying Yahoo! My God Buddha blessed Amen and asked me to find an article
Reference
Chunked HTTP responses cause a protocol Parse error
HTTP. php is written to perform an http post using HTTP/1.1 which means that
The Hessian client must support a HTTP header of "transfer-encoding:
Chunked ".
Protocol: parsereply () is written as follows:
If ($ this-> read (1 )! = 'R '){
Return new hessianerror ('hessian parser, malformed reply: expected
R', hessian_parser_error, 0, $ this-> stream );
}
Which will fail because the first line of a chunked response will contain
The chunk length. Protocol: parsereply () needs to be written to support
Chunking.
At the moment the workaround I have is to set HTTP/1.0 in http: Post.
Solution:
Change 1.1 in HTTP. php to 1.0
In the HTTP. php 200th line: $ out = "post $ this-> url http/1.1/R/N ";