AD

The jdom appears strange network access

Struts2 with jdom parsing a configuration file of the code, the recent exception of the inexplicably cast. Look completely abnormal to play not on the eight-pole, how the local connection will have network connectivity

java**.ConnectException: Connection timed out: connect
        at java**.PlainSocketImpl.socketConnect(Native Method)
        at java**.PlainSocketImpl.doConnect(Unknown Source)
        at java**.PlainSocketImpl.connectToAddress(Unknown Source)
        at java**.PlainSocketImpl.connect(Unknown Source)
        at java**.SocksSocketImpl.connect(Unknown Source)
        at java**.Socket.connect(Unknown Source)
        at java**.Socket.connect(Unknown Source)
        at sun**.NetworkClient.doConnect(Unknown Source)
        at sun**.**http.HttpClient.openServer(Unknown Source)
        at sun**.**http.HttpClient.openServer(Unknown Source)
        at sun**.**http.HttpClient.<init>(Unknown Source)
        at sun**.**http.HttpClient.New(Unknown Source)
        at sun**.**http.HttpClient.New(Unknown Source)
        at sun**.**protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
        at sun**.**protocol.http.HttpURLConnection.plainConnect(Unknown Source)
        at sun**.**protocol.http.HttpURLConnection.connect(Unknown Source)
        at sun**.**protocol.http.HttpURLConnection.getInputStream(Unknown Source)
        at com.sun**.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
        at com.sun**.apache.xerces.internal.impl.XMLEntityManager.startEntity(Unknown Source)
        at com.sun**.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(Unknown Source)
        at com.sun**.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(Unknown Source)
        at com.sun**.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(Unknown Source)
        at com.sun**.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(Unknown Source)
        at com.sun**.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
        at com.sun**.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
        at com.sun**.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
        at com.sun**.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
        at com.sun**.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
        at com.sun**.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
        at com.sun**.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
        at com.sun**.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
        at com.sun**.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:489)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:847)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:826)
        at xml.UrlFetcher.main(UrlFetcher.java:34)


Suihou guess the problem may be here, xml configuration, there is a Waibu dtd Define , jdom in the process of parsing the default reads the xml file in the dtd, so if the url format is outside the Wang visit will Chansheng. The most recent addition to the domestic gfw, the company on the gfw, all external network requests is a tragedy. .

<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"**struts.apache**/dtds/struts-2.0.dtd">


So here more miserable, and turned a jdom document, just do not know where to remove as a result of network access dtd. So baidu, google, the final enlightenment: (that is, so the following is my comment out of line)

                  Document doc;
                        Element root; 
                        SAXBuilder builder = new SAXBuilder();
                        //builder.setFeature("**apache**/xml/features/nonvalidating/load-external-dtd", false);
                        try {
                                doc = builder.build(new File(filename));
                                root = doc.getRootElement();

                                Element packageN = (Element) XPath.selectSingleNode(root, "//package");
                                System.out.println("packageN:"+packageN);
                                
                                String namespace = packageN.getAttribute("namespace").getValue();
                                System.out.println("   namespace:"+namespace);
                                
                                List actions = XPath.selectNodes(root, "//action");
                                Iterator iter = actions.iterator();
                                while (iter.hasNext()) {
                                        Element rule = (Element) iter.next();
                                        String action = rule.getAttribute("name").getValue();
                                        //System.out.println("     actionName:"+action);
                                        
                                        System.out.println(namespace+"/"+action);
                                        // All of the url list  , Haha  
                                        //System.out.println(namespace+"/"+action+".xhtml");
                                }
                                
                        } catch (JDOMException e) {
                                e.printStackTrace();
                        } catch (IOException e) {
                                e.printStackTrace();
                        }


Why so amazing? Fill **apache**/xml/features/nonvalidating/load-external-dtd not have a problem.

1. According to the above long error stack, locate the problem in com.sun**.apache.xerces.internal.jaxp.SAXParserImpl here.

2. First class search inside look nonvalidating, found to be

    /** Feature identifier: XInclude processing */
    private static final String XINCLUDE_FEATURE = 
        Constants.XERCES_FEATURE_PREFIX + Constants.XINCLUDE_FEATURE;

3. And then look for it above the field of reference: found this method:

    /**
     * Gets the XInclude processing mode for this parser
     * @return the state of XInclude processing mode
     */
    public boolean isXIncludeAware() {
        try {
            return xmlReader.getFeature(XINCLUDE_FEATURE);
        }
        catch (SAXException exc) {
            return false;
        }
    }

4. And then see a reference to this method and found that the realization of the parser inside! That given the established uri, will disable the dtd download

