Android から Picasa に接続するためにGoogle Data APIを使用しています。写真とメタデータを取得するのはうまくいきますが、PATCH の応答を解析するときに IllegalArgumentException が発生します (オリジナルと比較して)。parseAsString メソッドの出力は完全な xml 文字列を提供しますが、ヘッダーは「text/html」です。これはバグですか、それとも「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;
}
編集: 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)