Search Mailing List Archives

Limit search to: Subject & Body Subject Author
Sort by: Reverse Sort
Limit to: All This Week Last Week This Month Last Month
Select Date Range     through    

[bioontology-support] Error using the Annotator service in Linux

Leyla Jael García Castro leylajael at
Sat Feb 15 13:55:03 PST 2014

Hi Paul,

Here is the excerpt of the code that is calling the annotation. btw, I have
been playing around with the text that is giving us troubles, for instance
I moved it above other paragraphs that are correctly annotated. Then, it
was another paragraph the one that gave us the error. Is there maybe a
maximum API calls per second? Could be that why at some point the API key
seems to be not valid any more? I tried to look for hidden chars but there
was nothing special, just regular text with tabs and spaces.
We also tried to replace the "+" added by the encoder instead of the spaces
to "%20", and to spaces again, but  we got the same API key problem.

String ontologiesToAnnotate =
String annotatorURL = "";
String stopwords =
//and some others

        try {
        paragraph = paragraph.replaceAll("[^\\p{Alpha}\\p{Z}\\p{P}\\p{N}]",
        paragraph = URLEncoder.encode(paragraph,
        System.out.println("TO ANNOT: " + urlContext + "\n" + paragraph);
            HttpClient client = new HttpClient();
"Annotator Client Scientific Publications");  //Set this string for your

            PostMethod method = new PostMethod(annotatorURL);

            // Configure the form parameters
            method.addParameter("ontologies", ontologiesToAnnotate);

            method.addParameter("text", paragraph);
            method.addParameter("format", "xml"); //Options are 'text',
'xml', 'tabDelimited'
            method.addParameter("apikey", Config.getNCBOAPIKey());

            // Execute the POST method
            int statusCode = client.executeMethod(method);

            if( statusCode != -1 ) {
                try {
                InputStream temporal  = method.getResponseBodyAsStream();
                //testing, we want to see the response and if it is ok we
want to process it so we need it twice
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                byte[] buf = new byte[1024];
                int n = 0;
                while ((n = >= 0) {
                    baos.write(buf, 0, n);
                byte[] content = baos.toByteArray();
                InputStream annotatedParagraph = new
                if (annotatedParagraph != null) {
                 //Reader reader = new StringReader(annotatedParagraph);
             JAXBContext jc =
             Unmarshaller unmarshaller = jc.createUnmarshaller();
             AnnotationCollection xml;
             Object obj = new Object();
             try {
             obj = unmarshaller.unmarshal(annotatedParagraph);
             if (obj instanceof Empty) {
             return true; //no annotations were found but everything was ok
with the response
             xml = (AnnotationCollection)obj; //otherwise,
AnnotationCollection should be the unmarshalled object
             } catch (Exception e) {
             InputStream temp = new ByteArrayInputStream(content);
             String line;
                    BufferedReader reader = new BufferedReader(new
InputStreamReader(temp, "UTF-8"));
                    while ((line = reader.readLine()) != null) {
            logger.fatal("- FATAL DTD ERROR ANNOTATOR - NCBO annotations
for " + this.documentId + "(" + urlContext + ") cannot be unmarshalled: " +
e.getMessage() + " - class: " + obj.getClass());
             return false;

then I just start processing the response. If you need, I can send you the
actual java class, but I am afraid that it depends on some other libraries,
jaxb, etc. so unless I share you the whole project it would not work.
Please let me know should you need any further information.


On Fri, Feb 14, 2014 at 11:11 PM, Paul R Alexander
<palexander at>wrote:

> How is the call being invoked? Can you share the code that is actually
> doing the call?
> Thanks,
> Paul
> On Feb 14, 2014, at 1:20 PM, Leyla Jael García Castro <leylajael at>
> wrote:
> Hi all,
> I am using the Annotator service successfully on Windows but, what the
> odds, the same code with the same text is not working on Linux.
> This is the text after URL enconding:
> This+analysis+evidence+that+there+is+a+large+difference+in+efficiency+of+the+tested+methods+and+that+care+has+to+be+taken+when+deciding+which+method+to+be+used+for+the+analysis+of+missing+covariates+in+nonlinear+mixed+effects+modelling.
> And this is the response we are getting:
> <?xml version="1.0" encoding="UTF-8"?>
> <hash>
>   <status>401</status>
>   <error>You must provide a valid API Key. Your API Key can be obtained by
> logging in at</error>
> </hash>
> Any suggestions? This is really puzzle me.
> Best regards,
> lj
> _______________________________________________
> bioontology-support mailing list
> bioontology-support at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the bioontology-support mailing list