请选择 进入手机版 | 继续访问电脑版

默认
发表评论 11
想开发IM:买成品怕坑?租第3方怕贵?找开源自已撸?尽量别走弯路了... 找站长给点建议
[已回复] 求助RainbowChat中我新增了自定义的接口后,调用出错的问题
经查看源码及手册,1008-1-23接口未被使用,在LogicProcessor2中新增1008-1-23接口并在服务端、客户端编写对应业务逻辑:
在服务端maintainRegisterJobDispatcher
{
switch (action_id)
{
添加
case ACTION_APPEND5:
{....}

通过虚拟机调用该功能时,客户端提示Your network is valibale.
通过真机使用该功能时,提示未知错误。

服务端报告已正常收到客户端的数据请求,使用真机时服务端报告如下:


[DEBUG] - [16:53:27.104]>>S 客户端Cookie=null ip=192.168.1.102:39714 | (HttpController.process:110)
[DEBUG] - [16:53:27.105]【==> 收到接口请求-数据原型】:{"actionId":23,"device":0,"doInput":true,"jobDispatchId":1,"newData":"{\"user_country_code\":\"+86\",\"user_phone\":\"17051101258\"}","processorId":1008} | (MyControllerJSON.recieveFromClient:469)
[DEBUG] - [16:53:27.106]〖 [HTTP][客户端类型:Android] 捕获REST【接口1008-1-23】的请求,安全token=null 〗 | (MyControllerJSON.dispatch:96)
[DEBUG] - [16:53:27.107]【<== 处理完成-返回JSON结果】:{"success":true} | (MyControllerJSON.sendToClient:444)

请指点一下错在哪里

即时通讯网 - 即时通讯开发者社区! 来源: - 即时通讯开发者社区!

标签:RainbowChat
上一篇:[已回复] 关于修改注册项目涉及UserRegisterDTO的打jar包疑问下一篇:[已回复] 求助RainbowChat的Android端HTTP接口返回&quot;returnValue&quot;信息
推荐方案
评论 11
你贴的这么点log看不出来什么。

你需要把以下4 样东西抓出来,我就能帮你看看了在调用1008-1-23接口前,请先把服务端、客户端log全部清空一下,等一会要干净的抓出接下来的log):
  • 1)调用这个接口后的客户端完整log(一行都不要缺,不要掐头去尾);
  • 2)调用这个接口后的服务端端完整log(一行都不要缺,不要掐头去尾);
  • 3)服务端这个完整的case语句对应的代码(越全越好,不要只贴一点点);
  • 4)客户端调用这个接口的代码,以及这个接口的客户端实现代码。

客户端:
HttpRestHelper:

/**
                 * 【接口1008-1-23】短信验证码接口调用.
         *
                         * @return
                         */
        public static DataFromServer submitSendPinToServer(UserRegisterDTO sendPinData)
        {
                // 提交请求到http rest服务端
                DataFromClient dataFromClient = DataFromClient.n()
                                .setProcessorId(MyProcessorConst.PROCESSOR_LOGIC)
                                .setJobDispatchId(JobDispatchConst.LOGIC_REGISTER)
                                .setActionId(SysActionConst.ACTION_APPEND5)
                                .setNewData(new Gson().toJson(sendPinData));
                return HttpServiceFactory4AJASONImpl.getInstance().getDefaultService().sendObjToServer(dataFromClient);
        }
        public static String parseSendPinFromServer(String jsonOfResult)
        {
                JSONObject nwObj = JSONObject.parseObject(jsonOfResult);
                return nwObj.getString("stat_id");
        }
