├── navi ├── .gitignore └── src │ ├── test │ ├── java │ │ └── com │ │ │ └── baidu │ │ │ └── beidou │ │ │ └── navi │ │ │ ├── it │ │ │ ├── service │ │ │ │ ├── AuthService.java │ │ │ │ ├── ProxyService.java │ │ │ │ ├── impl │ │ │ │ │ ├── ProxyServiceImpl.java │ │ │ │ │ └── AuthServiceImpl.java │ │ │ │ ├── BookService.java │ │ │ │ └── CompanyService.java │ │ │ ├── TestAspectJProxyService.java │ │ │ ├── zoo │ │ │ │ ├── TestZooHtmlPage.java │ │ │ │ └── TestSimpleCompanyServiceWithZoo.java │ │ │ ├── exception │ │ │ │ └── IdDuplicateException.java │ │ │ ├── TestClient.java │ │ │ ├── TestProxyBookService.java │ │ │ ├── interceptor │ │ │ │ └── ProxyServiceInterceptor.java │ │ │ ├── TestHtmlPage.java │ │ │ ├── TestHACompanyService.java │ │ │ ├── TestSimpleCompanyService.java │ │ │ ├── TestHACompanyService2.java │ │ │ ├── TestJsonCompanyService.java │ │ │ ├── Config.java │ │ │ ├── TestProtobufCompanyService.java │ │ │ ├── TestSimpleNaviRpcClient.java │ │ │ ├── StandaloneServer.java │ │ │ ├── TestAuthService.java │ │ │ └── BaseTest.java │ │ │ ├── vo │ │ │ ├── BaseObject.java │ │ │ ├── BookBuilder.java │ │ │ ├── Book.java │ │ │ ├── Department.java │ │ │ ├── Book2.java │ │ │ └── Company.java │ │ │ ├── codec │ │ │ ├── JsonCodecTest.java │ │ │ ├── ProtobufCodecTest.java │ │ │ ├── ProtostuffCodecTest.java │ │ │ ├── ProtostuffCodecAddNewFieldTest.java │ │ │ └── BaseCodecTest.java │ │ │ └── util │ │ │ ├── ZkPathUtilTest.java │ │ │ └── ReflectionUtilTest.java │ └── resources │ │ ├── config.properties │ │ ├── log4j.properties │ │ ├── applicationContext-server.xml │ │ └── applicationContext.xml │ └── main │ ├── resources │ └── META-INF │ │ └── services │ │ └── com.baidu.beidou.navi.server.filter.Filter │ ├── online-resources │ └── META-INF │ │ └── services │ │ └── com.baidu.beidou.navi.server.filter.Filter │ └── java │ └── com │ └── baidu │ └── beidou │ └── navi │ ├── server │ ├── ServiceNameAware.java │ ├── callback │ │ └── Callback.java │ ├── locator │ │ ├── MethodResolver.java │ │ ├── ZooAware.java │ │ ├── PublishHandler.java │ │ ├── impl │ │ │ └── SimpleMethodResolver.java │ │ └── ServiceLocator.java │ ├── annotation │ │ ├── IgnoreNaviRpcMethod.java │ │ ├── NaviRpcAuth.java │ │ ├── NaviRpcService.java │ │ └── Authority.java │ ├── processor │ │ └── NaviRpcProcessor.java │ ├── filter │ │ ├── FilterCallback.java │ │ └── FilterBuilder.java │ ├── vo │ │ ├── NaviRpcResponse.java │ │ ├── NaviRpcRequest.java │ │ ├── AppIdToken.java │ │ ├── ResponseDTO.java │ │ └── RequestDTO.java │ └── NaviRpcExporter.java │ ├── constant │ ├── NaviStatus.java │ ├── HttpStatus.java │ └── NaviCommonConstant.java │ ├── client │ ├── attachment │ │ ├── AttachmentHandler.java │ │ └── Attachment.java │ ├── selector │ │ ├── NaviFailStrategy.java │ │ └── NaviSelectorStrategy.java │ ├── ha │ │ ├── FailStrategy.java │ │ ├── FailFastStrategy.java │ │ ├── LoadBalanceStrategy.java │ │ ├── FailOverStrategy.java │ │ └── LbFactory.java │ └── constant │ │ └── NaviRpcClientConstant.java │ ├── zk │ └── SimpleServerWatcher.java │ ├── codec │ ├── Codec.java │ ├── protobuf │ │ └── ProtobufUtils.java │ ├── protostuff │ │ └── ProtostuffUtils.java │ └── json │ │ └── JsonCodec.java │ ├── util │ ├── IdGenerator.java │ ├── ArrayUtil.java │ ├── Function.java │ ├── ByteUtil.java │ ├── AccessStringUtil.java │ ├── SystemPropertiesUtils.java │ ├── ZkRegisterInfoUtil.java │ ├── MethodUtil.java │ ├── IPUtils.java │ ├── ExtensionLocator.java │ ├── vo │ │ └── AccessLog.java │ └── MethodWrapper.java │ ├── exception │ ├── DataErrorException.java │ ├── rpc │ │ ├── CodecException.java │ │ ├── RpcTimeoutException.java │ │ ├── ServerErrorException.java │ │ ├── InvalidParamException.java │ │ ├── InvalidAccessException.java │ │ ├── MethodNotFoundException.java │ │ ├── HARpcException.java │ │ ├── RpcException.java │ │ ├── AuthAccessDeniedException.java │ │ ├── DeserilizeNullException.java │ │ └── ServiceAddressEmptyException.java │ ├── InvalidRequestException.java │ ├── InvalidProtocolException.java │ └── ServiceNotFoundException.java │ ├── protocol │ ├── ProtobufSerializeHandler.java │ ├── ProtostuffSerializeHandler.java │ ├── NaviProtocol.java │ ├── SerializeHandler.java │ └── SerializeHandlerFactory.java │ └── conf │ ├── RpcServerConf.java │ └── RpcClientConf.java ├── navi-mgr-console └── src │ └── main │ ├── webapp │ ├── monitor.jsp │ ├── dep │ │ ├── bootstrap │ │ │ ├── css │ │ │ │ ├── noie.css │ │ │ │ └── ie.css │ │ │ ├── img │ │ │ │ ├── glyphicons-halflings.png │ │ │ │ └── glyphicons-halflings-white.png │ │ │ └── fonts │ │ │ │ ├── glyphicons-halflings-regular.eot │ │ │ │ ├── glyphicons-halflings-regular.ttf │ │ │ │ └── glyphicons-halflings-regular.woff │ │ └── jquery-ui-1.10.4.custom │ │ │ ├── css │ │ │ └── ui-lightness │ │ │ │ └── images │ │ │ │ ├── animated-overlay.gif │ │ │ │ ├── ui-icons_222222_256x240.png │ │ │ │ ├── ui-icons_228ef1_256x240.png │ │ │ │ ├── ui-icons_ef8c08_256x240.png │ │ │ │ ├── ui-icons_ffd27a_256x240.png │ │ │ │ ├── ui-icons_ffffff_256x240.png │ │ │ │ ├── ui-bg_flat_10_000000_40x100.png │ │ │ │ ├── ui-bg_glass_65_ffffff_1x400.png │ │ │ │ ├── ui-bg_glass_100_f6f6f6_1x400.png │ │ │ │ ├── ui-bg_glass_100_fdf5ce_1x400.png │ │ │ │ ├── ui-bg_gloss-wave_35_f6a828_500x100.png │ │ │ │ ├── ui-bg_diagonals-thick_18_b81900_40x40.png │ │ │ │ ├── ui-bg_diagonals-thick_20_666666_40x40.png │ │ │ │ ├── ui-bg_highlight-soft_100_eeeeee_1x100.png │ │ │ │ └── ui-bg_highlight-soft_75_ffe45c_1x100.png │ │ │ └── datePicker.html │ ├── assets │ │ ├── js │ │ │ ├── index.js │ │ │ ├── footer.js │ │ │ ├── zkinfo.js │ │ │ ├── newapp.js │ │ │ ├── newconfigitem.js │ │ │ ├── login.js │ │ │ ├── common.js │ │ │ └── modifycommon.js │ │ ├── img │ │ │ ├── logo.png │ │ │ ├── bohemian.jpg │ │ │ ├── loading.gif │ │ │ ├── header-bg.png │ │ │ ├── index-big.jpg │ │ │ └── index-big.psd │ │ └── css │ │ │ └── img │ │ │ ├── diy │ │ │ ├── 2.png │ │ │ ├── 3.png │ │ │ ├── 4.png │ │ │ ├── 5.png │ │ │ ├── 6.png │ │ │ ├── 7.png │ │ │ ├── 8.png │ │ │ ├── 9.png │ │ │ ├── 1_close.png │ │ │ └── 1_open.png │ │ │ ├── loading.gif │ │ │ ├── line_conn.gif │ │ │ ├── zTreeStandard.gif │ │ │ └── zTreeStandard.png │ └── favicon.ico │ ├── resources │ ├── com │ │ └── baidu │ │ │ └── beidou │ │ │ └── navimgr │ │ │ └── common │ │ │ └── constant │ │ │ └── GlobalResponseStatusMsg.xml │ ├── log4j.properties │ ├── application.properties │ └── redis-config.properties │ ├── online-resources │ ├── log4j.properties │ ├── application.properties │ └── redis-config.properties │ └── java │ └── com │ └── baidu │ └── beidou │ └── navimgr │ ├── zoo │ ├── service │ │ ├── ZooService.java │ │ └── impl │ │ │ ├── OnlineZooServiceImpl.java │ │ │ └── OfflineZooServiceImpl.java │ ├── constant │ │ └── ZooConstant.java │ ├── DataErrorException.java │ └── ZkPathUtil.java │ ├── common │ ├── constant │ │ ├── WebResponseConstant.java │ │ ├── WebConstant.java │ │ └── GlobalResponseStatusMsg.java │ └── interceptor │ │ └── WebCommonInterceptor.java │ ├── auth │ ├── LoginValidator.java │ ├── vo │ │ ├── BaseObject.java │ │ └── User.java │ └── interceptor │ │ └── UserIdInterceptor.java │ └── util │ └── HttpUtils.java ├── .travis.yml ├── images ├── 3.jpeg ├── ut.png ├── .DS_Store ├── gmail.png ├── perf1.png ├── perf2.png ├── perf3.png ├── server1.png ├── server2.png ├── server3.png ├── server4.png ├── serverlog.png └── navi-zookeeper.jpg ├── .gitignore ├── navi-demo-client └── src │ ├── main │ ├── webapp │ │ ├── favicon.ico │ │ └── WEB-INF │ │ │ └── web.xml │ ├── java │ │ └── com │ │ │ └── baidu │ │ │ └── beidou │ │ │ └── sample │ │ │ ├── util │ │ │ └── codec │ │ │ │ ├── Codec.java │ │ │ │ ├── json │ │ │ │ └── JsonCodec.java │ │ │ │ ├── protobuf │ │ │ │ ├── ProtobufUtils.java │ │ │ │ └── ProtobufCodec.java │ │ │ │ └── protostuff │ │ │ │ ├── ProtostuffUtils.java │ │ │ │ └── ProtostuffCodec.java │ │ │ └── portal │ │ │ └── common │ │ │ └── constant │ │ │ └── WebResponseConstant.java │ └── resources │ │ ├── log4j.properties │ │ └── rpc-client.properties │ └── test │ ├── resources │ └── log4j.properties │ └── java │ └── com │ └── baidu │ └── beidou │ └── sample │ ├── api │ └── NaviRpcClientTest.java │ ├── simpletest │ ├── ResponseDTO.java │ └── RequestDTO.java │ └── xml │ └── BookMgrTest.java └── navi-demo-server └── src └── main ├── webapp └── favicon.ico ├── java └── com │ └── baidu │ └── beidou │ └── sample │ ├── annotation │ ├── vo │ │ ├── BaseObject.java │ │ ├── Department.java │ │ └── Company.java │ ├── service │ │ └── CompanyMgr.java │ └── exception │ │ └── IdDuplicateException.java │ ├── performancetest │ └── service │ │ ├── PerformanceTestService.java │ │ ├── impl │ │ └── PerformanceTestServiceImpl.java │ │ └── vo │ │ ├── Job.java │ │ └── BankAccount.java │ └── xml │ ├── service │ └── BookMgr.java │ ├── interceptor │ └── AccessLogInterceptor.java │ └── vo │ └── Book.java └── resources ├── log4j.properties └── rpc-server.properties /navi/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/monitor.jsp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | install: 4 | cd navi && mvn test -------------------------------------------------------------------------------- /images/3.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/images/3.jpeg -------------------------------------------------------------------------------- /images/ut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/images/ut.png -------------------------------------------------------------------------------- /images/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/images/.DS_Store -------------------------------------------------------------------------------- /images/gmail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/images/gmail.png -------------------------------------------------------------------------------- /images/perf1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/images/perf1.png -------------------------------------------------------------------------------- /images/perf2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/images/perf2.png -------------------------------------------------------------------------------- /images/perf3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/images/perf3.png -------------------------------------------------------------------------------- /images/server1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/images/server1.png -------------------------------------------------------------------------------- /images/server2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/images/server2.png -------------------------------------------------------------------------------- /images/server3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/images/server3.png -------------------------------------------------------------------------------- /images/server4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/images/server4.png -------------------------------------------------------------------------------- /images/serverlog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/images/serverlog.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/dep/bootstrap/css/noie.css: -------------------------------------------------------------------------------- 1 | .wmd-show { 2 | width: 628px; 3 | } -------------------------------------------------------------------------------- /images/navi-zookeeper.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/images/navi-zookeeper.jpg -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/js/index.js: -------------------------------------------------------------------------------- 1 | (function ($) { 2 | 3 | getSession2Redirect(); 4 | 5 | })(jQuery); -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /bin 3 | 4 | # Eclipse 5 | /.classpath 6 | /.project 7 | /.settings 8 | 9 | # Idea 10 | *.iml 11 | .idea -------------------------------------------------------------------------------- /navi-demo-client/src/main/webapp/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-demo-client/src/main/webapp/favicon.ico -------------------------------------------------------------------------------- /navi-demo-server/src/main/webapp/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-demo-server/src/main/webapp/favicon.ico -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/favicon.ico -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/assets/img/logo.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/img/bohemian.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/assets/img/bohemian.jpg -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/img/loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/assets/img/loading.gif -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/css/img/diy/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/assets/css/img/diy/2.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/css/img/diy/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/assets/css/img/diy/3.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/css/img/diy/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/assets/css/img/diy/4.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/css/img/diy/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/assets/css/img/diy/5.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/css/img/diy/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/assets/css/img/diy/6.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/css/img/diy/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/assets/css/img/diy/7.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/css/img/diy/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/assets/css/img/diy/8.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/css/img/diy/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/assets/css/img/diy/9.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/css/img/loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/assets/css/img/loading.gif -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/img/header-bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/assets/img/header-bg.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/img/index-big.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/assets/img/index-big.jpg -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/img/index-big.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/assets/img/index-big.psd -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/css/img/line_conn.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/assets/css/img/line_conn.gif -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/css/img/diy/1_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/assets/css/img/diy/1_close.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/css/img/diy/1_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/assets/css/img/diy/1_open.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/css/img/zTreeStandard.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/assets/css/img/zTreeStandard.gif -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/css/img/zTreeStandard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/assets/css/img/zTreeStandard.png -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/service/AuthService.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it.service; 2 | 3 | public interface AuthService { 4 | 5 | String sayHello(); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/dep/bootstrap/img/glyphicons-halflings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/dep/bootstrap/img/glyphicons-halflings.png -------------------------------------------------------------------------------- /navi/src/main/resources/META-INF/services/com.baidu.beidou.navi.server.filter.Filter: -------------------------------------------------------------------------------- 1 | com.baidu.beidou.navi.server.filter.impl.AccessLogFilter 2 | com.baidu.beidou.navi.server.filter.impl.SerializeFilter -------------------------------------------------------------------------------- /navi/src/main/online-resources/META-INF/services/com.baidu.beidou.navi.server.filter.Filter: -------------------------------------------------------------------------------- 1 | com.baidu.beidou.navi.server.filter.impl.AccessLogFilter 2 | com.baidu.beidou.navi.server.filter.impl.SerializeFilter -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/dep/bootstrap/img/glyphicons-halflings-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/dep/bootstrap/img/glyphicons-halflings-white.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/dep/bootstrap/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/dep/bootstrap/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/dep/bootstrap/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/dep/bootstrap/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/dep/bootstrap/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/dep/bootstrap/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /navi-mgr-console/src/main/resources/com/baidu/beidou/navimgr/common/constant/GlobalResponseStatusMsg.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/resources/com/baidu/beidou/navimgr/common/constant/GlobalResponseStatusMsg.xml -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/animated-overlay.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/animated-overlay.gif -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-icons_222222_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-icons_222222_256x240.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-icons_228ef1_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-icons_228ef1_256x240.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-icons_ef8c08_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-icons_ef8c08_256x240.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-icons_ffd27a_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-icons_ffd27a_256x240.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-icons_ffffff_256x240.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-icons_ffffff_256x240.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-bg_flat_10_000000_40x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-bg_flat_10_000000_40x100.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoremind/navi/HEAD/navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/css/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png -------------------------------------------------------------------------------- /navi/src/test/resources/config.properties: -------------------------------------------------------------------------------- 1 | server.port=8089 2 | 3 | zoo.server.port=8090 4 | zoo.zk_list=m1-ocean-1774.epc.baidu.com:8701,cp01-ocean-1551.epc.baidu.com:8701,cp01-ocean-1004.epc.baidu.com:8701,cp01-beidou-rd00.cp01:8701,cp01-beidou-rd01.cp01:8701 5 | zoo.zk_registry_namespace=/mytest/service -------------------------------------------------------------------------------- /navi-demo-client/src/main/java/com/baidu/beidou/sample/util/codec/Codec.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.sample.util.codec; 2 | 3 | public interface Codec { 4 | 5 | public T decode(Class clazz, byte[] bytes) throws Exception; 6 | 7 | public byte[] encode(Class clazz, T object) throws Exception; 8 | 9 | } 10 | -------------------------------------------------------------------------------- /navi-demo-server/src/main/java/com/baidu/beidou/sample/annotation/vo/BaseObject.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.sample.annotation.vo; 2 | 3 | public class BaseObject { 4 | 5 | private int id; 6 | 7 | public int getId() { 8 | return id; 9 | } 10 | 11 | public void setId(int id) { 12 | this.id = id; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/service/ProxyService.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it.service; 2 | 3 | /** 4 | * ClassName: ProxyService
5 | * Function: 测试利用spring框架做代理,例如cglib来拦截方法,navi-rpc是否work 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public interface ProxyService { 10 | 11 | String hellworld(String input); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/server/ServiceNameAware.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.server; 2 | 3 | /** 4 | * ClassName: ServiceNameAware
5 | * Function: 服务名称感应 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public interface ServiceNameAware { 10 | 11 | /** 12 | * 获取服务名称 13 | * 14 | * @return 名称 15 | */ 16 | String getName(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /navi/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=INFO, console 2 | 3 | # navi log 4 | log4j.logger.com.baidu.beidou.navi=DEBUG 5 | 6 | log4j.appender.console=org.apache.log4j.ConsoleAppender 7 | log4j.appender.console.encoding=gbk 8 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 9 | log4j.appender.console.layout.ConversionPattern=[%p]\t%d\t[%t]\t%c{3}\t(%F:%L)\t-%m%n 10 | -------------------------------------------------------------------------------- /navi-demo-client/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=TRACE, console 2 | 3 | # navi log 4 | log4j.logger.com.baidu.beidou.navi=DEBUG 5 | 6 | log4j.appender.console=org.apache.log4j.ConsoleAppender 7 | log4j.appender.console.encoding=gbk 8 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 9 | log4j.appender.console.layout.ConversionPattern=[%p]\t%d\t[%t]\t%c{3}\t(%F:%L)\t-%m%n 10 | -------------------------------------------------------------------------------- /navi-demo-client/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=TRACE, console 2 | 3 | # navi log 4 | log4j.logger.com.baidu.beidou.navi=DEBUG 5 | 6 | log4j.appender.console=org.apache.log4j.ConsoleAppender 7 | log4j.appender.console.encoding=gbk 8 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 9 | log4j.appender.console.layout.ConversionPattern=[%p]\t%d\t[%t]\t%c{3}\t(%F:%L)\t-%m%n 10 | -------------------------------------------------------------------------------- /navi-demo-server/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=INFO, console 2 | 3 | # navi log 4 | log4j.logger.com.baidu.beidou.navi=INFO 5 | 6 | log4j.appender.console=org.apache.log4j.ConsoleAppender 7 | log4j.appender.console.encoding=gbk 8 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 9 | log4j.appender.console.layout.ConversionPattern=[%p]\t%d\t[%t]\t%c{3}\t(%F:%L)\t-%m%n 10 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/server/callback/Callback.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.server.callback; 2 | 3 | /** 4 | * ClassName: Callback
5 | * Function: 在服务端的调用链中扮演响应holder角色的回调 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public interface Callback { 10 | 11 | /** 12 | * 处理返回报文 13 | * 14 | * @param result 15 | */ 16 | void handleResult(T result); 17 | 18 | } -------------------------------------------------------------------------------- /navi-mgr-console/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=INFO, console 2 | 3 | # My logging configuration... 4 | log4j.logger.com.baidu=INFO 5 | 6 | ## Console output 7 | log4j.appender.console=org.apache.log4j.ConsoleAppender 8 | log4j.appender.console.encoding=gbk 9 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.console.layout.ConversionPattern=[%p]\t%d\t[%t]\t%c{3}\t(%F:%L)\t-%m%n 11 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/online-resources/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=INFO, console 2 | 3 | # My logging configuration... 4 | log4j.logger.com.baidu=INFO 5 | 6 | ## Console output 7 | log4j.appender.console=org.apache.log4j.ConsoleAppender 8 | log4j.appender.console.encoding=gbk 9 | log4j.appender.console.layout=org.apache.log4j.PatternLayout 10 | log4j.appender.console.layout.ConversionPattern=[%p]\t%d\t[%t]\t%c{3}\t(%F:%L)\t-%m%n 11 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/vo/BaseObject.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.vo; 2 | 3 | /** 4 | * ClassName: BaseObject
5 | * Function: 测试用继承的基类,模拟主键id 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public class BaseObject { 10 | 11 | private int id; 12 | 13 | public int getId() { 14 | return id; 15 | } 16 | 17 | public void setId(int id) { 18 | this.id = id; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /navi-demo-server/src/main/java/com/baidu/beidou/sample/performancetest/service/PerformanceTestService.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.sample.performancetest.service; 2 | 3 | import java.util.Map; 4 | 5 | import com.baidu.beidou.sample.performancetest.service.vo.Person; 6 | 7 | public interface PerformanceTestService { 8 | 9 | public String receiveAndReturn(String input); 10 | 11 | public Map getPerson(Map personMap); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/js/footer.js: -------------------------------------------------------------------------------- 1 | (function($) { 2 | 3 | // 登出 4 | $("#signout").on("click", function() { 5 | $.ajax({ 6 | type: "GET", 7 | url: "/userLogout", 8 | dataType: "json" 9 | }).done(function(result) { 10 | if (result.status == 0) { 11 | VISITOR = {}; 12 | getSession(); 13 | } 14 | }); 15 | }); 16 | 17 | })(jQuery); -------------------------------------------------------------------------------- /navi-mgr-console/src/main/java/com/baidu/beidou/navimgr/zoo/service/ZooService.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navimgr.zoo.service; 2 | 3 | import com.baidu.beidou.navimgr.zoo.ZooNode; 4 | 5 | /** 6 | * ClassName: ZooService
7 | * Function: zookeeper服务 8 | * 9 | * @author Zhang Xu 10 | */ 11 | public interface ZooService { 12 | 13 | /** 14 | * 递归地获取一颗节点树 15 | * 16 | * @return 节点树root节点 17 | */ 18 | ZooNode getNodeRecrusively(); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/codec/JsonCodecTest.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.codec; 2 | 3 | import org.junit.Test; 4 | 5 | import com.baidu.beidou.navi.codec.json.JsonCodec; 6 | 7 | public class JsonCodecTest extends BaseCodecTest { 8 | 9 | @Test 10 | public void testCodec() throws Exception { 11 | encodeAndDecode(); 12 | } 13 | 14 | @Override 15 | public void initCodec() { 16 | codec = new JsonCodec(); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/codec/ProtobufCodecTest.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.codec; 2 | 3 | import org.junit.Test; 4 | 5 | import com.baidu.beidou.navi.codec.protobuf.ProtobufCodec; 6 | 7 | public class ProtobufCodecTest extends BaseCodecTest { 8 | 9 | @Test 10 | public void testCodec() throws Exception { 11 | encodeAndDecode(); 12 | } 13 | 14 | @Override 15 | public void initCodec() { 16 | codec = new ProtobufCodec(); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/codec/ProtostuffCodecTest.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.codec; 2 | 3 | import org.junit.Test; 4 | 5 | import com.baidu.beidou.navi.codec.protostuff.ProtostuffCodec; 6 | 7 | public class ProtostuffCodecTest extends BaseCodecTest { 8 | 9 | @Test 10 | public void testCodec() throws Exception { 11 | encodeAndDecode(); 12 | } 13 | 14 | @Override 15 | public void initCodec() { 16 | codec = new ProtostuffCodec(); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/server/locator/MethodResolver.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.server.locator; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | /** 6 | * ClassName: MethodResolver
7 | * Function: 判断方法是否为可暴露服务的接口 8 | * 9 | * @author Zhang Xu 10 | */ 11 | public interface MethodResolver { 12 | 13 | /** 14 | * 方法是否可以暴露为服务 15 | * 16 | * @param m 17 | * 方法 18 | * @return 是否可以暴露为服务,true为可以,false为不行 19 | */ 20 | boolean isSupport(Method m); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/server/locator/ZooAware.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.server.locator; 2 | 3 | import com.baidu.beidou.navi.zk.SimpleZooKeeperClient; 4 | 5 | /** 6 | * ClassName: ZooAware
7 | * Function: Zookeeper感应上下文,实现该接口的类需要对外公布zookeeper客户端{@link SimpleZooKeeperClient}引用 8 | * 9 | * @author Zhang Xu 10 | */ 11 | public interface ZooAware { 12 | 13 | /** 14 | * 返回zookeeper client 15 | * 16 | * @return zookeeper客户端引用 17 | */ 18 | SimpleZooKeeperClient getZkClient(); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/server/annotation/IgnoreNaviRpcMethod.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.server.annotation; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.RetentionPolicy; 5 | import java.lang.annotation.Target; 6 | 7 | /** 8 | * ClassName: IgnoreNaviRpcMethod
9 | * Function: Navi服务细粒度到方法级别,不暴露指定的方法出来的注解 10 | * 11 | * @author Zhang Xu 12 | */ 13 | @Target({ java.lang.annotation.ElementType.TYPE }) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface IgnoreNaviRpcMethod { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/server/locator/PublishHandler.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.server.locator; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * ClassName: PublishHandler
7 | * Function: 发布服务handler,配合{@link ServiceLocator}来对加载定位到的所有服务进行发布工作 8 | * 9 | * @author Zhang Xu 10 | */ 11 | public interface PublishHandler { 12 | 13 | /** 14 | * 发布服务 15 | * 16 | * @param descs 17 | * 所有的服务描述 18 | * @return 发布成功与否 19 | */ 20 | boolean publish(Collection> descs); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/constant/NaviStatus.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.constant; 2 | 3 | /** 4 | * ClassName: NaviStatus
5 | * Function: Navi内部的返回码定义 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public class NaviStatus { 10 | 11 | /** 12 | * 成功。 13 | */ 14 | public static int RPC_OK = 0; 15 | 16 | /** 17 | * 失败。通常是框架造成的,例如序列化失败等 18 | */ 19 | public static int RPC_FAIL = 1; 20 | 21 | /** 22 | * 系统内部错误。通常是业务逻辑造成的,不属于框架问题 23 | */ 24 | public static int SYS_ERROR = 2; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/js/zkinfo.js: -------------------------------------------------------------------------------- 1 | (function ($) { 2 | 3 | getSession(); 4 | 5 | fetchConfigUsage(); 6 | 7 | // 8 | // 渲染主列表 9 | // 10 | function fetchConfigUsage() { 11 | 12 | url = "/api/usage/list"; 13 | 14 | $.ajax({ 15 | type: "GET", 16 | url: url 17 | }).done(function (data) { 18 | if (data.success === "true") { 19 | var html = data.result.hostInfo; 20 | $("#hostInfo").html(html); 21 | } 22 | }); 23 | 24 | } 25 | 26 | })(jQuery); 27 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/vo/BookBuilder.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.vo; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class BookBuilder { 7 | 8 | public static List buildMulti() { 9 | List ret = new ArrayList(); 10 | 11 | Book book1 = new Book(1, "天方夜谭"); 12 | Book book2 = new Book(999, "读者文摘"); 13 | Book book3 = new Book(12345, "第一财经周刊"); 14 | 15 | ret.add(book1); 16 | ret.add(book2); 17 | ret.add(book3); 18 | 19 | return ret; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | #zookeeper 2 | zoo.offline.server_list=m1-ocean-1774.epc.baidu.com:8701,cp01-ocean-1551.epc.baidu.com:8701,cp01-ocean-1004.epc.baidu.com:8701,cp01-beidou-rd00.cp01:8701,cp01-beidou-rd01.cp01:8701 3 | zoo.offline.digest_auth=beidouRd123 4 | zoo.online.server_list=10.92.148.53:8701,10.92.148.54:8701,10.52.87.19:8701,10.23.240.168:8701,10.23.249.94:8701 5 | zoo.online.digest_auth=beidouRd123 6 | 7 | zoo.session_timeout=90000 8 | zoo.conn_timeout=60000 9 | zoo.node_path_prefix=/navi_rpc 10 | 11 | #特别注意:仅用于开发,测试环境设置为false, 便于访问排查问题 12 | ENABLE_AUTH=true -------------------------------------------------------------------------------- /navi-demo-client/src/main/java/com/baidu/beidou/sample/util/codec/json/JsonCodec.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.sample.util.codec.json; 2 | 3 | import com.baidu.beidou.navi.codec.Codec; 4 | 5 | public class JsonCodec implements Codec { 6 | 7 | private JsonMapper mapper = JsonMapper.buildNormalMapper(); 8 | 9 | public T decode(Class clazz, byte[] bytes) throws Exception { 10 | return mapper.fromJsonBytes(bytes, clazz); 11 | } 12 | 13 | public byte[] encode(Class clazz, T object) throws Exception { 14 | return mapper.toJsonBytes(object); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/online-resources/application.properties: -------------------------------------------------------------------------------- 1 | #zookeeper 2 | zoo.offline.server_list=m1-ocean-1774.epc.baidu.com:8701,cp01-ocean-1551.epc.baidu.com:8701,cp01-ocean-1004.epc.baidu.com:8701,cp01-beidou-rd00.cp01:8701,cp01-beidou-rd01.cp01:8701 3 | zoo.offline.digest_auth=beidouRd123 4 | zoo.online.server_list=10.92.148.53:8701,10.92.148.54:8701,10.52.87.19:8701,10.23.240.168:8701,10.23.249.94:8701 5 | zoo.online.digest_auth=beidouRd123 6 | 7 | zoo.session_timeout=90000 8 | zoo.conn_timeout=60000 9 | zoo.node_path_prefix=/navi_rpc 10 | 11 | #特别注意:仅用于开发,测试环境设置为false, 便于访问排查问题 12 | ENABLE_AUTH=true -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/client/attachment/AttachmentHandler.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.client.attachment; 2 | 3 | import com.baidu.beidou.navi.server.vo.RequestDTO; 4 | 5 | /** 6 | * ClassName: AttachmentHandler
7 | * Function: 附加属性对于{@link RequestDTO}的装饰 8 | * 9 | * @author Zhang Xu 10 | */ 11 | public interface AttachmentHandler { 12 | 13 | /** 14 | * 处理附加信息 15 | * 16 | * @param requestDTO 17 | * 请求DTO 18 | * @param attachment 19 | * 附加信息 20 | */ 21 | void handle(RequestDTO requestDTO, Attachment attachment); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/zk/SimpleServerWatcher.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.zk; 2 | 3 | import org.apache.zookeeper.WatchedEvent; 4 | import org.apache.zookeeper.Watcher; 5 | 6 | /** 7 | * ClassName: SimpleServerWatcher
8 | * 9 | * @author Zhang Xu 10 | */ 11 | public class SimpleServerWatcher implements Watcher { 12 | 13 | /** 14 | * @see org.apache.zookeeper.Watcher#process(org.apache.zookeeper.WatchedEvent) 15 | */ 16 | @Override 17 | public void process(WatchedEvent arg0) { 18 | // System.out.println("TestWatcher - " + arg0.getPath()); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/TestAspectJProxyService.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it; 2 | 3 | import static org.hamcrest.Matchers.is; 4 | import static org.junit.Assert.assertThat; 5 | 6 | import javax.annotation.Resource; 7 | 8 | import org.junit.Test; 9 | 10 | import com.baidu.beidou.navi.it.service.ProxyService; 11 | 12 | public class TestAspectJProxyService extends BaseTest { 13 | 14 | @Resource 15 | private ProxyService proxyServiceDirectCall; 16 | 17 | @Test 18 | public void testGet() { 19 | String back = proxyServiceDirectCall.hellworld("123"); 20 | assertThat(back, is("123")); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/server/annotation/NaviRpcAuth.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.server.annotation; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.RetentionPolicy; 5 | import java.lang.annotation.Target; 6 | 7 | /** 8 | * ClassName: NaviRpcAuth
9 | * Function: Navi服务权限控制 10 | * 11 | * @author Zhang Xu 12 | */ 13 | @Target({ java.lang.annotation.ElementType.TYPE }) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface NaviRpcAuth { 16 | 17 | /** 18 | * Authority配置 19 | * 20 | * @return 多个Authority 21 | */ 22 | Authority[] value(); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/client/attachment/Attachment.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.client.attachment; 2 | 3 | import com.baidu.beidou.navi.server.vo.AppIdToken; 4 | 5 | /** 6 | * ClassName: Attachment
7 | * Function: 附加信息 8 | * 9 | * @author Zhang Xu 10 | */ 11 | public class Attachment { 12 | 13 | /** 14 | * 客户端调用的appId和token 15 | */ 16 | private AppIdToken appIdToken; 17 | 18 | public AppIdToken getAppIdToken() { 19 | return appIdToken; 20 | } 21 | 22 | public Attachment setAppIdToken(AppIdToken appIdToken) { 23 | this.appIdToken = appIdToken; 24 | return this; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/zoo/TestZooHtmlPage.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it.zoo; 2 | 3 | import static org.hamcrest.Matchers.is; 4 | import static org.junit.Assert.assertThat; 5 | 6 | import org.junit.Ignore; 7 | import org.junit.Test; 8 | 9 | import com.baidu.beidou.navi.it.Config; 10 | 11 | @Ignore 12 | public class TestZooHtmlPage extends BaseZooTest { 13 | 14 | @Test 15 | public void testZooHtml() throws Throwable { 16 | String content = getContent(("http://127.0.0.1:" + Config.ZOO_SERVER_PORT + "/service_api/zookeeper")); 17 | assertThat(content.contains(Config.ZOO_REGISTRY_NAMESPACE), is(true)); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/client/selector/NaviFailStrategy.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.client.selector; 2 | 3 | /** 4 | * ClassName: NaviFailStrategy
5 | * Function: 错误信息枚举 6 | * 7 | * @author zhangxu04 8 | */ 9 | public enum NaviFailStrategy { 10 | 11 | /** 12 | * 失败重试 13 | */ 14 | FAILOVER(1), 15 | 16 | /** 17 | * 失败直接退出 18 | */ 19 | FAILFAST(2); 20 | 21 | private int strategy; 22 | 23 | private NaviFailStrategy(int strategy) { 24 | this.strategy = strategy; 25 | } 26 | 27 | public int getStrategy() { 28 | return strategy; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/server/annotation/NaviRpcService.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.server.annotation; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.RetentionPolicy; 5 | import java.lang.annotation.Target; 6 | 7 | /** 8 | * ClassName: NaviRpcService
9 | * Function: Navi服务暴露的注解 10 | * 11 | * @author Zhang Xu 12 | */ 13 | @Target({ java.lang.annotation.ElementType.TYPE }) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface NaviRpcService { 16 | 17 | /** 18 | * 实现的接口 19 | * 20 | * @return 21 | */ 22 | public abstract Class serviceInterface(); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/client/ha/FailStrategy.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.client.ha; 2 | 3 | /** 4 | * ClassName: FailStrategy
5 | * Function: 失败处理策略 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public interface FailStrategy { 10 | 11 | /** 12 | * 失败后是否立即退出 13 | * 14 | * @param currentRetryTime 15 | * 当前已经重试的次数,从0开始 16 | * @param clientSize 17 | * 客户端IP:PORT的可用数量 18 | * @return 是否立即退出 19 | */ 20 | boolean isQuitImmediately(int currentRetryTime, int clientSize); 21 | 22 | /** 23 | * 获取最大的重试次数 24 | * 25 | * @return 最大的重试次数 26 | */ 27 | int getMaxRetryTimes(); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/service/impl/ProxyServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it.service.impl; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | import com.baidu.beidou.navi.it.service.ProxyService; 6 | import com.baidu.beidou.navi.server.annotation.NaviRpcService; 7 | 8 | /** 9 | * ClassName: ProxyServiceImpl
10 | * Function: 测试利用spring框架做代理,例如cglib来拦截方法,navi-rpc是否work 11 | * 12 | * @author Zhang Xu 13 | */ 14 | @Service 15 | @NaviRpcService(serviceInterface = ProxyService.class) 16 | public class ProxyServiceImpl implements ProxyService { 17 | 18 | @Override 19 | public String hellworld(String input) { 20 | return input; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /navi-demo-client/src/main/java/com/baidu/beidou/sample/util/codec/protobuf/ProtobufUtils.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.sample.util.codec.protobuf; 2 | 3 | import java.io.IOException; 4 | 5 | import com.dyuproject.protostuff.LinkedBuffer; 6 | import com.dyuproject.protostuff.ProtobufIOUtil; 7 | import com.dyuproject.protostuff.Schema; 8 | 9 | public class ProtobufUtils { 10 | 11 | public static byte[] toByteArray(T message, Schema schema, LinkedBuffer buffer) { 12 | return ProtobufIOUtil.toByteArray(message, schema, buffer); 13 | } 14 | 15 | public static void mergeFrom(byte[] in, T message, Schema schema) throws IOException { 16 | ProtobufIOUtil.mergeFrom(in, message, schema); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/resources/redis-config.properties: -------------------------------------------------------------------------------- 1 | redis.group1.retry.times=1 2 | 3 | redis.group1.evictor.delayCheckSeconds=300 4 | # Disable evitor checking by set this to 0 since BDRP does not support PING-PONG command. 5 | redis.group1.evictor.checkPeriodSeconds=0 6 | redis.group1.evictor.failedTimesToBeTickOut=6 7 | 8 | redis.group1.client1.name=BeidouRedis1 9 | redis.group1.client1.host=10.48.52.31 10 | redis.group1.client1.port=16379 11 | redis.group1.client1.timeout=10000 12 | redis.group1.client1.password=beidouRd 13 | 14 | redis.group1.client2.name=BeidouRedis2 15 | redis.group1.client2.host=10.48.52.31 16 | redis.group1.client2.port=16380 17 | redis.group1.client2.timeout=10000 18 | redis.group1.client2.password=beidouRd 19 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/java/com/baidu/beidou/navimgr/common/constant/WebResponseConstant.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navimgr.common.constant; 2 | 3 | /** 4 | * ClassName: WebResponseConstant
5 | * Function: WEB用返回结果的常量 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public class WebResponseConstant { 10 | 11 | /** 12 | * 全局 13 | */ 14 | public static final String MESSAGE_GLOBAL = "global"; 15 | 16 | /** 17 | * 属性 18 | */ 19 | public static final String MESSAGE_FIELD = "field"; 20 | 21 | /** 22 | * 消息 23 | */ 24 | public static final String MESSAGE_MSG = "msg"; 25 | 26 | /** 27 | * 前端缓存标志 28 | */ 29 | public static final String MESSAGE_CACHE = "cache"; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/codec/Codec.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.codec; 2 | 3 | /** 4 | * ClassName: Codec
5 | * Function: 编码接口,用作报文序列化以及反序列化 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public interface Codec { 10 | 11 | /** 12 | * 编码序列化 13 | * 14 | * @param clazz 15 | * @param bytes 16 | * @return 17 | * @throws Exception 18 | */ 19 | T decode(Class clazz, byte[] bytes) throws Exception; 20 | 21 | /** 22 | * 解码反序列化 23 | * 24 | * @param clazz 25 | * @param object 26 | * @return 27 | * @throws Exception 28 | */ 29 | byte[] encode(Class clazz, T object) throws Exception; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /navi-demo-client/src/main/java/com/baidu/beidou/sample/util/codec/protostuff/ProtostuffUtils.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.sample.util.codec.protostuff; 2 | 3 | import java.io.IOException; 4 | 5 | import com.dyuproject.protostuff.LinkedBuffer; 6 | import com.dyuproject.protostuff.ProtostuffIOUtil; 7 | import com.dyuproject.protostuff.Schema; 8 | 9 | public class ProtostuffUtils { 10 | 11 | public static byte[] toByteArray(T message, Schema schema, LinkedBuffer buffer) { 12 | return ProtostuffIOUtil.toByteArray(message, schema, buffer); 13 | } 14 | 15 | public static void mergeFrom(byte[] in, T message, Schema schema) throws IOException { 16 | ProtostuffIOUtil.mergeFrom(in, message, schema); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /navi-demo-server/src/main/java/com/baidu/beidou/sample/annotation/service/CompanyMgr.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.sample.annotation.service; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import com.baidu.beidou.sample.annotation.vo.Company; 7 | 8 | public interface CompanyMgr { 9 | 10 | /** 11 | * query 12 | */ 13 | Company get(int id); 14 | 15 | List getByIds(List ids); 16 | 17 | Map getMapByIds(List ids); 18 | 19 | List getAll(); 20 | 21 | /** 22 | * add 23 | */ 24 | Company add(Company company); 25 | 26 | /** 27 | * delete 28 | */ 29 | void delete(int id); 30 | 31 | /** 32 | * update 33 | */ 34 | void update(Company company); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/online-resources/redis-config.properties: -------------------------------------------------------------------------------- 1 | redis.group1.retry.times=1 2 | 3 | redis.group1.evictor.delayCheckSeconds=300 4 | # Disable evitor checking by set this to 0 since BDRP does not support PING-PONG command. 5 | redis.group1.evictor.checkPeriodSeconds=0 6 | redis.group1.evictor.failedTimesToBeTickOut=6 7 | 8 | redis.group1.client1.name=BeidouRedis1 9 | redis.group1.client1.host=10.48.52.31 10 | redis.group1.client1.port=16379 11 | redis.group1.client1.timeout=10000 12 | redis.group1.client1.password=beidouRd 13 | 14 | redis.group1.client2.name=BeidouRedis2 15 | redis.group1.client2.host=10.48.52.31 16 | redis.group1.client2.port=16380 17 | redis.group1.client2.timeout=10000 18 | redis.group1.client2.password=beidouRd 19 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/util/IdGenerator.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.util; 2 | 3 | import java.util.UUID; 4 | 5 | /** 6 | * ClassName: IdGenerator
7 | * Function: id生成器 8 | * 9 | * @author Zhang Xu 10 | */ 11 | public class IdGenerator { 12 | 13 | /** 14 | * 生成一个Unique ID, 默认使用JDK自带的UUID 15 | *

16 | * 也可以使用: 17 | * 18 | *

19 |      * return UUIDGenerator.getInstance().generateTimeBasedUUID().toString();
20 |      * return Math.abs(new Random(System.currentTimeMillis()).nextInt());
21 |      * 
22 | * 23 | * @return 24 | */ 25 | public static int genUUID() { 26 | return Math.abs(UUID.randomUUID().toString().hashCode()); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/exception/DataErrorException.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.exception; 2 | 3 | /** 4 | * Zookeeper client data exception 5 | * 6 | * @author Zhang Xu 7 | */ 8 | public class DataErrorException extends RuntimeException { 9 | 10 | private static final long serialVersionUID = 3222573813262320183L; 11 | 12 | public DataErrorException() { 13 | } 14 | 15 | public DataErrorException(String message, Throwable cause) { 16 | super(message, cause); 17 | } 18 | 19 | public DataErrorException(String message) { 20 | super(message); 21 | } 22 | 23 | public DataErrorException(Throwable cause) { 24 | super(cause); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/exception/rpc/CodecException.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.exception.rpc; 2 | 3 | /** 4 | * ClassName: CodecException
5 | * Function: 编解码异常 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public class CodecException extends RpcException { 10 | 11 | private static final long serialVersionUID = -6280386297535195039L; 12 | 13 | public CodecException() { 14 | super(); 15 | } 16 | 17 | public CodecException(String message, Throwable cause) { 18 | super(message, cause); 19 | } 20 | 21 | public CodecException(String message) { 22 | super(message); 23 | } 24 | 25 | public CodecException(Throwable cause) { 26 | super(cause); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/client/ha/FailFastStrategy.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.client.ha; 2 | 3 | /** 4 | * ClassName: FailFastStrategy
5 | * Function: 失败立即退出策略 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public class FailFastStrategy implements FailStrategy { 10 | 11 | /** 12 | * @see com.baidu.beidou.navi.client.ha.FailStrategy#isQuitImmediately(int, int) 13 | */ 14 | @Override 15 | public boolean isQuitImmediately(int currentRetryTime, int clientSize) { 16 | return true; 17 | } 18 | 19 | /** 20 | * @see com.baidu.beidou.navi.client.ha.FailStrategy#getMaxRetryTimes() 21 | */ 22 | @Override 23 | public int getMaxRetryTimes() { 24 | return 1; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/exception/rpc/RpcTimeoutException.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.exception.rpc; 2 | 3 | /** 4 | * ClassName: RpcTimeoutException
5 | * 6 | * @author Zhang Xu 7 | */ 8 | public class RpcTimeoutException extends RpcException { 9 | 10 | private static final long serialVersionUID = 9029113876648829300L; 11 | 12 | public RpcTimeoutException() { 13 | } 14 | 15 | public RpcTimeoutException(String message) { 16 | super(message); 17 | } 18 | 19 | public RpcTimeoutException(Throwable cause) { 20 | super(cause); 21 | } 22 | 23 | public RpcTimeoutException(String message, Throwable cause) { 24 | super(message, cause); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/client/selector/NaviSelectorStrategy.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.client.selector; 2 | 3 | /** 4 | * ClassName: NaviSelectorStrategy
5 | * Function: 负载均衡策略枚举 6 | * 7 | * @author zhangxu04 8 | */ 9 | public enum NaviSelectorStrategy { 10 | 11 | /** 12 | * 随机 13 | */ 14 | RANDOM(1), 15 | 16 | /** 17 | * 轮训 18 | */ 19 | ROUNDROBIN(2), 20 | 21 | /** 22 | * 自然定义顺序 23 | */ 24 | NATURALORDER(3); 25 | 26 | private int strategy; 27 | 28 | private NaviSelectorStrategy(int strategy) { 29 | this.strategy = strategy; 30 | } 31 | 32 | public int getStrategy() { 33 | return strategy; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/exception/rpc/ServerErrorException.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.exception.rpc; 2 | 3 | /** 4 | * ClassName: ServerErrorException
5 | * 6 | * @author Zhang Xu 7 | */ 8 | public class ServerErrorException extends RpcException { 9 | 10 | private static final long serialVersionUID = 9029113876648829300L; 11 | 12 | public ServerErrorException() { 13 | } 14 | 15 | public ServerErrorException(String message) { 16 | super(message); 17 | } 18 | 19 | public ServerErrorException(Throwable cause) { 20 | super(cause); 21 | } 22 | 23 | public ServerErrorException(String message, Throwable cause) { 24 | super(message, cause); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/exception/rpc/InvalidParamException.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.exception.rpc; 2 | 3 | /** 4 | * ClassName: InvalidParamException
5 | * 6 | * @author Zhang Xu 7 | */ 8 | public class InvalidParamException extends RpcException { 9 | 10 | private static final long serialVersionUID = -2871706631475075323L; 11 | 12 | public InvalidParamException() { 13 | super(); 14 | } 15 | 16 | public InvalidParamException(String message, Throwable cause) { 17 | super(message, cause); 18 | } 19 | 20 | public InvalidParamException(String message) { 21 | super(message); 22 | } 23 | 24 | public InvalidParamException(Throwable cause) { 25 | super(cause); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/server/processor/NaviRpcProcessor.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.server.processor; 2 | 3 | import com.baidu.beidou.navi.server.callback.Callback; 4 | import com.baidu.beidou.navi.server.vo.NaviRpcRequest; 5 | import com.baidu.beidou.navi.server.vo.NaviRpcResponse; 6 | 7 | /** 8 | * ClassName: NaviRpcProcessor
9 | * Function: Navi Rpc处理单元接口 10 | * 11 | * @author Zhang Xu 12 | */ 13 | public interface NaviRpcProcessor { 14 | 15 | /** 16 | * 处理请求并且响应结果 17 | * 18 | * @param request 19 | * 请求 20 | * @param callback 21 | * 结果Callback 22 | */ 23 | public void service(NaviRpcRequest request, Callback callback); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /navi-demo-server/src/main/java/com/baidu/beidou/sample/xml/service/BookMgr.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.sample.xml.service; 2 | 3 | import java.util.List; 4 | 5 | import com.baidu.beidou.sample.xml.vo.Book; 6 | 7 | public interface BookMgr { 8 | 9 | /** 10 | * query 11 | */ 12 | Book get(int id); 13 | 14 | /** 15 | * query 16 | */ 17 | Book get(String name); 18 | 19 | /** 20 | * query 21 | */ 22 | Book get(int id, String name); 23 | 24 | /** 25 | * get all 26 | * 27 | */ 28 | List getAll(); 29 | 30 | /** 31 | * add 32 | */ 33 | Book add(Book book); 34 | 35 | /** 36 | * delete 37 | */ 38 | void delete(int id); 39 | 40 | /** 41 | * update 42 | */ 43 | void update(Book book); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/exception/rpc/InvalidAccessException.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.exception.rpc; 2 | 3 | /** 4 | * ClassName: InvalidAccessException
5 | * 6 | * @author Zhang Xu 7 | */ 8 | public class InvalidAccessException extends RpcException { 9 | 10 | private static final long serialVersionUID = -2871706631475075323L; 11 | 12 | public InvalidAccessException() { 13 | super(); 14 | } 15 | 16 | public InvalidAccessException(String message, Throwable cause) { 17 | super(message, cause); 18 | } 19 | 20 | public InvalidAccessException(String message) { 21 | super(message); 22 | } 23 | 24 | public InvalidAccessException(Throwable cause) { 25 | super(cause); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/exception/InvalidRequestException.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.exception; 2 | 3 | /** 4 | * ClassName: InvalidRequestException
5 | * 6 | * @author Zhang Xu 7 | */ 8 | public class InvalidRequestException extends RuntimeException { 9 | 10 | private static final long serialVersionUID = -6138595796119511714L; 11 | 12 | public InvalidRequestException() { 13 | } 14 | 15 | public InvalidRequestException(String message, Throwable cause) { 16 | super(message, cause); 17 | } 18 | 19 | public InvalidRequestException(String message) { 20 | super(message); 21 | } 22 | 23 | public InvalidRequestException(Throwable cause) { 24 | super(cause); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/exception/rpc/MethodNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.exception.rpc; 2 | 3 | /** 4 | * ClassName: MethodNotFoundException
5 | * 6 | * @author Zhang Xu 7 | */ 8 | public class MethodNotFoundException extends RpcException { 9 | 10 | private static final long serialVersionUID = -1760095868220273812L; 11 | 12 | public MethodNotFoundException() { 13 | super(); 14 | } 15 | 16 | public MethodNotFoundException(String message, Throwable cause) { 17 | super(message, cause); 18 | } 19 | 20 | public MethodNotFoundException(String message) { 21 | super(message); 22 | } 23 | 24 | public MethodNotFoundException(Throwable cause) { 25 | super(cause); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/exception/InvalidProtocolException.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.exception; 2 | 3 | /** 4 | * ClassName: InvalidProtocolException
5 | * 6 | * @author Zhang Xu 7 | */ 8 | public class InvalidProtocolException extends RuntimeException { 9 | 10 | private static final long serialVersionUID = -6138595796119511714L; 11 | 12 | public InvalidProtocolException() { 13 | } 14 | 15 | public InvalidProtocolException(String message, Throwable cause) { 16 | super(message, cause); 17 | } 18 | 19 | public InvalidProtocolException(String message) { 20 | super(message); 21 | } 22 | 23 | public InvalidProtocolException(Throwable cause) { 24 | super(cause); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/exception/ServiceNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.exception; 2 | 3 | /** 4 | * ClassName: ServiceNotFoundException
5 | * 6 | * @author Zhang Xu 7 | */ 8 | public class ServiceNotFoundException extends RuntimeException { 9 | 10 | private static final long serialVersionUID = -6138595796119511714L; 11 | 12 | public ServiceNotFoundException() { 13 | } 14 | 15 | public ServiceNotFoundException(String message, Throwable cause) { 16 | super(message, cause); 17 | } 18 | 19 | public ServiceNotFoundException(String message) { 20 | super(message); 21 | } 22 | 23 | public ServiceNotFoundException(Throwable cause) { 24 | super(cause); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/exception/rpc/HARpcException.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.exception.rpc; 2 | 3 | /** 4 | * 5 | * ClassName: HARpcException
6 | * Function: 启用ha策略的调用异常 7 | * 8 | * @author Zhang Xu 9 | */ 10 | public class HARpcException extends RpcException { 11 | 12 | private static final long serialVersionUID = 3599653969669270363L; 13 | 14 | public HARpcException() { 15 | super(); 16 | } 17 | 18 | public HARpcException(String message, Throwable cause) { 19 | super(message, cause); 20 | } 21 | 22 | public HARpcException(String message) { 23 | super(message); 24 | } 25 | 26 | public HARpcException(Throwable cause) { 27 | super(cause); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/exception/rpc/RpcException.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.exception.rpc; 2 | 3 | /** 4 | * Base rpc exception
5 | * All exception should inherit this super exception 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public class RpcException extends RuntimeException { 10 | 11 | private static final long serialVersionUID = 3599653969669270363L; 12 | 13 | public RpcException() { 14 | super(); 15 | } 16 | 17 | public RpcException(String message, Throwable cause) { 18 | super(message, cause); 19 | } 20 | 21 | public RpcException(String message) { 22 | super(message); 23 | } 24 | 25 | public RpcException(Throwable cause) { 26 | super(cause); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/server/annotation/Authority.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.server.annotation; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.RetentionPolicy; 5 | import java.lang.annotation.Target; 6 | 7 | /** 8 | * ClassName: Authority
9 | * Function: Navi服务权限控制内部,可重复使用,配合{@link NaviRpcAuth}使用 10 | * 11 | * @author Zhang Xu 12 | */ 13 | @Target({ java.lang.annotation.ElementType.TYPE }) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface Authority { 16 | 17 | /** 18 | * appId 19 | * 20 | * @return appId 21 | */ 22 | String appId(); 23 | 24 | /** 25 | * token 26 | * 27 | * @return token 28 | */ 29 | String token(); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/service/impl/AuthServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it.service.impl; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | import com.baidu.beidou.navi.it.service.AuthService; 6 | import com.baidu.beidou.navi.server.annotation.Authority; 7 | import com.baidu.beidou.navi.server.annotation.NaviRpcAuth; 8 | import com.baidu.beidou.navi.server.annotation.NaviRpcService; 9 | 10 | @Service 11 | @NaviRpcService(serviceInterface = AuthService.class) 12 | @NaviRpcAuth({ @Authority(appId = "beidou", token = "123456"), 13 | @Authority(appId = "ssp", token = "111111") }) 14 | public class AuthServiceImpl implements AuthService { 15 | 16 | @Override 17 | public String sayHello() { 18 | return "hi!"; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/exception/IdDuplicateException.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it.exception; 2 | 3 | /** 4 | * ClassName: IdDuplicateException
5 | * Function: ID重复异常 6 | * 7 | * @author zhangxu04 8 | */ 9 | public class IdDuplicateException extends RuntimeException { 10 | 11 | private static final long serialVersionUID = -6138595796119511714L; 12 | 13 | public IdDuplicateException() { 14 | } 15 | 16 | public IdDuplicateException(String message, Throwable cause) { 17 | super(message, cause); 18 | } 19 | 20 | public IdDuplicateException(String message) { 21 | super(message); 22 | } 23 | 24 | public IdDuplicateException(Throwable cause) { 25 | super(cause); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/exception/rpc/AuthAccessDeniedException.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.exception.rpc; 2 | 3 | /** 4 | * ClassName: AuthAccessDeniedException
5 | * 6 | * @author Zhang Xu 7 | */ 8 | public class AuthAccessDeniedException extends RpcException { 9 | 10 | private static final long serialVersionUID = -1760095868220273812L; 11 | 12 | public AuthAccessDeniedException() { 13 | super(); 14 | } 15 | 16 | public AuthAccessDeniedException(String message, Throwable cause) { 17 | super(message, cause); 18 | } 19 | 20 | public AuthAccessDeniedException(String message) { 21 | super(message); 22 | } 23 | 24 | public AuthAccessDeniedException(Throwable cause) { 25 | super(cause); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /navi-demo-server/src/main/java/com/baidu/beidou/sample/annotation/exception/IdDuplicateException.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.sample.annotation.exception; 2 | 3 | /** 4 | * 5 | * ClassName: IdDuplicateException
6 | * Function: ID重复异常 7 | * 8 | * @author zhangxu04 9 | */ 10 | public class IdDuplicateException extends RuntimeException { 11 | 12 | private static final long serialVersionUID = -6138595796119511714L; 13 | 14 | public IdDuplicateException() { 15 | } 16 | 17 | public IdDuplicateException(String message, Throwable cause) { 18 | super(message, cause); 19 | } 20 | 21 | public IdDuplicateException(String message) { 22 | super(message); 23 | } 24 | 25 | public IdDuplicateException(Throwable cause) { 26 | super(cause); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/exception/rpc/DeserilizeNullException.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.exception.rpc; 2 | 3 | /** 4 | * ClassName: DeserilizeNullException
5 | * Function: 解码后为空异常 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public class DeserilizeNullException extends RpcException { 10 | 11 | private static final long serialVersionUID = -6138595196129511714L; 12 | 13 | public DeserilizeNullException() { 14 | } 15 | 16 | public DeserilizeNullException(String message, Throwable cause) { 17 | super(message, cause); 18 | } 19 | 20 | public DeserilizeNullException(String message) { 21 | super(message); 22 | } 23 | 24 | public DeserilizeNullException(Throwable cause) { 25 | super(cause); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/dep/jquery-ui-1.10.4.custom/datePicker.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | jQuery UI Example Page 6 | 7 | 8 | 9 | 19 | 20 | 21 | 22 |

Date:

23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/exception/rpc/ServiceAddressEmptyException.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.exception.rpc; 2 | 3 | /** 4 | * ClassName: ServiceAddressEmptyException
5 | * 6 | * @author Zhang Xu 7 | */ 8 | public class ServiceAddressEmptyException extends RpcException { 9 | 10 | private static final long serialVersionUID = -2984282469636914907L; 11 | 12 | public ServiceAddressEmptyException() { 13 | } 14 | 15 | public ServiceAddressEmptyException(String message) { 16 | super(message); 17 | } 18 | 19 | public ServiceAddressEmptyException(Throwable cause) { 20 | super(cause); 21 | } 22 | 23 | public ServiceAddressEmptyException(String message, Throwable cause) { 24 | super(message, cause); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /navi-demo-client/src/main/java/com/baidu/beidou/sample/portal/common/constant/WebResponseConstant.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.sample.portal.common.constant; 2 | 3 | /** 4 | * 5 | * WEB用返回Json的状态码 6 | * 7 | * @author Zhang Xu 8 | * @version 2013-4-22 下午4:19:39 9 | */ 10 | public class WebResponseConstant { 11 | 12 | public static final int RESPONSE_STATUS_OK = 0; 13 | public static final int RESPONSE_STATUS_SYSTEM_ERROR = 1; //前端直接打印statusInfo.global信息 14 | public static final int RESPONSE_STATUS_BUSINESS_ERROR = 2; //需要按照前后端接口定义打印错误信息 15 | public static final int RESPONSE_STATUS_AUTH_DENIED = 126; 16 | public static final int RESPONSE_STATUS_NOT_LOGIN = 127; 17 | 18 | public static final String MESSAGE_GLOBAL = "global"; 19 | public static final String MESSAGE_FIELD = "field"; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /navi-demo-client/src/test/java/com/baidu/beidou/sample/api/NaviRpcClientTest.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.sample.api; 2 | 3 | import org.junit.Test; 4 | 5 | import com.baidu.beidou.navi.client.SimpleNaviRpcClient; 6 | import com.baidu.beidou.navi.client.SimpleNaviRpcClientBuilder; 7 | import com.baidu.beidou.sample.annotation.vo.Company; 8 | 9 | public class NaviRpcClientTest { 10 | 11 | @Test 12 | public void testGetBySiteUrl() throws Throwable { 13 | Object[] args = new Object[] { 88 }; 14 | SimpleNaviRpcClient client = new SimpleNaviRpcClientBuilder() 15 | .setIpPort("127.0.0.1:8080").setServiceName("CompanyMgr") 16 | .setConnectTimeout(5000).setReadTimeout(5000).build(); 17 | Company result = client.transport("get", args); 18 | System.out.println(result); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /navi-demo-server/src/main/java/com/baidu/beidou/sample/performancetest/service/impl/PerformanceTestServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.sample.performancetest.service.impl; 2 | 3 | import java.util.Map; 4 | 5 | import org.springframework.stereotype.Service; 6 | 7 | import com.baidu.beidou.navi.server.annotation.NaviRpcService; 8 | import com.baidu.beidou.sample.performancetest.service.PerformanceTestService; 9 | import com.baidu.beidou.sample.performancetest.service.vo.Person; 10 | 11 | @Service 12 | @NaviRpcService(serviceInterface = PerformanceTestService.class) 13 | public class PerformanceTestServiceImpl implements PerformanceTestService { 14 | 15 | public String receiveAndReturn(String input) { 16 | return input; 17 | } 18 | 19 | public Map getPerson(Map personMap) { 20 | return personMap; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/protocol/ProtobufSerializeHandler.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.protocol; 2 | 3 | import com.baidu.beidou.navi.codec.protobuf.ProtobufCodec; 4 | 5 | /** 6 | * ClassName: ProtobufSerializeHandler
7 | * Function: protobuf序列化handler 8 | * 9 | * @author Zhang Xu 10 | */ 11 | public class ProtobufSerializeHandler extends AbstractSerializeHandler implements SerializeHandler { 12 | 13 | /** 14 | * @see com.baidu.beidou.navi.protocol.SerializeHandler#getProtocol() 15 | */ 16 | @Override 17 | public NaviProtocol getProtocol() { 18 | return NaviProtocol.PROTOBUF; 19 | } 20 | 21 | /** 22 | * @see com.baidu.beidou.navi.protocol.AbstractSerializeHandler#setCodec() 23 | */ 24 | @Override 25 | public void setCodec() { 26 | this.codec = new ProtobufCodec(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/util/ArrayUtil.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.util; 2 | 3 | /** 4 | * ClassName: ArrayUtil
5 | * Function: 有关数组处理的工具类 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public class ArrayUtil { 10 | 11 | /** 12 | * 检查数组是否为null或空数组[]。 13 | *

14 | * 15 | *

16 |      * ArrayUtil.isEmpty(null)              = true
17 |      * ArrayUtil.isEmpty(new int[0])        = true
18 |      * ArrayUtil.isEmpty(new int[10])       = false
19 |      * 
20 | * 21 | * @param array 22 | * 要检查的数组 23 | * @return 如果为空, 则返回true 24 | */ 25 | public static boolean isEmpty(Object[] array) { 26 | if (array == null || array.length == 0) { 27 | return true; 28 | } 29 | return false; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/protocol/ProtostuffSerializeHandler.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.protocol; 2 | 3 | import com.baidu.beidou.navi.codec.protostuff.ProtostuffCodec; 4 | 5 | /** 6 | * ClassName: ProtostuffSerializeHandler
7 | * Function: protostuff序列化handler 8 | * 9 | * @author Zhang Xu 10 | */ 11 | public class ProtostuffSerializeHandler extends AbstractSerializeHandler implements 12 | SerializeHandler { 13 | 14 | /** 15 | * @see com.baidu.beidou.navi.protocol.SerializeHandler#getProtocol() 16 | */ 17 | @Override 18 | public NaviProtocol getProtocol() { 19 | return NaviProtocol.PROTOSTUFF; 20 | } 21 | 22 | /** 23 | * @see com.baidu.beidou.navi.protocol.AbstractSerializeHandler#setCodec() 24 | */ 25 | @Override 26 | public void setCodec() { 27 | this.codec = new ProtostuffCodec(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/client/constant/NaviRpcClientConstant.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.client.constant; 2 | 3 | /** 4 | * ClassName: NaviRpcClientConstant
5 | * Function: 客户端配置常量 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public class NaviRpcClientConstant { 10 | 11 | public static final String ENDODING = "UTF-8"; 12 | 13 | /** 14 | * 默认客户端连接超时时间,单位毫秒 15 | */ 16 | public static final int DEFAULT_CLIENT_CONN_TIMEOUT = 2000; 17 | 18 | /** 19 | * 默认客户端调用读超时时间,单位毫秒 20 | */ 21 | public static final int DEFAULT_CLIENT_READ_TIMEOUT = 90000; 22 | 23 | /** 24 | * 是否启用HTTP Persistent Connections复用tcp连接 25 | */ 26 | public static final String DEFAULT_HTTP_KEEPALIVE = "true"; 27 | 28 | /** 29 | * 用HTTP Persistent Connections复用tcp连接最大数量 30 | */ 31 | public static final String DEFAULT_MAX_CONNECTIONS = "8"; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/java/com/baidu/beidou/navimgr/auth/LoginValidator.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navimgr.auth; 2 | 3 | import org.apache.commons.lang.StringUtils; 4 | 5 | import com.baidu.beidou.navimgr.auth.constant.UserWebConstant; 6 | 7 | /** 8 | * ClassName: LoginValidator
9 | * Function: 登陆验证器 10 | * 11 | * @author Zhang Xu 12 | */ 13 | public class LoginValidator { 14 | 15 | /** 16 | * 是否合法用户 17 | * 18 | * @param username 19 | * 用户名 20 | * @param password 21 | * 密码md5 22 | * @return 是否合法 23 | */ 24 | public static boolean isValid(String username, String password) { 25 | return StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(password) 26 | && UserWebConstant.USERMAP.containsKey(username) 27 | && UserWebConstant.USERMAP.get(username).getPasswordMd5().equals(password); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /navi-demo-server/src/main/java/com/baidu/beidou/sample/xml/interceptor/AccessLogInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.sample.xml.interceptor; 2 | 3 | import org.aopalliance.intercept.MethodInterceptor; 4 | import org.aopalliance.intercept.MethodInvocation; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | /** 9 | * ClassName: AccessLogInterceptor
10 | * Function: 记录日志拦截器 11 | * 12 | * @author zhangxu04 13 | */ 14 | public class AccessLogInterceptor implements MethodInterceptor { 15 | 16 | private static final Logger log = LoggerFactory.getLogger(AccessLogInterceptor.class); 17 | 18 | public Object invoke(MethodInvocation invocation) throws Throwable { 19 | long start = System.currentTimeMillis(); 20 | Object obj = invocation.proceed(); 21 | long end = System.currentTimeMillis(); 22 | log.info("cost " + (end - start) + "ms"); 23 | return obj; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/util/ZkPathUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.util; 2 | 3 | import org.junit.Test; 4 | 5 | public class ZkPathUtilTest { 6 | 7 | @Test 8 | public void test() { 9 | System.out.println(ZkPathUtil.buildPath(new String[] { "/a", "/b", "/c" })); 10 | System.out.println(ZkPathUtil.buildPath(new String[] { "/a/", "/b", "/c" })); 11 | System.out.println(ZkPathUtil.buildPath(new String[] { "/a", "b", "/c" })); 12 | System.out.println(ZkPathUtil.buildPath(new String[] { "/a/", "b", "/c" })); 13 | 14 | System.out.println(ZkPathUtil.buildPath(new String[] { "/a/x/", "/b", "/c" })); 15 | System.out.println(ZkPathUtil.buildPath(new String[] { "/a/x", "/b", "c" })); 16 | System.out.println(ZkPathUtil.buildPath(new String[] { "/a/x/", "b", "c" })); 17 | System.out.println(ZkPathUtil.buildPath(new String[] { "/a/x", "b", "/c" })); 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/java/com/baidu/beidou/navimgr/common/constant/WebConstant.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navimgr.common.constant; 2 | 3 | 4 | /** 5 | * ClassName: WebConstant
6 | * Function: Web UI常量定义 7 | * 8 | * @author zhangxu04 9 | */ 10 | public class WebConstant { 11 | 12 | /** 13 | * URL前缀 14 | */ 15 | public static final String BASE_PATH = "/navi/"; 16 | 17 | /** 18 | * zookeeper相关URL前缀 19 | */ 20 | public static final String ZOO_URL_PATH = BASE_PATH + "zoo"; 21 | 22 | /** 23 | * 页面相关URL前缀 24 | */ 25 | public static final String PAGE_URL_PATH = BASE_PATH + "page"; 26 | 27 | /** 28 | * 登陆验证URL前缀 29 | */ 30 | public static final String AUTH_URL_PATH = BASE_PATH + "auth"; 31 | 32 | /** 33 | * 每页数量常量 34 | */ 35 | public interface PAGE_SIZE { 36 | int PAGE_SIZE_20 = 20; 37 | int PAGE_SIZE_50 = 50; 38 | int PAGE_SIZE_100 = 100; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/util/Function.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.util; 2 | 3 | /** 4 | * ClassName: Function
5 | * Function: 配合{@link ListUtil}使用的function回调 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public interface Function { 10 | 11 | /** 12 | * Returns the result of applying this function to {@code input}. This method is generally expected, but not 13 | * absolutely required, to have the following properties: 14 | *
    15 | *
  • Its execution does not cause any observable side effects. 16 | *
  • The computation is consistent with equals; that is, {@link Objects#equal Objects.equal}{@code (a, b)} 17 | * implies that {@code Objects.equal(function.apply(a), function.apply(b))}. 18 | *
19 | * 20 | * @throws NullPointerException 21 | * if {@code input} is null and this function does not accept null arguments 22 | */ 23 | T apply(F input); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/util/ByteUtil.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.util; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | /** 7 | * ClassName: ByteUtil
8 | * Function: 字节码工具类 9 | * 10 | * @author Zhang Xu 11 | */ 12 | public class ByteUtil { 13 | 14 | /** 15 | * 读取流中的字节码 16 | * 17 | * @param input 18 | * @param length 19 | * @return 20 | * @throws IOException 21 | */ 22 | public static byte[] readStream(InputStream input, int length) throws IOException { 23 | byte[] bytes = new byte[length]; 24 | int offset = 0; 25 | while (offset < bytes.length) { 26 | int bytesRead = input.read(bytes, offset, bytes.length - offset); 27 | if (bytesRead == -1) { 28 | break; // end of stream 29 | } 30 | offset += bytesRead; 31 | } 32 | return bytes; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/js/newapp.js: -------------------------------------------------------------------------------- 1 | var appId = -1; 2 | var envId = -1; 3 | var version = ""; 4 | getSession(); 5 | 6 | // 提交 7 | $("#item_submit").on("click", function (e) { 8 | $("#error").addClass("hide"); 9 | var app = $("#app").val(); 10 | var desc = $("#desc").val(); 11 | var emails = $("#emails").val(); 12 | 13 | // 验证 14 | if (!desc || !app) { 15 | $("#error").removeClass("hide"); 16 | $("#error").html("表单不能为空或填写格式错误!"); 17 | return; 18 | } 19 | $.ajax({ 20 | type: "POST", 21 | url: "/api/app", 22 | data: { 23 | "app": app, 24 | "desc": desc, 25 | "emails": emails 26 | } 27 | }).done(function (data) { 28 | $("#error").removeClass("hide"); 29 | if (data.success === "true") { 30 | $("#error").html(data.result); 31 | } else { 32 | Util.input.whiteError($("#error"), data); 33 | } 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /navi-demo-server/src/main/java/com/baidu/beidou/sample/annotation/vo/Department.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.sample.annotation.vo; 2 | 3 | import org.apache.commons.lang.builder.ToStringBuilder; 4 | import org.apache.commons.lang.builder.ToStringStyle; 5 | 6 | 7 | public class Department { 8 | 9 | private Integer id; 10 | 11 | private String name; 12 | 13 | public Department() { 14 | 15 | } 16 | 17 | public Department(Integer id, String name) { 18 | super(); 19 | this.id = id; 20 | this.name = name; 21 | } 22 | 23 | public Integer getId() { 24 | return id; 25 | } 26 | 27 | public void setId(Integer id) { 28 | this.id = id; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | 39 | public String toString() { 40 | return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE) 41 | .append("id", id) 42 | .append("name", name) 43 | .toString(); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/java/com/baidu/beidou/navimgr/zoo/constant/ZooConstant.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navimgr.zoo.constant; 2 | 3 | /** 4 | * ClassName: ZooConstant
5 | * Function: zookeeper相关常量 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public class ZooConstant { 10 | 11 | /** 12 | * zookeeper环境常量 13 | *
    14 | *
  • online:线上生产环境
  • 15 | *
  • offline:开发测试环境
  • 16 | *
17 | */ 18 | public static enum ZooEnv { 19 | /** 20 | * 线上生产环境 21 | */ 22 | ONLINE("online"), 23 | 24 | /** 25 | * 开发测试环境 26 | */ 27 | OFFLINE("offline"); 28 | 29 | private ZooEnv(final String value) { 30 | this.value = value; 31 | } 32 | 33 | private String value; 34 | 35 | public String getValue() { 36 | return value; 37 | } 38 | 39 | public void setValue(String value) { 40 | this.value = value; 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /navi-demo-client/src/test/java/com/baidu/beidou/sample/simpletest/ResponseDTO.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.sample.simpletest; 2 | 3 | /** 4 | * Response 5 | * 6 | * @author Zhang Xu 7 | */ 8 | public class ResponseDTO { 9 | 10 | private long id; 11 | 12 | private Object result; 13 | 14 | /** 15 | * @see com.baidu.beidou.navi.constant.NaviStatus 16 | */ 17 | private int status; 18 | 19 | private Throwable error; 20 | 21 | public long getId() { 22 | return id; 23 | } 24 | 25 | public void setId(long id) { 26 | this.id = id; 27 | } 28 | 29 | public Object getResult() { 30 | return result; 31 | } 32 | 33 | public void setResult(Object result) { 34 | this.result = result; 35 | } 36 | 37 | public int getStatus() { 38 | return status; 39 | } 40 | 41 | public void setStatus(int status) { 42 | this.status = status; 43 | } 44 | 45 | public Throwable getError() { 46 | return error; 47 | } 48 | 49 | public void setError(Throwable error) { 50 | this.error = error; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /navi-demo-server/src/main/java/com/baidu/beidou/sample/performancetest/service/vo/Job.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.sample.performancetest.service.vo; 2 | 3 | 4 | public class Job { 5 | 6 | private String companyName; 7 | 8 | private String title; 9 | 10 | private Long salary; 11 | 12 | 13 | 14 | public Job() { 15 | super(); 16 | } 17 | 18 | public Job(String companyName, String title, Long salary) { 19 | super(); 20 | this.companyName = companyName; 21 | this.title = title; 22 | this.salary = salary; 23 | } 24 | 25 | public String getCompanyName() { 26 | return companyName; 27 | } 28 | 29 | public void setCompanyName(String companyName) { 30 | this.companyName = companyName; 31 | } 32 | 33 | public String getTitle() { 34 | return title; 35 | } 36 | 37 | public void setTitle(String title) { 38 | this.title = title; 39 | } 40 | 41 | public Long getSalary() { 42 | return salary; 43 | } 44 | 45 | public void setSalary(Long salary) { 46 | this.salary = salary; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /navi/src/test/resources/applicationContext-server.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/conf/RpcServerConf.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.conf; 2 | 3 | /** 4 | * ClassName: RpcServerConf
5 | * Function: 服务端配置 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public class RpcServerConf extends RpcBaseConf { 10 | 11 | /** 12 | * 服务注册到zookeeper的path 13 | */ 14 | public static String ZK_REGISTRY_NAMESPACE = ""; 15 | 16 | /** 17 | * 如果服务没有在tomcat或者环境变量中定义端口,那么这个端口就是注册到zookeeper上的服务端口 18 | */ 19 | public static int SERVER_PORT = 8080; 20 | 21 | public String getZK_REGISTRY_NAMESPACE() { 22 | return ZK_REGISTRY_NAMESPACE; 23 | } 24 | 25 | public void setZK_REGISTRY_NAMESPACE(String zK_REGISTRY_NAMESPACE) { 26 | ZK_REGISTRY_NAMESPACE = zK_REGISTRY_NAMESPACE; 27 | } 28 | 29 | public int getSERVER_PORT() { 30 | return SERVER_PORT; 31 | } 32 | 33 | public void setSERVER_PORT(int sERVER_PORT) { 34 | SERVER_PORT = sERVER_PORT; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/service/BookService.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it.service; 2 | 3 | import java.util.List; 4 | 5 | import com.baidu.beidou.navi.vo.Book; 6 | 7 | /** 8 | * ClassName: BookMgr
9 | * Function: 测试用书籍服务 10 | * 11 | * @author Zhang Xu 12 | */ 13 | public interface BookService { 14 | 15 | /** 16 | * init 17 | */ 18 | void init(); 19 | 20 | /** 21 | * query 22 | */ 23 | Book get(int id); 24 | 25 | /** 26 | * query 27 | */ 28 | Book get(String name); 29 | 30 | /** 31 | * query 32 | */ 33 | Book get(int id, String name); 34 | 35 | /** 36 | * get all 37 | */ 38 | List getAll(); 39 | 40 | /** 41 | * add 42 | */ 43 | Book add(Book book); 44 | 45 | /** 46 | * delete 47 | */ 48 | void delete(int id); 49 | 50 | /** 51 | * update 52 | */ 53 | void update(Book book); 54 | 55 | } 56 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/util/ReflectionUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.util; 2 | 3 | import static org.hamcrest.Matchers.is; 4 | import static org.junit.Assert.assertThat; 5 | 6 | import org.junit.Test; 7 | 8 | import com.baidu.beidou.navi.server.annotation.Authority; 9 | import com.baidu.beidou.navi.server.annotation.NaviRpcAuth; 10 | 11 | public class ReflectionUtilTest { 12 | 13 | @Test 14 | public void testGetAllAnnotationsOfClass() { 15 | TestBean t = new TestBean(); 16 | NaviRpcAuth auth = ReflectionUtil.getAnnotation(t.getClass(), NaviRpcAuth.class); 17 | Authority[] authorities = auth.value(); 18 | assertThat(authorities.length, is(2)); 19 | for (Authority authority : authorities) { 20 | System.out.println(authority.appId() + "|" + authority.token()); 21 | } 22 | } 23 | 24 | } 25 | 26 | @NaviRpcAuth({ @Authority(appId = "beidou", token = "123456"), 27 | @Authority(appId = "ssp", token = "111111") }) 28 | class TestBean { 29 | 30 | } 31 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/codec/ProtostuffCodecAddNewFieldTest.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.codec; 2 | 3 | import static org.hamcrest.Matchers.is; 4 | import static org.junit.Assert.assertThat; 5 | 6 | import org.junit.Test; 7 | 8 | import com.baidu.beidou.navi.codec.protostuff.ProtostuffCodec; 9 | import com.baidu.beidou.navi.vo.Book; 10 | import com.baidu.beidou.navi.vo.Book2; 11 | 12 | public class ProtostuffCodecAddNewFieldTest extends BaseCodecTest { 13 | 14 | @Test 15 | public void testCodec() throws Exception { 16 | initCodec(); 17 | Book b = new Book(1, "java"); 18 | byte[] bytes = codec.encode(Book.class, b); 19 | System.out.println("bytes.length=" + bytes.length); 20 | Book2 b2 = codec.decode(Book2.class, bytes); 21 | System.out.println(b2); 22 | assertThat(b2.getId(), is(1)); 23 | assertThat(b2.getName(), is("java")); 24 | } 25 | 26 | @Override 27 | public void initCodec() { 28 | codec = new ProtostuffCodec(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/protocol/NaviProtocol.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.protocol; 2 | 3 | /** 4 | * ClassName: NaviProtocol
5 | * Function: Navi所支持的序列化协议枚举 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public enum NaviProtocol { 10 | 11 | /** 12 | * protostuff 13 | */ 14 | PROTOSTUFF("application/baidu.protostuff"), 15 | 16 | /** 17 | * protobuf 18 | */ 19 | PROTOBUF("application/baidu.protobuf"), 20 | 21 | /** 22 | * json 23 | */ 24 | JSON("application/baidu.json"); 25 | 26 | /** 27 | * content type名称 28 | */ 29 | private String name; 30 | 31 | /** 32 | * Creates a new instance of NaviProtocol. 33 | * 34 | * @param name 35 | */ 36 | private NaviProtocol(String name) { 37 | this.name = name; 38 | } 39 | 40 | public String getName() { 41 | return name; 42 | } 43 | 44 | public void setName(String name) { 45 | this.name = name; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/TestClient.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import com.baidu.beidou.navi.client.SimpleNaviRpcClient; 6 | import com.baidu.beidou.navi.it.service.CompanyService; 7 | import com.baidu.beidou.navi.it.service.impl.CompanyServiceImpl; 8 | import com.baidu.beidou.navi.protocol.ProtostuffSerializeHandler; 9 | import com.baidu.beidou.navi.protocol.SerializeHandler; 10 | import com.baidu.beidou.navi.vo.Company; 11 | 12 | public class TestClient { 13 | 14 | public void testClient() throws Throwable { 15 | // SerializeHandler h = new JsonSerializeHandler(); 16 | SerializeHandler h = new ProtostuffSerializeHandler(); 17 | SimpleNaviRpcClient c = new SimpleNaviRpcClient( 18 | "http://127.0.0.1:8088/service_api/CompanyService", h); 19 | CompanyService serv = new CompanyServiceImpl(); 20 | Method m = serv.getClass().getDeclaredMethods()[1]; 21 | Company company = (Company) (c.transport(m, new Object[] { 88 })); 22 | System.out.println(company); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/codec/BaseCodecTest.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.codec; 2 | 3 | import static org.hamcrest.Matchers.is; 4 | import static org.junit.Assert.assertThat; 5 | 6 | import com.baidu.beidou.navi.vo.Company; 7 | import com.baidu.beidou.navi.vo.CompanyBuilder; 8 | 9 | public abstract class BaseCodecTest { 10 | 11 | protected Codec codec; 12 | 13 | public abstract void initCodec(); 14 | 15 | public void encodeAndDecode() throws Exception { 16 | initCodec(); 17 | Company company = CompanyBuilder.buildSimple(); 18 | byte[] bytes = codec.encode(Company.class, company); 19 | System.out.println("bytes.length=" + bytes.length); 20 | Company c = codec.decode(Company.class, bytes); 21 | System.out.println(c); 22 | assertThat(c.getId(), is(88)); 23 | assertThat(c.getName(), is("百度时代网络技术(北京)有限公司")); 24 | assertThat(c.getDepartmentList().size(), is(4)); 25 | assertThat(c.getDepartmentList().get(0).getId(), is(101)); 26 | assertThat(c.getDepartmentList().get(0).getName(), is("R&D")); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/TestProxyBookService.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it; 2 | 3 | import static org.hamcrest.Matchers.is; 4 | import static org.junit.Assert.assertThat; 5 | 6 | import javax.annotation.Resource; 7 | 8 | import org.junit.Test; 9 | 10 | import com.baidu.beidou.navi.it.service.BookService; 11 | import com.baidu.beidou.navi.vo.Book; 12 | 13 | public class TestProxyBookService extends BaseTest { 14 | 15 | @Resource 16 | private BookService bookServiceDirectCall; 17 | 18 | @Test 19 | public void testGet() { 20 | Book book = bookServiceDirectCall.get(1); 21 | validateBook(book); 22 | } 23 | 24 | @Test 25 | public void testGetOverrideMethod() { 26 | Book book = bookServiceDirectCall.get("天方夜谭"); 27 | validateBook(book); 28 | } 29 | 30 | @Test 31 | public void testGetOverrideMethod2() { 32 | Book book = bookServiceDirectCall.get(1, "天方夜谭"); 33 | validateBook(book); 34 | } 35 | 36 | private void validateBook(Book b) { 37 | assertThat(b.getId(), is(1)); 38 | assertThat(b.getName(), is("天方夜谭")); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/client/ha/LoadBalanceStrategy.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.client.ha; 2 | 3 | import java.lang.reflect.Method; 4 | import java.util.List; 5 | 6 | import com.baidu.beidou.navi.client.NaviRpcClient; 7 | import com.baidu.beidou.navi.client.attachment.Attachment; 8 | 9 | /** 10 | * ClassName: LoadBalanceStrategy
11 | * Function: 负载均衡器 12 | * 13 | * @author Zhang Xu 14 | */ 15 | public interface LoadBalanceStrategy { 16 | 17 | /** 18 | * 根据客户端的连接采用负载均衡策略调用发起远程通信 19 | * 20 | * @param clientList 21 | * @param method 22 | * @param args 23 | * @return 24 | * @throws Throwable 25 | */ 26 | Object transport(List clientList, Method method, Object[] args) throws Throwable; 27 | 28 | /** 29 | * 根据客户端的连接采用负载均衡策略调用发起远程通信 30 | * 31 | * @param clientList 32 | * @param method 33 | * @param args 34 | * @param attachment 35 | * @return 36 | * @throws Throwable 37 | */ 38 | Object transport(List clientList, Method method, Object[] args, 39 | Attachment attachment) throws Throwable; 40 | 41 | } 42 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/protocol/SerializeHandler.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.protocol; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | import com.baidu.beidou.navi.exception.rpc.CodecException; 6 | 7 | /** 8 | * ClassName: SerializeHandler
9 | * Function: 序列化反序列化handler 10 | * 11 | * @author Zhang Xu 12 | */ 13 | public interface SerializeHandler { 14 | 15 | /** 16 | * 获取序列化协议类型 17 | * 18 | * @return 19 | */ 20 | NaviProtocol getProtocol(); 21 | 22 | /** 23 | * 反序列化解码成RequestDTO 24 | * 25 | * @param req 26 | * @param clazz 27 | * @param interf 28 | * @param genericType 29 | * @return T 30 | * @throws CodecException 31 | */ 32 | T deserialize(byte[] req, Class clazz, Class interf, Type genericType) 33 | throws CodecException; 34 | 35 | /** 36 | * 编码ResponseDTO为字节码 37 | * 38 | * @param res 39 | * @param clazz 40 | * @return 字节码 41 | * @throws CodecException 42 | */ 43 | byte[] serialize(T res, Class clazz) throws CodecException; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/interceptor/ProxyServiceInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it.interceptor; 2 | 3 | import org.aspectj.lang.ProceedingJoinPoint; 4 | import org.aspectj.lang.annotation.Around; 5 | import org.aspectj.lang.annotation.Aspect; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.stereotype.Component; 9 | 10 | /** 11 | * ClassName: ProxyServiceInterceptor
12 | * Function: 实验拦截器 13 | * 14 | * @author Zhang Xu 15 | */ 16 | @Aspect 17 | @Component 18 | public class ProxyServiceInterceptor { 19 | 20 | private static final Logger LOG = LoggerFactory.getLogger(ProxyServiceInterceptor.class); 21 | 22 | @Around("execution(* com.baidu.beidou.navi.it.service.impl.ProxyServiceImpl.*(..))") 23 | public Object validate4Query(ProceedingJoinPoint pjp) throws Throwable { 24 | Object[] args = pjp.getArgs(); 25 | if (args != null && args.length == 1 && (args[0] instanceof String)) { 26 | LOG.info("Intercept argument input - " + (String) args[0]); 27 | } 28 | return pjp.proceed(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /navi-demo-client/src/test/java/com/baidu/beidou/sample/simpletest/RequestDTO.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.sample.simpletest; 2 | 3 | /** 4 | * Request 5 | * 6 | * @author Zhang Xu 7 | */ 8 | public class RequestDTO { 9 | 10 | private long traceId; 11 | 12 | private String method; 13 | 14 | private Object[] parameters; 15 | 16 | private String[] paramterTypes; 17 | 18 | public long getTraceId() { 19 | return traceId; 20 | } 21 | 22 | public void setTraceId(long traceId) { 23 | this.traceId = traceId; 24 | } 25 | 26 | public String getMethod() { 27 | return method; 28 | } 29 | 30 | public void setMethod(String method) { 31 | this.method = method; 32 | } 33 | 34 | public Object[] getParameters() { 35 | return parameters; 36 | } 37 | 38 | public void setParameters(Object[] parameters) { 39 | this.parameters = parameters; 40 | } 41 | 42 | public String[] getParamterTypes() { 43 | return paramterTypes; 44 | } 45 | 46 | public void setParamterTypes(String[] paramterTypes) { 47 | this.paramterTypes = paramterTypes; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /navi-demo-server/src/main/java/com/baidu/beidou/sample/xml/vo/Book.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.sample.xml.vo; 2 | 3 | import java.util.Date; 4 | 5 | public class Book { 6 | 7 | // 书籍ID 8 | private int id; 9 | 10 | // 书籍URL 11 | private String name; 12 | 13 | // 书籍页数 14 | private long pageNum; 15 | 16 | // 书籍发布时间 17 | private Date publishDate; 18 | 19 | public Book(int id, String name, long pageNum, Date publishDate) { 20 | super(); 21 | this.id = id; 22 | this.name = name; 23 | this.pageNum = pageNum; 24 | this.publishDate = publishDate; 25 | } 26 | 27 | public int getId() { 28 | return id; 29 | } 30 | 31 | public void setId(int id) { 32 | this.id = id; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public void setName(String name) { 40 | this.name = name; 41 | } 42 | 43 | public long getPageNum() { 44 | return pageNum; 45 | } 46 | 47 | public void setPageNum(long pageNum) { 48 | this.pageNum = pageNum; 49 | } 50 | 51 | public Date getPublishDate() { 52 | return publishDate; 53 | } 54 | 55 | public void setPublishDate(Date publishDate) { 56 | this.publishDate = publishDate; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/vo/Book.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.vo; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.apache.commons.lang.builder.ToStringBuilder; 6 | import org.apache.commons.lang.builder.ToStringStyle; 7 | 8 | public class Book implements Serializable { 9 | 10 | /** 11 | * 书籍ID 12 | */ 13 | private int id; 14 | 15 | /** 16 | * 名称 17 | */ 18 | private String name; 19 | 20 | public Book() { 21 | 22 | } 23 | 24 | public Book(int id, String name) { 25 | this.id = id; 26 | this.name = name; 27 | } 28 | 29 | public int getId() { 30 | return id; 31 | } 32 | 33 | public void setId(int id) { 34 | this.id = id; 35 | } 36 | 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | public String toString() { 46 | return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).append("id", this.getId()) 47 | .append("name", name).toString(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/js/newconfigitem.js: -------------------------------------------------------------------------------- 1 | var appId = -1; 2 | var envId = -1; 3 | var version = ""; 4 | getSession(); 5 | 6 | // 提交 7 | $("#item_submit").on("click", function (e) { 8 | $("#error").addClass("hide"); 9 | 10 | if (version == '自定义版本') { 11 | version = $('#selfversion_value').val(); 12 | } 13 | 14 | var key = $("#key").val(); 15 | var value = $("#value").val(); 16 | 17 | // 验证 18 | if (appId < 1 || envId < 1 || version == "" || !value || !key) { 19 | $("#error").removeClass("hide"); 20 | $("#error").html("表单不能为空或填写格式错误!"); 21 | return; 22 | } 23 | $.ajax({ 24 | type: "POST", 25 | url: "/api/web/config/item", 26 | data: { 27 | "appId": appId, 28 | "version": version, 29 | "key": key, 30 | "envId": envId, 31 | "value": value 32 | } 33 | }).done(function (data) { 34 | $("#error").removeClass("hide"); 35 | if (data.success === "true") { 36 | $("#error").html(data.result); 37 | } else { 38 | Util.input.whiteError($("#error"), data); 39 | } 40 | }); 41 | }); 42 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/vo/Department.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.vo; 2 | 3 | import org.apache.commons.lang.builder.ToStringBuilder; 4 | import org.apache.commons.lang.builder.ToStringStyle; 5 | 6 | /** 7 | * ClassName: Department
8 | * Function: 部门 9 | * 10 | * @author Zhang Xu 11 | */ 12 | public class Department { 13 | 14 | private Integer id; 15 | 16 | private String name; 17 | 18 | public Department() { 19 | 20 | } 21 | 22 | public Department(Integer id, String name) { 23 | super(); 24 | this.id = id; 25 | this.name = name; 26 | } 27 | 28 | public Integer getId() { 29 | return id; 30 | } 31 | 32 | public void setId(Integer id) { 33 | this.id = id; 34 | } 35 | 36 | public String getName() { 37 | return name; 38 | } 39 | 40 | public void setName(String name) { 41 | this.name = name; 42 | } 43 | 44 | public String toString() { 45 | return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).append("id", id) 46 | .append("name", name).toString(); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/server/locator/impl/SimpleMethodResolver.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.server.locator.impl; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import com.baidu.beidou.navi.server.annotation.IgnoreNaviRpcMethod; 6 | import com.baidu.beidou.navi.server.locator.MethodResolver; 7 | 8 | /** 9 | * ClassName: SimpleMethodResolver
10 | * Function: 默认的简单服务暴露判断类,用于判断某个类下面的方法是否有资格暴露为服务的方法 11 | * 12 | * @author Zhang Xu 13 | */ 14 | public class SimpleMethodResolver implements MethodResolver { 15 | 16 | /** 17 | * 判断某个方法是否可以暴露为服务,这里的判断条件是满足以下 18 | *
    19 | *
  • 1)方法上没有{@link com.baidu.beidou.navi.server.annotation.IgnoreNaviRpcMethod IgnoreNaviRpcMethod}注解
  • 20 | *
21 | * 22 | * @param m 23 | * 方法 24 | * @return 是否可以暴露为服务,true为可以,false为不行 25 | * @see com.baidu.beidou.navi.server.locator.MethodResolver#isSupport(java.lang.reflect.Method) 26 | */ 27 | @Override 28 | public boolean isSupport(Method m) { 29 | IgnoreNaviRpcMethod anno = m.getAnnotation(IgnoreNaviRpcMethod.class); 30 | if (anno != null) { 31 | return false; 32 | } 33 | return true; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/codec/protobuf/ProtobufUtils.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.codec.protobuf; 2 | 3 | import java.io.IOException; 4 | 5 | import com.dyuproject.protostuff.LinkedBuffer; 6 | import com.dyuproject.protostuff.ProtobufIOUtil; 7 | import com.dyuproject.protostuff.Schema; 8 | 9 | /** 10 | * ClassName: ProtobufUtils
11 | * Function: 运行时Protobuf编码工具类 12 | * 13 | * @author Zhang Xu 14 | */ 15 | public class ProtobufUtils { 16 | 17 | /** 18 | * 将message根据schema转换为字节码 19 | * 20 | * @param message 21 | * @param schema 22 | * @param buffer 23 | * @return 24 | */ 25 | public static byte[] toByteArray(T message, Schema schema, LinkedBuffer buffer) { 26 | return ProtobufIOUtil.toByteArray(message, schema, buffer); 27 | } 28 | 29 | /** 30 | * 将字节码根据schema转换为message 31 | * 32 | * @param in 33 | * @param message 34 | * @param schema 35 | * @throws IOException 36 | */ 37 | public static void mergeFrom(byte[] in, T message, Schema schema) throws IOException { 38 | ProtobufIOUtil.mergeFrom(in, message, schema); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/constant/HttpStatus.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.constant; 2 | 3 | /** 4 | * ClassName: HttpStatus
5 | * Function: HTTP状态码 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public class HttpStatus { 10 | 11 | /** 200 OK (HTTP/1.0 - RFC 1945) */ 12 | public static final int SC_OK = 200; 13 | 14 | /** 400 Bad Request (HTTP/1.1 - RFC 2616) */ 15 | public static final int SC_BAD_REQUEST = 400; 16 | 17 | /** 401 Unauthorized (HTTP/1.0 - RFC 1945) */ 18 | public static final int SC_UNAUTHORIZED = 401; 19 | 20 | /** 403 Forbidden (HTTP/1.0 - RFC 1945) */ 21 | public static final int SC_FORBIDDEN = 403; 22 | 23 | /** 404 Not Found (HTTP/1.0 - RFC 1945) */ 24 | public static final int SC_NOT_FOUND = 404; 25 | 26 | /** 405 Method Not Allowed (HTTP/1.1 - RFC 2616) */ 27 | public static final int SC_METHOD_NOT_ALLOWED = 405; 28 | 29 | /** 406 Not Acceptable (HTTP/1.1 - RFC 2616) */ 30 | public static final int SC_NOT_ACCEPTABLE = 406; 31 | 32 | /** 500 Server Error (HTTP/1.0 - RFC 1945) */ 33 | public static final int SC_INTERNAL_SERVER_ERROR = 500; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/codec/protostuff/ProtostuffUtils.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.codec.protostuff; 2 | 3 | import java.io.IOException; 4 | 5 | import com.dyuproject.protostuff.LinkedBuffer; 6 | import com.dyuproject.protostuff.ProtostuffIOUtil; 7 | import com.dyuproject.protostuff.Schema; 8 | 9 | /** 10 | * ClassName: ProtostuffUtils
11 | * Function: Protostuff编码工具类 12 | * 13 | * @author Zhang Xu 14 | */ 15 | public class ProtostuffUtils { 16 | 17 | /** 18 | * 将message根据schema转换为字节码 19 | * 20 | * @param message 21 | * @param schema 22 | * @param buffer 23 | * @return 24 | */ 25 | public static byte[] toByteArray(T message, Schema schema, LinkedBuffer buffer) { 26 | return ProtostuffIOUtil.toByteArray(message, schema, buffer); 27 | } 28 | 29 | /** 30 | * 将字节码根据schema转换为message 31 | * 32 | * @param in 33 | * @param message 34 | * @param schema 35 | * @throws IOException 36 | */ 37 | public static void mergeFrom(byte[] in, T message, Schema schema) throws IOException { 38 | ProtostuffIOUtil.mergeFrom(in, message, schema); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/TestHtmlPage.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it; 2 | 3 | import static org.hamcrest.Matchers.is; 4 | import static org.junit.Assert.assertThat; 5 | 6 | import org.junit.Test; 7 | 8 | public class TestHtmlPage extends BaseTest { 9 | 10 | @Test 11 | public void testIndexHtml() throws Throwable { 12 | String content = getContent(("http://127.0.0.1:" + Config.PORT + "/service_api")); 13 | assertThat(content.contains("CompanyService"), is(true)); 14 | } 15 | 16 | @Test 17 | public void testServiceHtml() throws Throwable { 18 | String content = getContent(("http://127.0.0.1:" + Config.PORT + "/service_api/CompanyService")); 19 | assertThat(content.contains("get"), is(true)); 20 | } 21 | 22 | @Test 23 | public void testClassHtml() throws Throwable { 24 | String content = getContent(("http://127.0.0.1:" + Config.PORT 25 | + "/service_api/get_class_defination?" + "class=com.baidu.beidou.navi.vo.Company")); 26 | assertThat(content.contains("name"), is(true)); 27 | } 28 | 29 | @Test 30 | public void testZooHtml() throws Throwable { 31 | getContent(("http://127.0.0.1:" + Config.PORT + "/service_api/zookeeper")); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/java/com/baidu/beidou/navimgr/util/HttpUtils.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navimgr.util; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | 5 | /** 6 | * ClassName: HttpUtils
7 | * Function: http工具类 8 | * 9 | * @author Zhang Xu 10 | */ 11 | public class HttpUtils { 12 | 13 | /** 14 | * 获取浏览器信息 15 | * 16 | * @param request 17 | * 请求request 18 | * @return ua 19 | */ 20 | public static String getHttpBrowser(HttpServletRequest request) { 21 | if (request == null) { 22 | return null; 23 | } 24 | return request.getHeader("User-Agent"); 25 | } 26 | 27 | /** 28 | * 获得整个url,如http://www.weamea.com/music/index.jsp?id=4342 29 | * 30 | * @param request 31 | * 请求request 32 | * @return url 33 | */ 34 | public static String getFullURL(HttpServletRequest request) { 35 | if (request == null) { 36 | return null; 37 | } 38 | String url = request.getRequestURL().toString(); 39 | String QueryString = request.getQueryString(); 40 | if ((QueryString != null) && (QueryString.length() > 0)) { 41 | url = url + "?" + QueryString; 42 | } 43 | return url; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/java/com/baidu/beidou/navimgr/zoo/DataErrorException.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navimgr.zoo; 2 | 3 | /** 4 | * Zookeeper client data exception 5 | * 6 | * @author Zhang Xu 7 | */ 8 | public class DataErrorException extends RuntimeException { 9 | 10 | private static final long serialVersionUID = 3222573813262320183L; 11 | 12 | /** 13 | * Creates a new instance of DataErrorException. 14 | */ 15 | public DataErrorException() { 16 | } 17 | 18 | /** 19 | * Creates a new instance of DataErrorException. 20 | * 21 | * @param message 22 | * 错误信息 23 | * @param cause 24 | * 原因 25 | */ 26 | public DataErrorException(String message, Throwable cause) { 27 | super(message, cause); 28 | } 29 | 30 | /** 31 | * Creates a new instance of DataErrorException. 32 | * 33 | * @param message 34 | * 错误信息 35 | */ 36 | public DataErrorException(String message) { 37 | super(message); 38 | } 39 | 40 | /** 41 | * Creates a new instance of DataErrorException. 42 | * 43 | * @param cause 44 | * 原因 45 | */ 46 | public DataErrorException(Throwable cause) { 47 | super(cause); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/TestHACompanyService.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it; 2 | 3 | import javax.annotation.Resource; 4 | 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | 8 | import com.baidu.beidou.navi.it.service.CompanyService; 9 | 10 | public class TestHACompanyService extends AbstractCompanyServiceTest { 11 | 12 | @Resource 13 | private CompanyService companyServiceHA; 14 | 15 | @Test 16 | public void testGet() { 17 | testGet(companyServiceHA); 18 | } 19 | 20 | @Test 21 | public void testGetMulti() { 22 | testGetMulti(companyServiceHA); 23 | } 24 | 25 | @Test 26 | public void testGetAll() { 27 | testGetAll(companyServiceHA); 28 | } 29 | 30 | @Test 31 | public void testGetMapByIds() { 32 | testGetMapByIds(companyServiceHA); 33 | } 34 | 35 | @Test 36 | public void testAdd() { 37 | testAdd(companyServiceHA); 38 | } 39 | 40 | @Test 41 | public void testAddNegative() { 42 | testAddNegative(companyServiceHA); 43 | } 44 | 45 | @Test 46 | public void testDelete() { 47 | testDelete(companyServiceHA); 48 | } 49 | 50 | @Before 51 | public void testInit() { 52 | testInit(companyServiceHA); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/util/AccessStringUtil.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.util; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import com.baidu.beidou.navi.codec.json.JsonMapper; 7 | 8 | /** 9 | * ClassName: AccessStringUtil
10 | * Function: 记录日志的工具类,做截断用 11 | * 12 | * @author Zhang Xu 13 | */ 14 | public class AccessStringUtil { 15 | 16 | private static final Logger LOG = LoggerFactory.getLogger(AccessStringUtil.class); 17 | 18 | private static final JsonMapper jsonMapper = JsonMapper.buildNormalMapper(); 19 | 20 | private static final int TO_STRING_MAX_LENGTH = 800; 21 | 22 | public static String toJson(Object object) { 23 | try { 24 | return cutByMaxLength(jsonMapper.toJson(object)); 25 | } catch (Exception e) { 26 | LOG.error("Failed to serialize to json - " + object); 27 | return StringUtil.EMPTY; 28 | } 29 | } 30 | 31 | private static String cutByMaxLength(String str) { 32 | if (StringUtil.isEmpty(str)) { 33 | return StringUtil.EMPTY; 34 | } else { 35 | return str.length() > TO_STRING_MAX_LENGTH ? str.substring(0, TO_STRING_MAX_LENGTH) 36 | : str; 37 | } 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/server/filter/FilterCallback.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.server.filter; 2 | 3 | import com.baidu.beidou.navi.server.callback.Callback; 4 | import com.baidu.beidou.navi.server.vo.NaviRpcResponse; 5 | 6 | /** 7 | * Filter callback that works with filter chain.
8 | * 9 | * Every time result is properly handled by server, a cascade callback will 10 | * be invoked to the filter callback too. 11 | * 12 | * @author Zhang Xu 13 | */ 14 | public class FilterCallback implements Callback { 15 | 16 | /** 17 | * Usually refer to the next filter, or at the end refer to 18 | * the callback which constructed by user 19 | */ 20 | private final Callback callback; 21 | 22 | /** 23 | * Refer to the filter 24 | */ 25 | private final Filter filter; 26 | 27 | public FilterCallback(Callback callback, Filter filter) { 28 | this.callback = callback; 29 | this.filter = filter; 30 | } 31 | 32 | public void handleResult(NaviRpcResponse response) { 33 | // first handle filter callback 34 | filter.doOnCallbackHandleResultTrigger(response); 35 | 36 | // then process the next filter callback 37 | if (callback != null) { 38 | callback.handleResult(response); 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/js/login.js: -------------------------------------------------------------------------------- 1 | (function ($) { 2 | 3 | //$("#indexMain").attr("href", "/"); 4 | 5 | getSession2Redirect(); 6 | 7 | // 发送登录请求 8 | $(".form-submit").on("click", function () { 9 | 10 | var me = this; 11 | var username = $("#name").val(); 12 | var pwd = MD5($("#password").val()); 13 | var remember = $("#inlineCheckbox2").is(':checked') ? true : false; 14 | 15 | // 验证 16 | if (username.length <= 0 || !pwd) { 17 | $("#loginError").show(); 18 | return; 19 | } 20 | 21 | $.ajax({ 22 | type: "POST", 23 | url: "/userLogin", 24 | data: { 25 | "username": username, 26 | "password": pwd, 27 | "remember": remember 28 | }, 29 | dataType: "json" 30 | }).done(function (result) { 31 | if (result.status === 0) { 32 | window.VISITOR = result.data; 33 | $("#loginError").hide(); 34 | headShowInit(); 35 | window.location.href = "/main.html"; 36 | } else { 37 | Util.input.whiteError($("#loginError"), result); 38 | $("#loginError").show(); 39 | } 40 | }); 41 | }); 42 | 43 | })(jQuery); -------------------------------------------------------------------------------- /navi-mgr-console/src/main/java/com/baidu/beidou/navimgr/zoo/service/impl/OnlineZooServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navimgr.zoo.service.impl; 2 | 3 | import java.io.IOException; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.stereotype.Service; 8 | 9 | import com.baidu.beidou.navimgr.zoo.SimpleZooKeeperClient; 10 | import com.baidu.beidou.navimgr.zoo.service.ZooService; 11 | 12 | /** 13 | * ClassName: OnlineZooServiceImpl
14 | * Function: 线上zookeeper服务实现 15 | * 16 | * @author Zhang Xu 17 | */ 18 | @Service 19 | public class OnlineZooServiceImpl extends AbstractZooService implements ZooService { 20 | 21 | private static final Logger LOG = LoggerFactory.getLogger(OnlineZooServiceImpl.class); 22 | 23 | /** 24 | * 连接zookeeper 25 | * 26 | * @see com.baidu.beidou.navimgr.zoo.service.impl.AbstractZooService#doConnect() 27 | */ 28 | @Override 29 | public SimpleZooKeeperClient doConnect() throws IOException, InterruptedException { 30 | LOG.info("Connecting to zookeeper server - " + zooConf.getOnlineServerList()); 31 | return new SimpleZooKeeperClient(zooConf.getOnlineServerList(), 32 | zooConf.getOnlineDigestAuth(), new ServerServiceWatcher(), 33 | zooConf.getSessionTimeout(), zooConf.getConnTimeout()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/java/com/baidu/beidou/navimgr/zoo/service/impl/OfflineZooServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navimgr.zoo.service.impl; 2 | 3 | import java.io.IOException; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.stereotype.Service; 8 | 9 | import com.baidu.beidou.navimgr.zoo.SimpleZooKeeperClient; 10 | import com.baidu.beidou.navimgr.zoo.service.ZooService; 11 | 12 | /** 13 | * ClassName: OfflineZooServiceImpl
14 | * Function: 线下zookeeper服务实现 15 | * 16 | * @author Zhang Xu 17 | */ 18 | @Service 19 | public class OfflineZooServiceImpl extends AbstractZooService implements ZooService { 20 | 21 | private static final Logger LOG = LoggerFactory.getLogger(OfflineZooServiceImpl.class); 22 | 23 | /** 24 | * 连接zookeeper 25 | * 26 | * @see com.baidu.beidou.navimgr.zoo.service.impl.AbstractZooService#doConnect() 27 | */ 28 | @Override 29 | public SimpleZooKeeperClient doConnect() throws IOException, InterruptedException { 30 | LOG.info("Connecting to zookeeper server - " + zooConf.getOfflineServerList()); 31 | return new SimpleZooKeeperClient(zooConf.getOfflineServerList(), 32 | zooConf.getOfflineDigestAuth(), new ServerServiceWatcher(), 33 | zooConf.getSessionTimeout(), zooConf.getConnTimeout()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/client/ha/FailOverStrategy.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.client.ha; 2 | 3 | /** 4 | * ClassName: FailOverStrategy
5 | * Function: 失败重试策略 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public class FailOverStrategy implements FailStrategy { 10 | 11 | /** 12 | * 最大重试次数,默认为2 13 | */ 14 | private int maxRetryTimes = 2; 15 | 16 | /** 17 | * Creates a new instance of FailOverStrategy. 18 | */ 19 | public FailOverStrategy() { 20 | 21 | } 22 | 23 | /** 24 | * Creates a new instance of FailOverStrategy. 25 | * 26 | * @param maxRetryTimes 27 | */ 28 | public FailOverStrategy(int maxRetryTimes) { 29 | this.maxRetryTimes = maxRetryTimes; 30 | } 31 | 32 | /** 33 | * @see com.baidu.beidou.navi.client.ha.FailStrategy#isQuitImmediately(int, int) 34 | */ 35 | @Override 36 | public boolean isQuitImmediately(int currentRetryTime, int clientSize) { 37 | if (currentRetryTime + 1 == getMaxRetryTimes() || currentRetryTime + 1 == clientSize) { 38 | return true; 39 | } 40 | return false; 41 | } 42 | 43 | /** 44 | * @see com.baidu.beidou.navi.client.ha.FailStrategy#getMaxRetryTimes() 45 | */ 46 | @Override 47 | public int getMaxRetryTimes() { 48 | return maxRetryTimes; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/TestSimpleCompanyService.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it; 2 | 3 | import javax.annotation.Resource; 4 | 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | 8 | import com.baidu.beidou.navi.it.service.CompanyService; 9 | 10 | public class TestSimpleCompanyService extends AbstractCompanyServiceTest { 11 | 12 | @Resource 13 | private CompanyService companyServiceDirectCall; 14 | 15 | @Test 16 | public void testGet() { 17 | testGet(companyServiceDirectCall); 18 | } 19 | 20 | @Test 21 | public void testGetMulti() { 22 | testGetMulti(companyServiceDirectCall); 23 | } 24 | 25 | @Test 26 | public void testGetAll() { 27 | testGetAll(companyServiceDirectCall); 28 | } 29 | 30 | @Test 31 | public void testGetMapByIds() { 32 | testGetMapByIds(companyServiceDirectCall); 33 | } 34 | 35 | @Test 36 | public void testAdd() { 37 | testAdd(companyServiceDirectCall); 38 | } 39 | 40 | @Test 41 | public void testAddNegative() { 42 | testAddNegative(companyServiceDirectCall); 43 | } 44 | 45 | @Test 46 | public void testDelete() { 47 | testDelete(companyServiceDirectCall); 48 | } 49 | 50 | @Before 51 | public void testInit() { 52 | testInit(companyServiceDirectCall); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /navi-demo-server/src/main/java/com/baidu/beidou/sample/performancetest/service/vo/BankAccount.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.sample.performancetest.service.vo; 2 | 3 | import java.util.Date; 4 | 5 | public class BankAccount { 6 | 7 | private Integer bankId; 8 | 9 | private String bankName; 10 | 11 | private int balance; 12 | 13 | private Date lastedWithdrawTime; 14 | 15 | public BankAccount() { 16 | super(); 17 | } 18 | 19 | public BankAccount(Integer bankId, String bankName, int balance, Date lastedWithdrawTime) { 20 | super(); 21 | this.bankId = bankId; 22 | this.bankName = bankName; 23 | this.balance = balance; 24 | this.lastedWithdrawTime = lastedWithdrawTime; 25 | } 26 | 27 | public Integer getBankId() { 28 | return bankId; 29 | } 30 | 31 | public void setBankId(Integer bankId) { 32 | this.bankId = bankId; 33 | } 34 | 35 | public String getBankName() { 36 | return bankName; 37 | } 38 | 39 | public void setBankName(String bankName) { 40 | this.bankName = bankName; 41 | } 42 | 43 | public int getBalance() { 44 | return balance; 45 | } 46 | 47 | public void setBalance(int balance) { 48 | this.balance = balance; 49 | } 50 | 51 | public Date getLastedWithdrawTime() { 52 | return lastedWithdrawTime; 53 | } 54 | 55 | public void setLastedWithdrawTime(Date lastedWithdrawTime) { 56 | this.lastedWithdrawTime = lastedWithdrawTime; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/TestHACompanyService2.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it; 2 | 3 | import javax.annotation.Resource; 4 | 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | 8 | import com.baidu.beidou.navi.it.service.CompanyService; 9 | 10 | public class TestHACompanyService2 extends AbstractCompanyServiceTest { 11 | 12 | @Resource 13 | private CompanyService companyServiceHANatureOrder; 14 | 15 | @Test 16 | public void testGet() { 17 | testGet(companyServiceHANatureOrder); 18 | } 19 | 20 | @Test 21 | public void testGetMulti() { 22 | testGetMulti(companyServiceHANatureOrder); 23 | } 24 | 25 | @Test 26 | public void testGetAll() { 27 | testGetAll(companyServiceHANatureOrder); 28 | } 29 | 30 | @Test 31 | public void testGetMapByIds() { 32 | testGetMapByIds(companyServiceHANatureOrder); 33 | } 34 | 35 | @Test 36 | public void testAdd() { 37 | testAdd(companyServiceHANatureOrder); 38 | } 39 | 40 | @Test 41 | public void testAddNegative() { 42 | testAddNegative(companyServiceHANatureOrder); 43 | } 44 | 45 | @Test 46 | public void testDelete() { 47 | testDelete(companyServiceHANatureOrder); 48 | } 49 | 50 | @Before 51 | public void testInit() { 52 | testInit(companyServiceHANatureOrder); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/TestJsonCompanyService.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it; 2 | 3 | import javax.annotation.Resource; 4 | 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | 8 | import com.baidu.beidou.navi.it.service.CompanyService; 9 | 10 | public class TestJsonCompanyService extends AbstractCompanyServiceTest { 11 | 12 | @Resource 13 | private CompanyService companyServiceDirectCallJson; 14 | 15 | @Test 16 | public void testGet() { 17 | testGet(companyServiceDirectCallJson); 18 | } 19 | 20 | @Test 21 | public void testGetMulti() { 22 | testGetMulti(companyServiceDirectCallJson); 23 | } 24 | 25 | @Test 26 | public void testGetAll() { 27 | testGetAll(companyServiceDirectCallJson); 28 | } 29 | 30 | @Test 31 | public void testGetMapByIds() { 32 | testGetMapByIds(companyServiceDirectCallJson); 33 | } 34 | 35 | @Test 36 | public void testAdd() { 37 | testAdd(companyServiceDirectCallJson); 38 | } 39 | 40 | @Test 41 | public void testAddNegative() { 42 | testAddNegative(companyServiceDirectCallJson); 43 | } 44 | 45 | @Test 46 | public void testDelete() { 47 | testDelete(companyServiceDirectCallJson); 48 | } 49 | 50 | @Before 51 | public void testInit() { 52 | testInit(companyServiceDirectCallJson); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/zoo/TestSimpleCompanyServiceWithZoo.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it.zoo; 2 | 3 | import javax.annotation.Resource; 4 | 5 | import org.junit.Before; 6 | import org.junit.Ignore; 7 | import org.junit.Test; 8 | 9 | import com.baidu.beidou.navi.it.service.CompanyService; 10 | 11 | @Ignore 12 | public class TestSimpleCompanyServiceWithZoo extends AbstractCompanyServiceZooTest { 13 | 14 | @Resource 15 | private CompanyService companyServiceEnableZoo; 16 | 17 | @Test 18 | public void testGet() { 19 | testGet(companyServiceEnableZoo); 20 | } 21 | 22 | @Test 23 | public void testGetMulti() { 24 | testGetMulti(companyServiceEnableZoo); 25 | } 26 | 27 | @Test 28 | public void testGetAll() { 29 | testGetAll(companyServiceEnableZoo); 30 | } 31 | 32 | @Test 33 | public void testGetMapByIds() { 34 | testGetMapByIds(companyServiceEnableZoo); 35 | } 36 | 37 | @Test 38 | public void testAdd() { 39 | testAdd(companyServiceEnableZoo); 40 | } 41 | 42 | @Test 43 | public void testAddNegative() { 44 | testAddNegative(companyServiceEnableZoo); 45 | } 46 | 47 | @Test 48 | public void testDelete() { 49 | testDelete(companyServiceEnableZoo); 50 | } 51 | 52 | @Before 53 | public void testInit() { 54 | testInit(companyServiceEnableZoo); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/Config.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it; 2 | 3 | import java.io.FileNotFoundException; 4 | import java.io.IOException; 5 | import java.util.Properties; 6 | 7 | public class Config { 8 | 9 | public static int PORT; 10 | 11 | public static int ZOO_SERVER_PORT; 12 | 13 | public static String ZOO_LIST; 14 | 15 | public static String ZOO_REGISTRY_NAMESPACE; 16 | 17 | public Config() { 18 | 19 | } 20 | 21 | private static Properties props = new Properties(); 22 | 23 | static { 24 | try { 25 | props.load(Thread.currentThread().getContextClassLoader() 26 | .getResourceAsStream("config.properties")); 27 | } catch (FileNotFoundException e) { 28 | e.printStackTrace(); 29 | } catch (IOException e) { 30 | e.printStackTrace(); 31 | } 32 | PORT = Integer.parseInt(getValue("server.port")); 33 | ZOO_SERVER_PORT = Integer.parseInt(getValue("zoo.server.port")); 34 | ZOO_LIST = getValue("zoo.zk_list"); 35 | ZOO_REGISTRY_NAMESPACE = getValue("zoo.zk_registry_namespace"); 36 | } 37 | 38 | public static String getValue(String key) { 39 | return props.getProperty(key); 40 | } 41 | 42 | public static void updateProperties(String key, String value) { 43 | props.setProperty(key, value); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/TestProtobufCompanyService.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it; 2 | 3 | import javax.annotation.Resource; 4 | 5 | import org.junit.Before; 6 | import org.junit.Test; 7 | 8 | import com.baidu.beidou.navi.it.service.CompanyService; 9 | 10 | public class TestProtobufCompanyService extends AbstractCompanyServiceTest { 11 | 12 | @Resource 13 | private CompanyService companyServiceDirectCallProtobuf; 14 | 15 | @Test 16 | public void testGet() { 17 | testGet(companyServiceDirectCallProtobuf); 18 | } 19 | 20 | @Test 21 | public void testGetMulti() { 22 | testGetMulti(companyServiceDirectCallProtobuf); 23 | } 24 | 25 | @Test 26 | public void testGetAll() { 27 | testGetAll(companyServiceDirectCallProtobuf); 28 | } 29 | 30 | @Test 31 | public void testGetMapByIds() { 32 | testGetMapByIds(companyServiceDirectCallProtobuf); 33 | } 34 | 35 | @Test 36 | public void testAdd() { 37 | testAdd(companyServiceDirectCallProtobuf); 38 | } 39 | 40 | @Test 41 | public void testAddNegative() { 42 | testAddNegative(companyServiceDirectCallProtobuf); 43 | } 44 | 45 | @Test 46 | public void testDelete() { 47 | testDelete(companyServiceDirectCallProtobuf); 48 | } 49 | 50 | @Before 51 | public void testInit() { 52 | testInit(companyServiceDirectCallProtobuf); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/server/locator/ServiceLocator.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.server.locator; 2 | 3 | import java.util.Collection; 4 | 5 | import com.baidu.beidou.navi.server.ServiceNameAware; 6 | 7 | /** 8 | * ClassName: ServiceLocator
9 | * Function: 服务定位器,用于注入服务到运行容器,可辅助入口端路由到指定方法,另外还可以发布服务,例如到zookeeper中。 10 | *

11 | * 泛型<KEY>标示服务的唯一标示,例如可以是一个int的数字id,可以是一个String字符串; 12 | * 泛型<V>标示服务bean的一个封装,在上层作为基础路由定位到bean粒度级别的类型 13 | * 14 | * @author Zhang Xu 15 | */ 16 | public interface ServiceLocator { 17 | 18 | /** 19 | * 获取所有服务(通常是接口名称) 20 | * 21 | * @return 服务集合 22 | */ 23 | Collection getAllServices(); 24 | 25 | /** 26 | * 根据服务名称(通常是接口名称)获取服务 27 | * 28 | * @param 服务名称 29 | * @return 服务的一个封装 30 | */ 31 | V getService(String serviceName); 32 | 33 | /** 34 | * 根据服务标示获取服务方法的描述 35 | * 36 | * @param key 37 | * @return 服务方法的描述 38 | */ 39 | MethodDescriptor getServiceDescriptor(KEY key); 40 | 41 | /** 42 | * 注入服务 43 | * 44 | * @param v 45 | * 服务的实例或者封装类 46 | * @return 是否注册成功 47 | */ 48 | boolean regiserService(V v); 49 | 50 | /** 51 | * 整体发布服务 52 | * 53 | * @param handler 54 | * 发布处理handler 55 | * @return 是否发布成功 56 | */ 57 | boolean publishService(PublishHandler handler); 58 | 59 | } 60 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/js/common.js: -------------------------------------------------------------------------------- 1 | // 初始入口 2 | (function() { 3 | window.VISITOR = {}; 4 | })(); 5 | 6 | // 7 | // 头部显示初始化 8 | // 9 | function headShowInit() { 10 | if (VISITOR.id) { 11 | $(".login-no").hide(); 12 | $(".login-yes").show(); 13 | $("#username").show(); 14 | $("#username").html(VISITOR.name); 15 | } else { 16 | $(".login-no").show(); 17 | $(".login-yes").hide(); 18 | $("#username").hide(); 19 | } 20 | } 21 | 22 | // 23 | // 获取Session信息 24 | // 25 | function getSession() { 26 | $.ajax({ 27 | type: "GET", 28 | url: "/userSession", 29 | timeout: 3000, 30 | dataType: "json" 31 | }).done(function(result) { 32 | if (result.status == 0) { 33 | window.VISITOR.id = result.data.id; 34 | window.VISITOR.name = result.data.name; 35 | headShowInit(); 36 | } else { 37 | window.location.href = "/login.html"; 38 | } 39 | }).fail(function(xmlHttpRequest, textStatus) { 40 | window.location.href = "/login.html"; 41 | }); 42 | } 43 | 44 | // 获取是否登录并且进行跳转 45 | function getSession2Redirect() { 46 | $.ajax({ 47 | type: "GET", 48 | url: "/userSession", 49 | dataType: "json" 50 | }).done(function(result) { 51 | if (result.status == 0) { 52 | window.location.href = "/main.html"; 53 | } else {} 54 | }); 55 | //loginActions(); 56 | } -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/service/CompanyService.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it.service; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import com.baidu.beidou.navi.vo.Company; 7 | 8 | /** 9 | * ClassName: CompanyMgr
10 | * Function: 测试用服务,一个公司举例的服务 11 | * 12 | * @author Zhang Xu 13 | */ 14 | public interface CompanyService { 15 | 16 | /** 17 | * init 18 | */ 19 | void init(); 20 | 21 | /** 22 | * 根据公司id获取公司 23 | * 24 | * @param id 25 | * @return 26 | */ 27 | Company get(int id); 28 | 29 | /** 30 | * 批量的{@link #get(int)} 31 | * 32 | * @param ids 33 | * @return 34 | */ 35 | List getByIds(List ids); 36 | 37 | /** 38 | * 根据公司id批量获取id到公司的字典 39 | * 40 | * @param ids 41 | * @return 42 | */ 43 | Map getMapByIds(List ids); 44 | 45 | /** 46 | * 获取所有 47 | * 48 | * @return 49 | */ 50 | List getAll(); 51 | 52 | /** 53 | * 添加 54 | * 55 | * @param company 56 | * @return 57 | */ 58 | Company add(Company company); 59 | 60 | /** 61 | * 删除 62 | * 63 | * @param id 64 | */ 65 | void delete(int id); 66 | 67 | /** 68 | * 更新 69 | * 70 | * @param company 71 | */ 72 | void update(Company company); 73 | 74 | } 75 | -------------------------------------------------------------------------------- /navi-demo-client/src/test/java/com/baidu/beidou/sample/xml/BookMgrTest.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.sample.xml; 2 | 3 | import static org.hamcrest.Matchers.is; 4 | import static org.junit.Assert.assertThat; 5 | 6 | import java.util.List; 7 | 8 | import javax.annotation.Resource; 9 | 10 | import org.junit.Test; 11 | import org.springframework.test.context.ContextConfiguration; 12 | import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; 13 | 14 | import com.baidu.beidou.sample.xml.service.BookMgr; 15 | import com.baidu.beidou.sample.xml.vo.Book; 16 | 17 | @ContextConfiguration(locations = { "classpath:applicationContext-test-xml.xml" }) 18 | public class BookMgrTest extends AbstractJUnit4SpringContextTests { 19 | 20 | @Resource 21 | private BookMgr bookMgr; 22 | 23 | @Test 24 | public void testGetAll() { 25 | List result = bookMgr.getAll(); 26 | for (Book book : result) { 27 | System.out.println(book); 28 | } 29 | assertThat(result.size(), is(3)); 30 | } 31 | 32 | @Test 33 | public void testGetById() { 34 | try { 35 | Book result = bookMgr.get(999, "123"); 36 | System.out.println(result); 37 | } catch (Exception e) { 38 | e.printStackTrace(); 39 | } 40 | 41 | Book result = bookMgr.get("123"); 42 | System.out.println(result); 43 | 44 | result = bookMgr.get(999); 45 | System.out.println(result); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/server/vo/NaviRpcResponse.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.server.vo; 2 | 3 | /** 4 | * ClassName: NaviRpcResponse
5 | * Function: NaviRpc结果逻辑对象 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public class NaviRpcResponse { 10 | 11 | /** 12 | * 响应字节码 13 | */ 14 | private byte[] response; 15 | 16 | /** 17 | * 响应DTO 18 | */ 19 | private ResponseDTO responseDTO; 20 | 21 | /** 22 | * Creates a new instance of NaviRpcResponse. 23 | */ 24 | public NaviRpcResponse() { 25 | 26 | } 27 | 28 | /** 29 | * Creates a new instance of NaviRpcResponse. 30 | * 31 | * @param response 32 | */ 33 | public NaviRpcResponse(byte[] response) { 34 | this.response = response; 35 | } 36 | 37 | /** 38 | * Creates a new instance of NaviRpcResponse. 39 | * 40 | * @param responseDTO 41 | */ 42 | public NaviRpcResponse(ResponseDTO responseDTO) { 43 | this.responseDTO = responseDTO; 44 | } 45 | 46 | public byte[] getResponse() { 47 | return response; 48 | } 49 | 50 | public void setResponse(byte[] response) { 51 | this.response = response; 52 | } 53 | 54 | public ResponseDTO getResponseDTO() { 55 | return responseDTO; 56 | } 57 | 58 | public void setResponseDTO(ResponseDTO responseDTO) { 59 | this.responseDTO = responseDTO; 60 | } 61 | 62 | } -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/vo/Book2.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.vo; 2 | 3 | import org.apache.commons.lang.builder.ToStringBuilder; 4 | import org.apache.commons.lang.builder.ToStringStyle; 5 | 6 | public class Book2 { 7 | 8 | /** 9 | * 书籍ID 10 | */ 11 | private int id; 12 | 13 | /** 14 | * 名称 15 | */ 16 | private String name; 17 | 18 | /** 19 | * 增加的新列 20 | */ 21 | private String extraField; 22 | 23 | public Book2() { 24 | 25 | } 26 | 27 | public Book2(int id, String name, String extraField) { 28 | this.id = id; 29 | this.name = name; 30 | this.extraField = extraField; 31 | } 32 | 33 | public int getId() { 34 | return id; 35 | } 36 | 37 | public void setId(int id) { 38 | this.id = id; 39 | } 40 | 41 | public String getName() { 42 | return name; 43 | } 44 | 45 | public void setName(String name) { 46 | this.name = name; 47 | } 48 | 49 | public String getExtraField() { 50 | return extraField; 51 | } 52 | 53 | public void setExtraField(String extraField) { 54 | this.extraField = extraField; 55 | } 56 | 57 | public String toString() { 58 | return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).append("id", this.getId()) 59 | .append("name", name).append("extraField", extraField).toString(); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/java/com/baidu/beidou/navimgr/auth/vo/BaseObject.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navimgr.auth.vo; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * @author zhangxu 7 | */ 8 | public abstract class BaseObject implements Serializable, Cloneable { 9 | 10 | private static final long serialVersionUID = 8854260536880579592L; 11 | 12 | /** 13 | * 该对象的业务主键 14 | */ 15 | protected K id; 16 | 17 | /** 18 | * @return the id 19 | */ 20 | public K getId() { 21 | return id; 22 | } 23 | 24 | /** 25 | * @param id the id to set 26 | */ 27 | public void setId(K id) { 28 | this.id = id; 29 | } 30 | 31 | @Override 32 | public Object clone() throws CloneNotSupportedException { 33 | return super.clone(); 34 | } 35 | 36 | public int hashCode() { 37 | int result = 17; 38 | result = 37 * result + (getId() == null ? 0 : this.getId().hashCode()); 39 | return result; 40 | } 41 | 42 | @SuppressWarnings("rawtypes") 43 | public boolean equals(Object obj) { 44 | if (obj == null) { 45 | return false; 46 | } 47 | 48 | if (!this.getClass().equals(obj.getClass())) { 49 | return false; 50 | } 51 | 52 | K k1 = this.getId(); 53 | @SuppressWarnings("unchecked") 54 | K k2 = (K) ((BaseObject) obj).getId(); 55 | return k1 != null && k2 != null && k1.equals(k2); 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/protocol/SerializeHandlerFactory.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.protocol; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import com.baidu.beidou.navi.exception.InvalidProtocolException; 7 | 8 | /** 9 | * ClassName: SerializeHandlerFactory
10 | * Function: 序列化、反序列化工厂 11 | * 12 | * @author Zhang Xu 13 | */ 14 | public class SerializeHandlerFactory { 15 | 16 | /** 17 | * handler缓存map 18 | */ 19 | private static final Map HANDLER_MAP = new HashMap(); 20 | 21 | /** 22 | * 初始化 23 | */ 24 | static { 25 | HANDLER_MAP.put(NaviProtocol.PROTOSTUFF.getName(), new ProtostuffSerializeHandler()); 26 | HANDLER_MAP.put(NaviProtocol.PROTOBUF.getName(), new ProtobufSerializeHandler()); 27 | HANDLER_MAP.put(NaviProtocol.JSON.getName(), new JsonSerializeHandler()); 28 | } 29 | 30 | /** 31 | * 根据http请求中的content-type尝试寻找序列化handler 32 | * 33 | * @param protocol 34 | * @return 35 | * @throws InvalidProtocolException 36 | */ 37 | public static SerializeHandler getHandlerByProtocal(String protocol) 38 | throws InvalidProtocolException { 39 | SerializeHandler handler = HANDLER_MAP.get(protocol); 40 | if (handler != null) { 41 | return handler; 42 | } 43 | throw new InvalidProtocolException("rpc protocol not supported for " + protocol); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/server/vo/NaviRpcRequest.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.server.vo; 2 | 3 | import com.baidu.beidou.navi.server.NaviRpcExporter; 4 | 5 | /** 6 | * ClassName: NaviRpcRequest
7 | * Function: NaviRpc请求逻辑对象 8 | * 9 | * @author Zhang Xu 10 | */ 11 | public class NaviRpcRequest { 12 | 13 | /** 14 | * 服务接口以及实现定义 15 | */ 16 | private NaviRpcExporter exporter; 17 | 18 | /** 19 | * 请求字节码 20 | */ 21 | private byte[] request; 22 | 23 | /** 24 | * 请求DTO 25 | */ 26 | private RequestDTO requestDTO; 27 | 28 | /** 29 | * Creates a new instance of NaviRpcRequest. 30 | * 31 | * @param exporter 32 | * @param request 33 | */ 34 | public NaviRpcRequest(NaviRpcExporter exporter, byte[] request) { 35 | this.exporter = exporter; 36 | this.request = request; 37 | } 38 | 39 | public NaviRpcExporter getExporter() { 40 | return exporter; 41 | } 42 | 43 | public void setExporter(NaviRpcExporter exporter) { 44 | this.exporter = exporter; 45 | } 46 | 47 | public byte[] getRequest() { 48 | return request; 49 | } 50 | 51 | public void setRequest(byte[] request) { 52 | this.request = request; 53 | } 54 | 55 | public RequestDTO getRequestDTO() { 56 | return requestDTO; 57 | } 58 | 59 | public void setRequestDTO(RequestDTO requestDTO) { 60 | this.requestDTO = requestDTO; 61 | } 62 | 63 | } -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/assets/js/modifycommon.js: -------------------------------------------------------------------------------- 1 | // 2 | // 获取指定配置下的配置数据 3 | // 4 | function fetchItems(appId, envId, version, curConfigId) { 5 | 6 | var parameter = "" 7 | 8 | url = "/api/web/config/simple/list"; 9 | url += "?"; 10 | url += "appId=" + appId + "&"; 11 | url += "envId=" + envId + "&"; 12 | url += "version=" + version + "&"; 13 | 14 | $.ajax({ 15 | type: "GET", 16 | url: url 17 | }).done(function (data) { 18 | if (data.success === "true") { 19 | var html = '

  • 配置文件/配置项列表
  • '; 20 | var result = data.page.result; 21 | $.each(result, function (index, item) { 22 | html += renderItem(item); 23 | }); 24 | $("#sidebarcur").html(html); 25 | } 26 | }); 27 | var mainTpl = $("#tItemTpl").html(); 28 | // 渲染主列表 29 | function renderItem(item) { 30 | 31 | var link = ""; 32 | var key = ""; 33 | if (item.type == "配置文件") { 34 | link = 'modifyFile.html?configId=' + item.configId; 35 | key = '' + item.key; 36 | } else { 37 | link = 'modifyItem.html?configId=' + item.configId; 38 | key = '' + item.key; 39 | } 40 | 41 | var style = ""; 42 | if (item.configId == curConfigId) { 43 | style = "active"; 44 | } 45 | 46 | return Util.string.format(mainTpl, key, link, style); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /navi/src/test/resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 16 | 17 | 18 | 19 | 20 | classpath*:config.properties 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /navi-demo-server/src/main/java/com/baidu/beidou/sample/annotation/vo/Company.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.sample.annotation.vo; 2 | 3 | import java.util.Date; 4 | import java.util.List; 5 | 6 | import org.apache.commons.lang.builder.ToStringBuilder; 7 | import org.apache.commons.lang.builder.ToStringStyle; 8 | 9 | public class Company extends BaseObject { 10 | 11 | private String name; 12 | 13 | private Date establishTime; 14 | 15 | private List departmentList; 16 | 17 | public Company() { 18 | super(); 19 | } 20 | 21 | public Company(Integer id, String name, Date establishTime, List departmentList) { 22 | super(); 23 | this.setId(id); 24 | this.name = name; 25 | this.establishTime = establishTime; 26 | this.departmentList = departmentList; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public void setName(String name) { 34 | this.name = name; 35 | } 36 | 37 | public List getDepartmentList() { 38 | return departmentList; 39 | } 40 | 41 | public void setDepartmentList(List departmentList) { 42 | this.departmentList = departmentList; 43 | } 44 | 45 | public Date getEstablishTime() { 46 | return establishTime; 47 | } 48 | 49 | public void setEstablishTime(Date establishTime) { 50 | this.establishTime = establishTime; 51 | } 52 | 53 | public String toString() { 54 | return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE) 55 | .append("id", this.getId()) 56 | .append("name", name) 57 | .append("establishTime", establishTime) 58 | .append("departmentList", departmentList) 59 | .toString(); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/util/SystemPropertiesUtils.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.util; 2 | 3 | /** 4 | * ClassName: SystemPropertiesUtils
    5 | * Function: 系统properties工具类 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public class SystemPropertiesUtils { 10 | 11 | public static String getSystemProperty(String key, String defautValue) { 12 | String value = System.getProperty(key); 13 | if (value == null || value.length() == 0) { 14 | value = System.getenv(key); 15 | if (value == null || value.length() == 0) { 16 | value = defautValue; 17 | } 18 | } 19 | return value; 20 | } 21 | 22 | /** 23 | * Get system property 24 | * 25 | * @param dKey 26 | * -D parameter 27 | * @param shellKey 28 | * shell defined system environment property 29 | * @param defautValue 30 | * @return system property 31 | */ 32 | public static String getSystemProperty(String dKey, String shellKey, String defautValue) { 33 | String value = System.getProperty(dKey); 34 | if (value == null || value.length() == 0) { 35 | value = System.getenv(shellKey); 36 | if (value == null || value.length() == 0) { 37 | value = defautValue; 38 | } 39 | } 40 | return value; 41 | } 42 | 43 | public static boolean isDebug() { 44 | return java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments() 45 | .toString().indexOf("-agentlib:jdwp") > 0; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /navi-demo-client/src/main/java/com/baidu/beidou/sample/util/codec/protobuf/ProtobufCodec.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.sample.util.codec.protobuf; 2 | 3 | import com.dyuproject.protostuff.LinkedBuffer; 4 | import com.dyuproject.protostuff.Schema; 5 | import com.dyuproject.protostuff.runtime.RuntimeSchema; 6 | 7 | import com.baidu.beidou.navi.codec.Codec; 8 | 9 | public class ProtobufCodec implements Codec { 10 | 11 | public static final String NAME = "protostuff"; 12 | 13 | static { 14 | System.setProperty("protostuff.runtime.collection_schema_on_repeated_fields", "true"); 15 | System.setProperty("protostuff.runtime.morph_collection_interfaces", "true"); 16 | System.setProperty("protostuff.runtime.morph_map_interfaces", "true"); 17 | } 18 | 19 | private ThreadLocal linkedBuffer = new ThreadLocal() { 20 | @Override 21 | protected LinkedBuffer initialValue() { 22 | return LinkedBuffer.allocate(500); 23 | } 24 | }; 25 | 26 | public T decode(Class clazz, byte[] bytes) throws Exception { 27 | Schema schema = RuntimeSchema.getSchema(clazz); 28 | T content = clazz.newInstance(); 29 | ProtobufUtils.mergeFrom(bytes, content, schema); 30 | return content; 31 | } 32 | 33 | public byte[] encode(Class clazz, T object) throws Exception { 34 | try { 35 | Schema schema = RuntimeSchema.getSchema(clazz); 36 | byte[] protostuff = ProtobufUtils.toByteArray(object, schema, linkedBuffer.get()); 37 | return protostuff; 38 | } finally { 39 | linkedBuffer.get().clear(); 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /navi-demo-client/src/main/java/com/baidu/beidou/sample/util/codec/protostuff/ProtostuffCodec.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.sample.util.codec.protostuff; 2 | 3 | import com.dyuproject.protostuff.LinkedBuffer; 4 | import com.dyuproject.protostuff.Schema; 5 | import com.dyuproject.protostuff.runtime.RuntimeSchema; 6 | 7 | import com.baidu.beidou.navi.codec.Codec; 8 | 9 | public class ProtostuffCodec implements Codec { 10 | 11 | public static final String NAME = "protostuff"; 12 | 13 | static { 14 | System.setProperty("protostuff.runtime.collection_schema_on_repeated_fields", "true"); 15 | System.setProperty("protostuff.runtime.morph_collection_interfaces", "true"); 16 | System.setProperty("protostuff.runtime.morph_map_interfaces", "true"); 17 | } 18 | 19 | private ThreadLocal linkedBuffer = new ThreadLocal() { 20 | @Override 21 | protected LinkedBuffer initialValue() { 22 | return LinkedBuffer.allocate(500); 23 | } 24 | }; 25 | 26 | public T decode(Class clazz, byte[] bytes) throws Exception { 27 | Schema schema = RuntimeSchema.getSchema(clazz); 28 | T content = clazz.newInstance(); 29 | ProtostuffUtils.mergeFrom(bytes, content, schema); 30 | return content; 31 | } 32 | 33 | public byte[] encode(Class clazz, T object) throws Exception { 34 | try { 35 | Schema schema = RuntimeSchema.getSchema(clazz); 36 | byte[] protostuff = ProtostuffUtils.toByteArray(object, schema, linkedBuffer.get()); 37 | return protostuff; 38 | } finally { 39 | linkedBuffer.get().clear(); 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/client/ha/LbFactory.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.client.ha; 2 | 3 | import com.baidu.beidou.navi.client.selector.NaviFailStrategy; 4 | import com.baidu.beidou.navi.client.selector.NaviSelectorStrategy; 5 | import com.baidu.beidou.navi.conf.RpcClientConf; 6 | 7 | /** 8 | * ClassName: LbFactory
    9 | * Function: 负载均衡器工厂 10 | * 11 | * @author Zhang Xu 12 | */ 13 | public class LbFactory { 14 | 15 | /** 16 | * 构造负载均衡封装 17 | * 18 | * @param selectorStg 19 | * @param failStg 20 | * @return 21 | */ 22 | public static LoadBalanceStrategy build(NaviSelectorStrategy selectorStg, 23 | NaviFailStrategy failStg) { 24 | if (NaviSelectorStrategy.RANDOM.equals(selectorStg)) { 25 | return new RandomLoadBalanceStrategy(howToDealFailure(failStg)); 26 | } else if (NaviSelectorStrategy.ROUNDROBIN.equals(selectorStg)) { 27 | return new RRLoadBalanceStrategy(howToDealFailure(failStg)); 28 | } else if (NaviSelectorStrategy.NATURALORDER.equals(selectorStg)) { 29 | return new NatureOrderLoadBalanceStrategy(howToDealFailure(failStg)); 30 | } 31 | return new RandomLoadBalanceStrategy(howToDealFailure(failStg)); 32 | } 33 | 34 | /** 35 | * 构造容错处理策略 36 | * 37 | * @param failStg 38 | * @return 39 | */ 40 | private static FailStrategy howToDealFailure(NaviFailStrategy failStg) { 41 | if (NaviFailStrategy.FAILOVER.equals(failStg)) { 42 | return new FailOverStrategy(RpcClientConf.RPC_RETRY_TIMES); 43 | } else if (NaviFailStrategy.FAILFAST.equals(failStg)) { 44 | return new FailFastStrategy(); 45 | } 46 | return new FailOverStrategy(); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/java/com/baidu/beidou/navimgr/auth/vo/User.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navimgr.auth.vo; 2 | 3 | import java.util.Set; 4 | 5 | import com.google.common.collect.Sets; 6 | 7 | /** 8 | * ClassName: User
    9 | * Function: 用户实体 10 | * 11 | * @author Zhang Xu 12 | */ 13 | public class User extends BaseObject { 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | /** 18 | * 用户的userId 19 | */ 20 | private int userId; 21 | 22 | /** 23 | * 密码MD5 24 | */ 25 | private String passwordMd5; 26 | 27 | /** 28 | * 用户名 29 | */ 30 | private String userName; 31 | 32 | /** 33 | * 用户角色 34 | */ 35 | private Set roles = Sets.newHashSet(); 36 | 37 | /** 38 | * 用户权限 39 | */ 40 | private Set auths = Sets.newHashSet(); 41 | 42 | public int getUserId() { 43 | return userId; 44 | } 45 | 46 | public void setUserId(int userId) { 47 | this.userId = userId; 48 | } 49 | 50 | public String getPasswordMd5() { 51 | return passwordMd5; 52 | } 53 | 54 | public void setPasswordMd5(String passwordMd5) { 55 | this.passwordMd5 = passwordMd5; 56 | } 57 | 58 | public String getUserName() { 59 | return userName; 60 | } 61 | 62 | public void setUserName(String userName) { 63 | this.userName = userName; 64 | } 65 | 66 | public Set getRoles() { 67 | return roles; 68 | } 69 | 70 | public void setRoles(Set roles) { 71 | this.roles = roles; 72 | } 73 | 74 | public Set getAuths() { 75 | return auths; 76 | } 77 | 78 | public void setAuths(Set auths) { 79 | this.auths = auths; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/util/ZkRegisterInfoUtil.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.util; 2 | 3 | import com.baidu.beidou.navi.conf.RpcServerConf; 4 | import com.baidu.beidou.navi.constant.NaviCommonConstant; 5 | 6 | /** 7 | * ClassName: ZkRegisterInfoUtil
    8 | * Function: 注册到zookeeper的IP/Host/端口信息工具类 9 | * 10 | * @author Zhang Xu 11 | */ 12 | public class ZkRegisterInfoUtil { 13 | 14 | /** 15 | * 获取本地ip 16 | * 17 | * @return 本地ip 18 | */ 19 | public static String getLocalHostIp() { 20 | String localIp = NetUtils.getLocalHostIP(); 21 | return SystemPropertiesUtils.getSystemProperty( 22 | NaviCommonConstant.SYSTEM_PROPERTY_SERVER_HOST_FROM_ENV_4JPAAS2, localIp); 23 | } 24 | 25 | /** 26 | * 获取本地hostname 27 | * 28 | * @return 本地host 29 | */ 30 | public static String getLocalHostName() { 31 | String localHostName = NetUtils.getHostName(); 32 | return SystemPropertiesUtils.getSystemProperty( 33 | NaviCommonConstant.SYSTEM_PROPERTY_SERVER_HOST_FROM_ENV_4JPAAS2, localHostName); 34 | } 35 | 36 | /** 37 | * 获取服务端口 38 | * 39 | * @return 本地ipport 40 | */ 41 | public static String getLocalHostPort() { 42 | String defaultPort = SystemPropertiesUtils.getSystemProperty( 43 | NaviCommonConstant.SYSTEM_PROPERTY_SERVER_PORT_FROM_SLASH_D_4JPAAS1, 44 | NaviCommonConstant.SYSTEM_PROPERTY_SERVER_PORT_FROM_ENV_4JPAAS1, "" 45 | + RpcServerConf.SERVER_PORT); 46 | return SystemPropertiesUtils.getSystemProperty( 47 | NaviCommonConstant.SYSTEM_PROPERTY_SERVER_PORT_FROM_ENV_4JPAAS2, defaultPort); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/server/vo/AppIdToken.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.server.vo; 2 | 3 | import com.baidu.beidou.navi.util.StringUtil; 4 | 5 | /** 6 | * ClassName: AppIdToken
    7 | * Function: 进行权限控制的appId+token封装类 8 | * 9 | * @author Zhang Xu 10 | */ 11 | public class AppIdToken { 12 | 13 | /** 14 | * appId 15 | */ 16 | private String appId; 17 | 18 | /** 19 | * token 20 | */ 21 | private String token; 22 | 23 | /** 24 | * Creates a new instance of AppIdToken. 25 | * 26 | * @param appId 27 | * APP ID 28 | * @param token 29 | * TOKEN 30 | */ 31 | public AppIdToken(String appId, String token) { 32 | super(); 33 | this.appId = appId; 34 | this.token = token; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return appId + StringUtil.COLON + token; 40 | } 41 | 42 | /** 43 | * 是否相同 44 | * 45 | * @param appId 46 | * APP ID 47 | * @param token 48 | * TOKEN 49 | * @return 是否合法相同 50 | */ 51 | public static boolean isValid(AppIdToken appIdToken, String appId, String token) { 52 | if (appIdToken == null || StringUtil.isEmpty(appId) || StringUtil.isEmpty(token)) { 53 | return false; 54 | } 55 | return appIdToken.appId.equals(appId) && appIdToken.token.equals(token); 56 | } 57 | 58 | public String getAppId() { 59 | return appId; 60 | } 61 | 62 | public void setAppId(String appId) { 63 | this.appId = appId; 64 | } 65 | 66 | public String getToken() { 67 | return token; 68 | } 69 | 70 | public void setToken(String token) { 71 | this.token = token; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/java/com/baidu/beidou/navimgr/common/interceptor/WebCommonInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navimgr.common.interceptor; 2 | 3 | import java.io.IOException; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; 11 | 12 | import com.baidu.beidou.navimgr.common.constant.WebResponseConstant; 13 | import com.baidu.beidou.navimgr.common.vo.JsonObject; 14 | import com.baidu.beidou.navimgr.util.JsonUtils; 15 | import com.baidu.unbiz.biz.result.ResultCode; 16 | 17 | /** 18 | * ClassName: WebCommonInterceptor
    19 | * Function: web ui公共拦截器 20 | * 21 | * @author Zhang Xu 22 | */ 23 | public class WebCommonInterceptor extends HandlerInterceptorAdapter { 24 | 25 | /** 26 | * 当拦截器内发生错误时,返回json格式的错误信息 27 | * 28 | * @param request 29 | * 请求request 30 | * @param response 31 | * 返回response 32 | * @param message 33 | * 错误消息 34 | * @throws IOException 35 | */ 36 | protected void returnJsonSystemError(HttpServletRequest request, HttpServletResponse response, 37 | ResultCode resultCode) throws IOException { 38 | Map errors = new HashMap(); 39 | errors.put(WebResponseConstant.MESSAGE_GLOBAL, resultCode.getMessage().getMessage()); 40 | JsonObject json = JsonObject.create(); 41 | json.setStatus(resultCode.getCode()); 42 | json.setStatusInfo(errors); 43 | response.setContentType("application/json; charset=UTF-8"); 44 | response.setCharacterEncoding("UTF-8"); 45 | response.getWriter().write(JsonUtils.toJson(json)); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/java/com/baidu/beidou/navimgr/auth/interceptor/UserIdInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navimgr.auth.interceptor; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | 6 | import org.apache.commons.lang.StringUtils; 7 | 8 | import com.baidu.beidou.navimgr.auth.constant.UserWebConstant; 9 | import com.baidu.beidou.navimgr.common.constant.GlobalResponseStatusMsg; 10 | import com.baidu.beidou.navimgr.common.interceptor.WebCommonInterceptor; 11 | import com.baidu.beidou.navimgr.util.ThreadContext; 12 | 13 | /** 14 | * ClassName: UserIdInterceptor
    15 | * Function: 登陆访问者拦截器 16 | * 17 | * @author Zhang Xu 18 | */ 19 | public class UserIdInterceptor extends WebCommonInterceptor { 20 | 21 | /** 22 | * @see org.springframework.web.servlet.handler.HandlerInterceptorAdapter#preHandle(javax.servlet.http.HttpServletRequest, 23 | * javax.servlet.http.HttpServletResponse, java.lang.Object) 24 | */ 25 | @Override 26 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, 27 | Object handler) throws Exception { 28 | String userIdStr = request.getParameter(UserWebConstant.USERID); 29 | if (StringUtils.isEmpty(userIdStr)) { 30 | returnJsonSystemError(request, response, GlobalResponseStatusMsg.PARAM_MISS_ERROR); 31 | return false; 32 | } 33 | 34 | Integer userId = null; 35 | if (!StringUtils.isNumeric(userIdStr)) { 36 | returnJsonSystemError(request, response, GlobalResponseStatusMsg.PARAM_TYPE_ERROR); 37 | return false; 38 | } 39 | 40 | userId = Integer.parseInt(userIdStr); 41 | ThreadContext.putContext(UserWebConstant.CTX_USERID, userId); 42 | return true; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/TestSimpleNaviRpcClient.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it; 2 | 3 | import static org.hamcrest.Matchers.is; 4 | import static org.junit.Assert.assertThat; 5 | 6 | import org.junit.Test; 7 | 8 | import com.baidu.beidou.navi.client.SimpleNaviRpcClient; 9 | import com.baidu.beidou.navi.client.SimpleNaviRpcClientBuilder; 10 | import com.baidu.beidou.navi.exception.rpc.CodecException; 11 | import com.baidu.beidou.navi.protocol.NaviProtocol; 12 | import com.baidu.beidou.navi.vo.Company; 13 | 14 | public class TestSimpleNaviRpcClient extends BaseTest { 15 | 16 | private static final String IPPORT = "127.0.0.1:" + Config.PORT; 17 | 18 | @Test 19 | public void testSimpleGet() throws Throwable { 20 | Object[] args = new Object[] { 88 }; 21 | SimpleNaviRpcClient client = new SimpleNaviRpcClientBuilder().setIpPort(IPPORT) 22 | .setServiceName("CompanyService").setConnectTimeout(5000).setReadTimeout(5000) 23 | .build(); 24 | Company result = client.transport("get", args); 25 | System.out.println(result); 26 | } 27 | 28 | @Test 29 | public void testSimpleGetNegative() throws Throwable { 30 | try { 31 | Object[] args = new Object[] { 88 }; 32 | SimpleNaviRpcClient client = new SimpleNaviRpcClientBuilder().setIpPort(IPPORT) 33 | .setServiceName("CompanyService").setConnectTimeout(5000).setReadTimeout(5000) 34 | .setProtocol(NaviProtocol.JSON.getName()).build(); 35 | Company result = client.transport("get", args); 36 | System.out.println(result); 37 | } catch (CodecException e) { 38 | assertThat(e.getClass().getName(), is(CodecException.class.getName())); 39 | return; 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/codec/json/JsonCodec.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.codec.json; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | import org.codehaus.jackson.JsonNode; 6 | 7 | import com.baidu.beidou.navi.codec.Codec; 8 | 9 | /** 10 | * ClassName: JsonCodec
    11 | * Function: Json编码器 12 | * 13 | * @author Zhang Xu 14 | */ 15 | public class JsonCodec implements Codec { 16 | 17 | /** 18 | * Jackson json的Mapper 19 | */ 20 | private JsonMapper mapper = JsonMapper.buildNormalMapper(); 21 | 22 | /** 23 | * @see com.baidu.beidou.navi.codec.Codec#decode(java.lang.Class, byte[]) 24 | */ 25 | @Override 26 | public T decode(Class clazz, byte[] bytes) throws Exception { 27 | return mapper.fromJsonBytes(bytes, clazz); 28 | } 29 | 30 | /** 31 | * @see com.baidu.beidou.navi.codec.Codec#encode(java.lang.Class, java.lang.Object) 32 | */ 33 | @Override 34 | public byte[] encode(Class clazz, T object) throws Exception { 35 | return mapper.toJsonBytes(object); 36 | } 37 | 38 | /** 39 | * 解码成JsonNode 40 | * 41 | * @param bytes 42 | * @return 43 | * @throws Exception 44 | */ 45 | public JsonNode decode(byte[] bytes) throws Exception { 46 | JsonNode jsonNode = mapper.fromJson(bytes); 47 | return jsonNode; 48 | } 49 | 50 | /** 51 | * 根据JsonNode以及Type还原对象 52 | * 53 | * @param type 54 | * @param jsonNode 55 | * @return 56 | * @throws Exception 57 | */ 58 | @SuppressWarnings("unchecked") 59 | public T decode(Type type, JsonNode jsonNode) throws Exception { 60 | return (T) (mapper.fromJson(jsonNode, type)); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/conf/RpcClientConf.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.conf; 2 | 3 | import com.baidu.beidou.navi.client.selector.NaviFailStrategy; 4 | 5 | /** 6 | * ClassName: RpcClientConf
    7 | * Function: 客户端配置 8 | * 9 | * @author Zhang Xu 10 | */ 11 | public class RpcClientConf extends RpcBaseConf { 12 | 13 | /** 14 | * 订阅的服务端地址 15 | */ 16 | public static String[] ZK_WATCH_NAMESPACE_PATHS = {}; 17 | 18 | /** 19 | * 调用连接建立超时时间 20 | */ 21 | public static int RPC_CONNECTION_TIMEOUT = 3000; 22 | 23 | /** 24 | * 调用读超时时间 25 | */ 26 | public static int RPC_READ_TIMEOUT = 90000; 27 | 28 | /** 29 | * 启用{@link NaviFailStrategy#FAILOVER}时的失败重试次数 30 | */ 31 | public static int RPC_RETRY_TIMES = 2; 32 | 33 | public String[] getZK_WATCH_NAMESPACE_PATHS() { 34 | return ZK_WATCH_NAMESPACE_PATHS; 35 | } 36 | 37 | public void setZK_WATCH_NAMESPACE_PATHS(String[] zK_WATCH_NAMESPACE_PATHS) { 38 | ZK_WATCH_NAMESPACE_PATHS = zK_WATCH_NAMESPACE_PATHS; 39 | } 40 | 41 | public int getRPC_CONNECTION_TIMEOUT() { 42 | return RPC_CONNECTION_TIMEOUT; 43 | } 44 | 45 | public void setRPC_CONNECTION_TIMEOUT(int rPC_CONNECTION_TIMEOUT) { 46 | RPC_CONNECTION_TIMEOUT = rPC_CONNECTION_TIMEOUT; 47 | } 48 | 49 | public int getRPC_READ_TIMEOUT() { 50 | return RPC_READ_TIMEOUT; 51 | } 52 | 53 | public void setRPC_READ_TIMEOUT(int rPC_READ_TIMEOUT) { 54 | RPC_READ_TIMEOUT = rPC_READ_TIMEOUT; 55 | } 56 | 57 | public int getRPC_RETRY_TIMES() { 58 | return RPC_RETRY_TIMES; 59 | } 60 | 61 | public void setRPC_RETRY_TIMES(int rPC_RETRY_TIMES) { 62 | RPC_RETRY_TIMES = rPC_RETRY_TIMES; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/java/com/baidu/beidou/navimgr/common/constant/GlobalResponseStatusMsg.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navimgr.common.constant; 2 | 3 | import com.baidu.unbiz.biz.result.ResultCode; 4 | import com.baidu.unbiz.biz.result.ResultCodeMessage; 5 | import com.baidu.unbiz.biz.result.ResultCodeUtil; 6 | 7 | /** 8 | * ClassName: GlobalResponseStatusMsg
    9 | * Function: 默认web返回码和信息 10 | * 11 | * @author Zhang Xu 12 | */ 13 | public enum GlobalResponseStatusMsg implements ResultCode { 14 | 15 | /** 成功 */ 16 | OK, 17 | 18 | /** 服务器繁忙。前端直接打印statusInfo.global信息 */ 19 | SYSTEM_BUSY, 20 | 21 | /** 服务器内部错误。前端直接打印statusInfo.global信息 */ 22 | SYSTEM_ERROR, 23 | 24 | /** 系统业务错误。需要按照前后端接口定义打印错误信息 */ 25 | BIZ_ERROR, 26 | 27 | /** 无权限操作 */ 28 | AUTH_DENIED, 29 | 30 | /** 用户未登录 */ 31 | NOT_LOGIN, 32 | 33 | /** 用户名或密码错误 */ 34 | LOGIN_FAILED, 35 | 36 | /** 请求参数错误 */ 37 | PARAM_ERROR, 38 | 39 | /** 请求参数类型错误 */ 40 | PARAM_TYPE_ERROR, 41 | 42 | /** 请求参数绑定发生错误 */ 43 | PARAM_BIND_ERROR, 44 | 45 | /** 请求参数缺失错误 */ 46 | PARAM_MISS_ERROR, 47 | 48 | /** 请求方法错误 */ 49 | REQUEST_HTTP_METHOD_ERROR, 50 | 51 | /** 无法获取信息页面{0} */ 52 | GET_HTML_PAGE_FAILED, 53 | 54 | /** 连接Zookeeper失败,reason={0} */ 55 | GET_ZOO_TREE_FAILED; 56 | 57 | private final ResultCodeUtil util = new ResultCodeUtil(this); 58 | 59 | @Override 60 | public String getName() { 61 | return util.getName(); 62 | } 63 | 64 | @Override 65 | public ResultCodeMessage getMessage() { 66 | return util.getMessage(); 67 | } 68 | 69 | public ResultCodeMessage getMessage(Object... msg) { 70 | return util.getMessage(msg); 71 | } 72 | 73 | @Override 74 | public int getCode() { 75 | return util.getCode(); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/util/MethodUtil.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.util; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | /** 6 | * ClassName: MethodUtil
    7 | * Function: 方法工具类 8 | * 9 | * @author zhangxu04 10 | */ 11 | public class MethodUtil { 12 | 13 | /** 14 | * Get parameter type name string from a method 15 | * 16 | * @param method 17 | * @return 18 | */ 19 | public static String getArgsTypeName(Method method) { 20 | return getArgsTypeName(getArgsTypeNameArray(method)); 21 | } 22 | 23 | /** 24 | * Get parameter type name array from a method 25 | * 26 | * @param method 27 | * @return 28 | */ 29 | public static String[] getArgsTypeNameArray(Method method) { 30 | return getArgsTypeNameArray(method.getParameterTypes()); 31 | } 32 | 33 | /** 34 | * Get parameter type name array from a method 35 | * 36 | * @param argsTypes 37 | * @return 38 | */ 39 | public static String[] getArgsTypeNameArray(Class[] argsTypes) { 40 | String[] argsTypeArray = null; 41 | if (argsTypes != null) { 42 | argsTypeArray = new String[argsTypes.length]; 43 | for (int i = 0; i < argsTypes.length; i++) { 44 | argsTypeArray[i] = argsTypes[i].getName(); 45 | } 46 | } 47 | return argsTypeArray; 48 | } 49 | 50 | /** 51 | * Get parameter type name string from a arg types string array 52 | * 53 | * @param argTypes 54 | * @return 55 | */ 56 | public static String getArgsTypeName(String[] argTypes) { 57 | if (argTypes != null) { 58 | return StringUtil.join(argTypes, ','); 59 | } 60 | return StringUtil.EMPTY; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/StandaloneServer.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it; 2 | 3 | import org.eclipse.jetty.server.Server; 4 | import org.eclipse.jetty.servlet.ServletContextHandler; 5 | import org.eclipse.jetty.servlet.ServletHolder; 6 | import org.springframework.web.context.ContextLoaderListener; 7 | 8 | import com.baidu.beidou.navi.server.NaviRpcServlet; 9 | 10 | /** 11 | * ClassName: StandaloneServer
    12 | * Function: 利用jetty启动独立于运行容器的服务 13 | * 14 | * @author Zhang Xu 15 | */ 16 | public class StandaloneServer { 17 | 18 | protected Server server; 19 | 20 | public void start(int port) { 21 | try { 22 | server = new Server(port); 23 | ServletContextHandler context = new ServletContextHandler(); 24 | context.setContextPath("/"); 25 | ContextLoaderListener listener = new ContextLoaderListener(); 26 | context.setInitParameter("contextConfigLocation", "classpath*:/applicationContext.xml"); 27 | context.addEventListener(listener); 28 | server.setHandler(context); 29 | context.addServlet(new ServletHolder(new NaviRpcServlet()), "/service_api/*"); 30 | server.start(); 31 | } catch (Throwable t) { 32 | System.err.println("Server failed to start. " + t.getMessage()); 33 | throw new RuntimeException(t); 34 | } 35 | } 36 | 37 | public void stop() { 38 | if (server != null) { 39 | try { 40 | server.stop(); 41 | server = null; 42 | } catch (Throwable t) { 43 | throw new RuntimeException(t); 44 | } 45 | } 46 | } 47 | 48 | public static void main(String[] args) { 49 | StandaloneServer server = new StandaloneServer(); 50 | server.start(8088); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/vo/Company.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.vo; 2 | 3 | import java.util.Date; 4 | import java.util.List; 5 | 6 | import org.apache.commons.lang.builder.ToStringBuilder; 7 | import org.apache.commons.lang.builder.ToStringStyle; 8 | 9 | /** 10 | * ClassName: Company
    11 | * Function: 公司 12 | * 13 | * @author Zhang Xu 14 | */ 15 | public class Company extends BaseObject { 16 | 17 | private String name; 18 | 19 | private Date establishTime; 20 | 21 | private List departmentList; 22 | 23 | public Company() { 24 | super(); 25 | } 26 | 27 | public Company(int id, String name, Date establishTime, List departmentList) { 28 | super(); 29 | this.setId(id); 30 | this.name = name; 31 | this.establishTime = establishTime; 32 | this.departmentList = departmentList; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public void setName(String name) { 40 | this.name = name; 41 | } 42 | 43 | public List getDepartmentList() { 44 | return departmentList; 45 | } 46 | 47 | public void setDepartmentList(List departmentList) { 48 | this.departmentList = departmentList; 49 | } 50 | 51 | public Date getEstablishTime() { 52 | return establishTime; 53 | } 54 | 55 | public void setEstablishTime(Date establishTime) { 56 | this.establishTime = establishTime; 57 | } 58 | 59 | public String toString() { 60 | return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).append("id", this.getId()) 61 | .append("name", name).append("establishTime", establishTime) 62 | .append("departmentList", departmentList).toString(); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/TestAuthService.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it; 2 | 3 | import static org.hamcrest.Matchers.is; 4 | import static org.junit.Assert.assertThat; 5 | import static org.junit.Assert.fail; 6 | 7 | import javax.annotation.Resource; 8 | 9 | import org.junit.Test; 10 | 11 | import com.baidu.beidou.navi.exception.rpc.AuthAccessDeniedException; 12 | import com.baidu.beidou.navi.it.service.AuthService; 13 | 14 | public class TestAuthService extends BaseTest { 15 | 16 | @Resource 17 | private AuthService authServiceDirectCall; 18 | 19 | @Resource 20 | private AuthService authServiceDirectCallNoAuth; 21 | 22 | @Resource 23 | private AuthService authServiceDirectCallTokenWrong; 24 | 25 | @Test 26 | public void testSayHelloNegative() { 27 | String result = null; 28 | try { 29 | result = authServiceDirectCallNoAuth.sayHello(); 30 | System.out.println(result); 31 | } catch (AuthAccessDeniedException e) { 32 | assertThat(e.getClass().getName(), is(AuthAccessDeniedException.class.getName())); 33 | return; 34 | } 35 | fail("should not get here"); 36 | } 37 | 38 | @Test 39 | public void testSayHelloNegative2() { 40 | String result = null; 41 | try { 42 | result = authServiceDirectCallTokenWrong.sayHello(); 43 | System.out.println(result); 44 | } catch (AuthAccessDeniedException e) { 45 | assertThat(e.getClass().getName(), is(AuthAccessDeniedException.class.getName())); 46 | return; 47 | } 48 | fail("should not get here"); 49 | } 50 | 51 | @Test 52 | public void testSayHello() { 53 | String result = null; 54 | result = authServiceDirectCall.sayHello(); 55 | System.out.println(result); 56 | assertThat(result, is("hi!")); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/server/vo/ResponseDTO.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.server.vo; 2 | 3 | /** 4 | * ClassName: ResponseDTO
    5 | * Function: 响应DTO 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public class ResponseDTO { 10 | 11 | /** 12 | * 请求id 13 | */ 14 | private long traceId; 15 | 16 | /** 17 | * 请求结果对象 18 | */ 19 | private Object result; 20 | 21 | /** 22 | * 状态码 23 | * 24 | * @see com.baidu.beidou.navi.constant.NaviStatus 25 | */ 26 | private int status; 27 | 28 | /** 29 | * 请求发生异常时候的异常对象 30 | */ 31 | private Throwable error; 32 | 33 | /** 34 | * Creates a new instance of ResponseDTO. 35 | */ 36 | public ResponseDTO() { 37 | 38 | } 39 | 40 | /** 41 | * 构建响应DTO 42 | * 43 | * @param status 44 | * @param error 45 | * @return 46 | */ 47 | public static ResponseDTO build(int status, Throwable error) { 48 | ResponseDTO result = new ResponseDTO(); 49 | result.setStatus(status); 50 | result.setError(error); 51 | return result; 52 | } 53 | 54 | public long getTraceId() { 55 | return traceId; 56 | } 57 | 58 | public void setTraceId(long traceId) { 59 | this.traceId = traceId; 60 | } 61 | 62 | public Object getResult() { 63 | return result; 64 | } 65 | 66 | public void setResult(Object result) { 67 | this.result = result; 68 | } 69 | 70 | public int getStatus() { 71 | return status; 72 | } 73 | 74 | public void setStatus(int status) { 75 | this.status = status; 76 | } 77 | 78 | public Throwable getError() { 79 | return error; 80 | } 81 | 82 | public void setError(Throwable error) { 83 | this.error = error; 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /navi-demo-server/src/main/resources/rpc-server.properties: -------------------------------------------------------------------------------- 1 | ################################################ 2 | # 3 | # 是否启用zookeeper进行服务注册、发布 4 | # 当ZK_SERVER_LIST为空时,该值忽略直接为false 5 | # true:启用 6 | # false:不启用 7 | # 8 | ################################################ 9 | ENABLE_ZK_REGISTRY=true 10 | 11 | ################################################ 12 | # 13 | # zookeeper集群地址IP:PORT列表,按逗号分隔 14 | # 15 | ################################################ 16 | ZK_SERVER_LIST=m1-ocean-1774.epc.baidu.com:8701,cp01-ocean-1551.epc.baidu.com:8701,cp01-ocean-1004.epc.baidu.com:8701,cp01-beidou-rd00.cp01:8701,cp01-beidou-rd01.cp01:8701 17 | 18 | ################################################ 19 | # 20 | # zookeeper访问控制密串 21 | # 22 | ################################################ 23 | ZK_DIGEST_AUTH= 24 | 25 | ################################################ 26 | # 27 | # 启用zookeeper注册后,所发布服务的命名空间 28 | # 按照"/产品线/服务名称/版本"的格式定义 29 | # 30 | ################################################ 31 | ZK_REGISTRY_NAMESPACE=/navi-demo-server/main 32 | 33 | ################################################ 34 | # 35 | # zookeeper nio连接seesion超时时间(单位ms),一般设置为30s 36 | # 37 | ################################################ 38 | ZK_DEFAULT_SESSION_TIMEOUT_MILLS=30000 39 | 40 | ################################################ 41 | # 42 | # 启动zookeeper连接时的超时时间(单位ms) 43 | # 44 | ################################################ 45 | ZK_CONNECTION_TIMEOUT_MILLS=30000 46 | 47 | 48 | ################################################ 49 | # 50 | # *选择性配置* 51 | # 52 | # 启用zookeeper注册服务时,需要提前配置端口号。 53 | # (1) 在JPaaS1.0上环境,自动替换为环境变量中的 54 | # $VCAP_APP_PORT或者JVM启动参数中的 55 | # -Dport.http.nonssl。 56 | # (2) 在JPaaS2.0上环境,自动替换为环境变量中的 57 | # $JPAAS_HOST为注册IP, 58 | # $JPAAS_HTTP_PORT为访问端口。 59 | # (3) 如果不满足(1),(2)则直接取该配置值,因此通常在 60 | # 开发环境或者测试环境中需要设置此值为tomcat或者jetty端口。 61 | # 62 | ################################################ 63 | SERVER_PORT=8080 -------------------------------------------------------------------------------- /navi-mgr-console/src/main/webapp/dep/bootstrap/css/ie.css: -------------------------------------------------------------------------------- 1 | /* NAVBAR */ 2 | 3 | /* !CPU HIGH, fix for IE6 shake when scroll */ 4 | * html,* html body { 5 | _background-image: url(about:blank); 6 | _background-attachment: fixed; 7 | } 8 | /* !CPU HIGH, fix for IE6 not support fixed position */ 9 | .navbar-fixed-top { 10 | _position: absolute; 11 | _bottom: auto; 12 | _top: expression(eval(document.documentElement.scrollTop)); 13 | } 14 | /* !CPU HIGH, fix for IE6 not support fixed position */ 15 | .navbar-fixed-bottom { 16 | _position: absolute; 17 | _bottom: auto; 18 | _top: expression(eval(document.documentElement.scrollTop + 19 | document.documentElement.clientHeight-this.offsetHeight- ( parseInt(this.currentStyle.marginTop 20 | , 10)||0)-(parseInt(this.currentStyle.marginBottom, 10)||0))); 21 | } 22 | 23 | /* DROPDOWN */ 24 | .dropup,.dropdown { 25 | *zoom: 1; 26 | } 27 | 28 | /* CLOSE */ 29 | .close { 30 | _font-size: 15px; 31 | } 32 | 33 | .modal-header h3 { 34 | *display: inline; 35 | *zoom: 1; 36 | } 37 | 38 | /* MODALS */ 39 | .modal-backdrop { 40 | _position: absolute; 41 | _top: 0; 42 | _margin-top: 0; 43 | _width: expression(eval(document.documentElement.scrollWidth)); 44 | _height: expression(eval(document.documentElement.scrollHeight)); 45 | } 46 | 47 | .modal { 48 | _position: absolute; 49 | _top: 0; 50 | _margin-top: 0; 51 | _top: expression(eval(document.documentElement.scrollTop)); 52 | } 53 | 54 | .modal.fade.in { 55 | _filter: alpha(opacity = 100); 56 | } 57 | 58 | .modal-backdrop { 59 | _filter: alpha(opacity = 80); 60 | } 61 | 62 | .modal-body { 63 | _height: expression(this.scrollHeight > 400 ? "400px" : "auto"); 64 | } 65 | /* misou add-in */ 66 | .navbar-form .span4 { 67 | margin-top: 4px; 68 | } 69 | 70 | .navbar-form .btn-primary { 71 | margin-top: 4px; 72 | } 73 | 74 | .navbar-form .btn-warning { 75 | margin-top: 4px; 76 | } 77 | 78 | #topics_index { 79 | width: 620px; 80 | } 81 | 82 | .wmd-show { 83 | width: 618px; 84 | } -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/server/vo/RequestDTO.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.server.vo; 2 | 3 | /** 4 | * ClassName: RequestDTO
    5 | * Function: 请求DTO 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public class RequestDTO { 10 | 11 | /** 12 | * 请求追踪trace id 13 | */ 14 | private long traceId; 15 | 16 | /** 17 | * 请求方法名称 18 | */ 19 | private String method; 20 | 21 | /** 22 | * 请求参数数组 23 | */ 24 | private Object[] parameters; 25 | 26 | /** 27 | * 请求方法参数类名数组 28 | */ 29 | private String[] paramterTypes; 30 | 31 | /** 32 | * appId 33 | */ 34 | private String appId; 35 | 36 | /** 37 | * token 38 | */ 39 | private String token; 40 | 41 | public long getTraceId() { 42 | return traceId; 43 | } 44 | 45 | public void setTraceId(long traceId) { 46 | this.traceId = traceId; 47 | } 48 | 49 | public String getMethod() { 50 | return method; 51 | } 52 | 53 | public void setMethod(String method) { 54 | this.method = method; 55 | } 56 | 57 | public String[] getParamterTypes() { 58 | return paramterTypes; 59 | } 60 | 61 | public void setParamterTypes(String[] paramterTypes) { 62 | this.paramterTypes = paramterTypes; 63 | } 64 | 65 | public Object[] getParameters() { 66 | return parameters; 67 | } 68 | 69 | public void setParameters(Object[] parameters) { 70 | this.parameters = parameters; 71 | } 72 | 73 | public String getAppId() { 74 | return appId; 75 | } 76 | 77 | public void setAppId(String appId) { 78 | this.appId = appId; 79 | } 80 | 81 | public String getToken() { 82 | return token; 83 | } 84 | 85 | public void setToken(String token) { 86 | this.token = token; 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /navi/src/test/java/com/baidu/beidou/navi/it/BaseTest.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.it; 2 | 3 | import java.io.InputStream; 4 | import java.net.HttpURLConnection; 5 | import java.net.URL; 6 | 7 | import org.junit.AfterClass; 8 | import org.junit.BeforeClass; 9 | import org.junit.Test; 10 | import org.springframework.test.context.ContextConfiguration; 11 | import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; 12 | 13 | import com.baidu.beidou.navi.client.constant.NaviRpcClientConstant; 14 | import com.baidu.beidou.navi.util.ByteUtil; 15 | 16 | @ContextConfiguration(locations = { "classpath:applicationContext.xml" }) 17 | public class BaseTest extends AbstractJUnit4SpringContextTests { 18 | 19 | protected static StandaloneServer server; 20 | 21 | @BeforeClass 22 | public static void setUp() { 23 | server = new StandaloneServer(); 24 | server.start(Config.PORT); 25 | } 26 | 27 | @Test 28 | public void test() { 29 | 30 | } 31 | 32 | @AfterClass 33 | public static void tearDown() { 34 | if (server != null) { 35 | server.stop(); 36 | } 37 | } 38 | 39 | public String getContent(String path) throws Exception { 40 | HttpURLConnection httpconnection = (HttpURLConnection) new URL(path).openConnection(); 41 | httpconnection.setRequestMethod("GET"); 42 | httpconnection.setDoInput(true); 43 | httpconnection.setDoOutput(true); 44 | httpconnection.setRequestProperty("Content-Type", "text/html;charset=" 45 | + NaviRpcClientConstant.ENDODING); 46 | httpconnection.connect(); 47 | InputStream in = httpconnection.getInputStream(); 48 | int len = httpconnection.getContentLength(); 49 | byte[] resBytes = ByteUtil.readStream(in, len); 50 | String content = new String(resBytes, NaviRpcClientConstant.ENDODING); 51 | in.close(); 52 | httpconnection.disconnect(); 53 | return content; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /navi-demo-client/src/main/resources/rpc-client.properties: -------------------------------------------------------------------------------- 1 | ################################################ 2 | # 3 | # 客户端是否启用zookeeper进行服务发现 4 | # 当ZK_SERVER_LIST为空时,该值忽略直接为false 5 | # true:启用 6 | # false:不启用 7 | # 8 | ################################################ 9 | ENABLE_ZK_REGISTRY=true 10 | 11 | ################################################ 12 | # 13 | # zookeeper集群地址IP:PORT列表,按逗号分隔 14 | # 15 | ################################################ 16 | ZK_SERVER_LIST=m1-ocean-1774.epc.baidu.com:8701,cp01-ocean-1551.epc.baidu.com:8701,cp01-ocean-1004.epc.baidu.com:8701,cp01-beidou-rd00.cp01:8701,cp01-beidou-rd01.cp01:8701 17 | 18 | ################################################ 19 | # 20 | # zookeeper访问控制密串 21 | # 22 | ################################################ 23 | ZK_DIGEST_AUTH=beidouRd123 24 | 25 | ################################################ 26 | # 27 | # 客户端订阅zookeeper的path列表, 28 | # 可以调用多个不同的服务。 29 | # 30 | ################################################ 31 | ZK_WATCH_NAMESPACE_PATHS=/navi-demo-server/main 32 | 33 | ################################################ 34 | # 35 | # zookeeper nio连接seesion超时时间(单位ms),一般设置为30s 36 | # 37 | ################################################ 38 | ZK_DEFAULT_SESSION_TIMEOUT_MILLS=30000 39 | 40 | ################################################ 41 | # 42 | # 启动zookeeper连接时的超时时间(单位ms) 43 | # 44 | ################################################ 45 | ZK_CONNECTION_TIMEOUT_MILLS=30000 46 | 47 | ################################################ 48 | # 49 | # rpc连接超时时间(单位ms) 50 | # 51 | ################################################ 52 | RPC_CONNECTION_TIMEOUT=3000 53 | 54 | ################################################ 55 | # 56 | # rpc读超时时间(单位ms) 57 | # 58 | ################################################ 59 | RPC_READ_TIMEOUT=60000 60 | 61 | ################################################ 62 | # 63 | # rpc调用失败重试次数 64 | # 65 | ################################################ 66 | RPC_RETRY_TIMES=2 -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/server/filter/FilterBuilder.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.server.filter; 2 | 3 | import java.util.List; 4 | 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import com.baidu.beidou.navi.server.callback.Callback; 9 | import com.baidu.beidou.navi.server.processor.NaviRpcProcessor; 10 | import com.baidu.beidou.navi.server.vo.NaviRpcRequest; 11 | import com.baidu.beidou.navi.server.vo.NaviRpcResponse; 12 | import com.baidu.beidou.navi.util.CollectionUtil; 13 | import com.baidu.beidou.navi.util.ExtensionLocator; 14 | 15 | /** 16 | * ClassName: FilterBuilder
    17 | * Function: 调用链构造器
    18 | * 过滤器filter利用SPI技术从META-INF/services/*中指定的顺序加载初始化 19 | * 20 | * @author Zhang Xu 21 | */ 22 | public class FilterBuilder { 23 | 24 | private static final Logger LOG = LoggerFactory.getLogger(FilterBuilder.class); 25 | 26 | /** 27 | * 构造调用链 28 | * 29 | * @param processor 30 | * @return 31 | */ 32 | public static NaviRpcProcessor buildFilterChain(final NaviRpcProcessor processor) { 33 | NaviRpcProcessor last = processor; 34 | List filterList = ExtensionLocator.getInstanceList(Filter.class); 35 | if (CollectionUtil.isNotEmpty(filterList)) { 36 | for (int i = filterList.size() - 1; i >= 0; i--) { 37 | final Filter filter = filterList.get(i); 38 | final NaviRpcProcessor next = last; 39 | last = new NaviRpcProcessor() { 40 | @Override 41 | public void service(NaviRpcRequest request, Callback callback) { 42 | filter.doChain(next, request, new FilterCallback(callback, filter)); 43 | } 44 | }; 45 | LOG.info("Place " + filter.getClass().getName() + " filter to core processor"); 46 | } 47 | } 48 | return last; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/constant/NaviCommonConstant.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.constant; 2 | 3 | import com.baidu.beidou.navi.protocol.NaviProtocol; 4 | 5 | /** 6 | * ClassName: NaviCommonConstant
    7 | * Function: 一些公共的常量定义 8 | * 9 | * @author Zhang Xu 10 | */ 11 | public class NaviCommonConstant { 12 | 13 | /** 14 | * http前缀 15 | */ 16 | public static final String TRANSPORT_PROTOCOL = "http://"; 17 | 18 | /** 19 | * 默认服务的url前缀 20 | */ 21 | public static final String TRANSPORT_URL_BASE_PATH = "/service_api/"; 22 | 23 | /** 24 | * zookeeper页面的path 25 | */ 26 | public static final String ZOOKEEPER_URL_PATH = "zookeeper"; 27 | 28 | /** 29 | * zookeeper所有注册订阅node的根路径前缀 30 | */ 31 | public static final String ZOOKEEPER_BASE_PATH = "/navi_rpc"; 32 | 33 | /** 34 | * zookeeper path的分隔符 35 | */ 36 | public static final String ZK_PATH_SEPARATOR = "/"; 37 | 38 | /** 39 | * 默认序列化方式 40 | */ 41 | public static final String DEFAULT_PROTOCAL_CONTENT_TYPE = NaviProtocol.PROTOSTUFF.getName(); 42 | 43 | /** 44 | * System properties of server port for JPaaS1.0. Usually defined in shell. 45 | */ 46 | public static final String SYSTEM_PROPERTY_SERVER_PORT_FROM_ENV_4JPAAS1 = "VCAP_APP_PORT"; 47 | 48 | /** 49 | * System properties of server port for JPaaS1.0. Get from -D property 50 | */ 51 | public static final String SYSTEM_PROPERTY_SERVER_PORT_FROM_SLASH_D_4JPAAS1 = "port.http.nonssl"; 52 | 53 | /** 54 | * System properties of server host for JPaaS2.0. Usually defined in shell. 55 | */ 56 | public static final String SYSTEM_PROPERTY_SERVER_HOST_FROM_ENV_4JPAAS2 = "JPAAS_HOST"; 57 | 58 | /** 59 | * System properties of server port for JPaaS2.0. Usually defined in shell. 60 | */ 61 | public static final String SYSTEM_PROPERTY_SERVER_PORT_FROM_ENV_4JPAAS2 = "JPAAS_HTTP_PORT"; 62 | 63 | } 64 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/util/IPUtils.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.util; 2 | 3 | import java.net.InetAddress; 4 | import java.net.UnknownHostException; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | 8 | /** 9 | * 10 | * ClassName: IPUtils
    11 | * Function: IP地址工具类 12 | * 13 | * @author Zhang Xu 14 | */ 15 | public class IPUtils { 16 | 17 | private static final String IP_UNKNOWN = "unknown"; 18 | 19 | public static String getIpAddr(HttpServletRequest request) { 20 | if (request == null) { 21 | return null; 22 | } 23 | String ip = request.getHeader("x-forwarded-for"); 24 | if (ip == null || ip.length() == 0 || IP_UNKNOWN.equalsIgnoreCase(ip)) { 25 | ip = request.getHeader("Proxy-Client-IP"); 26 | } 27 | if (ip == null || ip.length() == 0 || IP_UNKNOWN.equalsIgnoreCase(ip)) { 28 | ip = request.getHeader("WL-Proxy-Client-IP"); 29 | } 30 | if (ip == null || ip.length() == 0 || IP_UNKNOWN.equalsIgnoreCase(ip)) { 31 | ip = request.getRemoteAddr(); 32 | } 33 | 34 | // 取X-Forwarded-For中第一个非unknown的有效IP字符串。 35 | if (ip.indexOf(",") != -1) { 36 | String[] ipList = ip.split(","); 37 | String tmp; 38 | for (int i = 0; i < ipList.length; i++) { 39 | tmp = ipList[i]; 40 | if (tmp != null && !IP_UNKNOWN.equalsIgnoreCase(tmp.trim())) { 41 | return tmp.trim(); 42 | } 43 | } 44 | } 45 | return ip; 46 | } 47 | 48 | public static String getLocalHostAddress() { 49 | try { 50 | InetAddress inet = InetAddress.getLocalHost(); 51 | String hostAddress = inet.getHostAddress(); 52 | return hostAddress; 53 | } catch (UnknownHostException e) { 54 | e.printStackTrace(); 55 | } 56 | return null; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/util/ExtensionLocator.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.util; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.ServiceLoader; 6 | import java.util.concurrent.ConcurrentHashMap; 7 | import java.util.concurrent.ConcurrentMap; 8 | import java.util.concurrent.locks.Lock; 9 | import java.util.concurrent.locks.ReentrantLock; 10 | 11 | import org.slf4j.Logger; 12 | import org.slf4j.LoggerFactory; 13 | 14 | /** 15 | * 16 | * ClassName: ExtensionLocator
    17 | * Function: 利用SPI技术从META-INF/services动态加下类配置 18 | * 19 | * @author Zhang Xu 20 | */ 21 | public class ExtensionLocator { 22 | 23 | private static final Logger LOG = LoggerFactory.getLogger(ExtensionLocator.class); 24 | 25 | private static ConcurrentMap, List> EXTENSION_LOCATOR = new ConcurrentHashMap, List>(); 26 | 27 | private static Lock lock = new ReentrantLock(); 28 | 29 | /** 30 | * Get instances dynamically for a class type 31 | * 32 | * @param type 33 | * @return 34 | */ 35 | @SuppressWarnings("unchecked") 36 | public static List getInstanceList(Class type) { 37 | if (type == null) { 38 | throw new IllegalArgumentException("Type should not be empty"); 39 | } 40 | 41 | List loader = (List) EXTENSION_LOCATOR.get(type); 42 | if (loader == null) { 43 | try { 44 | lock.lock(); 45 | List instanceList = new ArrayList(); 46 | ServiceLoader serviceLoader = ServiceLoader.load(type); 47 | for (T service : serviceLoader) { 48 | instanceList.add(service); 49 | } 50 | loader = instanceList; 51 | if (EXTENSION_LOCATOR.putIfAbsent(type, instanceList) != instanceList) { 52 | loader = (List) EXTENSION_LOCATOR.get(type); 53 | } 54 | } catch (Exception e) { 55 | LOG.error("Error to load SPI instances from META-INF/services/" + type, e); 56 | } finally { 57 | lock.unlock(); 58 | } 59 | } 60 | return loader; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/util/vo/AccessLog.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.util.vo; 2 | 3 | import com.baidu.beidou.navi.server.vo.RequestDTO; 4 | import com.baidu.beidou.navi.server.vo.ResponseDTO; 5 | 6 | public class AccessLog { 7 | 8 | private String fromIp; 9 | private String protocol; 10 | private String serviceIntfName; 11 | private RequestDTO request; 12 | private int requestByteSize; 13 | private ResponseDTO response; 14 | private long startTime; 15 | private long endTime; 16 | 17 | public AccessLog() { 18 | super(); 19 | } 20 | 21 | public String getFromIp() { 22 | return fromIp; 23 | } 24 | 25 | public void setFromIp(String fromIp) { 26 | this.fromIp = fromIp; 27 | } 28 | 29 | public String getProtocol() { 30 | return protocol; 31 | } 32 | 33 | public void setProtocol(String protocol) { 34 | this.protocol = protocol; 35 | } 36 | 37 | public String getServiceIntfName() { 38 | return serviceIntfName; 39 | } 40 | 41 | public void setServiceIntfName(String serviceIntfName) { 42 | this.serviceIntfName = serviceIntfName; 43 | } 44 | 45 | public RequestDTO getRequest() { 46 | return request; 47 | } 48 | 49 | public void setRequest(RequestDTO request) { 50 | this.request = request; 51 | } 52 | 53 | public int getRequestByteSize() { 54 | return requestByteSize; 55 | } 56 | 57 | public void setRequestByteSize(int requestByteSize) { 58 | this.requestByteSize = requestByteSize; 59 | } 60 | 61 | public ResponseDTO getResponse() { 62 | return response; 63 | } 64 | 65 | public void setResponse(ResponseDTO response) { 66 | this.response = response; 67 | } 68 | 69 | public long getStartTime() { 70 | return startTime; 71 | } 72 | 73 | public void setStartTime(long startTime) { 74 | this.startTime = startTime; 75 | } 76 | 77 | public long getEndTime() { 78 | return endTime; 79 | } 80 | 81 | public void setEndTime(long endTime) { 82 | this.endTime = endTime; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/util/MethodWrapper.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.util; 2 | 3 | /** 4 | * ClassName: MethodWrapper
    5 | * Function: 包含方法及其参数类型的封装类 6 | * 7 | * @author zhangxu04 8 | */ 9 | public class MethodWrapper { 10 | 11 | /** 12 | * 类名称或者接口class名称 13 | */ 14 | private String clazzName; 15 | 16 | /** 17 | * 方法名称 18 | */ 19 | private String methodName; 20 | 21 | /** 22 | * 参数类型名称字符串 23 | */ 24 | private String argTypesStr; 25 | 26 | /** 27 | * 转化为字符串 28 | */ 29 | @Override 30 | public String toString() { 31 | StringBuilder sb = new StringBuilder(); 32 | sb.append(clazzName); 33 | sb.append("-"); 34 | sb.append(methodName); 35 | sb.append("-"); 36 | if (argTypesStr != null) { 37 | sb.append(argTypesStr); 38 | } 39 | return sb.toString(); 40 | } 41 | 42 | /** 43 | * Creates a new instance of MethodWrapper. 44 | * 45 | * @param clazzName 46 | * @param methodName 47 | * @param argTypesStr 48 | */ 49 | public MethodWrapper(String clazzName, String methodName, String argTypesStr) { 50 | super(); 51 | this.clazzName = clazzName; 52 | this.methodName = methodName; 53 | this.argTypesStr = argTypesStr; 54 | } 55 | 56 | public String getClazzName() { 57 | return clazzName; 58 | } 59 | 60 | public void setClazzName(String clazzName) { 61 | this.clazzName = clazzName; 62 | } 63 | 64 | public String getMethodName() { 65 | return methodName; 66 | } 67 | 68 | public void setMethodName(String methodName) { 69 | this.methodName = methodName; 70 | } 71 | 72 | public String getArgTypesStr() { 73 | return argTypesStr; 74 | } 75 | 76 | public void setArgTypesStr(String argTypesStr) { 77 | this.argTypesStr = argTypesStr; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /navi-demo-client/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | navi server demo 8 | 9 | index 10 | 11 | 12 | 13 | contextConfigLocation 14 | classpath*:/applicationContext*.xml 15 | 16 | 17 | 18 | org.springframework.web.context.ContextLoaderListener 19 | 20 | 21 | 22 | spring 23 | org.springframework.web.servlet.DispatcherServlet 24 | 25 | contextConfigLocation 26 | classpath*:/spring-servlet.xml 27 | 28 | 1 29 | 30 | 31 | 32 | spring 33 | / 34 | 35 | 36 | spring 37 | /index 38 | 39 | 40 | 41 | 42 | encodingFilter 43 | org.springframework.web.filter.CharacterEncodingFilter 44 | 45 | encoding 46 | UTF-8 47 | 48 | 49 | forceEncoding 50 | true 51 | 52 | 53 | 54 | encodingFilter 55 | /* 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /navi-mgr-console/src/main/java/com/baidu/beidou/navimgr/zoo/ZkPathUtil.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navimgr.zoo; 2 | 3 | 4 | /** 5 | * ClassName: ZkPathUtil
    6 | * Function: zookeeper路径工具类 7 | * 8 | * @author Zhang Xu 9 | */ 10 | public class ZkPathUtil { 11 | 12 | /** 13 | * zookeeper path的分隔符 14 | */ 15 | private static final String ZK_PATH_SEPARATOR = "/"; 16 | 17 | /** 18 | * Try to assamble paths into a string without duplicated / character problem By default, every beginner path should 19 | * startWith / 20 | * 21 | * @param paths 22 | * in array 23 | * @return path 24 | */ 25 | public static String buildPath(String... paths) { 26 | StringBuffer result = new StringBuffer(); 27 | for (int i = 0; i < paths.length; i++) { 28 | String cur = paths[i]; 29 | int curLen = cur.length(); 30 | String next = null; 31 | if (i < paths.length - 1) { 32 | next = paths[i + 1]; 33 | } 34 | if (cur.endsWith(ZK_PATH_SEPARATOR)) { 35 | if (next != null) { 36 | if (next.startsWith(ZK_PATH_SEPARATOR)) { 37 | result.append(cur.substring(0, curLen - 1)); 38 | } else { 39 | result.append(cur.substring(0, curLen)); 40 | } 41 | } else { 42 | result.append(cur.substring(0, curLen - 1)); 43 | } 44 | } else { 45 | if (next != null) { 46 | if (next.startsWith(ZK_PATH_SEPARATOR)) { 47 | result.append(cur.substring(0, curLen)); 48 | } else { 49 | result.append(cur.substring(0, curLen)); 50 | result.append(ZK_PATH_SEPARATOR); 51 | } 52 | } else { 53 | result.append(cur.substring(0, curLen)); 54 | } 55 | } 56 | } 57 | return result.toString(); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /navi/src/main/java/com/baidu/beidou/navi/server/NaviRpcExporter.java: -------------------------------------------------------------------------------- 1 | package com.baidu.beidou.navi.server; 2 | 3 | /** 4 | * ClassName: NaviRpcExporter
    5 | * Function: 服务端暴露的NaviRpc服务封装 6 | * 7 | * @author Zhang Xu 8 | */ 9 | public class NaviRpcExporter implements ServiceNameAware { 10 | 11 | /** 12 | * 服务接口名称 13 | */ 14 | private String serviceInterfaceName; 15 | 16 | /** 17 | * 服务实现类 18 | */ 19 | private Object serviceBean; 20 | 21 | /** 22 | * Creates a new instance of NaviRpcExporter. 23 | */ 24 | public NaviRpcExporter() { 25 | 26 | } 27 | 28 | /** 29 | * Creates a new instance of NaviRpcExporter. 30 | * 31 | * @param serviceInterfaceName 32 | * @param serviceBean 33 | */ 34 | public NaviRpcExporter(String serviceInterfaceName, Object serviceBean) { 35 | this.serviceInterfaceName = serviceInterfaceName; 36 | this.serviceBean = serviceBean; 37 | } 38 | 39 | /** 40 | * 通过反射获取接口class 41 | * 42 | * @return 接口的class 43 | */ 44 | public Class getServiceInterface() { 45 | try { 46 | return Class.forName(serviceInterfaceName); 47 | } catch (Exception e) { 48 | throw new RuntimeException("Class not found for " + serviceInterfaceName); 49 | } 50 | } 51 | 52 | /** 53 | * 获取服务名称 54 | * 55 | * @return 名称 56 | * @see com.baidu.beidou.navi.server.ServiceNameAware#getName() 57 | */ 58 | @Override 59 | public String getName() { 60 | return this.getServiceInterface().getSimpleName(); 61 | } 62 | 63 | public String getServiceInterfaceName() { 64 | return serviceInterfaceName; 65 | } 66 | 67 | public void setServiceInterfaceName(String serviceInterface) { 68 | this.serviceInterfaceName = serviceInterface; 69 | } 70 | 71 | public Object getServiceBean() { 72 | return serviceBean; 73 | } 74 | 75 | public void setServiceBean(Object serviceBean) { 76 | this.serviceBean = serviceBean; 77 | } 78 | 79 | } 80 | --------------------------------------------------------------------------------