开发者

Java Swift BICDownload exitcode=0

I'm automating the download of BIC file, using the Swift Automation Interface Spec

The all ok scenario works ok, but in a simple error scenarios testing with invalid credentials the code in the java sample client application returns a ex开发者_如何学Pythonitcode of 0.

What is wrong with this code?

/* * Created on Mar 2, 2007 * S.W.I.F.T. s.c.r.l. */

public class BICDownloader {

public static void main(String[] args) { ... try { ... // Executing the method. statusCode = client.executeMethod(method);

  if (statusCode != HttpStatus.SC_OK) {
   // Handling HTTP error 404 and 500 not covered in this example
   // All http error cause in this example exit with status 1.
   System.err.println("Method failed: " + method.getStatusLine()+
   "\n" + method.getResponseBodyAsString());
   System.out.println(method.getRequestCharSet()+
  "\n" + method.getRequestHeader("").toString());
   exitcode = 1; 
  }
  else {
 ...
  }      
 } catch (HttpException e) {
  exitcode = 2;
  System.err.println("Fatal HTTP Error: " + e.getMessage());
  e.printStackTrace();
 } catch (IOException e) {
  exitcode = 3;
  System.err.println("Fatal I/O error: " + e.getMessage());
  e.printStackTrace();
 } finally {
  // Release the connection.
  method.releaseConnection();
  System.exit(exitcode);
 } 
 System.out.println("Dowload done");  

} }


The problem is caused by a hidden NullPointerException, the cause of problem is in the block of code

        System.out.println(method.getRequestCharSet()+
        "\n" + method.getRequestHeader("").toString());
        exitcode = 1;

The solution I chosen is changing the instruction method.getRequestHeader("").toString() to Arrays.toString(method.getRequestHeaders()) and adding the clause } catch (Exception e) just in case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