1 Reply Latest reply: Jan 24, 2013 12:31 PM by Amol Gavali RSS

    GET_FILE returns byte array even when a junk value is passed for ContentId.

    TejaswiniLakshmipathi
      Hi All,


      GET_FILE returns byte array even when a junk value is passed for ContentId.

      Why does it not throw an error, saying ContentId not found and return "null" value for byte array and also not able to create a pdf file with the byte array returned by GET_FILE(when a junk value is passed).

      So then what does that byte array contain.

      Can you please check the code below and let me know if Im missing something.

      Finaaly, I want the code to throw error if the ContentId is not present or return null value for the byte array. Would this be possible, if so then how?

      ******************************************************************************
      byte[] bytes = null;

      inputdataBinder = UCMFactory.idcClient.createBinder();

      inputdataBinder.putLocal(Constants.IDC_SERVICE,
      Constants.GET_FILE);
      inputdataBinder.putLocal(UCMFactory.prop.getProperty("contentId"),
      contentID);
      inputdataBinder.putLocal("RevisionSelectionMethod","LatestReleased")
      inputdataBinder.putLocal("Rendition","Primary");
      ServiceResponse response =
      UCMFactory.idcClient.sendRequest(UCMFactory.userContext,
      inputdataBinder);


      //take the ServiceResponse object and pass it to InputStream object
      InputStream stream = null;

      stream = response.getResponseStream();

      // convert InputStream to byte[]
      bytes = IOUtils.toByteArray(stream);
      ******************************************************************************

      Thanks,
      Tejaswini L
        • 1. Re: GET_FILE returns byte array even when a junk value is passed for ContentId.
          Amol Gavali
          you could code like something below

                  DataBinder fileinfobinder;
                  DataResultSet getFileResults;
                  
                  try{
                      fileinfobinder=response.getResponseAsBinder();
          
                      getFileResults = fileinfobinder.getResultSet ("FileInfo");
                      
                      if(null!=getFileResults){
                      
                      //The file is streamed back to us in the response
                      InputStream stream = response.getResponseStream ();
                      try {
                          int read = 0;
                          byte [] buf = new byte [256];
                          while ((read = stream.read (buf)) != -1) {
                              retrievedSize += read;
                              contentsInHex += toHexString (buf);
                          }
                      } finally {
                          //It is very important that we close the stream thus releasing the connection
                          stream.close ();
                      }
          
                      System.out.println(String.format("First 10 bytes in hex: %s", contentsInHex.substring (0, 10).toUpperCase ()));
                      System.out.println(String.format("Total bytes retrieved: %d of reported: %d", retrievedSize, reportedSize));
          
                      }
                      else{
                           
                           System.out.println("file not found");     
                      }
                  }catch(Exception e){
                       System.out.println("file not found");     
                  }
          Regards,
          Amol Gavali.