客户端 RegisterActivity:
protected void initViews()
        {
//                customeTitleBarResId = R.id.register_form_titleBar;
               
                //养成良好习惯:首先设置主layout,确保后绪的操作中使用到的组件都可以被find到
                setContentView(R.layout.register_form);
               
                this.setTitle(R.string.register_form_title);
                this.setLoadDataOnCreate(false);

                //各功能组件 country_box
                txtNickname = (TextView)this.findViewById(R.id.register_form_nicknameEdit);
                txtPassword = (TextView)this.findViewById(R.id.register_form_passwordEdit);

                txtPhone = (TextView)this.findViewById(R.id.et_usertel);
                txtSmsPin = (TextView)this.findViewById(R.id.et_code);
                cbAgreeLisence =(CheckBox)this.findViewById(R.id.register_form_agreeLisenseCb);
                btnLookCaluse = (Button)this.findViewById(R.id.register_form_to_clause);
                btnSubmit = (Button)this.findViewById(R.id.register_form_submitBtn);
                boxCountry = (RelativeLayout)this.findViewById(R.id.country_box);
                btnPinSend =  (Button)this.findViewById(R.id.btn_send);
                txtCountry = (TextView)this.findViewById(R.id.country_name_tv);
                txtCountryCode = (TextView)this.findViewById(R.id.country_code);
//                txtEmail = (TextView)this.findViewById(R.id.register_form_emailEdit);
//                txtConformPassword = (TextView)this.findViewById(R.id.register_form_conformPswEdit);
//                cbMan =(RadioButton)this.findViewById(R.id.register_form_manCb);
//                cbWomen =(RadioButton)this.findViewById(R.id.register_form_womanCb);
//                btnCancel = (Button)this.findViewById(R.id.register_form_cancelBtn);
        }
      
//监听验证码发送按钮事件
        btnPinSend.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v)
            {
                sendPin();
            }
        });
   
public UserRegisterDTO getPinData()
    {
        UserRegisterDTO uPin = new UserRegisterDTO();
        uPin.setUser_country_code(String.valueOf(this.txtCountryCode.getText()));
        uPin.setUser_phone(String.valueOf(this.txtPhone.getText()));
        return uPin;
    }
// 定义验证码发送方法start
        private  void sendPin(){
        if(String.valueOf(txtPhone.getText()).trim().length()<=6)
        {
            txtPhone.setError($$(R.string.register_form_valid_phone));
            return;
        }
        new SendPinTask().execute();
    }
        protected class SendPinTask extends DataLoadingAsyncTask<String, Integer, DataFromServer>
        {
                private UserRegisterDTO sendPinData = null;

                public SendPinTask()
                {
                        super(RegisterActivity.this, $$(R.string.pin_sending));
                }

                @Override
                protected void onPreExecute()
                {
                        super.onPreExecute();
                        btnPinSend.setEnabled(false);
                }

                /**
                 * 在后台(应该是指客户端后台doInBackground)执行实现验证码发送信息的提交和处理结果的读取 .
                 *
                 * @param parems 外界传进来的参数
                 * @return 查询结果,将传递给onPostExecute(..)方法
                 */
                @Override
                protected DataFromServer doInBackground(String... parems)
                {
                        //** 提交到服务端的数据,国家代码、手机号
                        sendPinData = getPinData();

                        // 提交请求到服务端,需在HttpRestHelper中定义submitSendPinToServer
                        return HttpRestHelper.submitSendPinToServer(sendPinData);
                }


                @Override
                protected void onPostExecute(DataFromServer result)
                {
                        super.onPostExecute(result);
                        btnPinSend.setText("倒计时");
                }

                //服务端编写验证码业务逻辑,生成随机码提交短信发送平台,记录sendPinData信息:国家代码、手机号、随机码
                //提交注册时,与该信息对比

                /**
                 * 处理服务端返回的结果信息.
                 */
                protected void onPostExecuteImpl(Object jsonOfResult)
                {
                        Object retVal = jsonOfResult;//dfs.getReturnValue();
                        if(retVal != null)
                        {
                                //需在HttpRestHelper中定义
                                String statcode = HttpRestHelper.parseSendPinFromServer((String)retVal);
                                if(!CommonUtils.isStringEmpty(statcode))
                                {
                                        // 返回值“0”,本次发送失败!
                                        if(statcode.equals("0"))
                                        {
                                                new AlertDialog.Builder(RegisterActivity.this)
                                                                .setTitle(R.string.general_error)
                                                                .setMessage("发送失败")
                                                                .setPositiveButton(R.string.general_ok,   null);
                                                //        .setNegativeButton(R.string.general_cancel, null).show();
                                                return; // 失败了,直接return
                                        }
                                        // 发送成功
                                        else
                                        {
                                                new AlertDialog.Builder(RegisterActivity.this)
                                                                .setTitle("ok")
                                                                .setMessage("发送成功")
                                                                .setPositiveButton(R.string.general_ok,   null);
                                                //        .setNegativeButton(R.string.general_cancel, null).show();
                                                return; // 成功了,直接return
                                        }
                                }
                        }

                        //否则是出现了其它注册失败问题,弹出提示框
                        new AlertDialog.Builder(RegisterActivity.this)
                                        .setTitle(R.string.general_error)
                                        .setMessage(R.string.register_form_error_message)
                                        .setPositiveButton(R.string.general_ok,   null)
                                        .setNegativeButton(R.string.general_cancel, null).show();
                        return;
                }
        }
