As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm not a Python developer, but I work with Python developers.
The scenario is the following: I have been asked to implement part of a system that integrates with a Python framework. I then agreed with the other team to develop my part in Java and provide full support to them implementing REST bindings. So I implemented a webapp in Java using Spring MVC and Hibernate. I can't go in detail but the design contract resembles the following:
The Python framework invokes a REST API with special authentication and authorization headers. The Spring MVC controller uses interceptor to perform authentication and authorization based on such HTTP headers, then gets invoked. The controller itself uses a path variable and two optional GET parameters to determine the type of object being accessed and the timestamp range
/api/{datatype}?[starttime=AAA]&[endtime=BBB]
Using a proper switch statement I choose the right Hibernate repository to query with these parameters and return an object (mapped to a table) that is translated to JSON by Jackson mapper for Spring MVC.
As a system integrator, I'd tell the guys to simply form legal HTTP requests to my component running on Tomcat and decode JSON (which is designed according to THEIR database model).
Instead the guys asked me to translate all the thing to Python. Apart being totally inexperienced in Python (I could barely write a console application that computes binomial coefficient, just not to implement yet another hello world or simple calculator), I guess that in Python no such thing as Hibernate, Spring and Jackson exist.
So, let's go to the question. Are there in Python any frameworks that allow me to...?
Easily create REST APIs with little code (Django????)
Easily intercept existing REST APIs and modularize the HTTP pipeline properly, i.e. doing authentication out-of-api-code, post-processing output stream, etc. through a mechanism similar to interceptors (I have seen something like that in their code base for authentication... we may mark this as solved)
Perform Dependency Injection. When switching between dev, staging, production, I currently change the class implementing an interface invoked by business code
Map objects to relations, such as Hibernate. That's currently my darkest point. I don't think there is any ORM in Python
Map objects to JSON (I know it's feasible, they already do in their codebase)
I won't post sample code believing it useless. I have tried to post a question as a general problem, not digging into specifics.
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
From yesterdays i have started learning java web services, have seen many blogs still confuse, about which service is best for practice. either SOAP or Rest?
Please suggest me best service method for request and response.
Thank You.
There is no best, only choices. Choose the one that meets your needs and get on with it. Or simply pick one if you don't know what meets your needs.
REST is a style based on HTTP. It requires a level of knowledge that you probably don't have. I'd recommend starting with SOAP because it's so well supported with tools. Once you're comfortable, learn REST.
I think this article could help you: When to use rest or soap.
Personally I always use SOAP because it uses XML to transport the information, and it is easy to understand the structure of the data you are using in the comunication. Rest hasn't exactly a format to read, so it makes the things more complex to understand.
If you are just starting to learn about Web services I think you should go with SOAP.
Best Answer I found on SO
Both methods are used by many of the large players. It's a matter of preference. My preference is REST because it's simpler to use and understand.
SOAP:
SOAP builds an XML protocol on top of HTTP or sometimes TCP/IP.
SOAP describes functions, and types of data.
SOAP is a successor of XML-RPC and is very similar, but describes a standard way to communicate.
Several programming languages have native support for SOAP, you typically feed it a web service URL and you can call its web service functions without the need of specific code.
Binary data that is sent must be encoded first into a format such as base64 encoded.
Has several protocols and technologies relating to it: WSDL, XSDs, SOAP, WS-Addressing
Representational state transfer (REST):
REST need not be over HTTP but most of my points below will have an HTTP bias.
REST is very lightweight, it says wait a minute, we don't need all of this complexity that SOAP created.
Typically uses normal HTTP methods instead of a big XML format describing everything. For example to obtain a resource you use HTTP GET, to put a resource on the server you use HTTP PUT. To delete a resource on the server you use HTTP DELETE.
REST is a very simple in that it uses HTTP GET, POST and PUT methods to update resources on the server.
REST typically is best used with Resource Oriented Architecture (ROA). In this mode of thinking everything is a resource, and you would operate on these resources.
As long as your programming language has an HTTP library, and most do, you can consume a REST HTTP protocol very easily.
Binary data or binary resources can simply be delivered upon their request.
There are endless debates on REST vs SOAP on google.
My favorite is this one.
Well, REST is more used than SOAP (something like 70% of the webservices, but I can't figure out where those figures come from). So if you want to be a professional developer, it may be more interesting to learn REST.
This question has been asked multiple times on SO over the years. You can find answers at Main differences between SOAP and RESTful web services in java and WSDL vs REST Pros and Cons and Restful vs Other Web Services
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I followed this (paragraph 7) tutorial to create a Rest service using jersey. However in the end i was kinda disappointed as it wasn't exactly what i was looking for.
What i had in mind was to create a java server with jersey that a client could make post requests to it , and the server could save the data in a MySQL database.
In the tutorial i was shown maybe how to make a post request? And even for that i used some html and 4 different java classes without any explanation on what anything does. In php the same thing was less than 40 lines of code and everything actually made sense.
I am not sure where to go from here , as everyone suggested to me to read this tutorial for what i needed. But i can't see why as i don't understand its purpose.
Do you know any tutorial i could have a look at , or point me to the right direction here? I ve never developed in java before neither have i used tomcat , so everything seems pretty new to me. I was used to php and apache.
The tutorial you have mentioned focus on creating RESTful Webservices with Java. It aims at distributed systems, where a client can make requests to a server. I think the tutorial is very helpful for that matter.
On the other hand, you seem to be searching for a tutorial that helps you creating a web application that can save/retrieve data to/from a database. You can find one, for example, in http://zetcode.com/tutorials/jeetutorials/mysqldatabase/
Then, for web clients, you have different alternatives, such as GWT or JSF. Also, for the persistence layer you might want to check Hibernate or JPA.
Relatively to Tomcat, it implements the Java Servlet and the JavaServer Pages (JSP) specifications from Sun Microsystems, and provides a "pure Java" HTTP web server environment for Java code to run. In short, Tomcat is the place where you deploy and run your Java web application; like you deploy a PHP application in Apache (with PHP installed).
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I've been tasked with creating a Java web application that consists of two pages, a "Draw" page and an "Evaluate" page. I'll be developing in Eclipse.
The "Draw" page will facilitate the following process:
Take user input from a form
Using a Servlet, build a model in the background
Send the model to an Applet (probably via JSON) on the client-side to be rendered visually
The "Evaluate" page will:
Take user input from a similar form to build a similar object (same class) using a Servlet
Run a the model through an algorithm on the Servlet, and display the results on screen.
The pages can be relatively independent.
My question is, exactly how should I go about implementing this combination?
I'm familiar with Servlet development and the Spring MVC/Webflow framework, but in no way an expert. However, I'm guessing Spring would be overkill for this simple application, and I've never implemented a Servlet that has more than one major function.
Should I make an HttpServlet that just has conditional logic in the doGet/doPost methods, and performs an operation based on the request's URL?
Should I make two separate Servlets?
If so, would I make two separate projects in Eclipse, or just one project with two Servlets registered in web.xml? Should I do something totally different?
I'm not looking for code, but just would like to have a stronger understanding of how to approach this type of application.
I'm going to provide an opposing view to that of Dmitri's. I think its great for people to know how to write plain servlets but when it comes to writing code for a business I think you'd be better off using Spring MCV. The main reasons are:
you already have experience with Spring MVC, so no learning curve
although the requirements seem straight forward, my experience is that web projects like this quickly grow way beyond their initial specs, at which point you'll be wishing you'd used Spring MVC
You will have to code and maintain the features in a servlet which are normally handled by Spring MVC - I love the saying: they have solved problems that you haven't even thought about yet.
every line of code you write has the potential to be buggy, by reducing the amount of code you write you reduce the risk of bugs
Spring MVC is designed in a such a way that you can use as little or as much of the features that you like/need. With annotations, you can get a simple app up and running with a surprising small number of lines of code/xml
testing is much easier with Spring MVC
Spring MVC follows a convention that other programmers already know. If you leave your job, then someone can pick it up very quickly. OTOH if you code a simple servlet, you could do it a number of different ways that could make it harder to maintain for someone else
with modern hardware/OS, the extra memory/overheads that adding Spring MVC adds to you project is negligible - we no longer run our servers with 128KB of memory but some people still have a mindset that we do. If in doubt benchmark it, don't early optimise!
Spring (or any other MVC) framework is definitely overkill for this, servlets will do just fine.
Make sure all of your actual logic is in a separate class, all your servlets should do is apply whatever processing needs to be done to read the user input, and call the appropriate methods on your service class. Basically keep the web-specific parts minimal.
Whether it's two separate servlets or one that switches on the request path doesn't really matter. I'd use two separate ones, since mapping requests to methods is pretty much what servlets are designed to do.
You do not need separate projects in Eclipse, just define the servlets in web.xml (or with annotations if on Servlet 3.0).
It sounds like you're on the right track.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I would like to work with Sencha Touch, but there is a small problem: I don't know JavaScript or how I would begin using Sencha Touch in JavaScript.
I already have a commercial license for Sencha Ext GWT and develop applications with it in Java.
What I need is Sencha Touch wrapped as a Java component or some guides on how to make my own Java wrapper for Sencha Touch.
I have looked at GWT4Touch, but it does not meet my requirements.
Can someone help me?
What requirements are those? We would be very interested in your input; perhaps there is something we can help you with. Just ask in the Emitrom forums :-)
For those that may not know off hand what GWT4Touch is, it is precisely what the question calls for: a Java API for Sencha Touch. We are re-branding it as Touch4j, so you may start seeing that name thrown around.
Check the demo at gwt4touch2-demo.appspot.com, or download the API from emitrom.com/gwt4touch and give it a try.
I also had the same issue a few weeks back. I didn't knew Javascript but I wanted to use Sencha Touch for prototyping(work related). I came across this book "Sencha Touch Mobile JavaScript Framework":
Actually if you read this book developing apps with Sencha touch is not that hard. I was able to develop a prototype in a week where I built UI pages using Panels, toolbars , MVC, remote proxies. I even integrated all this with Java Spring and Freemarker templates.
Here is the Store code to call the remote ajax proxy:
proxy: {
id: 'proxyID',
type: 'ajax',
url: '../api/sampleRestJsonAPI',
reader: {
type: 'json',
root: 'data'
}
You have to setup Java Spring (With MVC) so that when your code makes a call to the remote proxy it gives you something like:
{"data": {"field1":"value1", "field2":"value2"}}
Basically it should be a valid Json with the root you have specified in your store. The url config option might change based on how you structure your folders in your web app.
So with this I do all the heavy duty data processing in the Java Layer and keep the js layer very light.
Here is a good article on REST IN SPRING 3
What are your requirements that make GWT4Touch unsuitable? GWT4Touch seems to do a pretty good job if you want to write Java to create Sencha Touch applications.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I want to code a server daemon application that provides some backend functionality. I'd like to stick to Java since I'm pretty familiar with this language and I figure it'd be much easier to just dig into a new framework and not a new language in parallel.
So far I found many promising frameworks, but all of them resemble somehow a webserver. Thing is, I don't want to code a web-application in terms of web-sites so I doubt that I'll need all the webserver-functionality such as templates and this stuff.
What would be a good suggestion for this purpose or would using a regular web-framework such as "play" without the template-stuff be the best choice?
JAX-WS is a standard for creating SOAP web services. Wikipedia link to see what it is about.
For RESTful you would need to make http requests, usually get and post and this type of service works best if you develop a website. From what I understand you don't want this, but still if ever just check the spring framework.
Raw TCP/IP is so much harder and unless you know exactly what you want (performance and optimization wise) you`re better off using a framework.
A webserver is used to implement webservices. A webserver may serve more than html to clients.
I have a personal "stack" using for a long time that is Jetty + RESTEasy and it serves no html at all (only XML and Json).
Javascript + Rest (Glassfish + Jersey for rest). Glassfish – Java EE Full profile certified reference application server (server will used for REST host).