You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Peter Ertl (JIRA)" <ji...@apache.org> on 2010/11/12 15:17:14 UTC

[jira] Created: (WICKET-3163) support building wicket offline by resolving DTD references locally

support building wicket offline by resolving DTD references locally
-------------------------------------------------------------------

                 Key: WICKET-3163
                 URL: https://issues.apache.org/jira/browse/WICKET-3163
             Project: Wicket
          Issue Type: Improvement
          Components: wicket
    Affects Versions: 1.5-M3
            Reporter: Peter Ertl
            Assignee: Peter Ertl


Wicket developers, please give me some comment on this:

Some wicket test cases parse XML which refers to an external DTD. 

An example is org.apache.wicket.protocol.http.WicketFilterTest

It refers to org.apache.wicket.util.file.WebXmlFile will will parse a custom web.xml.

The web.xml will make the parser to look up http://java.sun.com/dtd/web-app_2_3.dtd

When building wicket offline this will cause a network error and the test will fail.

I would like to add 

  org.apache.wicket.util.xml.LocalEntityResolver

which may contain a set of local entitites to avoid hitting the network.

As wicket 1.5 is getting close to final I would like to get some feedback first before putting that into trunk...

By adding this like to WebXmlFile network lookup would be avoided.
 
  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  DocumentBuilder builder = factory.newDocumentBuilder();
  builder.setEntityResolver(LocalEntityResolver.getDefault());  // no more network lookups
  Document document = builder.parse(is);



----------------------------------------------------

package org.apache.wicket.util.xml;

import org.apache.wicket.util.lang.Args;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import javax.servlet.Filter;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

/**
 * entity resolver that tries to locate a document type definition (DTD) using a set of custom entity resolvers
 *
 * @author pete
 */
public class LocalEntityResolver implements EntityResolver
{
	private final Map<EntityKey, EntityLocator> entities = new HashMap<EntityKey, EntityLocator>(3);

	public static LocalEntityResolver getDefault()
	{
		LocalEntityResolver resolver = new LocalEntityResolver();
    
    //
    // look up servlet 2.3 web.xml DTD right from inside servlet-api.jar
    //
		resolver.put(new EntityKey("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN",
		                           "http://java.sun.com/dtd/web-app_2_3.dtd"),
		             new ServletApiEntityLocator("web-app_2_3.dtd"));

		return resolver;
	}

	public void put(EntityKey key, EntityLocator locator)
	{
		Args.notNull(key, "key");
		Args.notNull(locator, "locator");
		entities.put(key, locator);
	}

	public InputSource resolveEntity(String id, String url) throws SAXException, IOException
	{
		for (Map.Entry<EntityKey, EntityLocator> entry : entities.entrySet())
			if (entry.getKey().id.equals(id) || entry.getKey().url.equals(url))
				return entry.getValue().locateInputSource();

		return null;
	}

	public static class EntityKey
	{
		private final String id;
		private final String url;

		private EntityKey(String id, String url)
		{
			Args.notEmpty(id, "id");
			Args.notEmpty(url, "url");
			this.id = id;
			this.url = url;
		}

		@Override
		public boolean equals(Object o)
		{
			if (this == o)
				return true;
			if (!(o instanceof EntityKey))
				return false;

			EntityKey key = (EntityKey) o;

			if (!id.equals(key.id))
				return false;

			return url.equals(key.url);
		}

		@Override
		public int hashCode()
		{
			int result = id.hashCode();
			result = 31 * result + url.hashCode();
			return result;
		}
	}

	public static interface EntityLocator
	{
		InputSource locateInputSource() throws SAXException, IOException;
	}

	public static class ServletApiEntityLocator implements EntityLocator
	{
		private final String name;

		private ServletApiEntityLocator(String name)
		{
			this.name = name;
		}

		public InputSource locateInputSource()
		{
			InputStream stream = Filter.class.getResourceAsStream("resources/" + name);

			if (stream == null)
				return null;

			return new InputSource(stream);
		}
	}
}


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Re: [jira] Created: (WICKET-3163) support building wicket offline by resolving DTD references locally

Posted by Martijn Dashorst <ma...@gmail.com>.
+1

