Search in sources :

Example 6 with SolrRequestInfo

use of org.apache.solr.request.SolrRequestInfo in project lucene-solr by apache.

the class IgnoreCommitOptimizeUpdateProcessorFactoryTest method processCommit.

SolrQueryResponse processCommit(final String chain, boolean optimize, Boolean commitEndPoint) throws IOException {
    SolrCore core = h.getCore();
    UpdateRequestProcessorChain pc = core.getUpdateProcessingChain(chain);
    assertNotNull("No Chain named: " + chain, pc);
    SolrQueryResponse rsp = new SolrQueryResponse();
    SolrQueryRequest req = new LocalSolrQueryRequest(core, new ModifiableSolrParams());
    if (commitEndPoint != null) {
        ((ModifiableSolrParams) req.getParams()).set(DistributedUpdateProcessor.COMMIT_END_POINT, commitEndPoint.booleanValue());
    }
    try {
        SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
        CommitUpdateCommand cmd = new CommitUpdateCommand(req, false);
        cmd.optimize = optimize;
        UpdateRequestProcessor processor = pc.createProcessor(req, rsp);
        processor.processCommit(cmd);
    } finally {
        SolrRequestInfo.clearRequestInfo();
        req.close();
    }
    return rsp;
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrCore(org.apache.solr.core.SolrCore) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) CommitUpdateCommand(org.apache.solr.update.CommitUpdateCommand) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 7 with SolrRequestInfo

use of org.apache.solr.request.SolrRequestInfo in project lucene-solr by apache.

the class HttpSolrCall method call.

/**
   * This method processes the request.
   */
public Action call() throws IOException {
    MDCLoggingContext.reset();
    MDCLoggingContext.setNode(cores);
    if (cores == null) {
        sendError(503, "Server is shutting down or failed to initialize");
        return RETURN;
    }
    if (solrDispatchFilter.abortErrorMessage != null) {
        sendError(500, solrDispatchFilter.abortErrorMessage);
        return RETURN;
    }
    try {
        init();
        /* Authorize the request if
       1. Authorization is enabled, and
       2. The requested resource is not a known static file
        */
        if (cores.getAuthorizationPlugin() != null && shouldAuthorize()) {
            AuthorizationContext context = getAuthCtx();
            log.debug("AuthorizationContext : {}", context);
            AuthorizationResponse authResponse = cores.getAuthorizationPlugin().authorize(context);
            if (authResponse.statusCode == AuthorizationResponse.PROMPT.statusCode) {
                Map<String, String> headers = (Map) getReq().getAttribute(AuthenticationPlugin.class.getName());
                if (headers != null) {
                    for (Map.Entry<String, String> e : headers.entrySet()) response.setHeader(e.getKey(), e.getValue());
                }
                log.debug("USER_REQUIRED " + req.getHeader("Authorization") + " " + req.getUserPrincipal());
            }
            if (!(authResponse.statusCode == HttpStatus.SC_ACCEPTED) && !(authResponse.statusCode == HttpStatus.SC_OK)) {
                log.info("USER_REQUIRED auth header {} context : {} ", req.getHeader("Authorization"), context);
                sendError(authResponse.statusCode, "Unauthorized request, Response code: " + authResponse.statusCode);
                return RETURN;
            }
        }
        HttpServletResponse resp = response;
        switch(action) {
            case ADMIN:
                handleAdminRequest();
                return RETURN;
            case REMOTEQUERY:
                remoteQuery(coreUrl + path, resp);
                return RETURN;
            case PROCESS:
                final Method reqMethod = Method.getMethod(req.getMethod());
                HttpCacheHeaderUtil.setCacheControlHeader(config, resp, reqMethod);
                // if we fail cache validation, execute the query
                if (config.getHttpCachingConfig().isNever304() || !HttpCacheHeaderUtil.doCacheHeaderValidation(solrReq, req, reqMethod, resp)) {
                    SolrQueryResponse solrRsp = new SolrQueryResponse();
                    /* even for HEAD requests, we need to execute the handler to
               * ensure we don't get an error (and to make sure the correct
               * QueryResponseWriter is selected and we get the correct
               * Content-Type)
               */
                    SolrRequestInfo.setRequestInfo(new SolrRequestInfo(solrReq, solrRsp));
                    execute(solrRsp);
                    HttpCacheHeaderUtil.checkHttpCachingVeto(solrRsp, resp, reqMethod);
                    Iterator<Map.Entry<String, String>> headers = solrRsp.httpHeaders();
                    while (headers.hasNext()) {
                        Map.Entry<String, String> entry = headers.next();
                        resp.addHeader(entry.getKey(), entry.getValue());
                    }
                    QueryResponseWriter responseWriter = getResponseWriter();
                    if (invalidStates != null)
                        solrReq.getContext().put(CloudSolrClient.STATE_VERSION, invalidStates);
                    writeResponse(solrRsp, responseWriter, reqMethod);
                }
                return RETURN;
            default:
                return action;
        }
    } catch (Throwable ex) {
        sendError(ex);
        // walk the the entire cause chain to search for an Error
        Throwable t = ex;
        while (t != null) {
            if (t instanceof Error) {
                if (t != ex) {
                    log.error("An Error was wrapped in another exception - please report complete stacktrace on SOLR-6161", ex);
                }
                throw (Error) t;
            }
            t = t.getCause();
        }
        return RETURN;
    } finally {
        MDCLoggingContext.clear();
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) AuthorizationContext(org.apache.solr.security.AuthorizationContext) Method(org.apache.solr.servlet.cache.Method) AuthorizationResponse(org.apache.solr.security.AuthorizationResponse) QueryResponseWriter(org.apache.solr.response.QueryResponseWriter) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) Map(java.util.Map) ValidatingJsonMap(org.apache.solr.common.util.ValidatingJsonMap) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) HashMap(java.util.HashMap)

