I am trying to access this url for my autocomplete in the search box..
http://localhost:8080/api/v1/catalog/search/products?q=sauce
But, I am getting the following error.. It seems here that the
@Resource(name = "blExploitProtectionService")
protected ExploitProtectionService exploitProtectionService;
exploitProtectionService is null
And here is the error..
HTTP ERROR 500
Problem accessing /api/v1/catalog/search/products. Reason:
Server Error
Caused by:
java.lang.NullPointerException
at org.broadleafcommerce.core.web.api.endpoint.catalog.CatalogEndpoint.findProductsByQuery(CatalogEndpoint.java:190)
at com.mycompany.api.endpoint.catalog.CatalogEndpoint.findProductsByQuery(CatalogEndpoint.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
My web.xml is as follows
<servlet>
<servlet-name>RESTApiServlet</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.mycompany.api.endpoint</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>RESTApiServlet</servlet-name>
<url-pattern>/api/v1/*</url-pattern>
</servlet-mapping>
Next, my applicationContext.xml is
<context:component-scan base-package="org.broadleafcommerce.core.web.api"/>
and applicationContext-security.xml is
<!-- Set up Spring security for the RESTful API -->
<sec:http pattern="/api/**" create-session="stateless">
<sec:http-basic />
<sec:custom-filter ref="blRestCustomerStateFilter" after="REMEMBER_ME_FILTER"/>
</sec:http>
<!-- Used for REST api calls. This just takes in the passed in customerId and uses it to establish the customer. -->
<!-- Additional considerations MUST be made for implementations that are allowing external access to APIs. -->
<bean id="blRestCustomerStateFilter" class="org.broadleafcommerce.profile.web.core.security.RestApiCustomerStateFilter"/>
How to solve this problem? How do I make the exploitProtectionService
variable not null. How can it be initialized?
Thanks in advance.
Search functionality in REST is done by solr. When you pass q="something", then it will be search by solr query.
So when you pass * in q like, q=*, then it will work. But when you pass q="sauce", then it won't work, To make it work you have to make solr indexing based on product name.
To do so, put above sql lines in your project's core/src/main/resources/sql/load_catalog_data.sql :
Make sure after executing this lines, you get entry in your DB's BLC_FIELD and BLC_FIELD_SEARCH_TYPES tables.
After setting this, you have to modify solr configurations. To do so, open schema.xml from site/src/main/resources. Change default configurations to above lines,
After Doing this, you will be able to search for product name, so when you pass product name inside q="", then it will return you results. You can do the same for manufacturer, description etc...
For understanding solr, this link will be helpful. solr query in broadleaf