//验证码发送end
服务端 LogicProcessor2:
//freeman自定义【接口1008-1-23】ACTION_APPEND5验证手机号
                        case ACTION_APPEND5://ok
                        {
                                UserRegisterDTO urd = JSON.parseObject((String)newData, UserRegisterDTO.class);
                                String statidForReturn = null;
                                String country = urd.getUser_country_code();
                                String phone = urd.getUser_phone();

                                StringBuffer buffer = new StringBuffer();
                                Random random = new Random();
                                for (int i=0; i<4; i++) {
                                        buffer.append(random.nextInt(10));
                                }
                                //定义发送参数:外部接口地址、key、secret、手机号、签名、模板、随机码、有效时间
                                String jkUrl = null;
                                String jkKey="我的";
                                String jkSecret="我的";
                                String jkPhone = null;
                                String jkSign = null;
                                String jkTemplatId = null;
                                String jkBuffer = buffer.toString();
                                String jkTimeOut = null;
                                if (country=="86"){
                                                jkPhone = phone;
                                                jkUrl="http://api.1cloudsp.com/api/v2/single_send";
                                                jkSign="【彩虹注册】";
                                                jkTemplatId="10485";
                                                jkTimeOut="10分钟";
                                }else {
                                        jkPhone = country + phone;
                                        jkUrl="http://api.1cloudsp.com/intl/api/v2/send";
                                        jkSign="[rainbowIm]";
                                        jkTemplatId="1190";
                                        jkTimeOut="10Min";
                                }
                               
                        HttpClient httpClient = new HttpClient();
                        PostMethod postMethod = new PostMethod(jkUrl);
                        postMethod.getParams().setContentCharset("UTF-8");
                        postMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,new DefaultHttpMethodRetryHandler());

                        NameValuePair[] data = {
                                new NameValuePair("accesskey", jkKey),
                                new NameValuePair("secret", jkSecret),
                                new NameValuePair("sign", jkSign),
                                new NameValuePair("templateId", jkTemplatId),
                                new NameValuePair("mobile", jkPhone),
                                new NameValuePair("content", URLEncoder.encode(jkBuffer+"##"+jkTimeOut, "utf-8"))//(示例模板:{1}您好,您的订单于{2}已通过{3}发货,运单号{4})
                        };
                        postMethod.setRequestBody(data);
                        postMethod.setRequestHeader("Connection", "close");

                        int statusCode = httpClient.executeMethod(postMethod);
                        System.out.println("statusCode: " + statusCode + ", body: "
                                    + postMethod.getResponseBodyAsString());
                        if (postMethod.getStatusCode()==0) { //成功
                                req.getSession().setAttribute("code", jkBuffer);
                                req.getSession().setAttribute("number", jkPhone);
                                req.getSession().setAttribute("time", System.currentTimeMillis());
                                        statidForReturn = "1";//发送成功
                        }else {
                                        statidForReturn = "0";
                        }
                                return JSON.toJSONString(RestHashMap.n().p("stat_id", statidForReturn));                                               
                        }
