Using Lift's snippet processing outside of Lift - scala

Is there a way to use Lift's snippet processing outside the normal request handling process? I know I can call LiftSession.findAndProcessTemplate, but that obviously requires an instance of LiftSession. Is there a way to do that without LiftSession as long as I only use stateless snippets? Alternatively, is there a way to get an "empty" instance of LiftSession?

Sure, you can use net.liftweb.http.S.runTemplate:
http://scala-tools.org/mvnsites/liftweb-2.4-M4/#net.liftweb.http.S

Related

Citrusframework - Java action - Get result

Besides REST-API Calls, I need to call my own Java-Class, which basically does something, which I want to confirm later in the test via REST-API-Calls.
When calling my Java-Class, there is an expected behavior: It may fail or not fail, depending on the actual Test-Case.
Is there any chance to code this expectation this into my test-class:
java("com.org.xyz.App").method("run").methodArgs(args).build();
As this is the Main-Class, which should be executed later in a automated fashion, I would prefer to validate the Return-Code.
However, I'm looking for any possible way (Exception-Assertion, Stdout-Check, ..) to verify the status of the program.
As you are using the Java DSL to write test cases I would suggest to go with custom test action implementation and/or initializing your custom class directly in the test method and call the method as you would do with any other API.
You can wrap the custom code in a custom AbstractTestAction implementation as you then have access to the TestContext and your custom code is integrated into the test action sequence.
The java("com.org.xyz.App").method("run").methodArgs(args) API is just for compliance to the XML DSL where you do not have the opportunity to initialize own Java class instances. Way too complicated for your requirement in my opinion.

SumoLogic RESTFul API C# client

Is there any C# client anyone know about that we can use to run queries against SumoLogic? I see they have a Java Client but cannot find a corresponding C# client.
You can use SumoLogicMessageSender class.
You can find using this class here.
But, I don't recommend to use GetResult() like it writes in original code :
// this maintains synchronous behavior for single event scenarios.
this.SumoLogicMessageSender
.TrySend(bodyBuilder.ToString(), this.SourceName, this.SourceCategory, this.SourceHost)
.GetAwaiter()
.GetResult();

what is the best way to retrieve a node in adobe cq5?

What are the different ways to retrieve a node in adobe cq5 and out of those which has to prefer.
I knows three method only one is through session , request and another one is through resourceResolver.
Here are those..
Node rootNode = session.getNode(path);
by request
Node currentNode = request.getResource().adaptTo(Node.class);
by resourceResolver
String resourcePath = "path/to/resource";
Node.node = resourceResolver.getResource(resourcePath).adaptTo(Node.class);
Out of these which one one is best way to retrieve and why ?
First it is discouraged to ask question like this, as it triggers oppinion based answers. Nonetheless I try to be as objecitve as I can. I think it depends on the use case, e.g. where in your code do you want to get the node:
If you already are in a servlet,
request.getResource().adaptTo(Node.class) is probably the most
straightforward way.
If you already have a jcr Session, it is easiest to use the
getNode(path) method
If you already have a ResourceResolver getResource(path) or resolve(path) are fine as well.
Me personally prefer the Sling API over the JCR, so I usually work with Resources anyway thus I mostly use the ResourceResolver or its Adapters: PageManager, TagManager, etc.
I even think internally it all ends up with session.getNode(path) as the ResourceResolver relies on a Session (you can adapt it to it) and request.getResource() probably uses the resolve(path) method.
There is no "best way". If you already have a NODE object then if you are trying to get say... all the children then there is listChildren(). Really the best way is a use case.
The real question is why you want a NODE specifically. Unless you are creating data in the JCR, there is usually no need for the node interface. 99% of the time the system handles node creation for you, so you are reading data, in which case resource.adaptTo(ValueMap.class) is probably your best bet.
If you add more details about WHY you are concerned about this and the context, I can help you further.

GWT Client Server Communication

I'm wondering whether it is at all possible to make the client ask the server for a given string, and incorporate it into another string ?
I don't see how to do that using the async approach.
As far as I know there is no really simple way to do this, because the i18n machanism of GWT replaces strings at compile-time and not at runtime.
You can try one of the following approaches:
Load the i18n in your entrypoint, store all messages in a local Map and create the Label etc, with the values from you cache. PRO: all GWT standard CONS: one request more, before you can show a translated page
Use JSP and no HTML at serverside. Wthin you jsp can create a JSON from your
message.properties and put it into your hostpage. PRO: You can synchronous read te values CONS: You will need to write a JSP which reads the properties for the correnct language, You will need to write a JSNI method to load the translated values.
Rethink, if you need a different way of translation. The built-in i18n will create tranlated versions of your app at compile-tim
I think I would use the second approach.

Can I make a single Perl module act as multiple kinds of mod_perl handlers?

I'm writing a series of related mod_perl handlers for various login-related functions in Apache, so my Apache config file looks like this (for example)
PerlAccessHandler MyApache::MyAccess
PerlAuthenHandler MyApache::MyAuthen
PerlAuthzHandler MyApache::MyAuthz
Each of the modules (MyAccess, MyAuthen, MyAuthz) defines a
sub handler() {}
Which mod_perl calls at the relevant point in the processing of the request.
What I'd like to know is whether there is a way of doing this with one Perl module rather than three (it's just tidier and less work for users to install one module instead of 3)?
Is there some way to define the name of the handler method, perhaps. Or is there a way of detecting from within the handler() code which sort of handling I'm supposed to be doing?
It appears from the mod_perl 2.0 docs that you can use the "method" syntax to do what you're wanting (I've not tested this):
PerlAccessHandler MyApache::MyLoginModule->access_handler
PerlAuthenHandler MyApache::MyLoginModule->authen_handler
PerlAuthzHandler MyApache::MyLoginModule->authz_handler
I believe this will cause mod_perl to call each of the named methods in a static way on your MyApache::MyLoginModule class.
You can also create an object to be used when calling a handler method if you want to:
<Perl>
use MyApache::MyLoginModule;
$MyApache::MyLoginModule::access = MyApache::MyLoginModule->new(phase => 'access');
$MyApache::MyLoginModule::authen = MyApache::MyLoginModule->new(phase => 'authen');
$MyApache::MyLoginModule::authz = MyApache::MyLoginModule->new(phase => 'authz');
</Perl>
PerlAccessHandler $MyApache::MyLoginModule::access->handler
PerlAuthenHandler $MyApache::MyLoginModule::authen->handler
PerlAuthzHandler $MyApache::MyLoginModule::authz->handler
This approach would allow you to have a single handler method that could have different behavior based on the properties of the object set up upon object creation.
Disclaimer: It's been a while since I've worked with this part of mod_perl configuration so your results may vary!
Looks like one possibility might be using the push_handlers() call and setting up the handlers in code rather than in the apache conf file
See here: http://tinyurl.com/bwdeew