On Fri, Nov 12, 2010 at 3:17 PM, Peter Ertl (JIRA) <ji...@apache.org> wrote:
> support building wicket offline by resolving DTD references locally
> -------------------------------------------------------------------
>
>                 Key: WICKET-3163
>                 URL: https://issues.apache.org/jira/browse/WICKET-3163
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket
>    Affects Versions: 1.5-M3
>            Reporter: Peter Ertl
>            Assignee: Peter Ertl
>
>
> Wicket developers, please give me some comment on this:
>
> Some wicket test cases parse XML which refers to an external DTD.
>
> An example is org.apache.wicket.protocol.http.WicketFilterTest
>
> It refers to org.apache.wicket.util.file.WebXmlFile will will parse a custom web.xml.
>
> The web.xml will make the parser to look up http://java.sun.com/dtd/web-app_2_3.dtd
>
> When building wicket offline this will cause a network error and the test will fail.
>
> I would like to add
>
>  org.apache.wicket.util.xml.LocalEntityResolver
>
> which may contain a set of local entitites to avoid hitting the network.
>
> As wicket 1.5 is getting close to final I would like to get some feedback first before putting that into trunk...
>
> By adding this like to WebXmlFile network lookup would be avoided.
>
>  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
>  DocumentBuilder builder = factory.newDocumentBuilder();
>  builder.setEntityResolver(LocalEntityResolver.getDefault());  // no more network lookups
>  Document document = builder.parse(is);
>
>
>
> ----------------------------------------------------
>
> package org.apache.wicket.util.xml;
>
> import org.apache.wicket.util.lang.Args;
> import org.xml.sax.EntityResolver;
> import org.xml.sax.InputSource;
> import org.xml.sax.SAXException;
>
> import javax.servlet.Filter;
> import java.io.IOException;
> import java.io.InputStream;
> import java.util.HashMap;
> import java.util.Map;
>
> /**
>  * entity resolver that tries to locate a document type definition (DTD) using a set of custom entity resolvers
>  *
>  * @author pete
>  */
> public class LocalEntityResolver implements EntityResolver
> {
>        private final Map<EntityKey, EntityLocator> entities = new HashMap<EntityKey, EntityLocator>(3);
>
>        public static LocalEntityResolver getDefault()
>        {
>                LocalEntityResolver resolver = new LocalEntityResolver();
>
>    //
>    // look up servlet 2.3 web.xml DTD right from inside servlet-api.jar
>    //
>                resolver.put(new EntityKey("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN",
>                                           "http://java.sun.com/dtd/web-app_2_3.dtd"),
>                             new ServletApiEntityLocator("web-app_2_3.dtd"));
>
>                return resolver;
>        }
>
>        public void put(EntityKey key, EntityLocator locator)
>        {
>                Args.notNull(key, "key");
>                Args.notNull(locator, "locator");
>                entities.put(key, locator);
>        }
>
>        public InputSource resolveEntity(String id, String url) throws SAXException, IOException
>        {
>                for (Map.Entry<EntityKey, EntityLocator> entry : entities.entrySet())
>                        if (entry.getKey().id.equals(id) || entry.getKey().url.equals(url))
>                                return entry.getValue().locateInputSource();
>
>                return null;
>        }
>
>        public static class EntityKey
>        {
>                private final String id;
>                private final String url;
>
>                private EntityKey(String id, String url)
>                {
>                        Args.notEmpty(id, "id");
>                        Args.notEmpty(url, "url");
>                        this.id = id;
>                        this.url = url;
>                }
>
>                @Override
>                public boolean equals(Object o)
>                {
>                        if (this == o)
>                                return true;
>                        if (!(o instanceof EntityKey))
>                                return false;
>
>                        EntityKey key = (EntityKey) o;
>
>                        if (!id.equals(key.id))
>                                return false;
>
>                        return url.equals(key.url);
>                }
>
>                @Override
>                public int hashCode()
>                {
>                        int result = id.hashCode();
>                        result = 31 * result + url.hashCode();
>                        return result;
>                }
>        }
>
>        public static interface EntityLocator
>        {
>                InputSource locateInputSource() throws SAXException, IOException;
>        }
>
>        public static class ServletApiEntityLocator implements EntityLocator
>        {
>                private final String name;
>
>                private ServletApiEntityLocator(String name)
>                {
>                        this.name = name;
>                }
>
>                public InputSource locateInputSource()
>                {
>                        InputStream stream = Filter.class.getResourceAsStream("resources/" + name);
>
>                        if (stream == null)
>                                return null;
>
>                        return new InputSource(stream);
>                }
>        }
> }
>
>
> --
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
>
>



-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com

[jira] Updated: (WICKET-3163) support building wicket offline by resolving DTD references locally

Posted by "Peter Ertl (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-3163?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Peter Ertl updated WICKET-3163:
-------------------------------

    Attachment: LocalEntityResolver.java

