use of org.apache.solr.api.V2HttpCall in project lucene-solr by apache.
the class SolrRequestParsers method buildRequestFrom.
private SolrQueryRequest buildRequestFrom(SolrCore core, SolrParams params, Collection<ContentStream> streams, RTimerTree requestTimer, final HttpServletRequest req) throws Exception {
// The content type will be applied to all streaming content
String contentType = params.get(CommonParams.STREAM_CONTENTTYPE);
// Handle anything with a remoteURL
String[] strs = params.getParams(CommonParams.STREAM_URL);
if (strs != null) {
if (!enableRemoteStreams) {
throw new SolrException(ErrorCode.BAD_REQUEST, "Remote Streaming is disabled.");
}
for (final String url : strs) {
ContentStreamBase stream = new ContentStreamBase.URLStream(new URL(url));
if (contentType != null) {
stream.setContentType(contentType);
}
streams.add(stream);
}
}
// Handle streaming files
strs = params.getParams(CommonParams.STREAM_FILE);
if (strs != null) {
if (!enableRemoteStreams) {
throw new SolrException(ErrorCode.BAD_REQUEST, "Remote Streaming is disabled.");
}
for (final String file : strs) {
ContentStreamBase stream = new ContentStreamBase.FileStream(new File(file));
if (contentType != null) {
stream.setContentType(contentType);
}
streams.add(stream);
}
}
// Check for streams in the request parameters
strs = params.getParams(CommonParams.STREAM_BODY);
if (strs != null) {
for (final String body : strs) {
ContentStreamBase stream = new ContentStreamBase.StringStream(body);
if (contentType != null) {
stream.setContentType(contentType);
}
streams.add(stream);
}
}
final HttpSolrCall httpSolrCall = req == null ? null : (HttpSolrCall) req.getAttribute(HttpSolrCall.class.getName());
SolrQueryRequestBase q = new SolrQueryRequestBase(core, params, requestTimer) {
@Override
public Principal getUserPrincipal() {
return req == null ? null : req.getUserPrincipal();
}
@Override
public List<CommandOperation> getCommands(boolean validateInput) {
if (httpSolrCall != null) {
return httpSolrCall.getCommands(validateInput);
}
return super.getCommands(validateInput);
}
@Override
public Map<String, String> getPathTemplateValues() {
if (httpSolrCall != null && httpSolrCall instanceof V2HttpCall) {
return ((V2HttpCall) httpSolrCall).getUrlParts();
}
return super.getPathTemplateValues();
}
@Override
public HttpSolrCall getHttpSolrCall() {
return httpSolrCall;
}
};
if (streams != null && streams.size() > 0) {
q.setContentStreams(streams);
}
return q;
}
Aggregations