omeka / plugin-ZoteroImport

Imports libraries and collections from Zotero user and group accounts.
http://omeka.org/codex/Plugins/ZoteroImport
6 stars 2 forks source link

Zotero libraries unable to be verified #2

Closed zerocrates closed 9 years ago

zerocrates commented 13 years ago

Imported from Trac ticket #149 reported by jsafley on 2011-01-23:

Edit: this will be fixed when Omeka upgrades to the most recent Zend Framework version. After that happens, remove the patch and re-test.

When attempting to import, the following flash error occurs when verifying the library:

DOMDocument cannot parse XML: DOMDocument::loadXML(): Empty string
supplied as input. This may indicate that the library or collection
does not exist, you do not have access to the library, or the
private key is invalid.

The following warning occurs when getting the body of the Zotero Atom response:

Warning: gzinflate(): data error in
/var/www/omeka_1_3/application/libraries/Zend/Http/Response.php on
line 609

The response contains a gzipped body, but $response->getBody() returns FALSE because of the gzinflate() data error. DOMDocument::loadXML() cannot parse an empty string (which FALSE resolves to). Does PHP not recognize the Zotero compression? Did Zotero change the way it compresses the response body?

Trace:

ZoteroImport_IndexController::importLibraryAction()
ZoteroImport_IndexController::_verifyLibrary()
ZoteroApiClient_Service_Zotero::userItems()
ZoteroApiClient_Service_Zotero::_getFeed()
Zend_Feed_Abstract::__construct()
Zend_Http_Response::getBody()
zerocrates commented 13 years ago

Comment by jflatnes on 2011-01-23:

If it is truly a change on the Zotero side that Zend_Http can't deal with, you could probably set a blank Accept-Encoding header to stop Zotero sending compressed content altogether.

zerocrates commented 13 years ago

Comment by jsafley on 2011-01-24:

On this page Zotero is returning a gzip deflated response body that PHP cannot inflate using gzinflate() (see error above).

When using the universally acceptable "Accept-encoding: identity" header, Zotero responds with an Atom feed, but with junk before the XML (e.g. 4d2, 15ac). The following error occurs:

DOMDocument cannot parse XML: DOMDocument::loadXML(): Start tag expected, '<' not found in Entity, line: 1.
zerocrates commented 13 years ago

Comment by jsafley on 2011-01-24:

This may be a bug in Zend Framework that may or may not be fixed in newer versions. This bug wasn't exposed until Zotero moved to new sync servers on January 23, so it may be a minor HTTP configuration change in the new server. It may be related to HTTP 1.1 chunks, which account for the junk before the XML.

A workaround is to 1) set the Accept-Encoding header to an empty string or "identity" to prevent the gzinflate() error; and 2) to downgrade the HTTP version from 1.1 to 1.0 to prevent chunked transfer-coding. See the attached patch.

zerocrates commented 13 years ago

Comment by jsafley on 2011-01-24:

Funny thing is, curl correctly removes the chunk data when fetching the response body, but Zend doesn't remove them using Zend_Http_Response::getBody(). The error is possibly in Zend_Http_Response::decodeChunkedBody(), or possibly can be fixed simply by setting the Transfer-Encoding header to "chunked" in ZoteroApiClient_Service_Zotero::_getFeed().

Again, this applies to Zend 1.9.7. It may have been fixed in the more recent releases.

zerocrates commented 13 years ago

Comment by jsafley on 2011-01-24:

It appears that Zend_Http_Reponse does not recognize a "transfer-encoding:chunked" header in the Zotero response, and is therefore not decoding the chunked body, keeping all the chunk data, and resulting in invalid XML. Setting the header in the request does not work.

zerocrates commented 13 years ago

Comment by jsafley on 2011-01-25:

SOLVED:

Zend_Http_Response::extractHeaders() removes the "transfer-encoding:chunked" header, which would otherwise tell Zend_Http_Response::getBody() to parse the chunks, which it is not doing. This is because the Zotero sync server returns the header without horizontal white space between "transfer-encoding:" and "chunked", which correctly follows HTTP 1.1 protocol. Zend, on the other hand, ''does not'' follow the protocol. Fortunately, this is fixed in the most recent version of Zend Framework.

Solutions are to 1) wait until Omeka upgrades Zend Framework, or 2) apply the above patch as a hackish workaround.

zerocrates commented 13 years ago

Comment by jsafley on 2011-01-25:

Solution #3: politely ask Zotero to kindly put a space between "transfer-encoding:" and "chunked".

zerocrates commented 13 years ago

Comment by jsafley on 2011-01-25:

(In [3825]) Refs #149, applies a patch to circumvent a bug in Zend Framework 1.9.7 that removes the "transfer-encoding:chunked" response header from the Zotero sync server.