I've been tasked with creating a server which will receive requests for information from an iOS device (iPhone) and then return results based on this request. I've done some research, and it seems that JSON is the way to go for this task. The thing is that I have no idea where to start; how my server should be put together, how it will handle requests etc. Can anyone point me in the right direction and perhaps suggest some reading?
If you are comfortable with Java, I would recommend getting the Eclipse JavaEE version, and then:
Create a new "Dynamic Web Project".
File/New/Other/Web/Dynamic Web Project
Then, in your new project, create a "New Servlet".
File/New/Other/Web/Servlet
This should create a skeleton server, with a doGet and/or doPost method.
You can debug the servlet right away with Eclipse; it helps you get everything set up (comes with Jetty built in, these days)
You can be set up with your first webserver in 20 minutes.
Grab the JSON jar from json.org. Drop it in WebContent/WEB-INF/lib inside your project.
In the doPost of your new servlet, call request.getParameter(...) with the name of your post param that has the json in it.
Pass that to the JSON parser.
To pass JSON back, get the JSON string from a JSONObject, and use response.getWriter().append(...)
Ta-da!
Pretty brief answer, but then again, it's a pretty open question.
If you want to build it in Java and want to use what all the cool cats are using, Dropwizard is the way to go. It's geek factor has increased after its last photo session for Vogue (either that or the newest edition of Thoughtworks technology radar). No, really - it's good and extremely easy to deploy and monitor.
If you just want to get it done and over with, a short PHP script is the way to go.
WARINING: If you don't know PHP, it's fine: you can still use it. If you don't know Java, stay away from it. Learning Java on the go is a big mistake.
You can get started fast using Spring Roo. It can automatically create controllers for your domain objects that return JSON data for Restful requests.
Related
As an application to get a job I need to make a web app. I'm only familiar with Java SE so here comes my concerns. I need to make web service where at the beginning there will be authentication window, then I need to show the JSON data (probably parse it and show) as table or as list with button near to choose one of the row from the table to get to the next page where there user can choose a materials and so on.
I have data in JSON on server I need to pull it from there, then I need to show data which looks like this /materialDetails?ID=x where x is ID (it's probably HTTP or URI). Should I use Java REST? If yes I need to create a site in XML and then put java data inside? There're only a few tutorials on the internet and I can't find any good(sometimes the problem is in server, sometimes with dependencies). I was looking for information also on youtube but except https://www.youtube.com/watch?v=X36Dud8cS4Y I cant find anything useful? Could someone explain me this to make it at least a lil bit easier? Or just lead me to pick a specific framework. Thanks in advance
You could create a Dynamic Web Project with Tomcat and a MySQL Database for starters. You could use RESTEasy to create a WebService that gets data from your Database.
I don't know what exactly is expected from you, but this might be a good start. "Making a web app" is a bit like saying "I need to develop a java program", it is a bit vague !
I don't know REST but I think your application can be implemented with this technologies: HTML and Servlets/JSPs.
I would write an authentication page in HTML (one form element with 2 inputs and a button) which would pass credentials to a Java Server Page or a Servlet (they're equivalent). There I would build the table (another HTML element) thus producing a new HTML page.
P.S.: you're using JSON as a format so there's no need to learn XML.
I've had plenty of issues with PHP and apache caching things whenever it feels like it and I seems like it's always next to impossible to get rid of it.
I currently have the following problem: I'm writing a PHP stub to call a local web service in Java as an RPC. After making changes on the Java Soap side, my simple PHP unit test still thinks the old functions are still there.
I know Java is not caching because when I check the WSDL file in a browser, everything is fine, but PHP is not even responding to changes and thinks the old ones are still there!
I'm fed up with PHP! How do I make PHP stop doing this? How is anyone suppose to activity develop anything when it caches every other second?
EDIT:
The php is a very simple RPC.
$client = new SoapClient("http://localhost:9999/ws/login?wsdl");
$functions = $client->__getFunctions();
var_dump ($functions);
The functions simple do not reflect what's in the WSDL file so it's obviously not even bothering to check.
Per Owen's answer, you can disable WSDL caching with this which you should probably run in unit tests. I suppose it's enabled by default somewhere in an ini file or something.
ini_set("soap.wsdl_cache_enabled", 0);
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
I am developing a new report engine for my company, our main web application is writing by PHP 5 and running on an Apache server. The new report server which I designed to use Apache FOP 1.0 ruing on Tomcat7,so far I created My own XSLT stylesheets and I can manage to generate a PDF report from the URL and let it display in my web browser.My goal on this project is to generate dynamic report from xml file which export from the PHP application.
Could anyone explain to me the logic behind How I can give those two talk to each others. I understand I could POST the XML and XSLT as string to the report server and POST it back the result I want(like PDF).
I know this will need Java involved,and as a PHP dev. I really don't have much background about Java,if you could show me some examples or links, it would be much appreciate.
I am using Saxon-B with Fop 1.0 on Tomcat 7 for the report server.
if you need more info from me,please also leave a comment. I will add it soon.
Thanks
There are two things your going to need to study.
http://www.w3schools.com/php/php_ajax_intro.asp This is a tutorial on using the XHR object from php. You should go through that. Also, if you aren't familiar with the XHR object, I would read this as well: http://www.w3schools.com/XML/xml_http.asp
You're going to have to create a servlet capable of responding to these requests. There are various tutorials on how to create a servlet.
Here is a link to a youtube video I fall back on when I forget how to do servlets: http://www.youtube.com/watch?v=EOkN5IPoJVs
In the video, he just uses straight up javascript; so you're php code is going to be doing what the javascript did in the video (item 1 on my list).
The video uses an older version of eclipse (I think ganymede), but it is pretty close to the same process in the newest version of eclipse.
Just to be blunt, this isn't something you're going to be able to figure out and make work properly. You've probably got at least a day to a weeks worth of learning here depending on your experience and aptitude; and this will only get you something basic. The servlet you make won't be secure, it won't have user authentication...my point is don't take anything for granted.
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.