客户端log:
I/ViewRootImpl: onBatchedInputEventPending @@@@
I/ViewRootImpl: onBatchedInputEventPending @@@@
E/ViewRootImpl: lhf  @@ scheduleConsumeBatchedInput: mConsumeBatchedInputScheduled = true,mPendingInputEventHead = null,mTraversalScheduled=false, this = ViewRoot{17569436 com.x52im.rainbowchat_pro/com.x52im.rainbowchat.logic.register.RegisterActivity,ident = 2}
I/ViewRootImpl: onBatchedInputEventPending @@@@
E/ViewRootImpl: lhf  @@ scheduleConsumeBatchedInput: mConsumeBatchedInputScheduled = true,mPendingInputEventHead = null,mTraversalScheduled=false, this = ViewRoot{17569436 com.x52im.rainbowchat_pro/com.x52im.rainbowchat.logic.register.RegisterActivity,ident = 2}
I/ViewRootImpl: onBatchedInputEventPending @@@@
E/ViewRootImpl: lhf  @@ scheduleConsumeBatchedInput: mConsumeBatchedInputScheduled = true,mPendingInputEventHead = null,mTraversalScheduled=false, this = ViewRoot{17569436 com.x52im.rainbowchat_pro/com.x52im.rainbowchat.logic.register.RegisterActivity,ident = 2}
E/ViewRootImpl: lhf  @@ scheduleConsumeBatchedInput: mConsumeBatchedInputScheduled = true,mPendingInputEventHead = null,mTraversalScheduled=true, this = ViewRoot{17569436 com.x52im.rainbowchat_pro/com.x52im.rainbowchat.logic.register.RegisterActivity,ident = 2}
I/ViewRootImpl: onBatchedInputEventPending @@@@
E/ViewRootImpl: lhf  @@ scheduleConsumeBatchedInput: mConsumeBatchedInputScheduled = true,mPendingInputEventHead = null,mTraversalScheduled=true, this = ViewRoot{17569436 com.x52im.rainbowchat_pro/com.x52im.rainbowchat.logic.register.RegisterActivity,ident = 2}
I/ViewRootImpl: onBatchedInputEventPending @@@@
E/ViewRootImpl: lhf  @@ scheduleConsumeBatchedInput: mConsumeBatchedInputScheduled = true,mPendingInputEventHead = null,mTraversalScheduled=false, this = ViewRoot{17569436 com.x52im.rainbowchat_pro/com.x52im.rainbowchat.logic.register.RegisterActivity,ident = 2}
I/ViewRootImpl: onBatchedInputEventPending @@@@
E/ViewRootImpl: lhf  @@ scheduleConsumeBatchedInput: mConsumeBatchedInputScheduled = true,mPendingInputEventHead = null,mTraversalScheduled=false, this = ViewRoot{17569436 com.x52im.rainbowchat_pro/com.x52im.rainbowchat.logic.register.RegisterActivity,ident = 2}
E/ViewRootImpl: lhf  @@ scheduleConsumeBatchedInput: mConsumeBatchedInputScheduled = true,mPendingInputEventHead = null,mTraversalScheduled=true, this = ViewRoot{17569436 com.x52im.rainbowchat_pro/com.x52im.rainbowchat.logic.register.RegisterActivity,ident = 2}
D/libc-netbsd: [getaddrinfo]: mtk hostname=192.168.1.101; servname=(null); cache_mode=(null), netid=0; mark=0
D/libc-netbsd: getaddrinfo( app_uid:10143
               getaddrinfo() uid prop:
               getaddrinfo() getuid():10143
               [getaddrinfo]: mtk ai_addrlen=0; ai_canonname=(null); ai_flags=4; ai_family=0
D/libc-netbsd: [getaddrinfo]: mtk hostname=192.168.1.101; servname=(null); cache_mode=(null), netid=0; mark=0
               getaddrinfo( app_uid:10143
               getaddrinfo() uid prop:
               getaddrinfo() getuid():10143
D/libc-netbsd: [getaddrinfo]: mtk ai_addrlen=0; ai_canonname=(null); ai_flags=4; ai_family=0
I/System.out: [CDS]connect[/192.168.1.101:7080] tm:30
I/System.out: [OkHttp] sendRequest>>
I/System.out: [OkHttp] sendRequest<<
I/NetworkManagementSocketTagger: untagSocket(30)
I/System.out: --成功
服务端log:
[DEBUG] - [20:25:28.910]>>S 客户端Cookie=null ip=192.168.1.102:38902 | (HttpController.process:110)
[DEBUG] - [20:25:28.910]【==> 收到接口请求-数据原型】:{"actionId":23,"device":0,"doInput":true,"jobDispatchId":1,"newData":"{\"user_country_code\":\"+86\",\"user_phone\":\"12211112222\"}","processorId":1008} | (MyControllerJSON.recieveFromClient:469)
[DEBUG] - [20:25:28.911]〖 [HTTP][客户端类型:Android] 捕获REST【接口1008-1-23】的请求,安全token=null 〗 | (MyControllerJSON.dispatch:96)
[DEBUG] - [20:25:28.912]【<== 处理完成-返回JSON结果】:{"success":true} | (MyControllerJSON.sendToClient:444)
你贴的信息里,客户端的log不全,而且你把RainbowChat进程之外的log也抓出来,而它本身的log你几乎没有抓到。因为你说的客户报错,在log里一行都没体现出来。

所以,你要做的是:
  • 1)把服务端的代码全部注释掉,造一个静态的对象,看看return的值在客户端能不能收到,目的是排除你那一大砣httpclient调用外网的接口的逻辑干扰;
  • 2)一定要想办法把客户端的log抓出来,因为界面上的错误都会对应控制台下的异常信息,你要排除干扰抓出有用信息。

