Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for /select handler when using default solrconfig.xml AND upgrade to Solr 4.x #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<properties>
<mule.version>3.3.0</mule.version>
<mule.devkit.version>3.3.0</mule.devkit.version>
<solr.version>4.7.1</solr.version>
<junit.version>4.9</junit.version>
<mockito.version>1.8.2</mockito.version>
<jdk.version>1.6</jdk.version>
Expand Down Expand Up @@ -184,7 +185,7 @@
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>3.1.0</version>
<version>${solr.version}</version>
<!-- exclude nasty dependencies -->
<exclusions>
<exclusion>
Expand Down
21 changes: 13 additions & 8 deletions src/main/java/org/mule/modules/SolrConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@

package org.mule.modules;

import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.auth.AuthScope;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.commons.lang.StringUtils;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.SolrPingResponse;
import org.apache.solr.client.solrj.response.UpdateResponse;
Expand All @@ -39,7 +40,7 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URI;
import java.util.*;

Expand Down Expand Up @@ -95,7 +96,7 @@ public class SolrConnector {
@Connect
public synchronized void connect() throws ConnectionException {
try {
CommonsHttpSolrServer httpClientServer = new CommonsHttpSolrServer(serverUrl);
HttpSolrServer httpClientServer = new HttpSolrServer(serverUrl);


//if there are credentials, then set them.
Expand All @@ -104,12 +105,14 @@ public synchronized void connect() throws ConnectionException {
//set BASIC authentication on the underlying HTTP client.
URI uri = new URI(serverUrl);
AuthScope scope = new AuthScope(uri.getHost(), uri.getPort());
httpClientServer.getHttpClient().getState().setCredentials(scope, new UsernamePasswordCredentials(username, password));
DefaultHttpClient defaultClient = (DefaultHttpClient) httpClientServer.getHttpClient();
defaultClient.getCredentialsProvider().setCredentials(scope, new UsernamePasswordCredentials(username, password));

}


this.server = httpClientServer;
} catch (MalformedURLException ex) {
} catch (URISyntaxException ex) {
logger.error("The url: " + serverUrl + " is malformed.");
throw new ConnectionException(ConnectionExceptionCode.UNKNOWN, ex.getMessage(), "Url is not properly written", ex);
} catch (Exception ex) {
Expand Down Expand Up @@ -203,7 +206,9 @@ public QueryResponse query(@FriendlyName("Query") String q,
@Optional @Placement(group = "Sort Fields") @FriendlyName("Sort Fields") Map<String, SolrQuery.ORDER> sortFields) throws SolrModuleException {

SolrQuery query = new SolrQuery(q);
query.setQueryType(handler);
if ( null!=handler && ! handler.equals("/select") ) {
query.setQueryType(handler);
}

applyHighlightingLogic(query, highlightField, highlightSnippets);
applyFacetingLogic(query, facetFields, facetLimit, facetMinCount);
Expand Down