I am using solr-php-client and it its default request-handler is select there is no way to change it unless I change the code itself. however, there is the parameter qt. I updated solrconfig to include <requestDispatcher handleSelect="true" > and I tried to use request handler name with or without / in solrconfig as well as in the url with qt parameter.
This link is working:solr_server_port_index/custom?q=
While this is not: solr_server_port_index/select?qt=custom&q= neither this solr_server_port_index/select?qt=/custom&q=
what am I missing here?
Solr uses the qt parameter to determine which Query Handler should be used to process the request. Valid values are any of the names specified by declarations in solrconfig.xml.
if we won't specify qt parameter then there must be a request handler in solrConfig.xml for a given request.
my experiments with solr 1.4 with qt parameter is mentioned below
<requestHandler name="/ana" class="solr.DisMaxRequestHandler" >
......
</requestHandler>
http://url:8081/solr/select?wt=xml&q=questionDetail:question&start=0&rows=10&qt=/ana
working fine
http://url:8081/solr/ana?wt=xml&q=questionDetail:question&start=0&rows=10
working fine
http://anaplatha.99.jsb9.net:8081/solr/select?wt=xml&q=questionDetail:question&start=0&rows=10&qt=\ana
error : HTTP Status 400 - unknown handler: \ana(this error I am getting for any value of qt which is != /ana)
references ::
https://wiki.apache.org/solr/CoreQueryParameters
https://issues.apache.org/jira/browse/SOLR-3161
To work around the missing configurability of solr-php-client (I created issue #6 to track this), you can extend the Service class and override the _constructUrl method to detect calls to select - and replace it with your own request handler. Modify this example to take the request handler name as custom ->setRequestHandler or however you want to fix it:
class Custom_RequestHandler_Solr extends Apache_Solr_Service {
public function _constructUrl($servlet, $params = []) {
if ($servlet == 'select') {
$servlet = 'mycustomrequesthandler';
}
return parent::_constructUrl($servlet, $params);
}
}
Related
Example:
to("xslt:mapping.xsl?saxon=true&transformerCacheSize=5")
When I use Saxon, I will set this property all over the place. Having a String constant for them or creating my own xslt endpoint does not seem to be the proper way.
Is there something I can set those properties for all xslt endpoints?
You can configure it by subscribing to the CamelContext's startupListener and setting the XsltEndpoints' parameters (be careful, because the following example does set every XsltEndpoint endpoint's saxon and transformerCacheSize properties). Example (ctx is an instance of CamelContext):
ctx.addStartupListener((ctx, alreadyStarted) -> {
ctx.getEndpoints().forEach(e -> {
if(e instanceof XsltEndpoint) {
((XsltEndpoint) e).setTransformerCacheSize(5);
((XsltEndpoint) e).setSaxon(true);
}
});
});
In case of Spring Boot saxon=true can be configured using the application.properties file (XsltComponentConfiguration). AFAIK the transformerCacheSize cannot be configured from the properties file, because it is a parameter of the XsltEndpoint.
# application.properties
camel.component.xslt.saxon = true
If the configuration is always the same, you can declare a direct endpoint to handle all requests.
from("direct:my-xslt")
.to("xslt:mapping.xsl?saxon=true&transformerCacheSize=5")
And then from your other routes:
.to("direct:my-xslt")
Direct endpoints run in the same thread, so after all its just a way of isolating parts of the route that do a specific job.
As a bonus if you need to do any kind of transformation/log before/after your xslt that apply to all routes, you can simply do it in your direct route.
I want to serve JSONP content with CakePHP and was wondering what's the proper way of doing it so.
Currently I'm able to serve JSON content automatically by following this CakePHP guide.
Ok, I found a solution on this site. Basically you override the afterFilter method with:
public function afterFilter() {
parent::afterFilter();
if (empty($this->request->query['callback']) || $this->response->type() != 'application/json') {
return;
}
// jsonp response
App::uses('Sanitize', 'Utility');
$callbackFuncName = Sanitize::clean($this->request->query['callback']);
$out = $this->response->body();
$out = sprintf("%s(%s)", $callbackFuncName, $out);
$this->response->body($out);
}
I hope it helps someone else as well.
I've as yet not found a complete example of how to correctly return JSONP using CakePHP 2, so I'm going to write it down. OP asks for the correct way, but his answer doesn't use the native options available now in 2.4. For 2.4+, this is the correct method, straight from their documentation:
Set up your views to accept/use JSON (documentation):
Add Router::parseExtensions('json'); to your routes.php config file. This tells Cake to accept .json URI extensions
Add RequestHandler to the list of components in the controller you're going to be using
Cake gets smart here, and now offers you different views for normal requests and JSON/XML etc. requests, allowing you flexibility in how to return those results, if needed. You should now be able to access an action in your controller by:
using the URI /controller/action (which would use the view in /view/controller/action.ctp), OR
using the URI /controller/action.json (which would use the view in /view/controller/json/action.ctp)
If you don't want to define those views i.e. you don't need to do any further processing, and the response is ready to go, you can tell CakePHP to ignore the views and return the data immediately using _serialize. Using _serialize will tell Cake to format your response in the correct format (XML, JSON etc.), set the headers and return it as needed without you needing to do anything else (documentation). To take advantage of this magic:
Set the variables you want to return as you would a view variable i.e. $this->set('post', $post);
Tell Cake to serialize it into XML, JSON etc. by calling $this->set('_serialize', array('posts'));, where the parameter is the view variable you just set in the previous line
And that's it. All headers and responses will be taken over by Cake. This just leaves the JSONP to get working (documentation):
Tell Cake to consider the request a JSONP request by setting $this->set('_jsonp', true);, and Cake will go find the callback function name parameter, and format the response to work with that callback function name. Literally, setting that one parameter does all the work for you.
So, assuming you've set up Cake to accept .json requests, this is what your typical action could look like to work with JSONP:
public function getTheFirstPost()
$post = $this->Post->find('first');
$this->set(array(
'post' => $post, <-- Set the post in the view
'_serialize' => array('post'), <-- Tell cake to use that post
'_jsonp' => true <-- And wrap it in the callback function
)
);
And the JS:
$.ajax({
url: "/controller/get-the-first-post.json",
context: document.body,
dataType: 'jsonp'
}).done(function (data) {
console.log(data);
});
For CakePHP 2.4 and above, you can do this instead.
http://book.cakephp.org/2.0/en/views/json-and-xml-views.html#jsonp-response
So you can simply write:
$this->set('_jsonp', true);
in the relevant action.
Or you can simply write:
/**
*
* beforeRender method
*
* #return void
*/
public function beforeRender() {
parent::beforeRender();
$this->set('_jsonp', true);
}
I can get the currect app / WSGI instance with : webapp2.get_app() and the current request instance : webapp2.get_request() but how to get the current webapp2 handler instance from :
class MainHandler(webapp2.RequestHandler):
def get(self):
for :
webapp2.Route(r'/', handler=module.MainHandler, name='main'),
without using "self" to refer to this object. Is it possible?
The route object in the request object contains the handler name, but not the instance.
UPDATE : A solution has not been found yet. For now I store the handler (self) in a global, using dispatch of the webapp2.RequestHandler. But there must be another way.
To find a solution I study Nick Johnsonz "how to write your own Python webapp framework" : http://blog.notdot.net/2010/01/Writing-your-own-webapp-framework-for-App-Engine to understand how webapp2 works.
What have I done :
With webapp2.get_request() I can find the request.route and the request.route.handler_adapter instance. But not the handler instance. The handler instance is not saved.
Conclusion : I use the constructor of my webapp2.RequestHandler to save the handler instance (self) in the request registry (threadsafe). And I do not have to match the route name, because for every request new instances (handler and request) are created.
Your question (or perhaps the example code snippet) may need to be more well-defined in order for folks to provide a suitable answer.
As far as I can tell, you seem to be looking for a way to find the call stack of some function in order to determine the nearest RequestHandler instance. If that's the case, then this is more of a general Python question than webapp2, but the traceback module may be what you're looking for.
I'm writing an API using Kohana. Each external request must be signed by the client to be accepted.
However, I also sometime need to do internal requests by building a Request object and calling execute(). In these cases, the signature is unnecessary since I know the request is safe. So I need to know that the request was internal so that I can skip the signature check.
So is there any way to find out if the request was manually created using a Request object?
Can you use the is_initial() method of the request object? Using this method, you can determine if a request is a sub request.
Kohana 3.2 API, Request - is_initial()
It sounds like you could easily solve this issue by setting some sort of static variable your app can check. If it's not FALSE, then you know it's internal.
This is how I ended up doing it: I've overridden the Request object and added a is_server_side property to it. Now, when I create the request, I just set this to true so that I know it's been created server-side:
$request = Request::factory($url);
$request->is_server_side(true);
$response = $request->execute();
Then later in the controller receiving the request:
if ($this->request->is_server_side()) {
// Skip signature check
} else {
// Do signature check
}
And here is the overridden request class in application/classes/request.php:
<?php defined('SYSPATH') or die('No direct script access.');
class Request extends Kohana_Request {
protected $is_server_side_ = false;
public function is_server_side($v = null) {
if ($v === null) return $this->is_server_side_;
$this->is_server_side_ = $v;
}
}
Looking through Request it looks like your new request would be considered an internal request but does not have any special flags it sets to tell you this. Look at 782 to 832 in Kohana_Request...nothing to help you.
With that, I'd suggest extending the Kohana_Request_Internal to add a flag that shows it as internal and pulling that in your app when you need to check if it is internal/all others.
Maybe you are looking for is_external method:
http://kohanaframework.org/3.2/guide/api/Request#is_external
Kohana 3.3 in the controller :
$this->request->is_initial()
http://kohanaframework.org/3.3/guide-api/Request#is_initial
I am a newbie in solrnet and my question is how to change the url for SolrNet Client.
I found this on wiki
initailizing code
Startup.Init<Product>("http://localhost:8983/solr");
invoking code
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Product>>();
but I dont know how to change the url , could someone tell me how to do this, I am really thanks.
It cannot be changed with existing SOLRNet code as it is implemented on singleton pattern.
You have to download the code from github.
Currently following exception has been thrown
"Key ... already registered in container". You can change code in a way that it will always create new instance. (by pass Singleton pattern)
The default request handler is "/select". So SolrNet will send your requests to
http://localhost:8983/solr/select
If you wish to invoke a different request handler, you will need to get a instance of the SolrQueryExecuter and set the Handler property, accordingly.
Assuming you have a request handler named "/browse":
Startup.Init<Product>("http://localhost:8983/solr");
var executor = ServiceLocator.Current.GetInstance<ISolrQueryExecuter<Product>>() as SolrQueryExecuter<Product>;
if (executor != null)
{
executor.Handler = "/browse";
}