Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Abdera ArrayIndexOutOfBoundsException with non-existent atom-entry-study.xml in SWORD jar (upstream ideally) #893

Closed
raprasad opened this issue Sep 2, 2014 · 5 comments
Assignees
Labels
Type: Bug a defect

Comments

@raprasad
Copy link
Contributor

raprasad commented Sep 2, 2014


Author Name: Philip Durbin (@pdurbin)
Original Redmine Issue: 3305, https://redmine.hmdc.harvard.edu/issues/3305
Original Date: 2013-09-16


If you attempt to create a study via SWORD with an Atom entry file that doesn't exist you will see "org.apache.abdera.parser.ParseException: java.lang.ArrayIndexOutOfBoundsException" from the client side...

murphy:dvn pdurbin$ file atom-entry-study.xml
atom-entry-study.xml: cannot open `atom-entry-study.xml' (No such file or directory)
murphy:dvn pdurbin$ curl --insecure -s --data-binary "@atom-entry-study.xml" -H "Content-Type: application/atom+xml" -u sword:sword https://localhost:8181/dvn/api/data-deposit/v1/swordv2/collection/dataverse/sword | xmllint -format -
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>GlassFish Server Open Source Edition 3.1.2.2 - Error report</title>
    <style type="text/css">
<!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}HR {color : #525D76;}-->
    </style>
  </head>
  <body>
    <h1>HTTP Status 500 - </h1>
    <hr />
    <p><b>type</b> Exception report</p>
    <p>
      <b>message</b>
    </p>
    <p><b>description</b>The server encountered an internal error () that prevented it from fulfilling this request.</p>
    <p>
      <b>exception</b>
      ```org.apache.abdera.parser.ParseException: java.lang.ArrayIndexOutOfBoundsException
</p>
<p>
  <b>note</b>
  <u>The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.1.2.2 logs.</u>
</p>
<hr />
<h3>GlassFish Server Open Source Edition 3.1.2.2</h3>
murphy:dvn pdurbin$

... and in the Glassfish server.log, this error appears:

[#|2013-09-16T08:19:33.170-0400|WARNING|glassfis###1.2|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=33;_ThreadName=Thread-4;|StandardWrapperValve[edu.harvard.iq.dvn.core.web.servlet.SWORDv2CollectionServlet]: PWC1406: Servlet.service() for servlet edu.harvard.iq.dvn.core.web.servlet.SWORDv2CollectionServlet threw exception
org.apache.abdera.parser.ParseException: java.lang.ArrayIndexOutOfBoundsException
at org.apache.abdera.parser.stax.FOMParser.parse(FOMParser.java:128)
at org.apache.abdera.util.AbstractParser.parse(AbstractParser.java:65)
at org.swordapp.server.SwordAPIEndpoint.addDepositPropertiesFromEntry(SwordAPIEndpoint.java:334)
at org.swordapp.server.CollectionAPI.post(CollectionAPI.java:156)
at edu.harvard.iq.dvn.core.web.servlet.SWORDv2CollectionServlet.doPost(SWORDv2CollectionServlet.java:37)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:115)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:328)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at java.io.PushbackInputStream.unread(PushbackInputStream.java:218)
at org.apache.abdera.i18n.text.io.DynamicPushbackInputStream.unread(DynamicPushbackInputStream.java:91)
at org.apache.abdera.i18n.text.io.PeekAheadInputStream.peek(PeekAheadInputStream.java:61)
at org.apache.abdera.i18n.text.io.PeekAheadInputStream.peek(PeekAheadInputStream.java:52)
at org.apache.abdera.i18n.text.io.CharsetSniffingInputStream.detectEncoding(CharsetSniffingInputStream.java:110)
at org.apache.abdera.parser.stax.util.FOMSniffingInputStream.detectEncoding(FOMSniffingInputStream.java:39)
at org.apache.abdera.i18n.text.io.CharsetSniffingInputStream.(CharsetSniffingInputStream.java:81)
at org.apache.abdera.i18n.text.io.CharsetSniffingInputStream.(CharsetSniffingInputStream.java:74)
at org.apache.abdera.parser.stax.util.FOMSniffingInputStream.(FOMSniffingInputStream.java:35)
at org.apache.abdera.parser.stax.FOMParser.parse(FOMParser.java:107)
... 37 more
|#]


org.swordapp.server.SwordAPIEndpoint.addDepositPropertiesFromEntry(SwordAPIEndpoint.java:334) corresponds to https://github.com/IQSS/swordv2-java-server-library/blob/aeaef8342361bf3de7e9fc8f2a979cd742bc31ae/src/main/java/org/swordapp/server/SwordAPIEndpoint.java#L334 which is unmodified from https://github.com/swordapp/JavaServer2.0/blob/master/src/main/java/org/swordapp/server/SwordAPIEndpoint.java#L334

Here is the relevant block of code:

328 protected void addDepositPropertiesFromEntry(Deposit deposit, HttpServletRequest req)
329 throws IOException
330 {
331 InputStream entryPart = req.getInputStream();
332 Abdera abdera = new Abdera();
333 Parser parser = abdera.getParser();
334 Document entryDoc = parser.parse(entryPart);
335 Entry entry = entryDoc.getRoot();
336 deposit.setEntry(entry);
337 }


