2014-06-20 3 views
0

나는 아래 글래스 피시 REST는 API

가 CURR 명령

curl -s -S \ 
    -H 'Accept: application/json' \ 
    -H 'X-Requested-By: dummy' \ 
    -X DELETE http://localhost:4848/management/domain/applications/application/hello 

입니다 그리고 내 자바 코드가

URL url = new URL(
        "http://localhost:4851/"); 
      HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 
      conn.setDoOutput(true); 
      conn.setRequestMethod("POST"); 
      conn.setRequestProperty("Content-Type", "application/json"); 

      String input = "{\"DELETE\":\"http://localhost:4851/management/domain/applications/application/hello\"}"; 


      OutputStream os = conn.getOutputStream(); 
      os.write(input.getBytes()); 
      os.flush(); 

      if (conn.getResponseCode() != HttpURLConnection.HTTP_CREATED) { 
       throw new RuntimeException("Failed : HTTP error code : " 
         + conn.getResponseCode()); 
      } 

      BufferedReader br = new BufferedReader(new InputStreamReader(
        (conn.getInputStream()))); 

      String output; 
      System.out.println("Output from Server .... \n"); 
      while ((output = br.readLine()) != null) { 

       System.out.println(output); 
      } 

      conn.disconnect(); 

이다, 배포 및 글래스 피시에 응용 프로그램 배포를 취소하는 자바 클라이언트를 구현할 계획 불행히도, 나는 예상 한 결과를 얻을 수 없습니다. 누구나 조언을 구할 수 있습니까?

+0

끔찍한 질문입니다. 기대되는 결과는 무엇입니까? 무엇 대신에 무엇을 얻었습니까? 등등. – thecoshman

답변

1

Jersey 클라이언트를 사용하지 않는 이유는 무엇입니까?

import javax.ws.rs.client.Client; 
import javax.ws.rs.client.ClientBuilder; 
import javax.ws.rs.client.WebTarget; 
import javax.ws.rs.core.Response; 

public class DELETEClient { 
public static void main(String[] args) { 
    Client client = ClientBuilder.newClient(); 

    WebTarget target = client.target("http://localhost:4848/management/domain/applications/application/hello"); 

    String responseData = target.request().header("Accept", "application/json").header("X-Requested-By", "Dummy").delete(String.class); 
    Response response = target.request().delete(); 
    System.out.println(responseData); 
    System.out.println(response); 
} 
} 
+0

감사합니다. 내게 도움이됩니다. :) –

+0

전 대답을 받아들이는 것이 새로운 방법일까요? –

+0

왼쪽의 진드기 마트를 내 대답과 비교하십시오. – Satish

관련 문제