理论上这么多接口,你对着任何一个照葫芦画瓢不可能出问题。我建议你把客户端的调用代码和服务端的调用原理都看看,这样就能做到心中有数。

另外,正常情况下,服务端的接口返回,如果你指明了return值,都会有一个"returnValue"字段,你的却没有这个字段(而你的代码里明明有return了一个Json.toString),这也是一个奇怪的地方,你要追查一下为什么,以下是一个真常接口返回结果,仅供参考:
[DEBUG] - [18/09/03 22:13:40.641]【<== 处理完成-返回JSON结果】:{"success":true,"returnValue":"[{\"online\":false,\"user_uid\":\"400069\",\"user_mail\":\"jb2011@163.com\",\"nickname\":\"Jack Jiang\",\"user_sex\":\"1\",\"liveStatus\":0,\"man\":true,\"userAvatarFileName\":\"a.jpg\",\"whatsUp\":\"爱情原如树叶一样,在人忽视里绿了,在忍耐里露出蓓蕾。\"},{\"online\":false,\"user_uid\":\"400070\",\"user_mail\":\"413980957@qq.com\",\"nickname\":\"Lily Sala\",\"user_sex\":\"0\",\"liveStatus\":0,\"man\":false,\"userAvatarFileName\":\"a.jpg\",\"whatsUp\":\"今天好冷,温度只有几度!\"}]"} | (MyControllerJSON^sendToClient:345)
服务端代码净化为
                        case ACTION_APPEND5://ok
                        {
                                System.out.println("111");

                                return JSON.toJSONString(RestHashMap.n().p("stat_id", "0"));
                        }


服务端log:

