Load external page HTML via javascript or flash or java - java

I need to load somehow the html code of a webpage A into a javascript string of another webpage B, on a different host. I know this is impossible to do with javascript alone because of the same origin policy, and I know I could do it loading the page via php on my server and then send results back to the user's client but I wouldn't be able to handle so many requests, so I need it to be done directly by the user's browser. I can use nearly whatever browser scripting language/applet framework common enough to be installed on the majority of my users' computers, like flash and java.
On example, what if I use flash or java to load the external html code and then call a javascript callback function providing the source? Could this work?
Do you have ANY idea? I gratefully accept any suggestion, and I REALLY appreciate examples!
Thank you very much!
Matteo

It would require a digitally signed and trusted applet in order to reach cross-domain, short of the user running a plug-in 2 architecture JRE and the site implementing a Cross-Domain XML.
Ordinarily, unsigned Java applets or applications may only connect
back to the web server from which they originated. This restriction
prevents an applet from causing denial-of-service attacks by making
rapid connections to arbitrary machines on the Internet.
In Java SE 6 update 10, both the Java Web Start and Java Plug-In
technologies contain preliminary support for cross-domain policy
files, which specify how unsigned code may access web services on the
Internet. The crossdomain.xml policy file is hosted on a given server
and allows either selected clients, or clients from anywhere, to
connect to that server. Cross-domain policy files make accessing web
services much easier, particularly from unsigned applets.

"via php on my server and then send results back to the user's client but I wouldn't be able to handle so many requests"
So many requests? That is not so many reqs; just making php script to read couple page and creating new page depending the data. If that is too much for your server ..hard to believe.. you sure can do that kind of thing with flash (clients computer) to load those two pages, and parse the datas to one html page and display it (via js) to clients browser. Kind of weird question after all.. perhaps i did not understand it :)

Related

Confusion upon the difference between Java Client and Java Server

From my understanding the Java Client is what is rendered onto the browser such as the javascript, "the client side" for example what the user see's (tables, html, the sorting etc) things in the jsp. The server side is the servlet that makes the connection and call the specific class's based upon the request. I feel as though I am completely wrong as when I do research I am getting different answers. CAn I get some clarification on this please.
Java running on the client side means the end user needs Java installed and is running a Java program on their computer. This could be a standalone Java executable program (a traditional application), or it could be through a browser running a Java applet. Either way the end user's computer is actually running the Java code locally.
Java on the server side means that all the Java processing happens on a server somewhere, and the person accessing the site or service doesn't need Java installed. Servlets and JSPs fall into this category. The server does all the processing and then returns HTML/Javascript/CSS, etc to the end user. The user's web browser receives and processes those files to display the web site.
It sounds like you are getting confused because web browsers use Javascript to display dynamic sites, but Javascript is a totally separate language that has nothing to do with Java. In other words, a web site could be powered by Java servlets on the back end and could also use Javascript on the front-end, but they aren't directly related or dependent on each other. All the HTML, Javascript, CSS, etc that make up the web site are processed by the user's browser and the user doesn't have to know or care how all that stuff is generated on the back end.

Server s-de or client side detection on how many browsers are installed on customer machine

Is there any way to detect which browsers are installed on customer's machine after customers clicks on a URL. Usecase is below :
We are hosting a redirect server and URL for this redirect server would be provided to customers. On click of this URL , as customer lands on the redirect server servlet, we will fetch his user agent and detect from which browser he is coming. But if the browser he is using is an unsupported version for our application , I want to detect if he has any other supported browser versions installed on his machine and open that URL in that browser.
I am aware that this is something we can not do server side but is this something we can do on client side may be by using JS or something ?
Let me know. Thanks!
This is not going to be possible in the general case; JavaScript APIs are sandboxed to prevent malicious scripts from stealing confidential information from clients. You could theoretically make this work with some sort of client-side plugin, such as a Java applet, but such an approach would be very platform-dependent and almost certainly not worth the trouble.
You can only detect the browser being used, not the browsers installed. Detecting the browsers installed would require the ability to snoop on the user's machine and look through their files. What browser do you think is going to implement such functionality to allow you to do that? None, unless they want to get sued into oblivion.

Communicating with Java from PHP

I have a website that is a companion app for a java application. Namely, the web app fetches information from the java app and inputs it into my database and lets the user access this information. Right now I have the system set up so the Java app posts to the website's php files when I tell the Java app to.
However, I am wanting to set the system up so that the java app posts to the website when a command is issued from the website, such as a refresh command. Is this possible?
This is extremely vague. You should not think of the problem in terms of "posting from PHP to Java", in fact every HTTP request is simply that - an HTTP request. PHP and Java both offer several ways to respond to HTTP requests. It's up to you to compose the scripts that will respond to each request. Think of this in terms of the requests you need to make and the responses they should receive, then focus on writing a script for each of those interactions.
You can call Java directly from PHP. Zend Server and PHP/Java bridge both enable this. Depending on your requirements one of those may be appropriate.
Alternatively you can make use of message oriented middleware. This requires you to install and run a message broker such as RabbitMQ or ActiveMQ. However client libraries are available for much more than just PHP and Java.
Both of these would be better alternatives than relying on HTTP requests.