We should probably start by reporting this on the SWORD mailing list ( https://lists.sourceforge.net/lists/listinfo/sword-app-tech ) or submit another pull request as we did with https://github.com/swordapp/JavaServer2.0/pull/3


@raprasad
Copy link
Contributor Author

raprasad commented Sep 2, 2014


Original Redmine Comment
Author Name: Philip Durbin (@pdurbin)
Original Date: 2014-07-01T17:59:32Z


This bug still exists in the upstream, though it's in a different place now:

https://github.com/swordapp/JavaServer2.0/blob/sword2-server-1.0/src/main/java/org/swordapp/server/SwordAPIEndpoint.java#L355

Perhaps they should add a try/catch?

  StandardWrapperValve[edu.harvard.iq.dataverse.api.datadeposit.SWORDv2CollectionServlet]: Servlet.service() for servlet edu.harvard.iq.dataverse.api.datadeposit.SWORDv2CollectionServlet threw exception
org.apache.abdera.parser.ParseException: java.lang.ArrayIndexOutOfBoundsException
    at org.apache.abdera.parser.stax.FOMParser.parse(FOMParser.java:128)
    at org.apache.abdera.util.AbstractParser.parse(AbstractParser.java:65)
    at org.swordapp.server.SwordAPIEndpoint.addDepositPropertiesFromEntry(SwordAPIEndpoint.java:355)
    at org.swordapp.server.CollectionAPI.post(CollectionAPI.java:156)
    at edu.harvard.iq.dataverse.api.datadeposit.SWORDv2CollectionServlet.doPost(SWORDv2CollectionServlet.java:34)

@raprasad
Copy link
Contributor Author

raprasad commented Sep 2, 2014


Original Redmine Comment
Author Name: Philip Durbin (@pdurbin)
Original Date: 2014-07-01T18:18:16Z


I filed an issue upstream: swordapp/JavaServer2.0#6

@pdurbin
Copy link
Member

pdurbin commented Oct 21, 2014

As of 2c1cfd5 this error should be fixed. Rather than a crazy Glassfish exception we get a sane "Unable to parse SWORD entry" message to report back to the user:

$ touch /tmp/empty-file.xml

$ curl --insecure --data-binary @/tmp/empty-file.xml -H 'Content-Type: application/atom+xml' -u pete:pete https://localhost:8181/dvn/api/data-deposit/v1/swordv2/collection/dataverse/peteTop

<?xml version="1.0" encoding="ISO-8859-1"?> <sword:error href="Unable to parse SWORD entry: org.apache.abdera.parser.ParseException: java.lang.ArrayIndexOutOfBoundsException" xmlns:sword="http://purl.org/net/sword/terms/"><atom:title xmlns:atom="http://www.w3.org/2005/Atom">ERROR</atom:title><atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2014-10-21T10:58:27Z</atom:updated><atom:generator uri="http://www.swordapp.org/" version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"/><sword:treatment>Processing failed</sword:treatment><atom:summary xmlns:atom="http://www.w3.org/2005/Atom">Unable to parse SWORD entry: org.apache.abdera.parser.ParseException: java.lang.ArrayIndexOutOfBoundsException</atom:summary></sword:error>

Please note that this fix required patching the upstream SWORD library. I have submitted a pull request here:

throw SwordError for unparseable Atom entry swordapp/JavaServer2.0#6 by pdurbin · Pull Request #7 · swordapp/JavaServer2.0 - swordapp/JavaServer2.0#7

If the pull request gets accepted and a new upstream version is released, we should upgrade to it. I left a note about this in our pom.xml:

<dependency>

Passing to QA.

@esotiri
Copy link
Contributor

esotiri commented Oct 29, 2014

Create a study for non-existent atom-entry-study.xml

curl -s --insecure --data-binary "@xml/atom-entry-study-non-exixtent.xml" -H "Content-Type: application/atom+xml" https://$user:$passwd@$host/dvn/api/data-deposit/v1/swordv2/collection/dataverse/$DATAVERSE_ALIAS | xmllint -format -

Below is the sword output:

`

<sword:error xmlns:sword="http://purl.org/net/sword/terms/" href="Unable to parse SWORD entry: org.apache.abdera.parser.ParseException: java.lang.ArrayIndexOutOfBoundsException">
<atom:title xmlns:atom="http://www.w3.org/2005/Atom">ERROR</atom:title>
<atom:updated xmlns:atom="http://www.w3.org/2005/Atom">2014-10-29T12:08:36Z</atom:updated>
<atom:generator xmlns:atom="http://www.w3.org/2005/Atom" uri="http://www.swordapp.org/" version="2.0"/>
sword:treatmentProcessing failed</sword:treatment>
<atom:summary xmlns:atom="http://www.w3.org/2005/Atom">Unable to parse SWORD entry: org.apache.abdera.parser.ParseException: java.lang.ArrayIndexOutOfBoundsException</atom:summary>
</sword:error>
`

@esotiri
Copy link
Contributor

esotiri commented Oct 29, 2014

the message above is much better than the crazy glassfish exception, closing the issue.

@esotiri esotiri closed this as completed Oct 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug a defect
Projects
None yet
Development

No branches or pull requests

5 participants