1

Java Plug-in for Eclipse で作成された、blackberry 用の Java アプリがあります。Blackberry mds を介して Web サーバーで Web サービスを呼び出したいと考えています。私が使用しているコードは機能しますが、安定していません。つまり、100回連続でWebサーバーとの接続に成功しましたが、しばらくすると接続が切断されました。Blackberry からのログ ファイルは多く、読みにくいですが、少なくとも「無効なソケット」というフレーズは私にとっては良くないと感じています。

コードで StreamConnection クラスを使用していますが、いくつかのサンプル コードから、代わりに httpConnection が使用されていることがわかります。StreamConnection の代わりに HttpConnection を使用するタイミングを知っている人はいますか?

ここにコードを貼り付けます。おそらく、私が別のことをすべきだったことに気付く人もいるでしょう。

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;
    }

このコードが安定して動作しない理由について、コメントやアイデアをいただければ幸いです。

4

1 に答える 1

0

デフォルトでは、BESを介したすべてのリクエストがトランスコードされます。トランスコーディングをオフにして、問題が解決するかどうかを確認してください。トランスコーディングをオフにするには、以下のヘッダーを渡す必要があります。

MDトランスコーディングをオフにする:( "x-rim-transcode-content"、 "none)ヘッダーとして

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

ここにあるテスト用にVerboseHTTPロギングを有効にする方法もあります。これは、httpメッセージをトレースするのに役立ちます。 http://docs.blackberry.com/en/admin/deliverables/14334/Change_activities_MDSCS_writes_to_log_827932_11.jsp

于 2012-08-15T14:15:37.787 に答える