sentence
stringlengths 1
1.38k
| label
stringclasses 3
values |
---|---|
most welcome friend!!!
|
p
|
:).
|
o
|
Use CODETERM1 method on CODETERM2 .
|
o
|
I recommend the URL_http://jackson.codehaus.org/ [jackson-library] it makes things very easy.
|
p
|
To use it you would have an object like this... CODESNIPPET_JAVA1 .
|
o
|
Then you can use the objectMapper from the library to go from an array that you have in memory to a json String like so CODESNIPPET_JAVA2 .
|
o
|
Of course doing it this way depends on how your ids are stored but for me it generally makes my code a lot cleaner and the Jackson Library is pretty good performance wise.
|
p
|
Getting Access to HttpServletRequest object in restful web service.
|
o
|
I can get access to the HttpServlet Request object in a soap web service as follows:Declaring a private field for the WebServiceContext in the service implementation, and annotate it as a resource: CODESNIPPET_JAVA1 .
|
o
|
To get the HttpServletRequet object, I write the code as below: CODESNIPPET_JAVA2 .
|
o
|
But these things are not working in a restful web service.
|
n
|
I am using Apache CXF for developing restful web service.
|
o
|
Please tell me how can I get access to HttpServletRequest Object.
|
o
|
I'd recommend using CODETERM1 CODESNIPPET_JAVA1 .
|
p
|
You can use the CODETERM2 annotation to flag other types (such as ServletContext or the HttpServletRequest specifically).
|
o
|
See URL_http://cxf.apache.org/docs/jax-rs-basics.html#JAX-RSBasics- Contextannotations [Context-Annotations] .
|
o
|
Why use a framework for RESTful services in Java instead of vanilla servlets.
|
o
|
I know there are a few questions regarding the libraries you can use to do RESTful services in Java, but what is the value in using them against vanilla implementations.
|
o
|
I mean, if i was looking to create URL_http://stackoverflow.com/questions/6774904/nested-rest-routing [the-url- structure-described-by-Wim]
URL_www.example.com/images
URL_www.example.com/images/id/num
URL_www.example.com/images/tag/num
URL_www.example.com/images/tag/num/num/num Would it not be easier (for future developers) and faster (to implement and learn) to map the url pattern /images to a servlet and have a line or two that parses the url for the parameters instead of learning, implementing and configuring one of these libraries to do it for you.
|
o
|
URL_http://en.wikipedia.org/wiki/Apache_CXF [Apache-CXF]
URL_http://jersey.java.net/ [Jersey] (popular)
URL_http://en.wikipedia.org/wiki/Restlet [Restlet] (pioneer of JAX-RS)
URL_http://www.jboss.org/resteasy [RESTEasy] Essentially what I am asking is... What is the value in using a RESTful Java framework?
|
o
|
Would it not be adding a lot of complexity, in the implementation, for a simple problem?
|
o
|
EDIT: This jersey code is handled very neatly and everyone should know how to do it in servlet form if they are looking into libraries to do it for them.
|
o
|
CODESNIPPET_JAVA1 .
|
o
|
If all you are going to be doing is a "service" that returns text that is driven by URL parameters, so plain text returns, is a framework necessary?
|
o
|
Actually Jersey is the reference implementation of JAX-RS.
|
o
|
So I'd call it the pioneer, not Restlet.
|
o
|
Your edit makes your question answer itself.
|
o
|
If you just want to say "Hello World", you don't need JAX-RS.
|
o
|
But who just wants to do that?
|
o
|
I should have referenced wikipedia there, personally I am wary of calling things pioneers.
|
n
|
If that's all you're doing, why bother with servlets at all?
|
o
|
After all, with just GET you shouldn't be changing any state anywhere (well, not state worth the name; server logs don't count).
|
p
|
Donal I do not follow... What handles the GET request then?
|
o
|
JAX-RS is a very well designed API that makes mapping HTTP requests to methods, extracting parameters from various parts of a HTTP request, handling content negotiating, and many other low level tasks very easy.
|
p
|
Using JAX-RS, mainly via Apache CXF, for roughly two years now, I'd always prefer it over plain Servlets.
|
p
|
But is the time to learn, implement, understand for each developer worth it.
|
p
|
I mean does it save time?
|
o
|
Is it really more simple?
|
o
|
If it is just about extracting parameters, then surely it is easier to stay closer to the Java standard.
|
p
|
It would be rather simple to extract parameters in a servlet.
|
p
|
I feel that it is potentially too much added complexity for the value it provides.
|
o
|
You don't just want to extract parameters.
|
o
|
You want to set HTTP response codes, map incoming and outgoing bodies to objects, and other stuff.
|
o
|
Yes, JAX- RS helps with this.
|
o
|
@avanderw Maybe your experience is only with simple webapps, because I know from mine that it really helps a lot with more complex applications.
|
n
|
Doing all that stuff directly at the level of a servlet would be a lot of work, but JAXRS lets you focus much more on the resources within your application.
|
o
|
(Not that I'd claim it's perfect some surprising things are still very awkward but it definitely makes things a lot easier.
|
n
|
).
|
o
|
Would it not be easier (for future developers) and faster (to implement and learn) to map the url pattern CODETERM1 to a servlet and have a line or two that parses the url for the parameters instead of learning, implementing and configuring one of these libraries to do it for you.
|
o
|
Easier?
|
o
|
It's certainly not easier to write you've got to do all the path extraction yourself and all the method handling and all the content type negotiation (in _both_ directions) and all the cookie handling and the object deserialization/serialization thunks and well, lots of low-level stuff that would all need testing and debugging or easier to maintain either, since the JAX-RS interface lets you operate at the level of resources (the natural characterization of RESTful webapps) instead of requests; with much experience, maintenance is easiest when the gap between conceptual model and implementation is smallest.
|
p
|
It's also not faster to implement (because the low-level implementations of JAX-RS have already been tested and debugged for you; less for you to do) and the cost of learning it isn't very high as it is a mostly declarative API with very few surprises.
|
n
|
OK, these benefits might not seem so much when you're only dealing with simple webapps.
|
p
|
After all, you can hack something out in very little time and put the resulting lash-up online.
|
n
|
You'll then have to pray that you got it right without significant unexpected avenues for exploits or denial-of-service attacks.
|
n
|
And the maintenance programmers will have to understand just what those regular expressions you've sprayed through the code do (Good Luck With That!
|
p
|
) when adding small features or fixing bugs.
|
n
|
But as the webapp gets larger, the benefit of having a tested library to handle all the low-level stuff really does win out.
|
n
|
(Before you ask, some of the libraries you mention will merrily install themselves as servlets; this allows your code to just describe the business logic of the servlet and declare how mapping to the wire is done in abstract terms.
|
p
|
That's just enormously easier.
|
n
|
) .
|
o
|
When would using regular servlets instead of jersey be appropriate?
|
o
|
Should handling doPost in a httpservlet never be done?
|
o
|
@jontro When you like doing everything by hand?
|
o
|
I'm not convinced that there's really a good reason unless you've got a desperate need to keep the number of libraries down.
|
n
|
Frameworks are used to make you task more easier.
|
o
|
i agree that we can do the same thing by implementing servlets and then parse the url and then implement the basic logic.
|
o
|
Bu if you are using framework like jersey then u don't have to worry about those parsing patterns and other similar tasks.
|
n
|
ServletContainer class will take care of this (parsing url in it's service method) and there are lots of other classes also which will make your task easier.
|
o
|
And one more thing we are taking only a one scenario (matching patterns) but when our requirements will grow the same code written by our own servlets will become more complicated and complex.
|
n
|
This is just my point, why use a sledgehammer to hammer in a nail.
|
o
|
If the framework is easy enough to adopt then you should be able to go from vanilla to the framework with more ease than from another framework, when the need arises.
|
p
|
Why take the whole kitchen sink when all you need is the tap?
|
o
|
Actually JAX-RS is an API while CXF, Jersey, RESTEasy are implementations.
|
o
|
They all have their strong and weak sides, for example how easy they integrate with Spring.
|
p
|
But I would definitely recommend using JAX-RS.
|
p
|
I would go with using Jersey or a library in this case, if it does the following (adds enough value):
the config for the URL is all self-contained within one file, with the source
there are no hidden config files or overly verbose configs (e.g.
|
n
|
web.xml)
the parameters are nicely mapped to strongly typed variables (e.g.
|
p
|
use of annotations)
it is not convoluted to get to the values of parameters (e.g.
|
p
|
URL_http://stackoverflow.com/a/1943667/831203 [RESTlet] )
the overhead for running the library is low (I have had bad experiences with reflection solutions in other libraries)
it is well documented
it is well adopted In such a scenario, I find that using a library would add value to my project for the effort required to use it.
|
n
|
Jersey does seem to mach the requirements quite adequately, although I have not given other frameworks enough investigation yet.
|
p
|
Any easy REST tutorials for Java?
|
o
|
Every tutorial or explanation of REST just goes too complicated too quickly - the learning curve rises so fast after the initial explanation of CRUD and the supposed simplicity over SOAP.
|
p
|
Why can't people write decent tutorials anymore!
|
o
|
I'm looking at Restlet - and its not the best, there are things missing in the tutorial and the language/grammar is a bit confusing and unclear.
|
n
|
It has took me hours to untangle their First Steps tutorial (with the help of another Java programmer!
|
o
|
)
Tutorial Comments** Overall I'm not sure exactly who the tutorial was aimed at - because there is a fair degree of assumed knowledge all round, so coming into REST and Restlet framework cold leaves you with a lot of 'catchup work' to do, and re-reading paragraphs over and over again.
|
o
|
1.
|
o
|
We had difficulty working out that the jars had to be in copied into the correct lib folder.
|
p
|
2.
|
o
|
Problems with web.xml creating a HTTP Status 500 error -
The server encountered an internal error () that prevented it from fulfilling this request , the tutorial says:
"Create a new Servlet Web application as usual, add a "com.firstStepsServlet" package and put the resource and application classes in.
|
o
|
" This means that your fully qualified name for your class
is
so we had to alter web.xml to refer to the correct class e.g: original: CODESNIPPET_JAVA1 .
|
p
|
should be: CODESNIPPET_JAVA2 .
|
o
|
I was under the impression that the concepts of REST were supposed to be much simpler than SOAP - but it seems just as bad if not more complicated - don't get it at all!
|
n
|
grrrr Any good links - much appreciated.
|
p
|
Oh, how do I feel your pain!
|
n
|
Definitely an up vote!.
|
o
|
Check out URL_http://stackoverflow.com/questions/1710199/which-is-the-best-java - rest-api-restlet-or-jersey and consider if this is an exact duplicate or not.
|
o
|
I so agree with you!
|
o
|
One would think that an API like RESTlet would "help" you.
|
o
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.