> support building wicket offline by resolving DTD references locally
> -------------------------------------------------------------------
>
>                 Key: WICKET-3163
>                 URL: https://issues.apache.org/jira/browse/WICKET-3163
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket
>    Affects Versions: 1.5-M3
>            Reporter: Peter Ertl
>            Assignee: Peter Ertl
>         Attachments: LocalEntityResolver.java
>
>
> Wicket developers, please give me some comment on this:
> Some wicket test cases parse XML which refers to an external DTD. 
> An example is org.apache.wicket.protocol.http.WicketFilterTest
> It refers to org.apache.wicket.util.file.WebXmlFile will will parse a custom web.xml.
> The web.xml will make the parser to look up http://java.sun.com/dtd/web-app_2_3.dtd
> When building wicket offline this will cause a network error and the test will fail.
> I would like to add 
>   org.apache.wicket.util.xml.LocalEntityResolver
> which may contain a set of local entitites to avoid hitting the network.
> As wicket 1.5 is getting close to final I would like to get some feedback first before putting that into trunk...
> By adding this like to WebXmlFile network lookup would be avoided.
>  
>   DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
>   DocumentBuilder builder = factory.newDocumentBuilder();
>   builder.setEntityResolver(LocalEntityResolver.getDefault());  // no more network lookups
>   Document document = builder.parse(is);
> ----------------------------------------------------
> package org.apache.wicket.util.xml;
> import org.apache.wicket.util.lang.Args;
> import org.xml.sax.EntityResolver;
> import org.xml.sax.InputSource;
> import org.xml.sax.SAXException;
> import javax.servlet.Filter;
> import java.io.IOException;
> import java.io.InputStream;
> import java.util.HashMap;
> import java.util.Map;
> /**
>  * entity resolver that tries to locate a document type definition (DTD) using a set of custom entity resolvers
>  *
>  * @author pete
>  */
> public class LocalEntityResolver implements EntityResolver
> {
> 	private final Map<EntityKey, EntityLocator> entities = new HashMap<EntityKey, EntityLocator>(3);
> 	public static LocalEntityResolver getDefault()
> 	{
> 		LocalEntityResolver resolver = new LocalEntityResolver();
>     
>     //
>     // look up servlet 2.3 web.xml DTD right from inside servlet-api.jar
>     //
> 		resolver.put(new EntityKey("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN",
> 		                           "http://java.sun.com/dtd/web-app_2_3.dtd"),
> 		             new ServletApiEntityLocator("web-app_2_3.dtd"));
> 		return resolver;
> 	}
> 	public void put(EntityKey key, EntityLocator locator)
> 	{
> 		Args.notNull(key, "key");
> 		Args.notNull(locator, "locator");
> 		entities.put(key, locator);
> 	}
> 	public InputSource resolveEntity(String id, String url) throws SAXException, IOException
> 	{
> 		for (Map.Entry<EntityKey, EntityLocator> entry : entities.entrySet())
> 			if (entry.getKey().id.equals(id) || entry.getKey().url.equals(url))
> 				return entry.getValue().locateInputSource();
> 		return null;
> 	}
> 	public static class EntityKey
> 	{
> 		private final String id;
> 		private final String url;
> 		private EntityKey(String id, String url)
> 		{
> 			Args.notEmpty(id, "id");
> 			Args.notEmpty(url, "url");
> 			this.id = id;
> 			this.url = url;
> 		}
> 		@Override
> 		public boolean equals(Object o)
> 		{
> 			if (this == o)
> 				return true;
> 			if (!(o instanceof EntityKey))
> 				return false;
> 			EntityKey key = (EntityKey) o;
> 			if (!id.equals(key.id))
> 				return false;
> 			return url.equals(key.url);
> 		}
> 		@Override
> 		public int hashCode()
> 		{
> 			int result = id.hashCode();
> 			result = 31 * result + url.hashCode();
> 			return result;
> 		}
> 	}
> 	public static interface EntityLocator
> 	{
> 		InputSource locateInputSource() throws SAXException, IOException;
> 	}
> 	public static class ServletApiEntityLocator implements EntityLocator
> 	{
> 		private final String name;
> 		private ServletApiEntityLocator(String name)
> 		{
> 			this.name = name;
> 		}
> 		public InputSource locateInputSource()
> 		{
> 			InputStream stream = Filter.class.getResourceAsStream("resources/" + name);
> 			if (stream == null)
> 				return null;
> 			return new InputSource(stream);
> 		}
> 	}
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-3163) support building wicket offline by resolving DTD references locally

Posted by "Hudson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-3163?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12931682#action_12931682 ] 

Hudson commented on WICKET-3163:
--------------------------------

Integrated in Apache Wicket 1.5.x #508 (See [https://hudson.apache.org/hudson/job/Apache%20Wicket%201.5.x/508/])
    WICKET-3163: support offline builds of wicket (avoid hitting java.sun.com for lookup of web.xml 2.3 DTD)


