2016-07-29 1 views
0

Java Modern Batch를 만들려고합니다. 모든 것이 규칙적으로 작동합니다 : 작업은 "HttpURLConnection"호출 단계의 "Initialize"메서드에 삽입 할 때까지 작업을 시작하고 종료합니다. HTTP 호출을 사용하면 실행이 차단 된 채로 있으며 매번 서버를 다시 시작해야합니다.Java에서 HttpURLConnection을 사용하는 방법 현대 배치

String url = "http://mywebsite.com/api.xml"; 

URL obj = new URL(url); 
HttpURLConnection connection = (HttpURLConnection) obj.openConnection(); 

connection.setRequestMethod("GET"); 

int responseCode = connection.getResponseCode(); 
System.out.println("\nSending 'GET' request to URL : " + url); 
System.out.println("Response Code : " + responseCode); 

InputStreamReader isr = new InputStreamReader(connection.getInputStream()); 
BufferedReader in = new BufferedReader(isr); 
String inputLine; 
StringBuffer response = new StringBuffer(); 

try { 
    while ((inputLine = in.readLine()) != null) { 
     response.append(inputLine); 
    } 
} 
catch (Exception e) { 
    // TODO: handle exception 
} 
isr.close(); 
in.close();  
connection.disconnect(); 

String xml = response.toString(); 
+0

응답 코드가 성공하지 않으면 입력 내용을 읽지 마십시오. – EJP

답변

0

그것은 가치가있을 수도 있습니다 SO 스레드 (HttpURLConnection.getInputStream() blocks)보고 :

은 HttpURLConnection의의 코드입니다. 코드에서 읽기 타임 아웃을 설정하고 "블록"에서 벗어나는 데 도움이되는지 확인할 수 있습니다.

+0

불행히도이 제안은 문제를 해결하지 못했습니다. 어쨌든 고마워, ! – gvanzo