Example 8 with SolrRequestInfo

use of org.apache.solr.request.SolrRequestInfo in project lucene-solr by apache.

the class TestGroupingSearch method testGroupingSimpleFormatArrayIndexOutOfBoundsExceptionWithJavaBin.

@Test
public void testGroupingSimpleFormatArrayIndexOutOfBoundsExceptionWithJavaBin() throws Exception {
    assertU(add(doc("id", "1", "nullfirst", "1")));
    assertU(add(doc("id", "2", "nullfirst", "1")));
    assertU(add(doc("id", "3", "nullfirst", "2")));
    assertU(add(doc("id", "4", "nullfirst", "2")));
    assertU(add(doc("id", "5", "nullfirst", "2")));
    assertU(add(doc("id", "6", "nullfirst", "3")));
    assertU(commit());
    SolrQueryRequest request = req("q", "*:*", "group", "true", "group.field", "nullfirst", "group.main", "true", "wt", "javabin", "start", "4", "rows", "10");
    SolrQueryResponse response = new SolrQueryResponse();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        SolrRequestInfo.setRequestInfo(new SolrRequestInfo(request, response));
        String handlerName = request.getParams().get(CommonParams.QT);
        h.getCore().execute(h.getCore().getRequestHandler(handlerName), request, response);
        BinaryResponseWriter responseWriter = new BinaryResponseWriter();
        responseWriter.write(out, request, response);
    } finally {
        request.close();
        SolrRequestInfo.clearRequestInfo();
    }
    assertEquals(6, ((ResultContext) response.getResponse()).getDocList().matches());
    new BinaryResponseParser().processResponse(new ByteArrayInputStream(out.toByteArray()), "");
    out.close();
}
Also used : ResultContext(org.apache.solr.response.ResultContext) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) BinaryResponseParser(org.apache.solr.client.solrj.impl.BinaryResponseParser) ByteArrayInputStream(java.io.ByteArrayInputStream) BinaryResponseWriter(org.apache.solr.response.BinaryResponseWriter) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 9 with SolrRequestInfo

use of org.apache.solr.request.SolrRequestInfo in project lucene-solr by apache.

the class TestCrossCoreJoin method query.

public String query(SolrCore core, SolrQueryRequest req) throws Exception {
    String handler = "standard";
    if (req.getParams().get("qt") != null)
        handler = req.getParams().get("qt");
    SolrQueryResponse rsp = new SolrQueryResponse();
    SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
    core.execute(core.getRequestHandler(handler), req, rsp);
    if (rsp.getException() != null) {
        throw rsp.getException();
    }
    StringWriter sw = new StringWriter(32000);
    QueryResponseWriter responseWriter = core.getQueryResponseWriter(req);
    responseWriter.write(sw, req, rsp);
    req.close();
    SolrRequestInfo.clearRequestInfo();
    return sw.toString();
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) StringWriter(java.io.StringWriter) QueryResponseWriter(org.apache.solr.response.QueryResponseWriter) SolrRequestInfo(org.apache.solr.request.SolrRequestInfo)

Example 10 with SolrRequestInfo

use of org.apache.solr.request.SolrRequestInfo in project lucene-solr by apache.

the class PKIAuthenticationPlugin method setHeader.

@SuppressForbidden(reason = "Needs currentTimeMillis to set current time in header")
void setHeader(HttpRequest httpRequest) {
    SolrRequestInfo reqInfo = getRequestInfo();
    String usr;
    if (reqInfo != null) {
        Principal principal = reqInfo.getReq().getUserPrincipal();
        if (principal == null) {
            //so we don't not need to set a principal
            return;
        } else {
            usr = principal.getName();
        }
    } else {
        if (!isSolrThread()) {
            // then no need to add any header
            return;
        }
        //this request seems to be originated from Solr itself
        //special name to denote the user is the node itself
        usr = "$";
    }
    String s = usr + " " + System.currentTimeMillis();
    byte[] payload = s.getBytes(UTF_8);
    byte[] payloadCipher = keyPair.encrypt(ByteBuffer.wrap(payload));
    String base64Cipher = Base64.byteArrayToBase64(payloadCipher);
    httpRequest.setHeader(HEADER, myNodeName + " " + base64Cipher);
}
Also used : SolrRequestInfo(org.apache.solr.request.SolrRequestInfo) BasicUserPrincipal(org.apache.http.auth.BasicUserPrincipal) Principal(java.security.Principal) SuppressForbidden(org.apache.solr.common.util.SuppressForbidden)

Aggregations

SolrRequestInfo (org.apache.solr.request.SolrRequestInfo)29 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)22 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)16 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)9 SolrCore (org.apache.solr.core.SolrCore)9 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)8 Map (java.util.Map)5 QueryResponseWriter (org.apache.solr.response.QueryResponseWriter)5 Query (org.apache.lucene.search.Query)4 SolrException (org.apache.solr.common.SolrException)4 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)4 IOException (java.io.IOException)3 StringWriter (java.io.StringWriter)3 HashMap (java.util.HashMap)3 JavaBinCodec (org.apache.solr.common.util.JavaBinCodec)3 NamedList (org.apache.solr.common.util.NamedList)3 BinaryResponseWriter (org.apache.solr.response.BinaryResponseWriter)3 ResultContext (org.apache.solr.response.ResultContext)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2