> support building wicket offline by resolving DTD references locally
> -------------------------------------------------------------------
>
>                 Key: WICKET-3163
>                 URL: https://issues.apache.org/jira/browse/WICKET-3163
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket
>    Affects Versions: 1.5-M3
>            Reporter: Peter Ertl
>            Assignee: Peter Ertl
>             Fix For: 1.5-M4
>
>         Attachments: local-lookup.patch, LocalEntityResolver.java
>
>
> Wicket developers, please give me some comment on this:
> Some wicket test cases parse XML which refers to an external DTD. 
> An example is org.apache.wicket.protocol.http.WicketFilterTest
> It refers to org.apache.wicket.util.file.WebXmlFile will will parse a custom web.xml.
> The web.xml will make the parser to look up http://java.sun.com/dtd/web-app_2_3.dtd
> When building wicket offline this will cause a network error and the test will fail.
> I would like to add 
>   org.apache.wicket.util.xml.LocalEntityResolver
> which may contain a set of local entitites to avoid hitting the network.
> As wicket 1.5 is getting close to final I would like to get some feedback first before putting that into trunk...
> By adding this like to WebXmlFile network lookup would be avoided.
>  
>   DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
>   DocumentBuilder builder = factory.newDocumentBuilder();
>   builder.setEntityResolver(LocalEntityResolver.getDefault());  // no more network lookups
>   Document document = builder.parse(is);
> ----------------------------------------------------
> package org.apache.wicket.util.xml;
> import org.apache.wicket.util.lang.Args;
> import org.xml.sax.EntityResolver;
> import org.xml.sax.InputSource;
> import org.xml.sax.SAXException;
> import javax.servlet.Filter;
> import java.io.IOException;
> import java.io.InputStream;
> import java.util.HashMap;
> import java.util.Map;
> /**
>  * entity resolver that tries to locate a document type definition (DTD) using a set of custom entity resolvers
>  *
>  * @author pete
>  */
> public class LocalEntityResolver implements EntityResolver
> {
> 	private final Map<EntityKey, EntityLocator> entities = new HashMap<EntityKey, EntityLocator>(3);
> 	public static LocalEntityResolver getDefault()
> 	{
> 		LocalEntityResolver resolver = new LocalEntityResolver();
>     
>     //
>     // look up servlet 2.3 web.xml DTD right from inside servlet-api.jar
>     //
> 		resolver.put(new EntityKey("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN",
> 		                           "http://java.sun.com/dtd/web-app_2_3.dtd"),
> 		             new ServletApiEntityLocator("web-app_2_3.dtd"));
> 		return resolver;
> 	}
> 	public void put(EntityKey key, EntityLocator locator)
> 	{
> 		Args.notNull(key, "key");
> 		Args.notNull(locator, "locator");
> 		entities.put(key, locator);
> 	}
> 	public InputSource resolveEntity(String id, String url) throws SAXException, IOException
> 	{
> 		for (Map.Entry<EntityKey, EntityLocator> entry : entities.entrySet())
> 			if (entry.getKey().id.equals(id) || entry.getKey().url.equals(url))
> 				return entry.getValue().locateInputSource();
> 		return null;
> 	}
> 	public static class EntityKey
> 	{
> 		private final String id;
> 		private final String url;
> 		private EntityKey(String id, String url)
> 		{
> 			Args.notEmpty(id, "id");
> 			Args.notEmpty(url, "url");
> 			this.id = id;
> 			this.url = url;
> 		}
> 		@Override
> 		public boolean equals(Object o)
> 		{
> 			if (this == o)
> 				return true;
> 			if (!(o instanceof EntityKey))
> 				return false;
> 			EntityKey key = (EntityKey) o;
> 			if (!id.equals(key.id))
> 				return false;
> 			return url.equals(key.url);
> 		}
> 		@Override
> 		public int hashCode()
> 		{
> 			int result = id.hashCode();
> 			result = 31 * result + url.hashCode();
> 			return result;
> 		}
> 	}
> 	public static interface EntityLocator
> 	{
> 		InputSource locateInputSource() throws SAXException, IOException;
> 	}
> 	public static class ServletApiEntityLocator implements EntityLocator
> 	{
> 		private final String name;
> 		private ServletApiEntityLocator(String name)
> 		{
> 			this.name = name;
> 		}
> 		public InputSource locateInputSource()
> 		{
> 			InputStream stream = Filter.class.getResourceAsStream("resources/" + name);
> 			if (stream == null)
> 				return null;
> 			return new InputSource(stream);
> 		}
> 	}
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-3163) support building wicket offline by resolving DTD references locally

Posted by "Martin Grigorov (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-3163?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12931413#action_12931413 ] 

Martin Grigorov commented on WICKET-3163:
-----------------------------------------

As discussed in the IRC channel WicketFilterTest fails here from time to time with "Connection timed out" message. But Java doesn't say what is the endpoint for that connection.
Removing the DOCTYPE for web1.xml and web2.xml temporarily "fixes" the problem.
This started to happen last week.
Running the build in offline (mvn -o clean install) mode passes.
I suspect DTD resolving to be the problem but I am not sure.

