2013-06-27 21 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

您可以使用Apache Web客户端解析它

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();