Connecting from phonegap android to java server - java

We have a server written in java, and an application written in phonegap for the android with javascript.
How can we transfer and receive information from the application to the server?
We've tried using DWR to no avail, as the html file is on the android, so we can't call methods on the server.
Is there anyway around it so we can use DWR or another method to contact the server?
Thanks

We transfer and receive information by using AJAX calls and jQuery, and setting the server headers correctly (i.e., setting "Access-Control-Allow-Origin" to "*"). This allows any client to make cross-domain AJAX calls.

Related

how to run the applet on client side using jsp in server side

I am working client -server architecture, i need to install one fingerprint device in client side, then i need to run some application in client side using server side to get the fingerprint image from client to server which has taken from the client side.I am planning like, applets are client sides and jsp are at server sides.please help me out.
Your design looks fine to me, but what is the exact issue that you are facing.
From the Applet you need to call a servlet by using some API like Apache HttpClient.
http://hc.apache.org/httpclient-3.x/
You can then use the response of the Http call in your client (Applet).

How to develop a Proxy Server (TCP) for Android?

I am trying to develop a Proxy Server (TCP) in Android for YouTubeApp. I am going to use ProxyDroid (the phone is rooted), so that request/response goes through my Proxy Server. As its Android, I am using Java. But there are couple of challenges:
The request from the YouTubeApp has to be parsed. Is there is any existing library for parsing HTTP requests (in Java and can be used with Android)? Can anyone even suggest some snippets of code for this purpose? Or, do I have to do the parsing myself?
When requesting a remote site; e.g. www.google.com, do I have to use URL and openConnection()? Or, can sockets be used also? I am trying to find a way so that I can use sockets and get response from any site?
Hope to hear from u guys soon.

Can we read cookies using core-java that has been written using .NET MVC code?

Can we read cookies using core-java, that has been written using .NET MVC code? I have not find any help how to read cookies using core java code?
More Background Details -
Actually we have a java desktop application and we are planning to launch that java desktop application using JWS and that is working absolutely fine.
The issue is -- we ask some user related information from user on web page and launch java desktop application using JWS. Now we would like to have that information provided by user on web page in our java application.
We have write that information into cookies and how can we read that information from java code ?
Yes, you can receive cookies that have been set by another application (as long as the path value in the cookie matches). Cookies are part of the HTTP protocol and it does not matter how thay were defined. The client sends them in future requests depending on the URL path.
To access cookies in Java, have a look at getCookies() in HttpServletRequest.
update
The cookies set by your web-application that launches the Java client will have been set in the context of the browser client. Cookies are added to a HTTP response and cached by the client receiving them.
In the case that you describe you cannot access the same server-session from the Java client without trickery.
The solution I would use is to generate a unique ID in the web-app that is passed as argument to the Java client which can in turn request the values needed from the other session using a fetch of a URL using the generated ID as parameter. (This in essence connects the two HTTP sessions as being part of the same user process.)
For instance you could use a HttpURLConnection and a URL like <web-app>/data?id=<ID> to fetch/download the values as XML from your web application.
Core-java? Then try java.net.*:
A cookie is just a header line with "Set-Cookie: " before the URL content.
http://www.hccp.org/java-net-cookie-how-to.html

Accessing HTML DOM elements from Java

I'm developing (with Java) a P2P application. One of the features includes a chat service. When a user sends a message to all of the application users, each user gets the message and updates its chat HTML page.
How can I access, from my Java code, the DOM of this page and change it, without the need to refresh the page in order to see the new message?
Is there any object in Java that can get me this access? For example, can I call a JavaScript function that inserts the new message?
If by from Java you mean applet then:
You can define some javascript functions in your HTML page to return/modify what you want and then call the javascripts from the applet. Look at here.
If by Java you mean Web server then you have to use some AJAX solution, you can look for example at JQuery
What you're really looking for is a technology known as Comet. Comet is Reverse Ajax. It's a technique that uses long-lived HTTP connections to hold a connection open from a client browser to a server so that the server can push updates back to the client browser.
The basic flow is that the server pushes a command back to the browser in the response, and JavaScript parses the response via a callback function, and then the JavaScript updates the DOM, all without reloading the page.
You can learn more about Comet on the CometD Website, and if you're developing on Google App Engine, this blog post on the ChannelAPI will be helpful.

How to facilitate communication between php script on a server to a running Java application on another server?

How to establish a way for Java application to listen to data being sent by php ? Sockets or Http POST ?
Essentially, I have Java application running on another server waiting for certain string data sent by PHP script running on other server.
Any library suggestions or example codes will be appreciated.
I suggest implementing a REST api. If you can't or don't want to, using sockets is the most secure way...
If you are sending FROM php, I recommend using a RESTful API with authentication. Send JSON data, get JSON data back. It allows for better future expansion too.
Your best bet is probably going to be to set up a java servlet "container" (server), such as tomcat (you can pay a lot of money for something else, if you have to for corporate reasons).
http://tomcat.apache.org/
http://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/ServletRequest.html#getReader()
or
http://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/ServletRequest.html#getInputStream()
Be aware there is a bit of work up front, just to set up and host "hello.jsp", but adding the mapping for the "myservice" servlet in web.xml is not too bad.

Categories