Dynamically extend Spring REST interface at runtime [closed] - java

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.

Related

Pagination in Java Reactive Programming [closed]

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 4 years ago.
Improve this question
I am still new in Java Reactive Programming and my project Requirement wants me to implement Pagination with Reactive Programming in Java.
Like if I hit an API which returns me 10000 records in stream then I needs to return a flux with proper pagination.
Can anyone suggest me a good approach about this?
Like this is the approach that I am following.
Repository
public interface CouchBaseRepository extends ReactiveCouchBaseRepository<Book,Integer> {
#Query("#{#n1ql.selectEntity} where name=$1")
public Flux<Book> getPaginatedFlux(String name ,final Pageable pageable);
This is my Repositorty but when I up my application then it shows this following error.
java.lang.IllegalStateException: Method has to have one of the following return types! [interface org.springframework.data.domain.Page, interface org.springframework.data.domain.Slice, interface java.util.List]
I cannot use Page inteface here as it is blocking so Is there any way to deal with this problem?
I haven't worked with spring-webflux yet, so I can't comment on specific API calls, but I'll provide a "theoretical" answer that might help as well.
Flux represents a stream of data (possibly infinite). So, pagination is kind of not consistent with reactivity, only because they're talking about different things
Consider implementing pagination with input parameters (like usual limit/offset) in the method that returns Flux of (logically decided) up to 10000 records as per your requirement.
So, one call will be handled in a "reactive manner" but it will return only one page of data, if you want to load another page - do another reactive call.
Of course at the level of streams, after 10000 objects receive, the stream should be closed.
This is the approach I suggest.
There is an another option: implement everything via one stream, but in this case the client side (UI or whatever that consumes the paged data) will have to be "smart enough" to load /unload only the required data. In other words, if all-in-all you have, say 1 million objects to show, think whether you should avoid situation where all 1 million is loaded on client side at once.
In addition the page navigation will be kind of tricky (stuff like, get next/previous page). I haven't worked like this before. I think bottom line, the choice will be requirement driven.

how to implement the key words methods in selenium according to page when framework is keyword driven and data driven [closed]

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 5 years ago.
Improve this question
I am using a framework which is key word driven and data driven in selenium.
The problem is all the methods or actions for entire application is written in one single class which has gotten very lengthy and confusing like spaghetti.
I want to implements all the methods or actions page wise like a page object model but I also want it to be data driven and key word driven as well.
Any suggestions please??
#Bryan Oakley
Your comment made me think harder which helped me finding the solution .
returnedStatus = runReflectionMethod("com.dmainc.ptes.test.setup.KeyWord", methodName, paramListObject);
resultSet.add(returnedStatus);
excelSheet.setCellData(filePath, sheetName, "Result", row + 1, returnedStatus);
So If **runReflectionMethod("com.dmainc.ptes.test.setup.KeyWord", methodName, paramListObject);**
com.dmainc.ptes.test.setup.KeyWord this part needs to be variable rather then constant which its now.
so if I make it variable and I create various classes page wise which will include the respective methods/action then I can pass the required class name in this piece of code .My problem will be solved .
All the methods/actions will go into their respective classes and no code bloating.
Since your framework is keyword and data-driven, it should support keyword mapping, for example Robot framework:
a dictionary mapping all library names to instances
which means that you don't need to worry too much about the refactoring of the
all the methods or actions for entire application is written in one single class
This is a classical example of a Bloater - Large Class. There are a lot of resources out there, but would recommend starting with
Refactoring To Patterns and sourcemaking.

Model View Controller - what comes under what [closed]

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
in mvc what comes under what? beans, servlet and DAO. Where these tech will fit in the mvc. what will come under model, view (like jsp,html) and controller
Model: Any object that has values that need to be displayed in a view. These can be domain models, simple pojos, or anything else really. But typically the objects hold data that needs to be used in the view.
View: The thing that actually displays information to a User. In your case the JSP/HTML is considered the view. Note, a User does NOT have to be a human being.
Controller: Used to determine what Model needs to go to which View. In your case the servlet should be considered the controller.
DAO is actually part of the persistence layer, but generally it is ok for a Controller to access objects in the persistence layer and query them. You just don't want a controller writing data to a DAO. That is what services are for.

Should image manipulation logic go in the Controller or the View? [closed]

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
At the moment I have a zoom method in a View class which resizes an image being displayed.
Should this logic be in the View or inside the Controller ? Why so ?
The problem with putting it in the view is that the view in (at least some) web frameworks is implemented as little more than a template file and a mechanism to inject values into it. This doesn't feel like a suitable place in practice, since doing so would mix business logic with presentation, which in turn would defeat the purpose of using a framework in the first place.
If your application is re-rendering an image prior to outputting it, perhaps you could create a service class that carries out this function, and then call that from the controller. That way you avoid putting logic in your presentation layer, and you keep the resize logic separate from the web context of the controller, which increases testability.

Service to worker pattern - the best practice to transfer data from controller to view [closed]

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 4 years ago.
Improve this question
So the question. We use service to worker pattern and now are looking for an appropriate pattern to transfer data from controller to view. Any help is appreciated.
Unfortunately I couldn't attach diagram at first (it's a cool site,isn't it) as I didn't have reputation 10 and thanks to people now I can
Comment:TemplateEngine is any alternative to jsp template engine.
So I will try explain via text.
Classes:FrontController,Controller,View,Action,Jsp files, EJB, Entity (Anemic Model). So FrontController routes to Controller and invokes two methods of Controller by order. Controller has only two public methods processAction and processView. ProcessAction invokes Action (command pattern),so
FronController calls Controller.processAction()->Action -> EJB - >get Entity.
So here the FrontController must invoke the second method of Controller
FronController calls Controller.processView()->View -> Templating, jsp , helpers etc(at this point we need data that we have got in controller)
EDITED:
Controller.ProcessAction and Action.execute have the same signature:(HttpServletRequest request, HttpServletResponse response).
What about request/response object(context object). I've read core j2ee patterns and was surprised. As I understood this object takes data from request and even makes validation. Its main goal is to give as a tool to work with data that removes the dependency of different protocols (html,xml,json). There are two reasons why I was surprised:
Context object was created in frontcontroller - at this step we can hardly define that context object we will use. Often there are situations what we even need another controller.
I think that validation must be performed in EJB. The reason is very simple if we have two kinds of clients: browser and java application than their common point is EJB. So it's in the EBJ we must make validation.
So, I am very interested in other people's opinion.
I think that you can have GetData() in one controller, combine the GetData() in TemplateEngine layer. Or, another approach, is to add one more layer Service layer, to retrieve all the data, and controller will combine all the GetData() functions from service layer.
Thank you,

Categories

Resources