> support building wicket offline by resolving DTD references locally
> -------------------------------------------------------------------
>
>                 Key: WICKET-3163
>                 URL: https://issues.apache.org/jira/browse/WICKET-3163
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket
>    Affects Versions: 1.5-M3
>            Reporter: Peter Ertl
>            Assignee: Peter Ertl
>         Attachments: LocalEntityResolver.java
>
>
> Wicket developers, please give me some comment on this:
> Some wicket test cases parse XML which refers to an external DTD. 
> An example is org.apache.wicket.protocol.http.WicketFilterTest
> It refers to org.apache.wicket.util.file.WebXmlFile will will parse a custom web.xml.
> The web.xml will make the parser to look up http://java.sun.com/dtd/web-app_2_3.dtd
> When building wicket offline this will cause a network error and the test will fail.
> I would like to add 
>   org.apache.wicket.util.xml.LocalEntityResolver
> which may contain a set of local entitites to avoid hitting the network.
> As wicket 1.5 is getting close to final I would like to get some feedback first before putting that into trunk...
> By adding this like to WebXmlFile network lookup would be avoided.
>  
>   DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
>   DocumentBuilder builder = factory.newDocumentBuilder();
>   builder.setEntityResolver(LocalEntityResolver.getDefault());  // no more network lookups
>   Document document = builder.parse(is);
> ----------------------------------------------------
> package org.apache.wicket.util.xml;
> import org.apache.wicket.util.lang.Args;
> import org.xml.sax.EntityResolver;
> import org.xml.sax.InputSource;
> import org.xml.sax.SAXException;
> import javax.servlet.Filter;
> import java.io.IOException;
> import java.io.InputStream;
> import java.util.HashMap;
> import java.util.Map;
> /**
>  * entity resolver that tries to locate a document type definition (DTD) using a set of custom entity resolvers
>  *
>  * @author pete
>  */
> public class LocalEntityResolver implements EntityResolver
> {
> 	private final Map<EntityKey, EntityLocator> entities = new HashMap<EntityKey, EntityLocator>(3);
> 	public static LocalEntityResolver getDefault()
> 	{
> 		LocalEntityResolver resolver = new LocalEntityResolver();
>     
>     //
>     // look up servlet 2.3 web.xml DTD right from inside servlet-api.jar
>     //
> 		resolver.put(new EntityKey("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN",
> 		                           "http://java.sun.com/dtd/web-app_2_3.dtd"),
> 		             new ServletApiEntityLocator("web-app_2_3.dtd"));
> 		return resolver;
> 	}
> 	public void put(EntityKey key, EntityLocator locator)
> 	{
> 		Args.notNull(key, "key");
> 		Args.notNull(locator, "locator");
> 		entities.put(key, locator);
> 	}
> 	public InputSource resolveEntity(String id, String url) throws SAXException, IOException
> 	{
> 		for (Map.Entry<EntityKey, EntityLocator> entry : entities.entrySet())
> 			if (entry.getKey().id.equals(id) || entry.getKey().url.equals(url))
> 				return entry.getValue().locateInputSource();
> 		return null;
> 	}
> 	public static class EntityKey
> 	{
> 		private final String id;
> 		private final String url;
> 		private EntityKey(String id, String url)
> 		{
> 			Args.notEmpty(id, "id");
> 			Args.notEmpty(url, "url");
> 			this.id = id;
> 			this.url = url;
> 		}
> 		@Override
> 		public boolean equals(Object o)
> 		{
> 			if (this == o)
> 				return true;
> 			if (!(o instanceof EntityKey))
> 				return false;
> 			EntityKey key = (EntityKey) o;
> 			if (!id.equals(key.id))
> 				return false;
> 			return url.equals(key.url);
> 		}
> 		@Override
> 		public int hashCode()
> 		{
> 			int result = id.hashCode();
> 			result = 31 * result + url.hashCode();
> 			return result;
> 		}
> 	}
> 	public static interface EntityLocator
> 	{
> 		InputSource locateInputSource() throws SAXException, IOException;
> 	}
> 	public static class ServletApiEntityLocator implements EntityLocator
> 	{
> 		private final String name;
> 		private ServletApiEntityLocator(String name)
> 		{
> 			this.name = name;
> 		}
> 		public InputSource locateInputSource()
> 		{
> 			InputStream stream = Filter.class.getResourceAsStream("resources/" + name);
> 			if (stream == null)
> 				return null;
> 			return new InputSource(stream);
> 		}
> 	}
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-3163) support building wicket offline by resolving DTD references locally

Posted by "Peter Ertl (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-3163?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12931678#action_12931678 ] 

Peter Ertl commented on WICKET-3163:
------------------------------------

Seems like this improvement was really necessary as we get timeouts on hudson quite often, e.g.:

  https://hudson.apache.org/hudson/job/Apache%20Wicket%201.5.x/507/org.apache.wicket$wicket

Should be solved now :-)

