2012-12-07 2 views
1

메소드에서 이미지 및 기타 문자열 데이터를 수신해야하는 아파치 cxf rest service가 있습니다. 이를 위해 나는 이와 같은 서비스 정의를 만들었습니다. 휴식 서비스가 주어진 게시물을 받아 들일 수 없습니다. 멀티 파트로 주석 처리되었습니다.

@Override 
@POST 
@Path("attach/{formId}/{instanceId}") 
@Consumes("multipart/mixed") 
@Produces("application/xml") 
public UploadResult attach(@FormParam("username") @WebParam(name = "username") String user, 
          @FormParam("password") @WebParam(name = "password") String password, 
          @PathParam("formId") @WebParam(name = "formId") String formId, 
          @PathParam("instanceId") @WebParam(name = "instanceId") String instanceId, 
          @FormParam("group") @WebParam(name = "group") String group, 
          @FormParam("data") @WebParam(name = "data") byte[] data, 
          @FormParam("metadata") @WebParam(name = "metadata") byte[] metadata) 
    throws PDProcessingException, 
    PDSecurityException 
{ 
    return svc.attach(user, password, formId, instanceId, group, data, metadata); 
} 

지금 내 클라이언트와이 방법을 사용하려고하지만 늘 작동하고 415 지원되지 않는 MediaType에 반환합니다. 나는 Wiztools.org 위해 RESTClient와 나는 또한 노력이

public static String attach(String username, String hashedpassword, String attachmentUri) { 

    String retVal = ""; 
    HttpClient client = new DefaultHttpClient(); 
    HttpPost post = new HttpPost("http://192.168.101.27/pdxapi/service/rest/ClientApp/attach/DE_OJ_PDIX_TEST/SRSQS.0"); 
    try { 
     String hashedPw = DigestFactory.calculatePasswordHash(hashedpassword); 

     File file = new File(attachmentUri); 
     if (file == null || !file.exists()){ 
      throw new RuntimeException("there is no file " + attachmentUri); 
     } 
     MultipartEntity entity = new MultipartEntity(); 
     entity.addPart("username", new StringBody(username)); 
     entity.addPart("password", new StringBody(hashedPw)); 
     FileBody fileBody = new FileBody(file,"image/jpeg"); 
     entity.addPart("data",fileBody); 

     post.setEntity(entity); 
     HttpResponse response = client.execute(post); 
     if (response.getEntity() == null){ 

      retVal = "";     
     } 
     else{ 
      BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); 
      StringBuffer sb = new StringBuffer(); 
      String line = ""; 
      while ((line = rd.readLine()) != null) { 
       sb.append(line); 
      }    
      retVal = sb.toString();    
     } 

    } catch (IOException e) { 
     System.out.print("exception " + e.getMessage()); 
    } 
    return retVal; 
} 

같은 방법을 호출하는 테스트 클라이언트 코드로 주석 @Consumes ("다중/폼 데이터")하지만 같은 결과를 시도 . 조언이 있으십니까? 프로젝트에

감사

+0

-multiparts.html –

답변

관련 문제