[INFO] - [21:58:22.188]Hello EVA.EPC,init ok...  | (HttpController.init:55)
[DEBUG] - [21:58:22.189]>>S 客户端Cookie=null ip=192.168.1.102:56656 | (HttpController.process:110)
[DEBUG] - [21:58:22.189]【==> 收到接口请求-数据原型】:{"actionId":23,"device":0,"doInput":true,"jobDispatchId":1,"newData":"{\"user_country_code\":\"+86\",\"user_phone\":\"15512312311\"}","processorId":1008} | (MyControllerJSON.recieveFromClient:469)
[DEBUG] - [21:58:22.346]〖 [HTTP][客户端类型:Android] 捕获REST【接口1008-1-23】的请求,安全token=null 〗 | (MyControllerJSON.dispatch:96)
111
[DEBUG] - [21:58:22.453]【<== 处理完成-返回JSON结果】:{"success":true,"returnValue":"{\"stat_id\":\"0\"}"} | (MyControllerJSON.sendToClient:444)
[DEBUG] - [21:58:22.454]>>E 处理完成,客户端 ip=192.168.1.102:56656 的请处理成功了?true - ret=class java.lang.String | (HttpController.process:141)
客户端log我搞不出正确的,还是这些
09-08 21:58:21.918 30811-31098/com.x52im.rainbowchat_pro D/libc-netbsd: [getaddrinfo]: mtk hostname=192.168.1.101; servname=(null); cache_mode=(null), netid=0; mark=0
                                                                        getaddrinfo( app_uid:10143
                                                                        getaddrinfo() uid prop:
                                                                        getaddrinfo() getuid():10143
                                                                        [getaddrinfo]: mtk ai_addrlen=0; ai_canonname=(null); ai_flags=4; ai_family=0
09-08 21:58:21.918 30811-13411/com.x52im.rainbowchat_pro I/System.out: Close in OkHttp
09-08 21:58:21.919 30811-31098/com.x52im.rainbowchat_pro I/System.out: [CDS]connect[/192.168.1.101:7080] tm:30
09-08 21:58:21.919 30811-13411/com.x52im.rainbowchat_pro I/System.out: [CDS]close[59227]
09-08 21:58:21.919 30811-13411/com.x52im.rainbowchat_pro I/NetworkManagementSocketTagger: untagSocket(32)
09-08 21:58:21.929 30811-31098/com.x52im.rainbowchat_pro I/System.out: [OkHttp] sendRequest>>
09-08 21:58:21.930 30811-31098/com.x52im.rainbowchat_pro I/System.out: [OkHttp] sendRequest<<
09-08 21:58:22.240 30811-31098/com.x52im.rainbowchat_pro I/NetworkManagementSocketTagger: untagSocket(30)
09-08 21:58:22.241 30811-30811/com.x52im.rainbowchat_pro I/System.out: --成功
09-08 21:58:22.242 30811-30811/com.x52im.rainbowchat_pro E/ViewRootImpl: lhf  @@ scheduleConsumeBatchedInput: mConsumeBatchedInputScheduled = true,mPendingInputEventHead = null,mTraversalScheduled=true, this = ViewRoot{106dcb93 com.x52im.rainbowchat_pro/com.x52im.rainbowchat.logic.register.RegisterActivity,ident = 31}




                        if (postMethod.getStatusCode()==0) { //成功
                                req.getSession().setAttribute("code", jkBuffer);
                                req.getSession().setAttribute("number", jkPhone);
                                req.getSession().setAttribute("time", System.currentTimeMillis());
                                        statidForReturn = "1";//发送成功
                        }else {
                                        statidForReturn = "0";
                        }
              
                                return JSON.toJSONString(RestHashMap.n().p("stat_id", statidForReturn));        

这段代码中,如果if代码执行错误或未执行,未获得statidForReturn,即statidForReturn为null,是不是就不会返回returnValue了?
照目前情况,是否可以判定问题就出在case ACTION_APPEND5:{}里了?
                       
故障点大致找到了
服务端
                                System.out.println("aaaaa");//测试
                        HttpClient httpClient = new HttpClient();
                        System.out.println("1");//测试
                        PostMethod postMethod = new PostMethod(jkUrl);
                        System.out.println("2");//测试
                        postMethod.getParams().setContentCharset("UTF-8");
                        System.out.println("3");//测试
                        postMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,new DefaultHttpMethodRetryHandler());
                        System.out.println("bbbb");//测试
只能打出aaaaa,后面的都打不出。
代码没提示错误,或许是commons-httpclient-3.1.jar插件的问题,这个插件官网已不提供,从其他地方下的。也或许是这个插件失效了?
引用:freeman 发表于 2018-09-09 00:11
故障点大致找到了
服务端
                                System.out.println("aaaaa");//测试

很有可能就是这个原因吧,不然代码不可能走不下去。httpclient现在都用的不多了吧,你去用okhttp吧
打赏楼主 ×
使用微信打赏! 使用支付宝打赏!

返回顶部