derui / booklog-sns

6 stars 0 forks source link

バーコード検索APIで、Amazonから返却されたXMLを変換する箇所でIllegalArgumentExceptionが発生している #94

Closed kimura-m-29 closed 11 years ago

kimura-m-29 commented 11 years ago

何度読み取らせてもステータス500が返るので、ログを仕込んだところ、ちゃんとバーコードを読み取れていました。 が、その後の、Amazonから返却されたXMLを変換するところで下記のエラーが発生していました。

[info] application - start : 1 : /api/amazon_barcode with [Map(_ -> Buffer(1365267489594))]
[info] application - <ItemLookupResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01"><OperationRequest><HTTPHeaders><Header Value="Java/1.7.0_07" Name="UserAgent"/></HTTPHeaders><RequestId>e2443451-aae7-4147-a712-475be569afaa</RequestId><Arguments><Argument Value="ItemLookup" Name="Operation"/><Argument Value="AWSECommerceService" Name="Service"/><Argument Value="derui09-22" Name="AssociateTag"/><Argument Value="2011-08-01" Name="Version"/><Argument Value="Books" Name="SearchIndex"/><Argument Value="e8BTYGK9aedU2diDUdidplzri7GCutfupZj9y0N4J8k=" Name="Signature"/><Argument Value="9784774155074" Name="ItemId"/><Argument Value="EAN" Name="IdType"/><Argument Value="AKIAIVEDKHXVD2U62VOA" Name="AWSAccessKeyId"/><Argument Value="2013-04-06T16:58:10.000Z" Name="Timestamp"/><Argument Value="Medium" Name="ResponseGroup"/></Arguments><RequestProcessingTime>0.0315950000000000</RequestProcessingTime></OperationRequest><Items><Request><IsValid>True</IsValid><ItemLookupRequest><IdType>EAN</IdType><ItemId>9784774155074</ItemId><ResponseGroup>Medium</ResponseGroup><SearchIndex>Books</SearchIndex><VariationPage>All</VariationPage></ItemLookupRequest></Request><Item><ASIN>4774155071</ASIN><DetailPageURL>http://www.amazon.co.jp/WEB-DB-PRESS-Vol-73-%E8%A8%AD%E6%A8%82/dp/4774155071%3FSubscriptionId%3DAKIAIVEDKHXVD2U62VOA%26tag%3Dderui09-22%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D4774155071</DetailPageURL><ItemLinks><ItemLink><Description>Add To Wishlist</Description><URL>http://www.amazon.co.jp/gp/registry/wishlist/add-item.html%3Fasin.0%3D4774155071%26SubscriptionId%3DAKIAIVEDKHXVD2U62VOA%26tag%3Dderui09-22%26linkCode%3Dxm2%26camp%3D2025%26creative%3D5143%26creativeASIN%3D4774155071</URL></ItemLink><ItemLink><Description>Tell A Friend</Description><URL>http://www.amazon.co.jp/gp/pdp/taf/4774155071%3FSubscriptionId%3DAKIAIVEDKHXVD2U62VOA%26tag%3Dderui09-22%26linkCode%3Dxm2%26camp%3D2025%26creative%3D5143%26creativeASIN%3D4774155071</URL></ItemLink><ItemLink><Description>All Customer Reviews</Description><URL>http://www.amazon.co.jp/review/product/4774155071%3FSubscriptionId%3DAKIAIVEDKHXVD2U62VOA%26tag%3Dderui09-22%26linkCode%3Dxm2%26camp%3D2025%26creative%3D5143%26creativeASIN%3D4774155071</URL></ItemLink><ItemLink><Description>All Offers</Description><URL>http://www.amazon.co.jp/gp/offer-listing/4774155071%3FSubscriptionId%3DAKIAIVEDKHXVD2U62VOA%26tag%3Dderui09-22%26linkCode%3Dxm2%26camp%3D2025%26creative%3D5143%26creativeASIN%3D4774155071</URL></ItemLink></ItemLinks><SalesRank>5642</SalesRank><SmallImage><URL>http://ecx.images-amazon.com/images/I/51rcnZJm8PL._SL75_.jpg</URL><Height Units="pixels">75</Height><Width Units="pixels">53</Width></SmallImage><MediumImage><URL>http://ecx.images-amazon.com/images/I/51rcnZJm8PL._SL160_.jpg</URL><Height Units="pixels">160</Height><Width Units="pixels">113</Width></MediumImage><LargeImage><URL>http://ecx.images-amazon.com/images/I/51rcnZJm8PL.jpg</URL><Height Units="pixels">500</Height><Width Units="pixels">354</Width></LargeImage><ImageSets><ImageSet Category="primary"><SwatchImage><URL>http://ecx.images-amazon.com/images/I/51rcnZJm8PL._SL30_.jpg</URL><Height Units="pixels">30</Height><Width Units="pixels">21</Width></SwatchImage><SmallImage><URL>http://ecx.images-amazon.com/images/I/51rcnZJm8PL._SL75_.jpg</URL><Height Units="pixels">75</Height><Width Units="pixels">53</Width></SmallImage><ThumbnailImage><URL>http://ecx.images-amazon.com/images/I/51rcnZJm8PL._SL75_.jpg</URL><Height Units="pixels">75</Height><Width Units="pixels">53</Width></ThumbnailImage><TinyImage><URL>http://ecx.images-amazon.com/images/I/51rcnZJm8PL._SL110_.jpg</URL><Height Units="pixels">110</Height><Width Units="pixels">78</Width></TinyImage><MediumImage><URL>http://ecx.images-amazon.com/images/I/51rcnZJm8PL._SL160_.jpg</URL><Height Units="pixels">160</Height><Width Units="pixels">113</Width></MediumImage><LargeImage><URL>http://ecx.images-amazon.com/images/I/51rcnZJm8PL.jpg</URL><Height Units="pixels">500</Height><Width Units="pixels">354</Width></LargeImage></ImageSet></ImageSets><ItemAttributes><Author>設樂 洋爾</Author><Author>白土 慧</Author><Author>奥野 幹也</Author><Author>佐藤 鉄平</Author><Author>後藤 秀宣</Author><Author>mala</Author><Author>中島 聡</Author><Author>堤 智代</Author><Author>森田 創</Author><Author>A-Listers</Author><Author>はまちや2</Author><Author>大和田 純</Author><Author>松田 明</Author><Author>後藤 大輔</Author><Author>ひろせ まさあき</Author><Author>小林 篤</Author><Author>近藤 宇智朗</Author><Author>まかまか般若波羅蜜</Author><Author>Mr. O</Author><Binding>大型本</Binding><Creator Role="編集">WEB+DB PRESS編集部</Creator><EAN>9784774155074</EAN><EANList><EANListElement>9784774155074</EANListElement></EANList><IsAdultProduct>0</IsAdultProduct><ISBN>4774155071</ISBN><Label>技術評論社</Label><ListPrice><Amount>1554</Amount><CurrencyCode>JPY</CurrencyCode><FormattedPrice>¥ 1,554</FormattedPrice></ListPrice><Manufacturer>技術評論社</Manufacturer><NumberOfPages>192</NumberOfPages><PackageDimensions><Height Units="hundredths-inches">47</Height><Length Units="hundredths-inches">1008</Length><Weight Units="hundredths-pounds">93</Weight><Width Units="hundredths-inches">717</Width></PackageDimensions><ProductGroup>Book</ProductGroup><ProductTypeName>ABIS_BOOK</ProductTypeName><PublicationDate>2013-02-23</PublicationDate><Publisher>技術評論社</Publisher><Studio>技術評論社</Studio><Title>WEB+DB PRESS Vol.73</Title></ItemAttributes><OfferSummary><LowestNewPrice><Amount>1554</Amount><CurrencyCode>JPY</CurrencyCode><FormattedPrice>¥ 1,554</FormattedPrice></LowestNewPrice><LowestUsedPrice><Amount>1230</Amount><CurrencyCode>JPY</CurrencyCode><FormattedPrice>¥ 1,230</FormattedPrice></LowestUsedPrice><TotalNew>1</TotalNew><TotalUsed>4</TotalUsed><TotalCollectible>0</TotalCollectible><TotalRefurbished>0</TotalRefurbished></OfferSummary></Item></Items></ItemLookupResponse>
[error] play - Cannot invoke the action, eventually got an error: java.lang.IllegalArgumentException: For input string: ""
[error] application - 

