Custom Document Filter - ClassNotFoundException when starting Connector - google-search-appliance

I am developing a custom document filter. So far I have created a project in eclipse, added jar files necessary and successfully built a jar file with my own document filter.
What step am I missing to make the connector find the class ??
When it comes to configuring the document filter in the file 'connectorInstance.xml' something goes wrong and its seems the jar file cannot be found in the class path...
The Java package has the following classpath :
com.google.enterprise.connector.util.filter.DocFilterWildCardSearch
or also tried the following path
com.kapsch.gsa.filter.DocFilterWildCardSearch
I copied the 'DocFilterWildCardSearch.jar' file into the following path:
C:\Program Files\GoogleConnectors\GSAConnectors1\Tomcat\webapps\connector-manager\WEB-INF\lib
Restarted the connector and got the following error message:
Nov 20, 2013 4:50:29 PM [Init] com.google.enterprise.connector.servlet.StartUp doStartup
SEVERE: Connector Manager Startup failed:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DocumentFilters' defined in ServletContext resource [/WEB-INF/documentFilters.xml]: Cannot create inner bean 'asfsdf' of type [com.kapsch.gsa.filter.DocFilterWildCardSearch] while setting constructor argument with key [0]; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.kapsch.gsa.filter.DocFilterWildCardSearch] for bean with name 'asfsdf' defined in ServletContext resource [/WEB-INF/documentFilters.xml]; nested exception is java.lang.ClassNotFoundException: com.kapsch.gsa.filter.DocFilterWildCardSearch
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:230)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:117)
Config file for Document Filter : connectorInstance.xml
<?xml version="1.0"?>
<beans>
<bean class="com.example.connector.HelloWorldConnector" id="helloworld-connector"> </bean>
<bean class="com.google.enterprise.connector.util.filter.DocumentFilterChain" id="DocumentFilters">
<constructor-arg>
<list>
<bean class="com.kapsch.gsa.filter.DocFilterWildCardSearch" id="asfsdf">
<property value="Author" name="propertyName"/>
<property value="Roli" name="propertyValue"/>
<property value="false" name="overwrite"/>
</bean>
</list>
</constructor-arg>
</bean>
</beans>

Your settings are supposed to go inthe the documentFilters.xml file and not the connector instance file.
Google's got a support article on the subject here here.
It looks like you're attempting to nGram. I've got a filter already that I've been meaning to open source. If you would like it, drop me a note.
Finally, 7.2 is rumored to have wild carding in. We won't know for sure until it comes out.

Any chance you can include the output of jar tf on your doc filter jar file?
Michael is right in that you configure doc filters in documentfilters.xml.

Related

Passing path to a file in resources folder to spring bean definition

I have a spring bean definition as:
<bean class="...">
<property name="myFile" value="full\path\to\src\main\resources\a\b\myfile.dat"></property>
</bean>
This works fine. But its full path. I intend it to be like:
value="a\b\myfile.dat"
While trying to do so, I get FilesNotFoundException.
How to do it correctly?
Good day,
You have to read a file through ClassPathResource, here is a good example - https://www.baeldung.com/spring-classpath-file-access

How to resolve "cyclic loading of class path resource"?

