cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Baldwin <jfbald...@earthlink.net>
Subject Re: 4.0 web.xml filter config files
Date Mon, 06 Jul 2015 22:56:56 GMT
Probably a good idea to include it in the docs then?



> On Jul 6, 2015, at 2:43 PM, Andrus Adamchik <andrus@objectstyle.org> wrote:
> 
> Yeah, this looks about right. This is a correct way to use CayenneFilter. 
> 
>> On Jul 6, 2015, at 12:35 PM, Joe Baldwin <jfbaldwin@earthlink.net> wrote:
>> 
>> OK, after over an hour of hacking, I think I have figured out at least some of the
rules for specifying the location of Cayenne config files in a Tomcat environment.   I put
this together from bits an pieces I found in the docs - I could not find a full example.
>> 
>> For anyone who is configuring a Cayenne 4.X web.xml filter here is what I found.
  I cannot say this is the best or only way to do this, but it seems to work for at least
the basic Cayenne 4.X configuration files.  (I also have dbcp.properties in the same directory).
>> 
>> In this example, my domain name is “CMSDomain”.  This is an excerpt from my web.xml
file.   The init-param appears to be named “configuration-location”, and the value is
a path to the Cayenne Modeler xml file relative to classes (which is part of the standard
Tomcat classpath).   It appears that the filter derives the directory name from the embedded
path.
>> 
>> I could not find an example of this in the docs, but this appears to work in Cayenne
4.X.  If anyone has a better idea, please let me know.
>> 
>> 	<filter>
>> 		<filter-name>cayenne-CMSDomain</filter-name>
>> 		<filter-class>org.apache.cayenne.configuration.web.CayenneFilter</filter-class>
>> 		<init-param>
>> 			<param-name>configuration-location</param-name>
>> 			<param-value>config/cayenne/cayenne-CMSDomain.xml</param-value>
>> 		</init-param>
>> 	</filter>
>> 	<filter-mapping>
>> 		<filter-name>cayenne-CMSDomain</filter-name>
>> 		<url-pattern>/*</url-pattern>
>> 	</filter-mapping>
>> 
>> 
>> Joe
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> On Jul 6, 2015, at 11:48 AM, John Huss <johnthuss@gmail.com> wrote:
>>> 
>>> You can use subfolders inside WEB-INF/classes.  These are essentially java
>>> packages, although it doesn't really matter.  How you handle it would
>>> depend on your dev environment and build tool.
>>> 
>>> With ant based projects, just throw in the src folder under whatever
>>> package you want, then ensure your ant script includes it in the build.
>>> 
>>> With maven or other tools you would put in under
>>> src/main/resources/whatever/package/you/want.  With maven I imagine this
>>> just does the right thing.
>>> 
>>> Then in your code to create the runtime you just specify the whole package
>>> in path format.  new
>>> ServerRuntime("/whatever/package/you/want/cayenne-MyApp.xml").  If it
>>> doesn't work in the built version it's probably because you aren't actually
>>> copying the file in the build product.
>>> 
>>> 
>>> On Mon, Jul 6, 2015 at 10:34 AM Joe Baldwin <jfbaldwin@earthlink.net> wrote:
>>> 
>>>> OK, lets start over.  You say below:
>>>> 
>>>>>>> Yes, XML files can be placed in subdirectories of any CLASSPATH
>>>> directory. So if you have the project file under
>>>> "WEB-INF/classes/org/example/cayenne-myproject.xml" , your location would
>>>> be "org/example/cayenne-myproject.xml".
>>>> 
>>>> 
>>>> 
>>>> And I am reporting that this only works if the config files are in the
>>>> "WEB-INF/classes" directory.   If I put them in a directory, say
>>>> "WEB-INF/classes/cayenne-config” it fails.   My understanding from your
>>>> comment is that it is possible to put them in this directory.   If so, then
>>>> how is this done per Cayenne rules.  I would prefer an example.
>>>> 
>>>> If it is not possible to do so then please let me know.
>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>>>>> On Jul 6, 2015, at 11:14 AM, Andrus Adamchik <andrus@objectstyle.org>
>>>> wrote:
>>>>> 
>>>>> Try debugging your app, putting a breakpoint in
>>>> ClassLoaderResourceLocator.findResources(..) method. This may give you an
>>>> idea.
>>>>> 
>>>>> Andrus
>>>>> 
>>>>> 
>>>>>> On Jul 5, 2015, at 9:11 PM, Joe Baldwin <jfbaldwin@earthlink.net>
>>>> wrote:
>>>>>> 
>>>>>> OK, so the question is “how”.
>>>>>> 
>>>>>> (I spent about 45min hacking different combinations and none worked.
>>>> All I could get working is depositing all the config files in the top
>>>> level WEB-INF/classes dir.  I am sure I am missing something but the
>>>> previous two solutions stopped working with 4.0)
>>>>>> 
>>>>>> 
>>>>>> 
>>>>>>> On Jul 5, 2015, at 8:56 PM, Andrus Adamchik <andrus@objectstyle.org>
>>>> wrote:
>>>>>>> 
>>>>>>> 
>>>>>>>> On Jul 5, 2015, at 8:51 PM, Joe Baldwin <jfbaldwin@earthlink.net>
>>>> wrote:
>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> "configuration-location" init parameter.”
>>>>>>>> 
>>>>>>>> 
>>>>>>>> This was mentioned in the docs. Is this not good practice?
>>>>>>>> 
>>>>>>>> I would *prefer* to put them in a separate directory under
>>>> “classes”.   Is there a better way to do this - in your experience?
>>>>>>> 
>>>>>>> Yes, XML files can be placed in subdirectories of any CLASSPATH
>>>> directory. So if you have the project file under
>>>> "WEB-INF/classes/org/example/cayenne-myproject.xml" , your location would
>>>> be "org/example/cayenne-myproject.xml". This is a standard way of locating
>>>> any kind of resources in Java via ClassLoader.
>>>>>>> 
>>>>>>> Andrus
>>>>>> 
>>>>>> 
>>>>> 
>>>> 
>>>> 
>> 
>> 
> 


Mime
View raw message