From actionscript to google's datastore through java - java

I'm working on a flash game written in pure actionscript 3.0 in Flex.
I've just finished implementing replays for the game, but want to store the top 10 hiscores' replay data on my google-app-engine'd website.
I'm using Java for the app-engine stuff in Eclipse in java but I have no idea how to deal with communicating to my java code from my actionscript code.
I'll need to both read and write from actionscript -> java -> datastore. Does anyone have any experience with this?
For note, I'm horribly noob with anything to do with web development. I hear you can pass arguments to a URL when calling it, comparable to command-line arguments on a desktop executable and if so then sending all the data as a large string would be doable...
The question then would be how to call a url from AS3 code with additional data and then how to catch that on the java side.
Thanks to anyone who can help.
Jono

you can stuff the serialized replay into URLRequest::data and send it per POST.
You can also pass it as variables, creating a new URLVariables object, store that data with in it and pass it to URLRequest::data and send it either per POST or GET (the latter of which implies appending the parameters to the URL (whereas the former allows sending them in the request body)).
please note however, that there is no guarantee that GET parameters are properly supported if they exceed 2KB. also, requests using GET method should not have side effects. please see http request methods for further information.

Related

How can i use Java to call an existing RPG screen program?

I have existing RPG4 programs with green screens, i would like to be able to call the rpg programs with Java and bypass the green screens.
I have done some research on this and IBM OAR (Open Access: RPG) keeps coming up. but i have not found a working example yet.
My goal is to create a web app to collect the the same information and feed it to the back end RPG
any help would be greatly appreciated
EDIT
Delete: You can't.
Insert: A beginner will need to master several complex new concepts before tackling this.
END-EDIT
At least, not without changing the RPG program. Web requests are processed by server jobs, which run in batch - they are not connected to a 5250 terminal. Because they aren't connected to a terminal, when the RPG program tries to open the display file, it will fall over because there's no terminal to attach to.
In order for this to work you'd have to alter the RPG program to not try display file I/O if called by a batch process like a Java app (although Java isn't necessary in this web scenario).
One way to change the RPG program is to use input parameters; if you have them, then don't try to open the display file, but stuff the input parameters into the fields where the display file would have done. Since a display file also outputs from the program you'd need to reserve some parameters for the output information as well. This could get very ugly if a subfile is involved, as there would be potentially thousands of parameters.
OAR comes into the picture because one can write an OAR handler that continues to use the same display file I/O operations, but to direct the actual I/O elsewhere, like STDIN and STDOUT for an HTTP type application. Jon Paris and Susan Gantner have written an article called Getting a Handle on RPG's Open Access which you might find helpful. It's in the July 2010 e-edition of IBM Systems Magazine.
Better perhaps is to extract the business logic in the RPG program, implement it as stored procedures which can be called by the web application via traditional ODBC / JDBC. One can write stored procedures in RPG, so that's not as hard as it might seem.
OAR is probably going to be your best bet....
However, every example I can think of that I've seen has resolved around building a handler to replace a printer file (PRTF) or physical file (PF).
Replacing a display file (DSPF) is a whole other ball game. Primarily because the 5250 protocol is an "intelligent" protocol; unlike dumb character type protocols such as used by ANSI/VT100.
It certainly can and had been done. If you have a single basic screen, you might be able to do it. But for a complex application with multiple screens and subfiles you'll probably have a tough time. Especially if you don't have a in depth understanding of the 5250 protocol.
I'd recommend you take a look at one of the vendor toolset designed to use OAR to replace a 5250 screen with a web page. Those vendors have put years of time and effort into developing the handler needed.
http://www.profoundlogic.com/solutions/rpg-application-modernization.html
https://asna.com/us/products/wings
You might find the following publication useful:
Modernizing IBM i Applications
Lastly note that ROA isn't the only option. There's an older technique, "screen scraping" in which your application basically emulates a 5250 terminal. It's simpler than a full ROA handler, but the end result is simpler also. IBM has it's own tool, HATS. And for instance Profound logic also has a tool, GENIE. But you could conceivably build your own screen scraper, the opensource TN5250J would probably be a place to start. But even this would be non-trivial.
You should use a mix of parsin json on the iseries(this eliminates the subfile problems), one good javascript framework( I've used Extjs) and The Apache server for I.
I've developed a HTTP services framework based on json parameters send directly from the browser using Ajax, processing each request with any ILE language program(mostly rpgle) and returning the result in pure json created inside the program. With this approach, you just send/receive business data, leaving the front-end to the Javascript framework.
Hope this helps. Contact me if you need more help.

Remotely calling Java from php

I have a java program that runs on a couple different computers and I want to be able to be able to access them remotely. I don't need to do anything crazy, just some very basic input output (get and set type stuff). I could write a client type application and set each program to a server with RMI and do it that way but I will not always be on the same computer and do not want to have to carry the .java file around with me.
I'd prefer to write a simple php webpage that I can access from anywhere and have some very basic buttons that could send the commands to the different Applications and receive back some output.
Problems is that it would probably impossible to get my host to load anything other then php onto the server where I'd host my webpage.
Does anyone have any ideas? I've tried googling it and found a couple things out there that sort of sound like what I need but the more I look into them they seem to not be what I wanted after all.
If you really want to do this right I'd suggest looking at a Java web framework (I use Play! myself) to create a RESTful web service and then sending requests from your PHP code that will fetch JSON data.
A framework like Play will make it very easy to get a REST web service running. Just create some wrappers that invoke your existing java code and call renderJSON to output the result.
From the PHP code you'll issue the request using curl and then read the response using json_decode which will turn it into a handy php variable.
This also has the advantage that either end can be changed without the other noticing, as long as the json data format is kept the same.
Based on the way you described your setup you'll probably run into routing issues trying to reach your Java apps from your PHP host. I'd recommend you try something else: have your Java apps frequently check with your PHP app if there are any updates. You can simply use a Java URL connection and a timer:
http://download.oracle.com/javase/6/docs/api/java/util/Timer.html
http://download.oracle.com/javase/6/docs/api/java/net/URL.html

How to use Teambox REST API for uploading files

Below I am pasting content from Teambox api documentation:
https://teambox.com/api/upload
uploads#create POST
/api/1/projects/:project_id/uploads
/api/1/uploads
Creates a new upload. Note that you will need to post an upload using form encoding for this to work.
Parameters you should pass
{
"page_id": 456,
"project_id": 123,
"name": "Name",
"asset": "<File Data>"
}
Questions:
What do we mean by upload using form encoding?
What does asset: <File Data> represent?
Any code example would be great too. Thanks
Seems that you have to post data to teambox in your call.
POST is one of the methods commonly used by web forms, when passing data to a server.
This "official" link tells what is what
First described manners describe a call thought as a GET request.
Latest form you get takes the shape of a POST call.
You can build a POST call in many ways, depending on the native language your client app uses.
If is a javascript based web app, you can use XHTTPRequest object which resides on browsers.
If your app runs in a Linux based system, maybe you can use libraries that allow you build-up that call, such cURL library.
So, can you show the code or get deeper in your description?
Would be nice to know your environment and programming language.

Calling JavaScript methods from Java

I have a webpage that has JavaScript in it. The script contains a method that updates the webpage. I also have a java UDP server. When I get some parameters from a client, I want to call the method in the javascript to update the page.
Is it possible to call methods in Javascript from Java source code? Any pointers?
Thanks!
EDIT: For Ajax, the "request" initiates from the webpage. I want something that can change the webpage by itself - without this request.
A more succinct question would be: Can I dynamically update a webpage from java source file?
In order to reading javascript result you need a browser runtime AFAIK (You cannot get javascript result through a raw socket). You have to include a browser (JTextPane should be able to do it) into your udp server.
DWR is the answer, but it seems dead with no progress for some months. I don't think so you can directly call JavaScript methods from Java without passing an Asynchronous call using Ajax.
I have no idea on how you would dynamically change your content of webpage without an request being passed.
This is what we wanted to do:
-Send co-ordinates from an android phone to a server
-Plot these on a map in a browser window
The complexity was - One 'box' was server for android, and client for google maps. And we needed some glue between these two functionalities.
We initially tried ActiveMQ but could not get it to work.
Due to time constraints, we were forced to explore other approaches... our end result isn't elegant, but it works.
We have a FIFO on the server to which the co-ordinates are written. On the same server, our map page is also hosted. On a button press, XMLHttpRequest is sent to the server. In response, a co-ordinate is dequeued and sent back, which is plotted on the map using google maps api.
I will be happy to share more details/answer questions...

Sending HTML Form Data to Java

I have a Java program that I'm trying to interact with over the web.
I need to gather form data from the user on a Drupal site that I don't have any control over, send it to the Java program, and send the output back to the user. The Java program needs to load a lot of libraries every time it's run, so it needs to be up waiting for data from the user.
It'd be best for me to just have an HTML form for the input. What's the simplest way to deal with HTML form data using Java?
Also, I'm trying to call the Java program from a shell script. I want the program running in the background though so the libraries are loaded in advance. So ideally, I could use the server I set up for both applications.
Thanks for any help.
It sounds like you really just want to write a servlet (or use a higher level web framework, but a servlet would work fine). That makes it very easy to get web form data - you just ask for values by name, basically.
You could then "script" the application using curl, wget or something similar to make requests to the servlet.
Apologies if this doesn't answer your question - I'm finding it slightly tricky to understand exactly what you're trying to do, particularly as there are multiple layers of web UI involved, as far as I can see.
The easiest way to make POST requests with java is to use the Apache HttpClient or the more recent HttpComponents libraries.

Categories

Resources