2016-09-23 24 views
0

を投げ、私はWebサービスからXMLを取得しようとしたが、それはコードの下に実行した後InvalidMediaTypeExceptionを投げています:春RestTemplate私は春の休憩に新しいですInvalidMediaTypeException

restTemplate.getForObject("http://www.dictionaryapi.com/api/v1/references/learners/xml/{word}?key={key}",String.class,uriVariables); 

Webサービスは、XMLドキュメントを返す、と私は思いましたまず問題があるかもしれないが、別のWebService(urlにはパスとして 'xml'が含まれていない)がうまく動作する。

スタックトレース:

Exception in thread "main" org.springframework.http.InvalidMediaTypeException: Invalid mime type "xml": does not contain '/' 
at org.springframework.http.MediaType.parseMediaType(MediaType.java:385) 
at org.springframework.http.HttpHeaders.getContentType(HttpHeaders.java:722) 
at org.springframework.web.client.HttpMessageConverterExtractor.getContentType(HttpMessageConverterExtractor.java:114) 
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:85) 
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:835) 
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:819) 
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:599) 
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:557) 
at org.springframework.web.client.RestTemplate.postForEntity(RestTemplate.java:384) 

それでは、どのように私は彼らのURLパスに単語 "XML" が含まれているWebサービスとデータを交換することができます。

+0

私は思っていますが、私は間違っているかもしれません、あなたが得るスタックはURIの "xml"によって引き起こされない、我々は "webService"メソッドを見ることができますか? –

+0

突然、サードパーティのWebServiceなので、http://www.dictionaryapi.com/api/v1/references/learners/xml/apple?key=4d0a2da0-791e-4616-986f-2b26da530f04でリクエストを行うと、私はこの結果を受け取ります。例えば、 "http://www.thomas-bayer.com/sqlrest/CUSTOMER/"のリクエストは有効です。 –

+0

URLパラメータのxmlはここでは問題にはならないかもしれません。 uri変数で渡すサービスやデータに問題があるはずです – Nimesh

答えて

1

ここで問題となっているのは、サービスが応答が返されていることです。具体的には、コンテンツタイプが混乱しているxmlです。あなたは普通の人(そしてサービス)がapplication/xmlを代わりに使用するので、Springを処理するようにSpringを設定する必要があります。カスタムMediaTypeの設定については、thisの回答をご覧ください。

関連する問題