Я использую Google Data API для подключения Picasa с Android. Для извлечения изображений и метаданных это прекрасно работает, но я получаю исключение IllegalArgumentException при разборе ответа PATCH (относительно оригинала). Заголовок «text / html», хотя выход метода parseAsString обеспечивает идеальную строку XML. Это ошибка или мне нужно создать свой собственный анализатор для "text / html"?
Я бы тоже не отказался от обновления с помощью PUT-метода. У кого-нибудь есть хороший пример, как это сделать с Java?
Здесь исключение:
Uncaught handler: thread main exiting due to uncaught exception
java.lang.IllegalArgumentException: No parser defined for Content-Type: text/html; charset=UTF-8
at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:277)
at com.unimelb.pt3.external.google.api.Entry.executePatchRelativeToOriginal(Entry.java:95)
at com.unimelb.pt3.external.google.api.PhotoEntry.executePatchRelativeToOriginal(PhotoEntry.java:67)
at com.unimelb.pt3.Picasa.updatePicture(Picasa.java:135)
at com.unimelb.pt3.Tools.updatePictureOnPicasa(Tools.java:209)
at com.unimelb.pt3.ui.WaterfallView.onDraw(WaterfallView.java:145)
at android.view.View.draw(View.java:6535)
at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
at android.view.View.draw(View.java:6538)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
at android.view.View.draw(View.java:6538)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1830)
at android.view.ViewRoot.draw(ViewRoot.java:1349)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1114)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
Вот код в записи:
Entry executePatchRelativeToOriginal(HttpTransport transport, Entry original)
throws IOException {
HttpRequest request = transport.buildPatchRequest();
request.setUrl(getEditLink());
request.headers.ifMatch = etag;
AtomPatchRelativeToOriginalContent content =
new AtomPatchRelativeToOriginalContent();
content.namespaceDictionary = Util.NAMESPACE_DICTIONARY;
content.originalEntry = original;
content.patchedEntry = this;
request.content = content;
Log.i(Prototype.TAG, request.url.toString());
HttpResponse response = request.execute();
// Log.i(Prototype.TAG, response.parseAsString());
return response.parseAs(getClass());
}
Вот соответствующий код из основного занятия:
public void updatePicture(String url, String description, String[] tags) throws IOException {
PhotoEntry photo = photos.get(url);
PhotoEntry patched = photo.clone();
patched.summary = description;
String keywords = "";
for(int i=0; i<tags.length; i++) {
keywords += tags[i] + ((i==tags.length-1) ? "" : ", ");
}
patched.mediaGroup.keywords = keywords;
photo = patched.executePatchRelativeToOriginal(transport, photo);
}
private HttpTransport setUpTransport() {
HttpTransport transport = GoogleTransport.create();
GoogleHeaders headers = (GoogleHeaders) transport.defaultHeaders;
headers.setApplicationName("google-picasaatomsample-1.0");
headers.gdataVersion = "2";
AtomParser parser = new AtomParser();
parser.namespaceDictionary = Util.NAMESPACE_DICTIONARY;
transport.addParser(parser);
return transport;
}
EDIT:
Я добавил в метод setUpTransport следующие строки:
XmlHttpParser p2 = new XmlHttpParser();
p2.contentType = "text/html";
p2.namespaceDictionary = Util.NAMESPACE_DICTIONARY;
transport.addParser(p2);
Это приводит к другому IllegalArgumentException с этим журналом:
Uncaught handler: thread main exiting due to uncaught exception
java.lang.IllegalArgumentException: expected start of XML element, but got something else (event type 4)
at com.google.api.client.xml.Xml.parseElementInternal(Xml.java:180)
at com.google.api.client.xml.Xml.parseElement(Xml.java:152)
at com.google.api.client.xml.XmlHttpParser.parse(XmlHttpParser.java:73)
at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:280)
at com.unimelb.pt3.external.google.api.Entry.executePatchRelativeToOriginal(Entry.java:95)
at com.unimelb.pt3.external.google.api.PhotoEntry.executePatchRelativeToOriginal(PhotoEntry.java:67)
at com.unimelb.pt3.Picasa.updatePicture(Picasa.java:130)
at com.unimelb.pt3.Tools.updatePictureOnPicasa(Tools.java:209)
at com.unimelb.pt3.ui.WaterfallView.onDraw(WaterfallView.java:145)
at android.view.View.draw(View.java:6535)
at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:158)
at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
at android.view.View.draw(View.java:6538)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
at android.view.View.draw(View.java:6538)
at android.widget.FrameLayout.draw(FrameLayout.java:352)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1830)
at android.view.ViewRoot.draw(ViewRoot.java:1349)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1114)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)