I have a project in Flex (client) and Java red5 that I would like to move to jquery for the client. I would like to reuse some parts of the Java server-side code, and use Java's jQuery support.
Are there other solutions that I could use for the communication with the server?
Yes, I've read that http://www.playframework.org is an excellent framework for building Java-based RESTful web services. This way, you can easily integrate jQuery and JSON requests with your Java web service.
This site, http://coffeebean.loicdescotte.com/2011/01/how-to-export-objects-to-json-with-play.html, has a great example of how to export content as JSON.
As for the jQuery itself, check the doc's or start with something like this:
$.ajax({
url: "your-web-service.php",
context: document.body,
dataType: "json",
success: function(data){
// do something with data
$(this).addClass("done");
}
});
JSON is probably your best bet, very simple and well supported in both Java and JQuery.
JSON keeps things simple but you could also use XML as your data interchange format. jQuery plays well with both JSON and XML. If you were hoping to do something like SOAP I suppose it could be done but I'm pretty sure jQuery doesn't exactly do SOAP out of the box.
As far as moving to PHP goes, in your situation I wouldn't bother. If your app server is running securely, solidly, and fast enough then why even consider a change?
Related
I'm currently building a project using angular 2 for front end.
Our backend is in core java (Servlet) and its not RESTful.
So, It it possible to use angular 2 with non-restapi backend?
Why wouldn't it?
Does your backend send HTML? JSON? XML? Text? Static files like JS, CSS, etc..
Chances are it does, at least one of them, so Angular can manipulate the response body anyway it wants - or any way you program it to.
It is the HTTP request/response paradigm that is important. Angular supports it, so it will handle non-RESTful backends (i.e response bodies).
Chances are you would need to probably modify your backend to send the proper data - either HTML snippets (JSP snippets gets translated to HTML in the end) or if you want JSON/XML strings,objects, whatever.
It is not impossible to do.
this is my first post on stackoverflow.
I am quite good at Java SE and client side Java Programming, but new to Java web development.
When I search for Java webframeworks, a huge amount of framework are offered, but nothing really seems to fit my needs.
What I actually want is a dumb server and a smart client.
I want the client to ask for certain information and the server to return the requested information in a xml or json format, so that the client itself manages the data.
In most cases the webframeworks render the html pages etc. on the server side, but I just want for example to use AJAX or the android xml parser to get the information and then fill the UI on the clientside.
I am not sure, if Webservices are the right thing for me, because I want to make several async requests to the server.
Or should I simply use servlets, which just return the right xml on request.
A second thing is how to handle the authorization and authentication of the users, which send the request to the webserver.
I do not want to allow everyone to receive the xml or json, which is generated by the server.
In short:
Is there a java based webframework, which can handle authorization and authentication of users and just returns xml or json to a smart client?
Which java based webframework fits best to my needs?
On the following webpage my aim is described, but unfortunately there is no hint how to implement such a "dumb" server...
http://seng130.wordpress.com/lectures-2/web-application-architecture/
You will likely need to use multiple frameworks. Spring-Security to handle your url intercept based on authority. Then use Servlet with Spring-MVC to handle the request within the Controller methods. Tutorial here: http://static.springsource.org/spring-security/site/tutorial.html You can have those methods return string values of JSON or XML. I would suggest using Jackson to convert your objects to a JSON form on the fly and the javax libraries for XML.
Example of Spring-MVC with Jackson:
http://www.mkyong.com/spring-mvc/spring-3-mvc-and-json-example/
Example with Jersey servlet and Jackson
http://www.mkyong.com/webservices/jax-rs/json-example-with-jersey-jackson/
We have several classic asp web application that instantiates a visual basic 6 component, passes a (possibly huge) xml string, and gets back a (also possibly huge) xml string.
This component is the only way we have to interact with the database.
We are planning to rewrite this component using java. The idea is to left the rest of the asp application untouched.
So we need to execute some java component passing and receiving a string, from classic asp running on an iis...
We are looking for something with the less overhead possible (obviously, I'm trying to avoid having a web service call for each db operation)
which would be the best approach to achieve such a thing?
thanks a lot
this is the code we need to migrate:
Private Function ComandoExecute( Xml )
Dim Comando
Set Comando = Server.CreateObject("TramitesConsultaComando.clsComando")
ComandoExecute = Comando.execute(Xml)
Set Comando = Nothing
End Function
The component is a dll that runs thru com+
There are other options for serialization you could look at:
Plain old HTTP - just encode information in the headers and body. You'll need to use a HTTPClient from ASP for this though.
JSON - look at http://www.webdevbros.net/2007/04/26/generate-json-from-asp-datatypes/ for generating JSON from ASP datatypes
On the Java side just use a Servlet, you can embed this in something like Jetty or Tomcat. There's a very simple example here:
http://docs.codehaus.org/display/JETTY/Embedding+Jetty
you can write socket server on Java which will receive data from aSP.NET pages, ASP.NET will open socket and sent information this is in case you want to avoid HTTP, but I agree with Jon, sending JSON by HTTP using POST command and de-serialize this JSON using Google GSON library is much simpler approach.
I want to write ajax code in java i.e. i want use the functionality of ajax without using ajax. I'm looking for some API of JAVA which can do so.
Like we post data of a web page through JAVA program similarly I want to perform operation of ajax through JAVA program.
Please suggest.
Google Web Toolkit is Java-only framework for writing AJAX aplications.
Echo is an alternative to gwt
You can use jQuery for this. In jQuery you have the great form plugin which unobtrusively changes an existing form into an ajaxform.
HTML (in JSP):
<form id="myform" action="myservlet" method="post">
<input type="text" name="foo">
<input type="submit">
</form>
<div id="message">${message}</div>
JS ((in)directly in JSP):
$('#myform').ajaxForm({
success: function(message) { $('#message').text(message); }
});
Java ((in)directly in doPost() method of the Servlet behind myservlet):
String foo = request.getParameter("foo");
String message = "You entered 'bar': " + ("bar".equals(foo) ? "yes" : "no");
if ("XMLHttpRequest".equals(request.getHeader("x-requested-with"))) {
// Ajax request.
response.getWriter().write(message);
} else {
// Normal request.
request.setAttribute("message", message);
request.getRequestDispatcher("page.jsp").forward(request, response);
}
If you want to get some steps further, you can use Gson in Servlet to convert complete Java objects to Javascript object notation (JSON). This way you can access the data the javabean-like way in Javascript.
If your application is running on browser and its a web application, you can go with GWT. If your application is a core java application.. you can simply create a HttpURLConnection and use it.
JavaServer Faces (JSF) 2.0 should be able to do partial updates of a page in place, using AJAX under the covers. It sounds to me as if that is what you need.
I think the easiest way to get a JSF 2.0 capable server running right now, is using the latest version of Glassfish.
There are plenty of Java based AJAX frameworks out there.
Apache Struts [complex AJAX-tags (by integrating DOJO-toolkit)]
Direct Web Remoting is a framework for calling Java methods directly from Javascript code.
Guiseā¢ Framework - elegant server-side component architecture that doesn't require developers to write HTML or JavaScript
GWT - Java software development framework that makes writing AJAX applications
JAXCENT - Just-Java Framework and API for AJAX
IT Mill - Ajax framework for developing web applications for with Java language at server-side
and even more JAVA AJAX Frameworks
I suggest you take a lok at DWR - Easy Ajax for Java:
DWR is a Java library that enables
Java on the server and JavaScript in a
browser to interact and call each
other as simply as possible.
DWR is Easy Ajax for Java
It enables you to ajax-ify your web application with minimal effort.
It is not a complete new web-framework; it focuses solely on ajaxification, allowing you to keep and use your existing web framework.
If you want to use a "heavier" web framework like JSF, there exist ajax-ready JSF frameworks like IceFaces and RichFaces with provide ajax out-of-the-box.
you can submit form to servlet, when servlet response, you using jquery or prototype javascript framwork to get data from server by using Ajax call function.
I tried it and it run smoothly!
Good luck!
The quick answer is GWT. However, why would you want to do this? JavaScript is similar to Java. If you know Java, then you can easily write JavaScript code. The advantage of using JavaScript would be that you would be more versatile and would not be locked into a single tool. Using GWT to generate JavaScript (AJAX) code is not natural.
I am building a REST based API (Read only) for accessing services of my application. I plan on writing a web application that will leverage these APIs to provide basic information on the status of the application. I plan to use AJAX (using jQuery) to show the information.
Originally I planned on using Grails, Spring MVC, RoR or one of the web frameworks to handle the back end of my application. The REST APIs I will be providing though are already built on a stanalone REST framework so I would only be leveraging the web framework for the core application and not the business logic. In the future, I might need the server side framework to handle other tasks but for now most of the work is done in the REST APIs.
My question is, should I bother with using a web application framework on the server side? I should be able to make all the API calls I need from AJAX directly from the browser. I cannot think of much I would need to do on the server side. Would it make sense to have the application be standard HTML + AJAX + REST?
Its hard to say without actually knowing more about your current setup. This is what your situation sounds like:
You already have an app ready to go with all of the business logic contained. Sounds like its written in Java?
You already have the services written and exposed through a REST api using some other standalone framework. Meaning that if you wanted to, you could access the data right now with the browser without any extra work.
You have not yet built the web application, but when you do, it will get all of its content from the REST api using XHR and jquery. I say that, because otherwise, I would think that you would already be using some kind of framework to generate the other content.
If I am correct in my assumptions, then I would say that you have no need for an additional framework layer. Grails, RoR, SpringMVC my use ajax, and aid in exposing REST services, but the bulk of what they provide is an easy way to make an application that must generate html on the server, deal with form submissions, and handle sessions in a request/response cycle. It doesn't really sound like you'll be doing any of that, and it will likely make your app more complicated.
If you did at some point need the things that rails etc. provides, I would say that you may not need to use rails to expose the rest apis you have now. You could use rails just for what you need, and continue to use what you have for the REST api.
Well, the AJAX calls need to pull data from a server somewhere. If the goal is to avoid a complicated setup on the server side, CherryPy can keep the server side code VERY small.
I've written a simple exapmle below. The first class would be where you put the logic for your ReST API. The code below the class is all you need to get the server up and running.
Install Python 2.6, save the code below to restExample.py. Then in your command line run the python file by doing "python restExample.py". Point your browser to http://localhost:8080/blog/999 and see some JSON come back.
import cherrypy
import json
# Create the controller
class Blog_Controller(object):
def get(self, entryID):
cherrypy.response.headers['Content-Type'] = 'application/json'
return json.dumps({'title':'Entry Title from DB', 'entry_text': 'Text From DB'})
def update(self, entryID, titleFromPOSTFormInput, textFromPOSTFormInput):
# Update DB with passed in arguments. entryID comes from URL,
# other two entries come from POST
cherrypy.response.headers['Content-Type'] = 'application/json'
return json.dumps({'success':True})
# Setup URL routes
d = cherrypy.dispatch.RoutesDispatcher()
d.connect(name='blog_entry', route='blog/:entryID', action='get',
controller=Blog_Controller(),
conditions={'method': ['GET']})
d.connect(name='blog_entry', route='blog/update/:entryID', action='update',
controller=Blog_Controller(),
conditions={'method': ['POST']})
config = { '/' : { 'request.dispatch': d } }
cherrypy.tree.mount(root=None, config=config)
# Start the webserver
engine = cherrypy.engine
try:
engine.start()
except:
sys.exit(1)
else:
engine.block()
It sounds like this might be a good use case for GWT with Restlet.
Forgive me for tooting my own horn, but if you are doing AJAX REST stuff with jQuery, you should probably check out my JSON-REST plugin:
http://plugins.jquery.com/project/rest
If you are getting XML back, then this won't be as useful, but you may still be able to adapt some of the code to your needs.