Accessing Server Files using Java Applet on Same Server

As a kind of personal project, I'm trying to develop a Java Applet that will stream from a collection of music that I will host on the same machine as the applet. I know when you request files in an applet, it looks for them in the files of the computer which is accessing the applet. I, however, want to access files that are hosted on the same server as the applet.
My intention is to, when the client wants to stream a specific song, the server will begin loading the data and streaming the data to the client. I think this would be possible using the URL class in Java, but would that not be going out to the internet only to come back to the very same server to get its files? Or will it recognize that the files are local and access them without going out to the web?
Summary: What is the best way for an applet to access files that are hosted on the same server as itself?
An applet runs on the client machine. In order to access files the server you're going to have implement functionality on the server-side to expose those files to your client. There are various ways to do this in Java - the most common would be:
1) a custom servlet or
2) a web service
Here are some links to articles which could be helpful:
Can a web service return a stream?
FileServlet serving from absolute path
As an aside I think your question is quite broad. You're probably going to have to investigate one or both of the methods above, try to implement one of them and then come back to SO with more specific questions.

Make PHP execute and communicate with a Java application on a web server

I have a java application that will take the image as an input and output another image. I have a website with a popular host (PHP+MYSQL Hosting). I want to create a page on the website with PHP with a form where a user can upload an image which will then pass the image onto the Java application.
What I am planning on doing is when then user uploads the image, it gets stored in a folder on the web server. I will then call the java app on the server passing the url of the image as an argument and then the java app will output another image, let’s say, to a result folder. The PHP page after the execution will then display the result image on the browser.
Now my questions are:
Is it possible to execute java apps on popular webhosts (for example mine is WebHostingBuzz.com)?
The java app is fairly heavy as it does a lot of image processing. Should I offload the java app to another web server? If yes, are there any services that will run my java app?
(Optional) It’s a demo of my java app and I don’t want to store the images people upload. Is there a way where I can directly pass the uploaded image to the java app and output the image generated directly instead of storing it on the web server? I would prefer this because, if the image is big, I can make PHP stop the execution after a timeout.
How do I communicate with the java app from PHP for info on its execution, for example When PHP calls the java app, the page has to wait till the app finishes processing? I want the java app to send a response to the PHP page saying that the processing is completed and the page is redirected or refreshed accordingly.
I hope you get the idea, please suggest the technologies that I can use to implement this and also if you have a better idea, post it!
Thanks!
Now my questions are: Is it possible to execute java apps on popular webhosts (for example mine is WebHostingBuzz.com)?
It's technically possible. But the hosting has to install JRE at the host and give the PHP user sufficient OS-level and filesystem-level permissions. So you're really dependent on the hosting whether they provide this opportunity. Best is to just contact their support team and ask it.
If it is supported, you could just use shell_exec().
$result = shell_exec("java -jar /path/to/imageprocessor.jar " + $imagepath);
if ($result) {
// Shell execution succeed.
} else {
// Shell execution failed.
}
For asynchronous communication / background processing, the client has to fire an ajaxical request.
If it is not supported, consider porting Java to PHP. The GD image library has pretty a lot of functions which may be of use.
Google App Engine allows to host Java (and Python) web applications. The SDK and the basic account is free of charges. With the SDK, you could develop and test the application locally and then simply deploy to App Engine (NetBeans and Eclipse plugins are available).
Then the PHP app could send the data in a HTTP POST to the Google App Engine application and get the result in the response data.
Or the data is stored first in a database blob and a processing job is put in a task queue (a 'message queue'). This has the advantage that the PHP client request will return immediately after the data has been POSTed. Then, the PHP application could poll for the result data while Google App Engine processes the image. The PHP side would be more responsive this way.
Wouldn't it be easier to make your java app a web app, that PHP could call via an url in wich he would put the url of the image so java can download it?
like http://yourjavaserver/imageprocessing?imgurl=IMAGE_URL
and the java servlet would reply with the image file itlsef.
You can look for "java hosting" on google, to find a host for this, but it's more expensive than PHP hosting. Maybe the best choice would be to get a dedicated server which could host both PHP and java applications...
I think your best bet here is with your java app running as cron(or a deamon) that can load the file details from the database. This will require a (one or more) page-refresh on the users part after the generation is complete, at which point your script can recall the image from the database/filesystem.
I do not think you will be able to do this in real-time due to timeout restrictions on the PHP webpage. However, you could write a java applet that can take the file and process it before sending it to the server (or depending on how you intend to use it, perhaps you do not need to upload it after the transformation?).

Categories