0

リクエストに応じてフロントエンドに画像を送信しようとしています.JSONの一部としてリクエストボディに入れると機能しますが、画像/ pngを使用したいのですが、もっと理にかなっていますが、試してみると406が表示されますそれ。

コントローラ:

@RequestMapping(value = RESTPaths.EQUIPMENT_FILE_GET_IMAGE + "/{equipmentId}", method = RequestMethod.GET,
        produces = MediaType.IMAGE_PNG_VALUE)
public @ResponseBody byte[] insertDataFile(@PathVariable("equipmentId") final Long equipmentId)
        throws InternalServerError {
    return equipmentFileService.getImage(equipmentId);
}

テスト (クライアント):

mockMvc.perform(
            get(RESTPaths.EQUIPMENT_FILE_CONTROLLER + RESTPaths.EQUIPMENT_FILE_GET_IMAGE + "/" + equipment.getId())
                    .with(httpBasic("user", "password")).accept(MediaType.IMAGE_PNG)
                    .contentType(TestUtil.APPLICATION_JSON_UTF8)).andDo(MockMvcResultHandlers.print()).andExpect(status().isOk());
}

私は何が欠けていますか?

4

2 に答える 2

0

ByteArrayHttpMessageConverter を登録する servlet-context.xml ファイルに mvc 注釈を追加してみてください

<mvc:annotation-driven> <mvc:message-converters> <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>image/jpeg</value> <value>image/png</value> </list> </property> </bean> </mvc:message-converters> </mvc:annotation-driven>
于 2015-07-06T19:53:34.670 に答える
0

解決済み:

@RequestMapping(value = RESTPaths.EQUIPMENT_FILE_GET_IMAGE + "/{equipmentId}", method = RequestMethod.GET)
@ResponseBody
public  ResponseEntity<byte[]> getImage(@PathVariable("equipmentId") final Long equipmentId)
        throws InternalServerError {
    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.IMAGE_JPEG);
    return new ResponseEntity<byte[]>(equipmentFileService.getImage(equipmentId), headers, HttpStatus.OK);
}
于 2015-07-10T11:30:13.923 に答える