> support building wicket offline by resolving DTD references locally
> -------------------------------------------------------------------
>
>                 Key: WICKET-3163
>                 URL: https://issues.apache.org/jira/browse/WICKET-3163
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket
>    Affects Versions: 1.5-M3
>            Reporter: Peter Ertl
>            Assignee: Peter Ertl
>             Fix For: 1.5-M4
>
>         Attachments: local-lookup.patch, LocalEntityResolver.java
>
>
> Wicket developers, please give me some comment on this:
> Some wicket test cases parse XML which refers to an external DTD. 
> An example is org.apache.wicket.protocol.http.WicketFilterTest
> It refers to org.apache.wicket.util.file.WebXmlFile will will parse a custom web.xml.
> The web.xml will make the parser to look up http://java.sun.com/dtd/web-app_2_3.dtd
> When building wicket offline this will cause a network error and the test will fail.
> I would like to add 
>   org.apache.wicket.util.xml.LocalEntityResolver
> which may contain a set of local entitites to avoid hitting the network.
> As wicket 1.5 is getting close to final I would like to get some feedback first before putting that into trunk...
> By adding this like to WebXmlFile network lookup would be avoided.
>  
>   DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
>   DocumentBuilder builder = factory.newDocumentBuilder();
>   builder.setEntityResolver(LocalEntityResolver.getDefault());  // no more network lookups
>   Document document = builder.parse(is);
> ----------------------------------------------------
> package org.apache.wicket.util.xml;
> import org.apache.wicket.util.lang.Args;
> import org.xml.sax.EntityResolver;
> import org.xml.sax.InputSource;
> import org.xml.sax.SAXException;
> import javax.servlet.Filter;
> import java.io.IOException;
> import java.io.InputStream;
> import java.util.HashMap;
> import java.util.Map;
> /**
>  * entity resolver that tries to locate a document type definition (DTD) using a set of custom entity resolvers
>  *
>  * @author pete
>  */
> public class LocalEntityResolver implements EntityResolver
> {
> 	private final Map<EntityKey, EntityLocator> entities = new HashMap<EntityKey, EntityLocator>(3);
> 	public static LocalEntityResolver getDefault()
> 	{
> 		LocalEntityResolver resolver = new LocalEntityResolver();
>     
>     //
>     // look up servlet 2.3 web.xml DTD right from inside servlet-api.jar
>     //
> 		resolver.put(new EntityKey("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN",
> 		                           "http://java.sun.com/dtd/web-app_2_3.dtd"),
> 		             new ServletApiEntityLocator("web-app_2_3.dtd"));
> 		return resolver;
> 	}
> 	public void put(EntityKey key, EntityLocator locator)
> 	{
> 		Args.notNull(key, "key");
> 		Args.notNull(locator, "locator");
> 		entities.put(key, locator);
> 	}
> 	public InputSource resolveEntity(String id, String url) throws SAXException, IOException
> 	{
> 		for (Map.Entry<EntityKey, EntityLocator> entry : entities.entrySet())
> 			if (entry.getKey().id.equals(id) || entry.getKey().url.equals(url))
> 				return entry.getValue().locateInputSource();
> 		return null;
> 	}
> 	public static class EntityKey
> 	{
> 		private final String id;
> 		private final String url;
> 		private EntityKey(String id, String url)
> 		{
> 			Args.notEmpty(id, "id");
> 			Args.notEmpty(url, "url");
> 			this.id = id;
> 			this.url = url;
> 		}
> 		@Override
> 		public boolean equals(Object o)
> 		{
> 			if (this == o)
> 				return true;
> 			if (!(o instanceof EntityKey))
> 				return false;
> 			EntityKey key = (EntityKey) o;
> 			if (!id.equals(key.id))
> 				return false;
> 			return url.equals(key.url);
> 		}
> 		@Override
> 		public int hashCode()
> 		{
> 			int result = id.hashCode();
> 			result = 31 * result + url.hashCode();
> 			return result;
> 		}
> 	}
> 	public static interface EntityLocator
> 	{
> 		InputSource locateInputSource() throws SAXException, IOException;
> 	}
> 	public static class ServletApiEntityLocator implements EntityLocator
> 	{
> 		private final String name;
> 		private ServletApiEntityLocator(String name)
> 		{
> 			this.name = name;
> 		}
> 		public InputSource locateInputSource()
> 		{
> 			InputStream stream = Filter.class.getResourceAsStream("resources/" + name);
> 			if (stream == null)
> 				return null;
> 			return new InputSource(stream);
> 		}
> 	}
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (WICKET-3163) support building wicket offline by resolving DTD references locally

Posted by "Peter Ertl (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-3163?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Peter Ertl resolved WICKET-3163.
--------------------------------

       Resolution: Fixed
    Fix Version/s: 1.5-M4

Checked in a custom entity resolver that pulls web.xml 2.3 DTD right from inside servlet-api.jar.

For verification I added 

  127.0.0.1 java.sun.com

to

  /etc/hosts

which makes the build fail.

After applying the fix the builds still works fine, even when pointing java.sun.com to localhost :-)

