Printing messages on the OSGi console - console

I'm implementing a very light weight (embedded) OSGi framework which runs on a target piece of hardware. To attach a console I'm using org.apache.felix.gogo.shell and org.apache.felix.shell.remote.
To date, I've logged all custom messages using System.out.println which has worked fine, but now that I'm using the remote console I require something that will allow me to 'print' my messages to the OSGi console (and hopefully appear both on the target's console as well as the telnet console provided by felix.shell.remote).
I'm guessing there must be a way to get a handle to an OutputStream (or similar) to do this; My question is how? It seems that most people redirect their stdout etc. to solve problems like this.
I'm using declarative services, so I was hoping to be able to setup a component which attaches a referenced service (not important, but would make it nice and neat).
Any help is greatly appreciated.

The best way is to use logging for custom messages using the OSGi Log Service. That way you can get recent logs from the LogReader service from inside your shell or webconsole. If you insist on using popular frameworks like log4j etc. then you can get a bridge with Pax logging.
Alternatively, redirecting the output to a file in a known location works. You can then make a command in gogo that views that file or provide a tail function that continuously displays the new parts of the file.

Related

Get API response under the Network Tab of Browser using Karate [duplicate]

I am writing UI automation script using karate DSL. In this at certain point I need to get value from network call in chrome. I want to interact with one of the webservice call in chrome devtools network tab and get the json response of that webservice.
I need this because I have to extract the value from that particular call and pass it on to the next step in my automation script.
I have seen the question related to sessionStorage(Is there a way of getting a sessionStorage using Karate DSL?) but I wonder how to do the same for network call using script command or any other way?
The first thing I would recommend is don't forget that Karate is an API testing tool at its core. Maybe all you need to do is manually make that call and get the response. You should be able to scrape the HTML and get the host and parameters needed.
That said - there's a new feature (only for Chrome) which is documented here: https://github.com/intuit/karate/tree/develop/karate-core#intercepting-http-requests - and is available in 0.9.6.RC2
It may not directly solve for what you want, but in a Karate mock, you should be able to set a value for use later e.g. by using a Java singleton or writing to a temp-file.
If there is something oddly more specific you need, please contribute code to Karate. Finally, there is an experimental way in which you can actually make raw requests to the Chrome DevTools session: https://github.com/intuit/karate/tree/develop/examples/ui-test#devtools-protocol-tips - it is for advanced users, but maybe you are one :)

How to handle offline mode for Google visualisation in GWT

I have a GWT application that uses many Google maps and charts. I want to have an offline mode where the user have the application installed on his the computer and without using the Google apps, he can continue using the other features.
For now the maps in the application throught a nullpointer error because they cannot initialize. I thought about checking the internet connection in EntryPoint and change the behaviour accordingly, but I am hoping for a simpler solution. Any thought ?
per https://developers.google.com/chart/interactive/faq#offline
You cannot do that:
Can I use charts offline?
No; your computer must have live access to http://www.google.com/jsapi in order to use charts. This is because the visualization libraries that your page requires are loaded dynamically before you use them. The code for loading the appropriate library is part of the included jsapi script, and is called when you invoke the google.load() method. Our terms of service do not allow you to download the google.load or google.visualization code to use offline.
Can I download and host the chart code locally, or on an intranet?
Sorry; our terms of service do not allow you to download and save or host the google.load or google.visualization code
Update
I thinks the terms and conditions are changed now. As you can save and download JsAPI, ServiceBase to use charts offline.
But you still can't make ajax calls :Ajax
Hope it will be available soon, cheers!

Best practices place to put URL that configs my app?

We have a Qt app that when it starts tries to connect to a servlet to get config parameters that it needs to keep running.
The URL may change frequently because we have to test the application in several environments. Right now (as a temporary solution) the URL is a constant in source code, but it is a little bit ugly.
Where is the best place to mainting this URL, so that we do not need to change the source code every time I want to change the environment target?
In a database table maybe (my application uses a SQLite DB), in a settings file, or in some other way?
Thank you for you replies.
You have a number of options:
Hard coded (like you have already)
Run-time user input
Command line arguments
QSettings
Read from a bespoke file as text.
I would think option 3 would be the most simple to implement without being intrusive, but it does depend on what kind of application you have.
I would keep the list of url in a document, e.g. a XML, stored in a central, well known place, e.g. a known web server, and hardcode the url of the known place in the app.
The list could then be edited externally without recompiling your app;
The app would at startup download and parse the list, pointing to the right servlet based upon an environment specified as a command line parameter.

Development shell in ASP.NET

I write a lot of code, most of it I throw away eventually when I am done with it; recently I was thinking that if I just kept every small piece of utility script I wrote, named it, tagged it and filed it in a dev shell, I will never loose the code, and on top of that I won't need to redo something I have done already, which is the main motivation, as I keep finding myself writing something I've done earlier.
Is there a ASP.NET shell style environment anywhere?
If not, what would be the best way to go about this?
I am looking to be able to do the following:
Write big or small bits of code.
Derive from or chain together alread written code/libraries/services.
Ability to have everything on my desktop (would that mean IIS on the desktop? or is there an lighter weight mechanism?), sync'ed with the server at home, so if I am on the move I can still access this and make this part of my day-to-day workflow.
You could build a unique solution, with many class library projects inside. Each project would address a specific scenario, something like this:
MyStuff (Solution)
MyStuff.Common
MyStuff.Validation
MyStuff.Web
MyStuff.Encryption
etc.
Then you can put this solution on an online versioning service like bitbucket or assembla, so you can access your source code from anywhere, edit it and commit it back to the server. This way you get the advantages of versioning and you store your code on a remote server so even if your harddisk breaks it's not a problem, cause what's on the server is what matters.
You should either look into a source control system (Git perhaps?) or into a file storage / syncing / sharing service like DropBox.
DropBox would allow you to access code snippets from wherever you are and works really easily (just drop a file into a folder).
If you need versioning and branching you're going to have to look into a source control system. Since you have a server at home, that should be no problem.

Presenting different versions of an app dynamically

I maintain a web application that is painful to upgrade. It's not painful because the code is bad, but because there are a lot of devices connected to this application via the web and getting them to update their clients is a lot like moving concrete.
So I had an idea that I could simply present a different version of the application to different customers. The session stores the client information. So what I'd ultimately like to do is peak at that session and then use that to present the "correct" version of my app to them.
Physically the apps are stored in a manner like such:
C:\Program Files\Company\Program\Version\Web\WebApp
So you can see that I could have multiple versions installed at once. Basically if customer A goes to the site they get presented with C:\Program Files\Company\Program\1.0.0.0\Web\WebApp\foo.aspx And if customer B visits the site, they get to see C:\Program Files\Company\Program\2.0.0.0\Web\WebApp\foo.aspx.
I initially thought of using the IIS rewrite module, but I really don't want to redirect them. I want this to be seamless. Any ideas on how this can be implemented?
update:
After further research, I thought it would be clever to use the Global.asax.cs to accomplish my goal. So in the Application_BeginRequest event handler, I wrote the following:
string url = Request.Url.ToString();
if (url.Contains("MyTest"))
{
Context.RewritePath("/art/test.html");
}
By the way, /art/ is a virtual directory that I grafted into this directory via IIS. This would be similar to how I would set it up in production. Anyway, I get the following error when I try this.
The virtual path '/art/test.html' maps to another application, which is not allowed.
So how do I do this then? Is there an "allowed" strategy for accomplishing this? Doing it through the Global.asax.cs would be ideal since I could use the HTTP Context to "know" which customer is connecting to the app.
Okay, I have it mostly figured out. Here's how I did it. I basically created a parent app that would route to the various versions. In that app, I use the Context.RewritePath as I did above except I added a ~ in front of the url. Now I'm having issues with the viewstate, but I think I can get it figured out from here. (I hope). I'll update this answer later when I ultimately get a perfectly working solution.

Resources