isXIncludeAware


   SAXParserImpl(SAXParserFactoryImpl spf, Hashtable features, boolean secureProcessing)
        throws SAXException
    {
        // Instantiate a SAXParser directly and not through SAX so that we use the right ClassLoader
        xmlReader = new JAXPSAXParser(this);
 
        // JAXP default is false while SAX 2 default is true!
        xmlReader.setFeature0(NAMESPACES_FEATURE, spf.isNamespaceAware());
        // SAX "namespaces" and "namespace-prefixes" features should not
        // both be false.  We make them opposite for backward compatibility
        // since JAXP 1.0 apps may want to receive xmlns* attributes.
        xmlReader.setFeature0(NAMESPACE_PREFIXES_FEATURE, !spf.isNamespaceAware());
        
        // Avoid setting the XInclude processing feature if the value is false.
        // This will keep the configuration from throwing an exception if it
        // does not support XInclude.
        if (spf.isXIncludeAware()) {
            xmlReader.setFeature0(XINCLUDE_FEATURE, true);
        }


==============================

ow do I keep the DTD from loading? Even when I turn off validation the parser tries to load the DTD file.

Even when validation is turned off, an XML parser will by default load the external DTD file in order to parse the DTD for external entity declarations. Xerces has a feature to turn off this behavior named "**apache**/xml/ features / nonvalidating / load-external-dtd "and if you know you're using Xerces you can set this feature on the builder.

builder.setFeature (
"Http://apache**/xml/features/nonvalidating/load-external-dtd", false);

If you're using another parser like Crimson, your best bet is to set up an EntityResolver that resolves the DTD without actually reading the separate file.

import org.xml.sax .*;
import java.io. *;

public class NoOpEntityResolver implements EntityResolver (
public InputSource resolveEntity (String publicId, String systemId) (
return new InputSource (new StringBufferInputStream (""));
)
)

Then in the builder

builder.setEntityResolver (new NoOpEntityResolver ());

There is a downside to this approach. Any entities in the document will be resolved to the empty string, and will effectively disappear. If your document has entities, you need to setExpandEntities (false) code and ensure the EntityResolver only suppresses the DocType.
标签: impl, lt, configuration file, sun, network connectivity, unknown source, jdom, apache xerces, local connection, www protocol
分类: Java
时间: 2010-08-19

相关文章

  1. Sql * Plus network access basic principles and resolve related terms

    sql * plus network access to run the basic mechanism: listener.ora file SID_LIST_LISTENER = # naming SID_LIST_ ...
  2. On network access issues that can not be

    Today's a project, there is a very strange question. Moving in the project process, the outer web will appear ...
  3. java network access outside the local LAN IP

    Recently, the house to meet two Azeri communications needs, need to be outside the local network IP to tell th ...
  4. vm ubuntu10 IP configuration, network access to hosts

    Phenomenon Vm After installation, the default is NAT mode. After installation, configure the dns, Internet ok. ...
  5. Made to increase the amount of all network access software, httpclient, jsoup,

    My freshman year was extraordinary brush are also relevant online network popular software, has found himself ...
  6. Tomcat services in the local area network access settings

    In the tomcat service in the LAN can access the following three kinds of settings: 1) http://localhost/webName ...
  7. LAN to external network access to my tomcat

    First: Open a browser, enter the router IP, default is 192.168.1.1; Second: Check the public network IP ; Thir ...
  8. Real-time network access to the state of the machine

    IntentFilter mNetworkStateChangedFilter = new IntentFilter(); mNetworkStateChangedFilter .addAction(Connectivi ...
  9. Peanut shell + D_Link + Tomcat setting network access within the dynamic domain name

    Steps: 1: Registered peanut shell, domain names for free Access http://www.oray.com/ test peanut shells, and c ...
  10. Mysql on Ubuntu virtual machine outside the network access considerations

    1. After installing mysql, if you want to access other machines on the virtual machine should be shut down mys ...
  11. Linux, public network access to local / external network IP

    Run the command: curl http://members.3322.org/dyndns/getip
  12. Python IP external network access to the machine

    import re,urllib2 class Getmyip: def getip(self): try: myip = self.visit("http://www.ip138.com/ip2city.as ...
  13. mysql add new user to develop external network access

    / / First create a database for the user (phplampDB) mysql> create database hitalking / / Authorized hitalk ...
  14. Share this network through the wireless network card to another laptop Internet access

    Two notebooks (both integrated WIFI wireless network card), but only one cable; including a laptop through the ...
  15. "In the use of Samba to build Wisamba can not access, you may not have permission to use the network" as a cause of the problem and solution

    I have a platform Linux machine with Windows to copy files to some convenient, ready to enable samba, all step ...
  16. Computers can only access the router settings outside the company network or intranet access only

    We set up some computer companies require only allow access within the network, some computers only allow acce ...
  17. Local area network to share Internet access

    Environment: a pen drive this win7 system, a desktop computer xp sp3 system with a usb wireless card In order ...
  18. How to access the external network within a network server

    This article is from Baidu Q http://zhidao.baidu.com/question/261441575.html How to access external network wi ...
  19. [Reserved] administrators must know: Windows common network commands Xiangjie

    As a qualified network management, must have a strong technical skills, because the work is always among the p ...