This also removes some possible wait on a slow internet connection.


> support building wicket offline by resolving DTD references locally
> -------------------------------------------------------------------
>
>                 Key: WICKET-3163
>                 URL: https://issues.apache.org/jira/browse/WICKET-3163
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket
>    Affects Versions: 1.5-M3
>            Reporter: Peter Ertl
>            Assignee: Peter Ertl
>             Fix For: 1.5-M4
>
>         Attachments: local-lookup.patch, LocalEntityResolver.java
>
>
> Wicket developers, please give me some comment on this:
> Some wicket test cases parse XML which refers to an external DTD. 
> An example is org.apache.wicket.protocol.http.WicketFilterTest
> It refers to org.apache.wicket.util.file.WebXmlFile will will parse a custom web.xml.
> The web.xml will make the parser to look up http://java.sun.com/dtd/web-app_2_3.dtd
> When building wicket offline this will cause a network error and the test will fail.
> I would like to add 
>   org.apache.wicket.util.xml.LocalEntityResolver
> which may contain a set of local entitites to avoid hitting the network.
> As wicket 1.5 is getting close to final I would like to get some feedback first before putting that into trunk...
> By adding this like to WebXmlFile network lookup would be avoided.
>  
>   DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
>   DocumentBuilder builder = factory.newDocumentBuilder();
>   builder.setEntityResolver(LocalEntityResolver.getDefault());  // no more network lookups
>   Document document = builder.parse(is);
> ----------------------------------------------------
> package org.apache.wicket.util.xml;
> import org.apache.wicket.util.lang.Args;
> import org.xml.sax.EntityResolver;
> import org.xml.sax.InputSource;
> import org.xml.sax.SAXException;
> import javax.servlet.Filter;
> import java.io.IOException;
> import java.io.InputStream;
> import java.util.HashMap;
> import java.util.Map;
> /**
>  * entity resolver that tries to locate a document type definition (DTD) using a set of custom entity resolvers
>  *
>  * @author pete
>  */
> public class LocalEntityResolver implements EntityResolver
> {
> 	private final Map<EntityKey, EntityLocator> entities = new HashMap<EntityKey, EntityLocator>(3);
> 	public static LocalEntityResolver getDefault()
> 	{
> 		LocalEntityResolver resolver = new LocalEntityResolver();
>     
>     //
>     // look up servlet 2.3 web.xml DTD right from inside servlet-api.jar
>     //
> 		resolver.put(new EntityKey("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN",
> 		                           "http://java.sun.com/dtd/web-app_2_3.dtd"),
> 		             new ServletApiEntityLocator("web-app_2_3.dtd"));
> 		return resolver;
> 	}
> 	public void put(EntityKey key, EntityLocator locator)
> 	{
> 		Args.notNull(key, "key");
> 		Args.notNull(locator, "locator");
> 		entities.put(key, locator);
> 	}
> 	public InputSource resolveEntity(String id, String url) throws SAXException, IOException
> 	{
> 		for (Map.Entry<EntityKey, EntityLocator> entry : entities.entrySet())
> 			if (entry.getKey().id.equals(id) || entry.getKey().url.equals(url))
> 				return entry.getValue().locateInputSource();
> 		return null;
> 	}
> 	public static class EntityKey
> 	{
> 		private final String id;
> 		private final String url;
> 		private EntityKey(String id, String url)
> 		{
> 			Args.notEmpty(id, "id");
> 			Args.notEmpty(url, "url");
> 			this.id = id;
> 			this.url = url;
> 		}
> 		@Override
> 		public boolean equals(Object o)
> 		{
> 			if (this == o)
> 				return true;
> 			if (!(o instanceof EntityKey))
> 				return false;
> 			EntityKey key = (EntityKey) o;
> 			if (!id.equals(key.id))
> 				return false;
> 			return url.equals(key.url);
> 		}
> 		@Override
> 		public int hashCode()
> 		{
> 			int result = id.hashCode();
> 			result = 31 * result + url.hashCode();
> 			return result;
> 		}
> 	}
> 	public static interface EntityLocator
> 	{
> 		InputSource locateInputSource() throws SAXException, IOException;
> 	}
> 	public static class ServletApiEntityLocator implements EntityLocator
> 	{
> 		private final String name;
> 		private ServletApiEntityLocator(String name)
> 		{
> 			this.name = name;
> 		}
> 		public InputSource locateInputSource()
> 		{
> 			InputStream stream = Filter.class.getResourceAsStream("resources/" + name);
> 			if (stream == null)
> 				return null;
> 			return new InputSource(stream);
> 		}
> 	}
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WICKET-3163) support building wicket offline by resolving DTD references locally

