2017-06-15 34 views
-1

ファイルをアップロードする方法はPOSTです。ファイルをアップロードするためにTokenを渡す私のheaderメソッド 'POST'はサポートされていません405

private RessourceMetadata doSave(Ressource ressource) throws IOException, FileNotFoundException { 
     String tempFilePath = writeDocumentToTempFile(ressource); 
     MultiValueMap<String, Object> parts = createMultipartFileParam(tempFilePath); 
     RessourceMetadata ressourceMetadata = getRestTemplate().postForObject(
       getServiceUrl() 
         + "/uploadFileProperties?group={group}&projectId={projectId}&version={version}&env={env}", 
       parts, RessourceMetadata.class, ressource.getGroup(), ressource.getId(), ressource.getVersion(), 
       ressource.getEnv()); 
     return ressourceMetadata; 
    } 

....

private MultiValueMap<String, Object> createMultipartFileParam(String tempFilePath) { 
    MultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>(); 
    parts.add("file", new FileSystemResource(tempFilePath)); 
    parts.add("Authorization", "hrYIwyXoKGkY2juJfJb012Qx768RtUYA"); 
    return parts; 
} 

エラー:

o.s.w.s.PageNotFound - Request method 'POST' not supported 
2017-Jun-15 09:50:31.852 ERROR [main] f.g.d.d.w.c.ServiceClient - Error while uploading file 
org.springframework.web.client.HttpClientErrorException: 405 Method Not Allowed 

私のコードで何が悪いのでしょうか?

POSTメソッド:あなたはgetServiceUrl()メソッドを呼び出し、それにあなたのパスを追加するにdoSave()メソッドで

@RequestMapping(value = "/uploadFileProperties", method = RequestMethod.POST) 
@ResponseStatus(HttpStatus.OK) 
@ApiImplicitParams({ 
     @ApiImplicitParam(name = "Authorization", value = "Authorization token", required = true, dataType = "string", paramType = "header") }) 
public @ResponseBody RessourceMetadata uploadProperties(
     @ApiParam(name = "file", value = "fichier properties à uploader", defaultValue = "", required = true) @RequestParam("file") MultipartFile file, 
     @ApiParam(name = "group", value = "groupe projet", defaultValue = "", required = true) @RequestParam("group") String group, 
     @ApiParam(name = "projectId", value = "id projet (francevisas, diplomatie...)", defaultValue = "", required = true) @RequestParam("projectId") String projectId, 
     @ApiParam(name = "version", value = "version du projet", defaultValue = "", required = true) @RequestParam("version") String version, 
     @ApiParam(name = "env", value = "environnement (dev, prod, formation...)", defaultValue = "", required = true) @RequestParam("env") String env) { 

    try { 
     Ressource ressource = new Ressource(file.getBytes(), group, projectId, version, env, 
       PropertiesFileUtils.getPropertiesFilename()); 
     getRessourceService().save(ressource); 
     return ressource.getMetadata(); 
    } catch (RuntimeException e) { 
     log.error("Error while uploading.", e); 
     throw e; 
    } catch (Exception e) { 
     log.error("Error while uploading.", e); 
     throw new RuntimeException(e); 
    } 
} 
+1

かなり明らかです。 URLはPOSTを受け付けません。あなたの質問は何ですか? – shmosel

+0

@shmosel投稿できないのはなぜですか? – Mercer

+0

私はspringの例外フォーマットはわかりませんが、 'oswsPageNotFound'が正しくないURLのため"ページが見つかりません "ページにリダイレクトされているのを見ているようですが、' POST'をサポートしていないページ – AxelH

答えて

0

。 getServiceUrl()は他のドメインを返す必要があります。これを確認するには、doSave()メソッドでデバッグモードに入り、getServiceメソッドが正しい値を与えるかどうかを確認します。さらに、getServiceUrlがPostmanからあなたに与えるドメインでPOSTリクエストを試してください。