2013-06-27 2 views
0

프록시 서버 뒤에 저장된 XML 파일의 구문 분석은 어떻게 처리됩니까?프록시 URL이있는 SAXBuilder 사용

import java.io.IOException; 
import java.net.URL; 

import org.jdom.Document; 
import org.jdom.JDOMException; 
import org.jdom.input.SAXBuilder; 

public class FileParsing { 
    public static void parseXMLFile(String xmlFilePath) throws IOException, JDOMException { 
      URL xmlFileURL = new URL(xmlFilePath); 
      SAXBuilder builder = new SAXBuilder(); 
      Document xmlDoc = builder.build(xmlFileURL); 

      // File parsing code... 
    } 
} 

이 지금 나는이 예외가 :

java.io.IOException: Server returned HTTP response code: 502 for URL: https://proxyserver.com/xmlFileOfInterest.xml 

나는 파일이 프록시 서버에 있기 때문에 이것이 있으리라 믿고있어 나는 다음과 같은 코드가 있습니다. 이것이 내 문제의 원인인가? 그렇다면 프록시 서버에있는 파일을 처리하는 적절한 방법은 무엇입니까?

답변

0

당신은 구문 분석 아파치 웹 클라이언트를 사용하여 그것을

WebClient client = WebClient.create(xmlFilePath 
       ,String.class,null);  
     client = client.type(MediaType.APPLICATION_XML); 

HTTPConduit httpConduit = (HTTPConduit)WebClient.getConfig(client).getConduit(); 
     HTTPClientPolicy policy = new HTTPClientPolicy();    
     policy.setProxyServer(proxyurl); 
     policy.setProxyServerPort(8080); 
     httpConduit.setClient(policy); 

    Response r = client.post(); 
InputStream response= (InputStream)r.getEntity();