Posted by "Peter Ertl (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-3163?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Peter Ertl updated WICKET-3163:
-------------------------------

    Attachment: local-lookup.patch

> support building wicket offline by resolving DTD references locally
> -------------------------------------------------------------------
>
>                 Key: WICKET-3163
>                 URL: https://issues.apache.org/jira/browse/WICKET-3163
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket
>    Affects Versions: 1.5-M3
>            Reporter: Peter Ertl
>            Assignee: Peter Ertl
>         Attachments: local-lookup.patch, LocalEntityResolver.java
>
>
> Wicket developers, please give me some comment on this:
> Some wicket test cases parse XML which refers to an external DTD. 
> An example is org.apache.wicket.protocol.http.WicketFilterTest
> It refers to org.apache.wicket.util.file.WebXmlFile will will parse a custom web.xml.
> The web.xml will make the parser to look up http://java.sun.com/dtd/web-app_2_3.dtd
> When building wicket offline this will cause a network error and the test will fail.
> I would like to add 
>   org.apache.wicket.util.xml.LocalEntityResolver
> which may contain a set of local entitites to avoid hitting the network.
> As wicket 1.5 is getting close to final I would like to get some feedback first before putting that into trunk...
> By adding this like to WebXmlFile network lookup would be avoided.
>  
>   DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
>   DocumentBuilder builder = factory.newDocumentBuilder();
>   builder.setEntityResolver(LocalEntityResolver.getDefault());  // no more network lookups
>   Document document = builder.parse(is);
> ----------------------------------------------------
> package org.apache.wicket.util.xml;
> import org.apache.wicket.util.lang.Args;
> import org.xml.sax.EntityResolver;
> import org.xml.sax.InputSource;
> import org.xml.sax.SAXException;
> import javax.servlet.Filter;
> import java.io.IOException;
> import java.io.InputStream;
> import java.util.HashMap;
> import java.util.Map;
> /**
>  * entity resolver that tries to locate a document type definition (DTD) using a set of custom entity resolvers
>  *
>  * @author pete
>  */
> public class LocalEntityResolver implements EntityResolver
> {
> 	private final Map<EntityKey, EntityLocator> entities = new HashMap<EntityKey, EntityLocator>(3);
> 	public static LocalEntityResolver getDefault()
> 	{
> 		LocalEntityResolver resolver = new LocalEntityResolver();
>     
>     //
>     // look up servlet 2.3 web.xml DTD right from inside servlet-api.jar
>     //
> 		resolver.put(new EntityKey("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN",
> 		                           "http://java.sun.com/dtd/web-app_2_3.dtd"),
> 		             new ServletApiEntityLocator("web-app_2_3.dtd"));
> 		return resolver;
> 	}
> 	public void put(EntityKey key, EntityLocator locator)
> 	{
> 		Args.notNull(key, "key");
> 		Args.notNull(locator, "locator");
> 		entities.put(key, locator);
> 	}
> 	public InputSource resolveEntity(String id, String url) throws SAXException, IOException
> 	{
> 		for (Map.Entry<EntityKey, EntityLocator> entry : entities.entrySet())
> 			if (entry.getKey().id.equals(id) || entry.getKey().url.equals(url))
> 				return entry.getValue().locateInputSource();
> 		return null;
> 	}
> 	public static class EntityKey
> 	{
> 		private final String id;
> 		private final String url;
> 		private EntityKey(String id, String url)
> 		{
> 			Args.notEmpty(id, "id");
> 			Args.notEmpty(url, "url");
> 			this.id = id;
> 			this.url = url;
> 		}
> 		@Override
> 		public boolean equals(Object o)
> 		{
> 			if (this == o)
> 				return true;
> 			if (!(o instanceof EntityKey))
> 				return false;
> 			EntityKey key = (EntityKey) o;
> 			if (!id.equals(key.id))
> 				return false;
> 			return url.equals(key.url);
> 		}
> 		@Override
> 		public int hashCode()
> 		{
> 			int result = id.hashCode();
> 			result = 31 * result + url.hashCode();
> 			return result;
> 		}
> 	}
> 	public static interface EntityLocator
> 	{
> 		InputSource locateInputSource() throws SAXException, IOException;
> 	}
> 	public static class ServletApiEntityLocator implements EntityLocator
> 	{
> 		private final String name;
> 		private ServletApiEntityLocator(String name)
> 		{
> 			this.name = name;
> 		}
> 		public InputSource locateInputSource()
> 		{
> 			InputStream stream = Filter.class.getResourceAsStream("resources/" + name);
> 			if (stream == null)
> 				return null;
> 			return new InputSource(stream);
> 		}
> 	}
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.