锘??xml version="1.0" encoding="utf-8" standalone="yes"?> 鍒氬湪欏圭洰涓簲鐢ㄥ埌浜唈ava涓巔hp閫氳繃webservice榪涜鏁版嵁浜や簰銆傝寰楁尯鏈夋剰鎬濓紝璐村嚭鏉ワ紝璺熷ぇ瀹跺垎浜? 涓.java緙栧啓webservice鏈嶅姟绔?php浣滀負瀹㈡埛绔皟鐢? 1.棣栧厛鎴戜滑鍐欎竴涓畝鍗曠殑java綾誨茍鍙戝竷webservice. package com.php; import java.util.Map; public class WebServiceImpl { public String sendTransact(Map map) throws Exception { 2.閰嶇疆server-config.wsdd <deployment xmlns="http://xml.apache.org/axis/wsdd/" <handler name="URLMapper" <service name="IWebService" provider="java:RPC"> </deployment> 3.鍙戝竷鍒癹boss鍚?璁塊棶http://localhost:8088/testphpweb/services/IWebService?wsdl鑳界湅鍒皒ml鏂囦歡灝辮鏄巜ebservice鍙戝竷濂戒簡銆?/p>
4.鍐檛estphpweb.php鏂囦歡 <?php // 瑕佽闂殑webservice璺緞 // 鐢熸垚瀹㈡埛绔璞?br>$client = new soapclient($NusoapWSDL, true); // 璁劇疆鍙傛暟(娉ㄦ剰錛歅HP鍙兘浠?鏁扮粍闆?鏂瑰紡浼犻掑弬鏁?濡傛灉鏈嶅姟绔槸java錛岀敤Map鎺ユ敹) echo "begin remote 銆傘傘?lt;br>"; // 鏄劇ず鎵ц緇撴灉 5.鍚姩apache,璁塊棶http://localhost/service/testphpweb.php php欏甸潰鏄劇ず: ::: PHP CALL JAVA-WEBSERVICE ::: jboss鍚庡彴鐩戣緇撴灉: 17:12:20,781 INFO [STDOUT] ::: Call testModel1 ::: 鍒版,php浣滀負瀹㈡埛绔皟鐢╦ava鍐欑殑webservice鏈嶅姟绔畬鎴? 浜?php緙栧啓webservice鏈嶅姟绔?java浣滀負瀹㈡埛绔皟鐢? 1.緙栧啓php webservice <?php function sendManifest($param) 銆銆//鎶婃帴鏀跺埌鐨勬暟鎹樉紺哄嚭鏉?br> return "hello ".$param["projectid"]."<=>".$param["projectname"]."<=>".$param["moduleid"]; $server = new nusoap_server(); //閰嶇疆WSDL namespace // 娉ㄥ唽web鏈嶅姟 $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; 2.鍚姩apache鍚庯紝璁塊棶 http://localhost/service/phpserver.php,濡傛灉欏甸潰濡備笅鍥炬墍紺猴紝琛ㄧずwebservice鍙戝竷濂戒簡銆?br> 3.緙栧啓java瀹㈡埛绔疌allPhpServer .java 騫惰皟鐢╬hp webservice package com.php; import java.util.HashMap; public class CallPhpServer { Call call = (Call) service.createCall(); String result=new String(str.getBytes("iso-8859-1"),"GBK"); ::: call php webservice :::
瀹樻柟緗戠珯錛岃嫳鏂囩殑錛岄渶瑕佺殑鏈嬪弸鑷繁鍘葷湅錛屾湁浜涘鏉傦紝鐜板湪鍥犱負娌℃椂闂達紝鍏堜笉鐮旂┒錛屽仛涓鍙楓?
System.out.println("::: Call testModel1 :::");
if(map!=null){
String bugmanifestid = StringUtil.getValue(map.get("bugmanifestid"));
String editedby = StringUtil.getValue(map.get("editedby"));
String dditeddate = StringUtil.getValue(map.get("dditeddate"));
String fullinfo = StringUtil.getValue(map.get("fullinfo"));
String action = StringUtil.getValue(map.get("action"));
System.out.println("bugmanifestid ->" +bugmanifestid);
System.out.println("editedby ->" +editedby);
System.out.println("dditeddate ->" +dditeddate);
System.out.println("fullinfo ->" +fullinfo);
System.out.println("action ->" +action);
}
return "success";
}
}
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
type="java:org.apache.axis.handlers.http.URLMapper" />
<handler name="auth"
type="java:com.php.AuthenticationHandler" />
<handler name="URLLogging"
type="java:com.php.LogHandler">
<parameter name="filename" value="c:\\MyService.log" />
</handler>
<parameter name="className"
value="com.php.WebServiceImpl" />
<parameter name="allowedMethods" value="*" />
<namespace>http://localhost:8088/testphpweb</namespace>
</service>
<transport name="http">
<requestFlow>
<handler type="URLMapper" />
<handler type="URLLogging" />
</requestFlow>
</transport>
header("Content-Type: text/html; charset=GB2312");
echo " ::: PHP CALL JAVA-WEBSERVICE ::: <br>";
require_once("nusoap/lib/nusoap.php");
$NusoapWSDL="http://localhost:8088/testphpweb/services/IWebService?wsdl";
$param = array( 'bugmanifestid' => 'E090500001',
'editedby' => '寮犱笁',
'dditeddate' => '2009-05-19',
'fullinfo' => '宸茶仈緋誨垬寰峰崕,絳瑰浠婃櫄鍚冮キ鐨勪簨,絳夊緟鍥炲',
'action' => '0');
// 璋冪敤榪滅▼鏂規硶
$result = $client->call('sendTransact', array($param));
echo "end remote 銆傘傘?lt;br>";
if (!$err=$client->getError()){
echo '緇撴灉 : '.$result;
}else{
echo '閿欒 : '.$err;
}
?>
begin remote 銆傘傘?br>end remote 銆傘傘?br>緇撴灉 : success
17:12:20,781 INFO [STDOUT] bugmanifestid ->E090500001
17:12:20,781 INFO [STDOUT] editedby ->寮犱笁
17:12:20,781 INFO [STDOUT] dditeddate ->2009-05-19
17:12:20,781 INFO [STDOUT] fullinfo ->宸茶仈緋誨垬寰峰崕,絳瑰浠婃櫄鍚冮キ鐨勪簨,絳夊緟鍥炲
17:12:20,796 INFO [STDOUT] action ->0
header("Content-Type: text/html; charset=GB2312");
require_once("nusoap/lib/nusoap.php");
{
}
$server->configureWSDL('myservice', //鏈嶅姟鍚嶇О
'http://localhost/service/web_call_center.php', //tns鎸囧畾鐨刵amespace,涓鑸~鍐欒嚜宸辯殑URI
true, //endpoint url or false
'rpc', //鏈嶅姟鏍峰紡
'http://schemas.xmlsoap.org/soap/http', //浼犺緭鍗忚,涓鐩存槸榪欎釜銆?br> 'http://localhost/service/web_call_center.php' //wsdl 'types'鍏冪礌targetNamespace
);
$server->register('sendManifest', // 鏈嶅姟
array(
'projectid' => 'xsd:string',
'projectname' => 'xsd:string',
'moduleid' => 'xsd:string',
'modulepath' => 'xsd:string',
'bugtitle' => 'xsd:string',
'bugtype' => 'xsd:string',
'openedby' => 'xsd:string',
'openeddate' => 'xsd:string',
'assignedto' => 'xsd:string',
'assigneddate' => 'xsd:string',
'fixedtime' => 'xsd:string',
'fullinfo' => 'xsd:string',
'bugmanifestid' => 'xsd:string'), // 杈撳叆鍙傛暟;鏁扮粍錛屾寚瀹氱被鍨?br> array('resultCode' => 'xsd:string'), // 杈撳嚭;鏁扮粍,鎸囧畾綾誨瀷
'http://localhost/service/web_call_center.php', // namespace of method
'', // soapaction
'rpc', // style
'encoded', // use
'serviceConsumeNotify' // documentation
);
$server->service($HTTP_RAW_POST_DATA);
?>
import java.util.Map;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public static String callManifest() throws Exception {
System.out.println("0");
Service service = new Service();
System.out.println("1");
call.setTargetEndpointAddress(new java.net.URL("http://localhost/service/phpserver.php"));
call.setOperationName("sendManifest");
System.out.println("2");
Map map=new HashMap();
map.put("projectid", "109");
map.put("projectname", new String("鏂癕M鍥介檯鐗╂祦騫沖彴".getBytes(),"iso-8859-1"));
map.put("moduleid", "11");
map.put("modulepath", new String("璐㈠姟綆$悊".getBytes(),"iso-8859-1"));
map.put("bugtitle", new String("鍏充簬鎬昏處鎶ヨ〃鏁版嵁鐨勯棶棰?.getBytes(),"iso-8859-1"));
map.put("bugtype", "TrackThings");
map.put("openedby", "zhangsan");
map.put("openeddate", "2009-05-31");
map.put("assignedto", "liumang");
map.put("assigneddate", "2009-05-31");
map.put("fixedtime", "2009-06-03");
map.put("fullinfo", new String("鐜板湪鎬昏處鎶ヨ〃欏甸潰涓嬬殑鍚堣鏁版嵁涓嶅,鐑﹁鎶撶揣浜嬩歡鏍稿疄紜鏇存,璋㈣阿!".getBytes(),"iso-8859-1"));
map.put("bugmanifestid", "E090500001");
call.addParameter("param", org.apache.axis.Constants.SOAP_ARRAY,javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.Constants.XSD_STRING);
System.out.println("3");
Object obj=call.invoke(new Object[]{map});
return obj.toString();
}
public static void main(String[] args) throws Exception {
System.out.println("::: call php webservice :::");
String str = callManifest();
System.out.println(result);
}
}
鎺у埗鍙版樉紺虹粨鏋?
0
log4j:WARN No appenders could be found for logger (org.apache.axis.i18n.ProjectResourceBundle).
log4j:WARN Please initialize the log4j system properly.
1
2
3
hello 109<=>鏂癕M鍥介檯鐗╂祦騫沖彴<=>11
鍒版錛宩ava浣滀負瀹㈡埛绔皟鐢╬hp鐨剋ebservice鏈嶅姟绔畬鎴?
2銆佸畨瑁呭ソapache,php
3銆佷笅杞絧hp-java-bridge_5.5.4_documentation.zip
4銆佽В鍘嬬緝php-java-bridge_5.5.4_documentation.zip
5銆佸皢瑙e帇緙╁悗鏍圭洰褰曚笅JavaBridge.war鎷瘋礉鍒皌omcat鏈嶅姟鍣ㄧ殑webapp鐩綍涓?br>6銆佸惎鍔╰omcat鏈嶅姟鍣?br>7銆佸湪php涓嬌鐢╦ava鍙渶澧炲姞涓嬮潰涓琛岃鍙ワ細
<php? require_once(http://127.0.0.1:8080/JavaBridge/java/Java.inc); ?>
鍙互浜嗭細
<php?
$date=new Java('java.util.Date');
echo $date->getDate();
?>
榪愯閫氳繃錛孫K!
璋冪敤鑷繁鐨勭被錛屽厛 鎵撳寘鎴恓ar鏂囦歡 錛岃繍琛屼腑鍐欙細jar cf Test.jar Test.java銆傛斁鍒皌omcat鍙戝竷鐩綍WEB-INF/lib涓?
Test.java濡備笅錛?br>public class Test {
public String rsStr;
public static void main(String[] args)
{
System.out.println("Hello World!");
}
public void setString( String param ){
if( param.equals("") ) {
rsStr = "Hello,how are you!";
}else{
rsStr = param;
}
}
public String getString(){
return rsStr;
}
}
璋冪敤鐨刾hp鏂囦歡濡備笅錛?br><?php require_once("http://localhost:8080/JavaBridge/java/Java.inc");
$t = new java("Test");
echo get_class($t);
$t->setString("ffffffffffff");
echo $t->getString();
//echo "ddjsa;fjsjf;sja;fl";
$t->setString("dddddddddddddddd");
echo $t->getString();
$t->setString("33333333333333333333");
echo $t->getString();
//*******************************my jar
$t1 = new java("IndexTest");
print($t1->searchWord("city","涓婃搗","E:\\workspace\\tuan800"));
?>
璋冪敤鑷畾涔夌被涓寘鍚玦mport鐨勮鎵撳寘jar錛歟clipse鐨別xport鐨刯ar file鍔熻兘錛岄変腑瑕佹墦鍖呯殑綾繪墍鍦ㄧ殑欏圭洰銆傛墦鍖呭悗灝嗗叾鏀懼埌tomcat鍙戝竷鐩綍鐨刉EB-INF/lib涓嬨?br>浣嗘槸lucene鎹㈡垚3.0.0鐗堢殑鏃跺欙紝鎵撳寘灝卞彧鐢ㄦ墦綾伙紝lucene鐨勬牳蹇冨寘鐩存帴鎷瘋礉鍒皌omcat鍙戝竷鐩綍鐨刉EB-INF/lib涓嬨?br>姝e父璋冪敤鍗沖彲銆?br>jar鍖?br>http://repo1.maven.org/maven2/org/apache/lucene/lucene-core/3.0.0/
鎼滅儲綾伙細
http://apps.hi.baidu.com/share/detail/5600609
瀹夎PHP4.3.5RC3.dev(Win32)+Apache 2.0.52(For Win32)鍜宩2sdk 1.4 (For Win32)閮戒笉鐢ㄨ浜嗭紝濡傛灉涓嶄細瀹夎錛岃鐪嬬浉鍏蟲墜鍐屻?br> 鍦≒HP閰嶇疆鏂囦歡php.ini涓壘鍒?" ;extension=php_java.dll " 榪欎笂琛岋紝騫舵妸鍓嶉潰鐨勫垎鍙峰幓鎺?
鍐嶆壘鍒幫細
[Java]
;java.class.path =
;java.home =
;java.library =
;java.library.path =
鏀逛負:
java.class.path = "JAVA鐨凜LASS_PATH;(灝嗚鏀劇疆鑷繁鐨刢lass鏂囦歡鐨勭洰褰?d:java_for_php"
java.home = "JAVA鐨凧AVAHOME"
java.library = "JAVA鐨凧AVAHOMEjrebinserverjvm.dll"
java.library.path = "PHP瀹夎鐩綍extensions"
淇敼濂藉悗錛宲hp.ini 鏂囦歡蹇呴』鏀懼湪Windows瀹夎鐩綍鍐咃紝閲嶆柊鍚姩Apache銆?/p>
鍦╠:java_for_php鍐呮柊寤轟竴涓狿hpCallJava.java 錛屽唴瀹瑰涓嬶細
public class PhpCallJava {
public String testString;
public String test (String str) {
if (str.equals("")) {
return "This is a empty string!";
} else {
return str;
}
}
public String GetTestString () {
return "Your string is: " + testString;
}
}
緙栬瘧PhpCallJava.java 鐢熸垚PhpCallJava.class
鏂板緩涓涓狿HP鏂囦歡錛屽唴瀹瑰涓嬶細
<?php
$myjava = new Java("PhpCallJava");
echo "Test Result are <b>".$myjava->test("Hello JAVA, I m PHP.")."</b><br>n";
$myjava->testString = "JAVA, I gave you a string.";
echo "You have set string is: <b>".$myjava->testString."</b><br>n";
echo "My java method reports:<b>".$myjava->GetTestString ()."</b><br>n";
?>
緇撴灉:
Test Result are Hello JAVA, I m PHP.
You have set string is: JAVA, I gave you a string.
My java method reports:Your string is: JAVA, I gave you a string.
鏈瘒鏂囩珷鏉ヨ嚜<A >IDC涓撳緗?lt;/a> 鍘熸枃閾炬帴錛?a >http://www.soidc.net/articles/1213781103032/20051018/1214037658733_1.html