Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I'll be receiving many HTTP POST request, let's assume at least 50 per minute, 24/7. I have no control over how these requests are transmitted, so I'm tied to http post here.
Which framework could I best use for receiving these many post requests? Does Spring offer a framework for handling POST push messages?
At the danger of sounding arrogant, it seems that 50 request per minute, i.e. less than one request per second, is not so many. Of course, it does depend on what the processing of the requests entails.
Spring does offer the Spring WebMVC framework (see http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html) which will most likely help you very well to achieve your task.
You"ll have to create a Controller and annotate one of the methods to handle POST requests, something like this (adapted from the Spring docs):
#Controller
#RequestMapping("/YourPath")
public class YourController {
#RequestMapping(method = RequestMethod.POST)
public String processThePost(...many options to receive params from the request...) {
// process the parameters
return "redirect:/someFrontEndServlet";
}
}
is is a REST POST? you could try Jersey for this https://jersey.java.net/ and my favorite tutorial is this http://www.vogella.com/tutorials/REST/article.html
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
Read book REST practice and get a better understanding of web scale out base on the cache. But when I try to add http cache control in my Spring Boot project I found nothing special to the cache control. The only resource I got is ResponseEntity: the javadoc. And the most useful article for ETag is http://www.baeldung.com/etags-for-rest-with-spring.
This makes me confusing... If the cache control is really great why little support for Etag generation and cache control resources found? Or maybe this is not the best practice right now?
Right now my implementation looks like this:
#RestController
public class Api {
#GetMapping("/with-cache")
public ResponseEntity cache() throws InterruptedException {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setCacheControl("max-age=3600");
httpHeaders.setETag("\"3Rstthw\"");
Thread.sleep(1000);
return new ResponseEntity<>("Hello", httpHeaders, HttpStatus.OK);
}
}
Looks not very elegant. Hope some one can give an answer for this.
Annotations were considered for response headers but decided against, so you will have to handle it manually somehow (not necessarily like in your code though).
Main reason to decide against is the way that responses are complex with possible redirections etc. so annotations are a poor fit.
Quote from the last comment
The specific use case brought up here is Cache-Control. Note that in
4.1 we added ResponseEntity builders and in 4.2 we added a CacheControl builder that works with the ResponseEntity builders
making it very convenient to do that programmatically and has some
further benefits when combined with eTags and lastModified (an
automatic check + 304). We also specifically considered and decided
against a #CacheControl header since this a cross-cutting requirement.
Instead the WebContentInterceptor can be used to configure cache
settings per URL pattern and that accepts a CacheControl builder as
well.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have Spring Boot RESTful service API. The consumers are other applications. One of the app's controller returns up to 1 000 000 strings on request.
What is the best practice of splitting such responses in Spring applications?
Update:
I figured out the response is needed for developer's needs and would be executed only once. So it's better to create the script for this operation.
Thanks for the answers.
Here is a good example to use multi part request in spring boot: https://murygin.wordpress.com/2014/10/13/rest-web-service-file-uploads-spring-boot/
However, I would prefer to think about your problem from an architectural point of view.Why should the rest returns such a huge response?And is it necessary to really returns all those results? There are a few factors that might help me to give a better answer.
This is the kind of situation when there is always a trade off.
1)The basic question is, can't you provide additional(they don't have to be mandatory, they can be optional parameters) to reduce the amount of returned results?
2)How frequent does your data change?If they don't change pretty often(let's say once a day) then you can introduce a sort of paging mechanism so you return only a segment of the result. From your side , you can introduce a caching mechanism between your business logic layer/data base and the rest client.
3)If your data are changing frequently(like you are providing list of flight prices), then you can introduce a caching layer per client ID. You can cache the results from your side and send it to the client divided into several requests. Of course you will have to add a time stamp and expiry date for each cached request or otherwise you will face memory issues.
4) This leads us to another question, where does the pain comes from?
Does the application clients complain about not being able to handle the amount of data they receive? Or do they complain from your response time of your service?Or are you having performance issue on your server side?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Locally I attach to my DAO from my client like so;
try {
AssetsDao _dao = getAssetsDao();
Assets _result[] = _dao.findAll();
for (int i=0; i<_result.length; i++ ) {
display( _result[i] );
}
}
catch (Exception _e) {
_e.printStackTrace();
}
If my DAO tier is on another server, what are the methods that I can use to access this tier? I know I can create a web service and have heard I can use RMI but what is the most common method?
The question leaves lots of room for speculation. So you may want to expand quite a bit.
E.g. if the current implementation of your DAOs is using a database, you may as well already be able to use a different computer (i.e. server) by just adjusting your database's configuration.
Update (taking OP's clarification into account):
You have to come up with or (better) use an existing technique to let your client talk with your server; this has nothing to do with DAOs, though, as remotely accessing the service of DAOs is the same as accessing any other service remotely. Look at Remoting and web services using Spring. Although this is part of the spring framework documentation, it will give you a first start.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to build an application with REST interface using Spring. The interface must be extendable at runtime: The application extends the Interface dynamically depending on unknown configuration. This configuration may change with time.
For example I have a Rest interface at http://domain.com/rest. The interface has a REST item at */rest/item which supports POST to create a new REST method. Calling POST on this REST item leads to an extension of the interface regarding to parameters given in POST request (e.g item name, properties, allowed operations (GET POST) and the code which is called by those operations). This may lead us to a new REST item at */rest/newItem.
Since I only found Spring examples using a static XML config I'm wondering...
Is this possible with spring?
Any example to quickstart this approach?
You definitely can have dynamic URL structure with Spring MVC. Take a look at path patterns. In such case you would have one request mapping with path pattern (e.g. #RequestMapping(value = "/rest/*")) and your dynamic logic.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
Which Java libraries parse HTTP Accept header?
You should read this article : http://www.xml.com/pub/a/2005/06/08/restful.html
The article uses Python but it's not a problem : at the end, the following link is shared : http://code.google.com/p/mimeparse
As you can see, "mimeparse" is :
Basic functions for handling mime-types in Erlang, JavaScript, Perl, PHP, Python, Ruby, Java
According to the home page :
List<String> mimeTypesSupported = Arrays.asList(StringUtils.split(
"application/xbel+xml,text/xml", ','));
String bestMatch = MIMEParse.bestMatch(mimeTypesSupported, "text/*;q=0.5,*/*;q=0.1");
Have a look at the HttpClient Util.parseHeader method.
Edit: (trying to make this answer worth being accepted post-factum)
The spring framework provides this functionality within its MediaType component.
If you are already using Spring MVC you can simply request for a #RequestHeader-annotated parameter of type HttpHeaders and access the list of accepted media types by simply calling HttpHeaders.getAccept().