import ip from 'ip' ; import java from 'js-to-java' ; import { IDubboService } from 'apache-dubbo-js' ; enum Sex { male , female } interface IUserRequest { id : number ; name : string ; email : string ; sex : Sex ; } class UserResponse { status : string ; info : Map < string , string > ; __fields2java ( ) { return java ( 'org.apache.dubbo.demo.UserResponse' , { status : java . String ( this . status ) , info : this . info , } ) ; } } class TypeRequest { map : Map < string , string > ; bigDecimal : { value : string ; } ; __fields2java ( ) { return java ( 'org.apache.dubbo.demo.TypeRequest' , { map : this . map , bigDecimal : java . BigDecimal ( this . bigDecimal . value ) , } ) ; } } class DemoProvider implements IDubboService { dubboInterface = 'org.apache.dubbo.demo.DemoProvider' ; version = '1.0.0' ; methods = { sayHello ( name ) { return java . String ( `Hello ${ name }, response from provider ${ ip . address ( ) }` ) ; } , echo ( ) { return 'pang' ; } , test ( ) { console . log ( 'test' ) ; } , getUserInfo ( request ) { console . log ( request ) ; const res = new UserResponse ( ) ; res . status = 'ok' ; const map = new Map ( ) ; map . set ( 'id' , '1' ) ; map . set ( 'name' , 'test' ) ; res . info = map ; return res ; } , } ; } const basicTypeProvider = { dubboInterface : 'org.apache.dubbo.demo.BasicTypeProvider' , version : '2.0.0' , methods : { testBasicType ( req ) { const response = new TypeRequest ( ) ; response . bigDecimal = { value : '100.00' } ; const map = new Map ( ) ; map . set ( 'hello' , 'world' ) ; response . map = map ; return response ; } , } , } as IDubboService ; class ErrorProvider implements IDubboService { dubboInterface = 'org.apache.dubbo.demo.ErrorProvider' ; version = '1.0.0' ; methods = { errorTest ( ) { throw new Error ( 'ErrorProvider error' ) ; } , } ; } export default [ new DemoProvider ( ) , basicTypeProvider , new ErrorProvider ( ) ] ;