Author Topic: ODWek Java API - recreateHit issues <Resolved>  (Read 9114 times)

ODCoder

  • Guest
ODWek Java API - recreateHit issues <Resolved>
« on: March 12, 2019, 02:21:12 AM »
Hello all,

I have successfully managed to return a list of documents based on a search criteria.  The next step is the user selects which document they want to return and it displays the document.    So I have returned a list of documents, which includes the (I assume encrypted) document ID ODHit.getDocId().  Now I'm trying to get the document using recreateHit as follows:

Code: [Select]

try
{
odHit = odFolder.recreateHit(inDocID);
}


I was expecting to maybe have an issue because im sending back an encrypted docid, but to my surprise, I get the follow error in the exception:

Code: [Select]

Error 500: java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: The user specified does not have access to any folders


Is that just a masked way of saying that its encrypted?  Do I have to do a bit more than just recreateHit?  I'm not seeing much in the documentation that suggests I need to do more.

Any idea's?

Thanks very much!

DB
« Last Edit: March 21, 2019, 02:44:13 AM by ODCoder »

rjrussel

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Re: ODWek Java API - recreateHit issues
« Reply #1 on: March 12, 2019, 05:49:36 AM »
What version of OnDeamand are you running?

My guess is you need to switch to getOpenDocId() as the docID's are now tied to a user. 

Thanks,

RR




ODCoder

  • Guest
Re: ODWek Java API - recreateHit issues
« Reply #2 on: March 12, 2019, 06:16:54 AM »
Ohhh, ok that kind of makes sense.  OnDemand 10.1.  I will give that a try now. Thank you!

ODCoder

  • Guest
Re: ODWek Java API - recreateHit issues
« Reply #3 on: March 12, 2019, 06:27:29 AM »
rjrussel, I've been looking at this call.  It doesn't accept any parameters, it just simply returns a string with the new DocID, so what do you pass it?  I can't pass it an ODHit with the user tied docid, or I just get permission denied as before?

Thanks again for your help.

DB

rjrussel

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Re: ODWek Java API - recreateHit issues
« Reply #4 on: March 12, 2019, 07:07:47 AM »
See if this (albeit crude) example helps:

     odServer.logon("shortrib", "admin", "password");
   
   ODFolder folder = odServer.openFolder("Baxter Bay");
   Vector<ODHit> hits = folder.search();
      
   ODHit odHit = (ODHit)hits.get(0);
         
   String hit = odHit.getOpenDocId();
   odServer.logoff();
   odServer.terminate();
   odServer = new ODServer(odConfig);
   odServer.initialize("TestOpenDocId");
   odServer.setPort(0);
   odServer.logon("shortrib", "rjrussel", "password");
   folder = odServer.openFolder("Baxter Bay");
   ODHit hit2 = folder.recreateHit(hit);
        System.out.println("Recreated:" + hit2.getDocumentName());


Keep in mind in order for recreate hit to work the user recreating the hit MUST have permissions to the document. If that user doesn't you will still get an error.

Thanks,
RR

ODCoder

  • Guest
Re: ODWek Java API - recreateHit issues
« Reply #5 on: March 12, 2019, 07:16:12 AM »
Right, I'm with you now, I didn't think about it that way around.

Thanks RR that's perfect!

ODCoder

  • Guest
Re: ODWek Java API - recreateHit issues
« Reply #6 on: March 12, 2019, 07:30:34 AM »
Hi RR, that didn't work.

Here is the situation.  I'm wrapping the java API into rest calls.  The first rest call uses search(), and returns JSON with a list of doc ID's and metadata.  The 2nd REST API, uses the DOC ID to retrieve the document, as base64 JSON.

So these are 2 separate connections, potentially minutes apart, maybe that's the issue here?

rjrussel

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Re: ODWek Java API - recreateHit issues
« Reply #7 on: March 12, 2019, 08:13:59 AM »
So you confirmed you are using getOpenDocId()?

What error are you getting when you attempt to recreate the hit?

ODCoder

  • Guest
Re: ODWek Java API - recreateHit issues
« Reply #8 on: March 12, 2019, 08:49:42 AM »
Correct, I'm using getOpenDocID.

The error I'm getting is-

Code: [Select]


Error 500: java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: The user specified does not have access to any folders


Obvoiusly teh 500 apache stuff is just hte webservice error.  The "The user specified does not have access to any folders" is the OD error.

For reference, here is the first part of hte call:

Code: [Select]

ODServer odServer;
ODFolder odFolder = null;
ODHit odHit;
ODHit odHitNew;
ODConfig odConfig;
byte[] data_from_server;
File file;

odConfig = new ODConfig();
odServer = new ODServer(odConfig);
odServer.setPort(inPort);
odServer.initialize( "TcSQLSearch.java" );

