2011-09-08 164 views
1

我有一个用于Eclipse的Java插件创建的Java应用程序。我想通过Blackberry mds在网络服务器上调用web服务。我使用的代码有效,但并不稳定。这意味着我成功地连续100次与Web服务器联系,但过了一段时间,连接中断。来自Blackberry的日志文件很多,并且不容易阅读,但至少我觉得“无效套接字”这个短语对我不好。黑莓:通过黑莓企业服务器调用webservice的Java应用程序

我在我的代码中使用了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; 
    } 

我明白为什么这个代码不运行的稳定有任何意见或想法。

回答

0

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

关闭MD转码( “X-轮圈转码内容”,“无)为标题

MDS日志将是有益的(默认位置C:\ Program Files文件\ Research In Motion公司\ BlackBerryEnterprise服务器\日志)/ 他们最终以“MDAT”日志记录级别可以按照以下说明更改。 http://docs.blackberry.com/en/admin/deliverables/14334/Change_logging_level_for_MDSCS_552126_11.jsp

你也可以的方式,使测试放牧,HTTP日志记录,在这里找到,它可以帮助通过跟踪http消息。 http://docs.blackberry.com/en/admin/deliverables/14334/Change_activities_MDSCS_writes_to_log_827932_11.jsp