Wicket: Get Browser Information - java

How do I get information about the browser in a Java/Wicket/Maven Project?
Greetings

You can capture the browser information using the following code
getApplication().getRequestCycleSettings().setGatherExtendedBrowserInfo(true);
WebClientInfo w = (WebClientInfo)getWebRequestCycle().getClientInfo();
ClientProperties cp = w.getProperties();
// do something with the data
cp.getNavigatorAppName();
cp.getNavigatorAppCodeName();
cp.getNavigatorAppVersion();
cp.getBrowserVersionMajor();
cp.getBrowserVersionMinor();
Exerpt taken from WICKET Documentation
EDIT
Updated from comments.
The above code is for Wicket 1.4.x. For newer versions of Wicket replace getWebRequestCycle() with getRequestCycle()

If there is no getClientInfo() on getRequestCycle() (like there wasn't for me either), you could try the answer to this question:
Checking User Agent in Wicket
WebSession.get().getClientInfo();
It worked for me.

Wicket 6.x also provides org.apache.wicket.ajax.AjaxClientInfoBehavior. A demo of it can be seen at: http://www.wicket-library.com/wicket-examples-6.0.x/ajaxhellobrowser/

Related

Elasticsearch Java API from 2.x to 5.x issues

I've updated to elasticsearch java library version 5.2.0.
In 2.x,
I was using SearchRequestBuilder.addField() in order to add a field to the search request. Nevertheless, It seems to be replaced. I've written the available methods intellisense is showing me. Which of them do I need to pick?
addDocValueField
addFieldDataField
addScriptField
addStoredField
storedFields
fields
SearchRequestBuilder.setNoFields is also removed. Which would be the alternative?
Currently, I'm calling scripts from Java using this code. Is there any more elegant way to call it in 5.x Java API?
Code:
return AggregationBuilders
.terms(this.getName())
.field(this.getName())
.script(new Script(
ScriptType.FILE,
"painless",
"year",
ImmutableMap.of("field", this.getName())
)
);
As you can see I setting field as script parameter. Nevertheless, I don't quite understand how to get it from script code.
Thanks.
When in doubt, go to the source
use setFetchSource(String[] includes, String[] excludes) instead
use setFetchSource(false) instead
if you need to execute this script for each document, you can use addScriptField()

Restlet- Beginner Stuff for Client Side - Path, Accept Header, QueryParam

Before I started with Restlet I already wrote a Jersey client. It was very intutiv - it seems like Restlet isnt. There is not much documentation and I can't solve the easiest problems.
Where I am:
service = new ClientResource("http://localhost:8080/com-project-core/rest");
service.setChallengeResponse(ChallengeScheme.HTTP_BASIC, "admin", "geheima");
What I get from documentation:
String myString = service.get(String.class);
or wrapping up a Resource:
ConnectedResourceIF connectedResource = service.wrap(ConnectedResourceIF.class);
Thats working. But what about:
A. When I want to change my service path? In Jersey it was intuitiv like
service.path("foo").path("bar")
for
http://localhost:8080/com-project-core/rest/foo/bar
B. I want to set a acceptHeader. In jersey it was like
service.accept(MediaType.TEXT_PLAIN)
C. I want to set query parameters. In jersey:
service.queryParam("1","foo").queryParam("2","bar")
Sorry, hope someone can solve this beginner problems. I cant find somethign in the restlet documentation.
For A:
service.getChild("/foo/bar", ConnectedResourceIF.class);
For B (need a recent 2.1 RCx version):
service.accept(MediaType.TEXT_PLAIN);
For C (need a recent 2.1 RCx version):
service.setQueryValue("1","foo");
service.setQueryValue("2","bar");
The best place to look for such things is the Javadocs, because those API changes are pretty recent:
http://www.restlet.org/documentation/snapshot/jee/api/org/restlet/resource/ClientResource.html
We are working on a new in-depth tutorial for next 2.2 version. First finishing "Restlet in Action" book :)

ORM tools/framework regarding mongodb for Java

is there any ORM tool/framework for mongoDB with java and also support maven, so that it will be helpful to apply constraints, use of cursers in database operations?
There are some. Start reading:
http://www.mongodb.org/display/DOCS/Java+Language+Center
As for maven support, just look up libraries in mvnrepository.com ( most of them will be there )
This is what you need:
http://www.infoq.com/articles/mongodb-java-orm-bcd
It is maven-based.
See this presenation on slide share http://www.slideshare.net/mongodb/java-persistence-frameworks-for-mongodb
To work with Mongo Db at grass root level I found http://howtodoinjava.com/2014/05/29/mongodb-selectqueryfind-documents-examples/ link very helpful
You can use morphia.
It is a wrapper over mongo-java-driver and works well in the production environment. It is well documented and supports raw queries as well.
Also, well SO community support
try MongoDBExecutor. It will definitely increase the productivity of development. Here is simple sample about CRUD:
#Test
public void test_crud_by_id() {
Account account = createAccount();
account.setId(ObjectId.get().toString());
// create
collExecutor.insert(account);
// read
Account dbAccount = collExecutor.get(Account.class, account.getId());
// update
dbAccount.setFirstName("newFirstName");
collExecutor.update(dbAccount.getId(), N.asMap(FIRST_NAME, dbAccount.getFirstName()));
// delete
collExecutor.delete(dbAccount.getId());
// check
assertFalse(collExecutor.exists(dbAccount.getId()));
}
Declaration: I'm the developer of AbacusUtil