odFolder = odServer.openFolder(inFolder);

try
{

odServer.logon(inServerName, inUserName, inPassword);
}
catch (Exception ex)
{
throw new WebApplicationException(Response.ok(ex).build());

}

try
{
odHit = odFolder.recreateHit(inDocID);


}
catch (Exception ex)
{
throw new WebApplicationException(Response.ok(ex).build());

}


rjrussel

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Re: ODWek Java API - recreateHit issues
« Reply #9 on: March 12, 2019, 09:39:10 AM »
I see it now....

You should really log on before you try and open the folder  ;D

             odFolder = odServer.openFolder(inFolder);
      
      try
      {
         
         odServer.logon(inServerName, inUserName, inPassword);
      }


Swap those two calls and watch the magic happen.

-RR

ODCoder

  • Guest
Re: ODWek Java API - recreateHit issues
« Reply #10 on: March 12, 2019, 09:48:59 AM »
Yes your quite right! And I spotted that too, probably around the time you did :)

Now I'm getting:

{"errorMsg":"Unable to restore hit from DocID","errorId":9,"message":"Unable to restore hit from DocID","localizedMessage":"Unable to restore hit from DocID","stackTrace":[{"className":"com.ibm.edms.od.ODFolder","fileName":"ODFolder.java","lineNumber":2180,"methodName":"recreateHit","nativeMethod":false},

Regardless of which method I use to retrieve the docid

rjrussel

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Re: ODWek Java API - recreateHit issues
« Reply #11 on: March 12, 2019, 10:04:53 AM »
Assuming you have permission to the doc it's probably an encoding issue.....

Create yourself a little stand alone app. Get it working and then incorporate into your rest service.

In most cases the docID you include in your rest response should be URL encoded. Something like:
URLEncoder.encode(odHit.getOpenDocId(), java.nio.charset.StandardCharsets.UTF_8.toString()))

However, when you pass it back in to retrieve the content you shouldn't have to decode....

You're very close.... Good luck

-RR


Alessandro Perucchi

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1002
    • View Profile
Re: ODWek Java API - recreateHit issues
« Reply #12 on: March 12, 2019, 01:20:11 PM »
Well if you get the docid with a user, then use another user to recreate the docid, then it will never work in a default setup.
In order to make it work, you must use an encryption key when you get the docid, and then when you use the other user, you use the same key to decrypt the docid you want to recreate.

Look at this method, because this is exactly what you want to use : ODServer.setEncryptionKey(...). Here is what the Javadoc says:

Quote
Document identifiers (docids) are now encrypted. This method can be called after a user logon to specify the encryption key to be used for docid generation. If this method is not called ODWEK will generate the encryption key. In both instances, the encrypted docid is bound to the userid currently logged in when the docid is generated. This ensures that only this user can retrieve the contents of the document using the docid. This userid binding to the docid can be circumvented by calling this method prior to user logon. When used in this fashion it is imperative that the calling application ensure the docid is only used to retrieve the contents of the document by users with the proper permissions.

Alessandro Perucchi

#Install #Migrations #Conversion #Educate #Repair #Upgrade #Migrate #Enhance #Optimize #AIX #Linux #Multiplatforms #DB2 #Windows #Oracle #TSM #Tivoli #Performance #Audits #Customizing #Availability #HA #DR #JavaApi #ContentNavigator #ICN #WEBi #ODWEK #Services #PDF #AFP #XML

Alessandro Perucchi

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1002
    • View Profile
Re: ODWek Java API - recreateHit issues
« Reply #13 on: March 12, 2019, 01:22:54 PM »
Hmmmm I'm reading the new method ODHit.getOpenDocID(...), interesting, so it means the encryption key method is not anymore needed! Thank you! I will go to bed less stupid than this morning! :-D
Alessandro Perucchi

#Install #Migrations #Conversion #Educate #Repair #Upgrade #Migrate #Enhance #Optimize #AIX #Linux #Multiplatforms #DB2 #Windows #Oracle #TSM #Tivoli #Performance #Audits #Customizing #Availability #HA #DR #JavaApi #ContentNavigator #ICN #WEBi #ODWEK #Services #PDF #AFP #XML

rjrussel

  • Full Member
  • ***
  • Posts: 137
    • View Profile
Re: ODWek Java API - recreateHit issues
« Reply #14 on: March 12, 2019, 05:16:24 PM »
Using the getOpenDocID() comes with some overhead so it should be used wisely. Since there is no user tied to it we must makes sure the user who now has possession of the docid is authorized to see the content they are requesting.

So in the case of REST based services one should be using connection pooling (whenever possible) and therefor the getOpenDocID really shouldn't be needed..... At least in most cases.....