! @6dpe52phk - Internal server error, for (POST) [/api/amazon_barcode?_=1365267489594] ->

play.api.Application$$anon$1: Execution exception[[IllegalArgumentException: For input string: ""]]
        at play.api.Application$class.handleError(Application.scala:289) ~[play_2.10.jar:2.1.0]
        at play.api.DefaultApplication.handleError(Application.scala:383) [play_2.10.jar:2.1.0]
        at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$handleAction$1$4$$anonfun$apply$28.apply(PlayDefaultUpstreamHandler.scala:391) [play_2.10.jar:2.1.0]
        at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$handleAction$1$4$$anonfun$apply$28.apply(PlayDefaultUpstreamHandler.scala:391) [play_2.10.jar:2.1.0]
        at scala.Option.map(Option.scala:145) [scala-library.jar:na]
        at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$handleAction$1$4.apply(PlayDefaultUpstreamHandler.scala:391) [play_2.10.jar:2.1.0]
java.lang.IllegalArgumentException: For input string: ""
        at scala.collection.immutable.StringLike$class.parseBoolean(StringLike.scala:238) ~[scala-library.jar:na]
        at scala.collection.immutable.StringLike$class.toBoolean(StringLike.scala:226) ~[scala-library.jar:na]
        at scala.collection.immutable.StringOps.toBoolean(StringOps.scala:31) ~[scala-library.jar:na]
        at aws.ItemLookup$.documentToJson(ItemLookup.scala:47) ~[na:na]
        at controllers.AWSRequest$$anonfun$searchByBarcode$1$$anonfun$apply$4.apply(AWSRequest.scala:71) ~[na:na]
        at controllers.AWSRequest$$anonfun$searchByBarcode$1$$anonfun$apply$4.apply(AWSRequest.scala:61) ~[na:na]

※ログ中のXMLは、私が埋め込んだログなので、リポジトリ上のソースでは出力されません。

エラー発生箇所はItemLookup.scalaの47行目の「if (!I.isValid(res).text.toBoolean) {」ですが、resが空になっているようです。

kimura-m-29 commented 11 years ago

それにしても、ちゃんと読み取れていて感動しました…!

derui commented 11 years ago

修正したと思っていましたが・・・。いずれにしろ修正しました。

kimura-m-29 commented 11 years ago

ありがとうございます!確認します

kimura-m-29 commented 11 years ago

ファイル選択でバーコード画像を読み取らせたところ、ちゃんと書籍情報が返ってきました! ありがとうございます。 次はPCのカメラで試してみますー

kimura-m-29 commented 11 years ago

PCのカメラでも読み取れました!!! ありがとうございますー