【问题标题】:Blackberry: Java app calling webservice through blackberry enterprise serverBlackberry:通过黑莓企业服务器调用webservice的Java app
【发布时间】:2011-11-12 21:19:11
【问题描述】:

我有一个用于黑莓的 Java 应用程序,使用 Java Plug-in for Eclipse 创建。我想通过 Blackberry mds 在网络服务器上调用网络服务。我使用的代码有效,但不稳定。这意味着我连续 100 次成功地与 Web 服务器取得联系,但过了一会儿,连接断开了。 Blackberry 的日志文件很多且不易阅读,但至少我觉得“无效套接字”这句话对我不利。

我在我的代码中使用了 StreamConnection 类,但我从一些示例代码中看到改用了 httpConnection。有谁知道什么时候使用 HttpConnection 而不是 StreamConnection?

我在这里粘贴我的代码。也许你们中的一些人看到了我应该做的不同的事情:

private boolean sendStatusMessage(String phoneNumber, String status) {
        StreamConnection conn = null;
        OutputStream output = null; //mari added        

        try {
            String body = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:i3w=\"http://I3WebAction\">"
                    + "<soapenv:Header/>"
                    + "<soapenv:Body>"
                    + "<i3w:I3SetMobileStatus><i3w:p_Status>"
                    + status
                    + "</i3w:p_Status><i3w:p_PhoneNumber>"
                    + phoneNumber
                    + "</i3w:p_PhoneNumber>"
                    + "</i3w:I3SetMobileStatus></soapenv:Body></soapenv:Envelope>";

            String URL = "socket://" + soapServer + ":" + port
                    + ";deviceside=false";
            conn = (StreamConnection) Connector.open(URL);

            //OutputStream output = conn.openOutputStream();
            output = conn.openOutputStream();           

            OutputStreamWriter writer = new OutputStreamWriter(output);
            writer.write("POST /SOAPListener/I3SOAPISAPIU.dll HTTP/1.1\r\n");
            writer.write("Accept-Encoding: gzip,deflate\r\n");
            writer.write("Content-Type: text/xml;charset=UTF-8\r\n");
            writer.write("SOAPAction: \"http://I3WebAction/I3SetMobileStatus\"\r\n");
            writer.write("User-Agent: Jakarta Commons-HttpClient/3.1\r\n");
            writer.write("Host: lvkdb01\r\n");
            writer.write("Content-Length: " + body.length() + "\r\n");
            writer.write("\r\n");
            writer.write(body);

            writer.flush();
            writer.close(); //mari added

        } catch (Exception e) {
            Dialog.alert(e.getMessage());
            return false;
        } finally {
            try {
                // Close stream regardless of exceptions and return-points
                output.close();
            } catch (IOException e) {
                // If closing the stream causes exception, the stream is most
                // likely not open or available. We display an error message,
                // and continues the program.
                Dialog.alert(e.getMessage());
                return false;
            }
            try {
                // Close stream regardless of exceptions and return-points
                conn.close();
            } catch (IOException e) {
                // If closing the stream causes exception, the stream is most
                // likely not open or available. We display an error message,
                // and continues the program.
                Dialog.alert(e.getMessage());
                return false;
            }
        }
        return true;
    }

感谢任何有关此代码为何无法稳定运行的 cmets 或想法。

【问题讨论】:

    标签: web-services blackberry httpconnection


    【解决方案1】:

    默认情况下,所有通过 BES 的请求都会被转码。尝试关闭转码,看看是否能解决您的问题。要关闭转码,您需要传递以下标头。

    关闭MD转码:("x-rim-transcode-content", "none) as a header

    MDS 日志会很有用(默认位置 c:\Program Files\Research In Motion\BlackBerryEnterprise Server\Logs)/ 它们以“MDAT”结尾。可以按照这些说明更改日志记录级别。 http://docs.blackberry.com/en/admin/deliverables/14334/Change_logging_level_for_MDSCS_552126_11.jsp

    您还可以启用 Verbose HTTP 日志记录以进行测试,可在此处找到,这可以帮助跟踪 http 消息。 http://docs.blackberry.com/en/admin/deliverables/14334/Change_activities_MDSCS_writes_to_log_827932_11.jsp

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多