I have two separate projects. One is maven, spring webservices(Let's say this is project A) and the other is maven batch project(Let's call it B).
I am trying to inject a class(let's say class "batch.java") from B into a class(let's call it "api.java") of A.
One major problem statement is that B has a dependency on A( on a different class of A, not on api.java).And I believe this is causing the cyclic loading error on startup.
I will paste my code here and I request to please provide a solution to it:
file:B.xml
<import resource="classpath:A.xml" />
<bean id="batch" class="XXX">
<!-- lookup methods from project A -->
</bean>
file:A.xml
<import resource="classpath*:B.xml"/>
<bean id="api" scope="prototype" lazy-init="true">
<property name="batch" ref="batch" />
</bean>
The code compiles fine but when I try to start my wsdl I get the following error:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:B.xml]
Offending resource: class path resource [A.xml]; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:A.xml]
Offending resource: class path resource [B.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Detected cyclic loading of class path resource [A.xml] - check your import definitions!
org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
Unfortunately you need to break the cyclic dependency.
Put all commonly used bean definitions into a separate context and reference this context in your sub-contexts.
Then you should end up with at least 3 context.xml's - eg:
common-context.xml (contains all bean definitions that are used in all sub-contexts)
a-context.xml (includes common-context.xml)
b-context.xml (includes common-context.xml)

Spring session factory not finding mapping files in multiple directories with same class path

I am having problems when loading hibernate mappings from multiple paths.
My Spring session factory is define as follows:
<beans>
...
<bean id="sessionFactory" class="org.springframwork.orm.hibernate3.LocalSessionFactory">
</bean>
<property name="mappingLocations">
<list>
<value>classpath:/mapping/*.hbm.xml</value>
</list>
</property>
When I put my mappings Foo.hbm.xml and Bar.hbm.xml into the directory src/main/resources/mappings, then both mappings are found when Hibernate is initialized.
But when I put Foo.hbm.xml into the directory src/main/resources/mapping and Bar.hbm.xml into the directory src/test/resources/mapping, then only the latter mapping file can be found. Hibernate will fail with "cannot find mapping for Foo" error.
I can see that the mappings are copied to the directories target/classes/mapping and target/test-classes/mapping, so why cannot hibernate (or the spring local session factory bean) find both mapping files? I thought that "classpath:/mapping/*.hbm.xml" would find both target/classes/mapping and target/test-classes/mapping directories?
edit: I am getting this problem when running unit tests, so I expect that mappings found in both src/main/resources and src/test/resources would be found.
You are using maven. And since you put your Bar mapping into the test resource directory, it is only available when running tests.
I assume you have a persistence-unit configured similar to the example below
<persistence-unit ...>
<class>something.Foo</class>
<class>something.Bar</class>
</persistence-unit>
What happens at start-up is that Spring starts Hibernate, hibernates reads the persistence-unit and asks the factory for the mappings. But remember, Bar is only a test class. So Spring finds the mappings from src/main/resources, but since it does not run as a test, it does not see src/test/resources.

Spring context scanning behavior

I'm getting the following:
2013-03-27 18:51:54,944 ERROR pringframework.web.context.ContextLoader: 227 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'exporter' defined in URL ... Cannot resolve reference to bean 'dynamicNamingStrategy' while setting bean property 'namingStrategy'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dynamicNamingStrategy' is defined
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at
and also STS is complaining:
Multiple annotations found at this line:
- Referenced bean 'dynamicNamingStrategy'
not found
with the following Spring contexts setup:
In a project, I have a jmx management context (core-app-web-common-management-context.xml) with following (excerpt):
<context:annotation-config />
<context:component-scan
base-package="com.a.b.c.management.*" />
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter"
lazy-init="false">
<property name="autodetect" value="true"></property>
<property name="namingStrategy" ref="dynamicNamingStrategy"/>
where dynamicNamingStrategy is defined in a different project (and packaged into a different jar) and is referred to in the component-scan above, as follows
package com.a.b.c.management;
#Component("dynamicNamingStrategy")
public class DynamicNamingStrategy extends KeyNamingStrategy {
......
The above Spring context is in turn imported into the main context located in the same project:
<import resource="classpath*:/META-INF/spring/core-app-web-common-management-context.xml"/>
So, somehow the #Component scanning for DynamicNamingStrategy is not working...
If I instead use this property definition in exporter, then it works:
<property name="namingStrategy"><bean class="com.a.b.c.management.DynamicNamingStrategy" /></property>
but I'd like to understand why the component scanning mechanism falters in the first instance, apparently I'm missing something.
Also, Spring Explorer view in STS is missing that bean as well. Enabling support for elements in configuration files option doesn't seem to make a difference.
Drop the .* at the end of your package name in your <context:component-scan> elements base-package attribute. I would think that this is causing the component-scan to look for a package named *, which there probably isn't one (can't be one).
The base-package is just that, the base package. The component-scan will scan all children of all base packages, therefore there is no need to have the .* wildcard at the end of your package name.

Maven Spring fileUpload using uploadTempDir property

Actually my requirement is to store uploaded files in the classpath directory i.e. src/main/resources/uploads. (I am using maven project)
But the dispatcher is not able to find this path. I am getting the following error.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'multipartResolver' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'uploadTempDir' threw exception; nested exception is java.io.FileNotFoundException: class path resource [uploads] cannot be resolved to URL because it does not exist
The below configuration is added in the dispatcher file:
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="1048576"/>
<property name="uploadTempDir" ref="uploadDirResource"/>
</bean>
<bean id="uploadDirResource" class="org.springframework.core.io.ClassPathResource">
<constructor-arg>
<value>/uploads</value>
</constructor-arg>
</bean>
The path src/main/resources(/uploads) is a path used by Maven BEFORE compiling. Your Server does not know anything about this path!
The artefacts in src/main/resources(/uploads) are copied within the war file into the directory WEB-INF/classes/uploads.
But this directory also contain the java class fiels, and you should never allow a user to modify or add files to that directory!
One point that is may not correct with you configration is the whitespace in
<value>/uploads </value>

Resources