What is the difference between GraphDatabaseService or NeoService in neo4j

I'm learning to use neo4j, but am a bit confused on its usage. When I'm adding nodes and relationships, I can do it like this:
GraphDatabaseService graphDb = new EmbeddedGraphDatabase("C:/temp/graphdb");
Transaction tx = graphDb.beginTx();
try {
org.neo4j.graphdb.Node node = graphDb.createNode();
...
I could also do it like this:
NeoService neoService = new EmbeddedNeo("C:/temp/graphdb");
Transaction tx = neoService.beginTx();
try {
org.neo4j.api.core.Node node = neoService.createNode();
...
What is the difference here really? Which one should I use? Why are they 2 different mechanisms? Is this just API evolution here? :) I want to use the MetaModel API and it needs a NeoService, so the choice there is clear I guess.
Sorry,
you should use the first one, since in the latest 1.0-RC1 the namespace was moved. This is just naming, the semantics are the same. The second example is outdated and should be removed form the official documentation. Where did you find that?
Cheers,
/peter neubauer
You're spot on with the API evolution comment. The old API is NeoService, so you shouldn't use that. Go with your first snippet. For more information on the API change see e.g. the release mail for the latest rc:
http://www.mail-archive.com/user#lists.neo4j.org/msg02378.html
If you use the latest snapshot (0.7-SNAPSHOT) of the meta-model component, you'll find that it uses the latest API. For our 1.0 release (should be out Real Soon Now :), we're going to make non-SNAPSHOT releases of all components that will use the new API.
-EE
And regarding the meta model, please use the meta-model component (now with the maven artifactId: neo4j-meta-model).
I also notice that the component overview http://components.neo4j.org/neo4j-meta-model/ has some invalid example code and descriptions. I'll try to fix that.

Starting OpenOffice from applet

I have this code down and this working fine from command line ...
But when I put this in applet I get following error
com.sun.star.lang.IllegalArgumentException
at com.sun.star.comp.bridgefactory.BridgeFactory.createBridge(BridgeFactory.java:158)
at
com.sun.star.comp.urlresolver.UrlResolver$_UrlResolver.resolve(UrlResolver.java:130)
Anybody have solution for this problem ? Where I can find BridgeFactory source ?
Runtime.getRuntime().exec("C:/Program Files/OpenOffice.org 3/program/soffice.exe -accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager"); // oooUrlW - the url of soffice.exe
Thread.sleep(5000);
XComponentContext xLocalContext = com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null);
XMultiComponentFactory xLocalServiceManager = xLocalContext.getServiceManager();
Object urlResolver = xLocalServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver",xLocalContext);
XUnoUrlResolver xUnoUrlResolver = (XUnoUrlResolver) UnoRuntime.queryInterface(XUnoUrlResolver.class,urlResolver);
Object initialObject = xUnoUrlResolver.resolve("uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");
XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,initialObject);
XComponentContext remoteContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, xPropertySet.getPropertyValue("DefaultContext"));
XMultiComponentFactory remoteServiceManager = remoteContext.getServiceManager();
Object desktop = remoteServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", remoteContext);
xDesktop =(XDesktop) UnoRuntime.queryInterface( XDesktop.class, desktop);
XComponent xCalcComponent =
newDocComponent(xDesktop, "scalc");
XSpreadsheetDocument xCalcDocument =
(XSpreadsheetDocument)UnoRuntime.queryInterface(
XSpreadsheetDocument.class, xCalcComponent);
XSpreadsheets a=xCalcDocument.getSheets();
Object o = a.getByName("Sheet1");
XSpreadsheet sheet = (XSpreadsheet)UnoRuntime.queryInterface(
XSpreadsheet.class, o);
XCell jjjj = sheet.getCellByPosition(0, 0);
jjjj.setFormula("Some Text ");
Is your applet signed ? else I don't think you can call
Runtime.getRuntime().exec("C:/Program Files/OpenOffice.org 3/program/soffice.exe-accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");
from an applet.
I agree with Pierre... you would need a trusted/signed applet to do that. You might also want to reconsider why you are trying to do this with an applet rather than a standalone application (using webstart or something if you need to web-deliverable).
One more thing to consider is that the end-user would have to have OpenOffice installed locally (unless they have changed the way their API works) for any Java-OO.o access to work correctly. This requirement may have changed though, it has been a while since I have played around with their API.
Good luck and I hope this helps a little.
It is signed, and I found kind of solution - on client I grant
permission java.security.AllPermission; and now everything work...
I still did'nt try grant SignedBy "MyCompany" permission java.securyty.AllPermission
which I must do...
Error message is misleading me
com.sun.star.lang.IllegalArgumentException ... stupid message
I must use applet ... it is Oracle Forms application and I need to start Calc on client and fill some data.
Thanks on help.
There is a very simple way to place OOo in an applet - use the OfficeBean
While you'll still have your java security problem, your code will be a lot tighter. We're using this to do the same thing. My post on how to get OO 3.2 working in Java 6 applets is here is you want to take a look. It works for 3.1 and 3.2.

Categories