is OAPageBean Class is act as a Controller? - oaf

Hi Every One.Now i started to learn OAF.I read some articles related
to OAF.In this articles they mention when user first sent a request
for OA.jsp page then that request received by OAPageBean class.As per
my knowledge if OAF follow MVC architecture then that request received
by Controller.So any one please clarify me whether OAPageBean is a
controller or bean and how it work when browser sent a request for jsp
page?

OAPageBean is not a controller. It is the main OA Framework page processing class.
The OAPageBean calls the processRequest method when a browser issues a GET request.
The OAPageBean then calls processFormData for pages that insert or update data.
The OAPageBean calls the processFormRequest method when a browser issues a POST request.

Related

Is there any way to identify if type of an HTTP request is changed by the intercepter?

Is it possible to validate if an HTTP request originated from the client as GET, but was intercepted in between and converted to POST, or vice versa?
It is one of the security validations that is required as part of the project I am working on, but not getting enough clue about it. One of the way we thought of using as validation is to check if it is a GET request with a body than it could be POST. But that is just one case. Also if a POST is changed to GET by forging the request, I believe the data in the body can also be removed.
edit: Added more information about application and the intercepter
It is a regular Java web application developed using Struts with JSPs on the client side. The request from the web pages are being intercepted using Burp Suit Proxy to change the payload in the request.

Post to external URL and show page

There is a requirement in the webapp I am developing (not changeable unfortunately ) that states that I have to send via post certain parameters to a servlet from a JSF managed bean. That servlet then forwards to a page where it shows some of the parameters sent via POST in a form for the client to see.
That servlet is part of an external application, thus I cannot use RequestDispatche.
I have tried Apache Http client but i get to a point that the post URL responds with the content of the page (i can actually see the HTML in my logs), what i would like to do is forward to the page not receive it as answer in my code.
If this makes no sense let me know :).
EDIT:
what i need to do is:
JSF BEAN->POST data to an external servlet -> Follow servlet redirect/forward to an external page
One way I'm thinking of doing this is forwarding to an internal facelets or JSP page that builds a hidden form with all required parameters and automatically submits it to the post Servlet
So after trying to find other ways to do it, I have decided to go this way:
Create an internal page, with a hidden form that will be automatically committed with a small javascript.
Get all required data in the bean, navigate to page, fill hidden fields with the required info, post to external servlet.
I should also say that a better way to do this kind of interaction would be:
Post data to servlet (for example using apache http client)
manage the servlet response (for example 200 OK)
navigate via GET (using a redirect) to the servlet by passing some id as a
get parameter through which the data can be shown in the page
This would require the servlet to accept POST and get requests, and also to have a way to get the data sent via post when it's called via get. This was not the case for us.

Handling a response from node.js without rendering it?

I am returning a simple response in node.js with res.send() in response to a POST request. My problem is that I want the client to stay on the same page. Currently the client just gets taken to a blank page that has the contents of res.send() written on it. But I want the client to update it's current page (the page from which the POST request was sent) instead of displaying the response. Is there a way to do this?
You need to change the action of your HTML form using jquery, angular, or backbone (etc..) The page change is the default functionality of a html form submission, and this cannot be resolved by node.js.

Post Form to a page in CQ5

I have a custom search component which searches for some parameter(s) from a dropdown [myParam] and displays the search results in another page. I currently use the default (GET) form
<form id="searchForm" action="/content/myWeb/searchResult.html" method="get" target="_blank">
In the result page, a component picks up the request params and processes the search.
I need to make it a POST submission so that the search parameters are NOT visible in the URL. But if I make it a method="Post" in the form above, I get this error:
Status
500
Message
javax.jcr.nodetype.ConstraintViolationException: no matching property definition found for {}myParam
Location /content/myWeb/searchResult
Parent Location /content/myWeb
Path
/path/to/search/page
That exception is the incidental way that Sling tells you that the servlet to which you are attempting to POST can not be found. What happens, in this case, is that Sling defaults to the SlingDefaultPostServlet, which attempts to to POST properties (represented by your form values) to the node /content/myWeb/searchResult. There's no way for Sling to say "I can't find a servlet that's registered to your request", so it just falls back to it's default behavior.
I'm assuming /content/myWeb/searchResult is a cq:Page node type. That node type is very restrictive, which is why it tells you that you cannot add properties that correspond to your form values.
This worked before, because your GET request to /content/myWeb/searchResult.html was able to resolve and execute. All GET requests to a page node can be served up by the system, inherently.
Now, since you are trying to do a POST, you need to create and register a new servlet that can handle this POST request. To do this, you'll need to create a SlingPostServlet and register it to your specific path (not recommended) or a specific selector/extension combination (recommended). That servlet should process the request parameters and respond with an HTML document.
A caveat...
What I just described will help you technically build what you are asking. That said, I don't agree with the premise that you should "make it a POST to hide the request parameters." The reason this is so much extra work, is because you are circumventing the principles of REST, which Sling is theoretically built to support. Your URL (via request path and parameters) should be communicating "I want the page at /content/myWeb/searchResult, given the criteria param1=x, param2=y, and so on". The GET with request params is an appropriately RESTful request.
I suggest you rethink what you're trying to do. Building a more complex solution around RESTful principles is not a good practice.
Just as a sidenote, you can always check if a given URL is bound to a servlet via the sling servlet resolver. Reachable via the OSGI-console or via URL:
http://localhost:4502/system/console/servletresolver
This can at least help you find closure on, if the servlet is registered to the given URL.
You can create a POST.jsp for your page, which could handle the POST request.
It is not restful to make get like request with POST, but sometimes it can be useful. Also With POST, dispatcher won't cache your request.

JSF lifecycle, how can response complete happen in the middle of the life cycle?

I am going through the article on JSF LifeCycles. I have the following doubt.
In many phases, the Response Complete is happening. How it is happening in
the middle of the life cycle. Can anyone explain it in detail?
Quoting from the JSF 2.0 spec:
The responseComplete() method, on the other hand, signals the JSF implementation that the HTTP response for this request has been completed by some means other than rendering the component tree, and that the request processing lifecycle for this request should be terminated when the current phase is complete. For example, an event listener that decided an HTTP redirect was required would perform the appropriate actions on the response object (i.e. calling ExternalContext.redirect()) and then call this method.
Calling ExternalContext.redirect(String) in a JSF servlet application causes a 302 response to be sent to the browser via the underlying API. In this case, it would be an error (or at least futile) to emit data in the response body, so ExternalContext.redirect(String) calls responseComplete().
If you are asking how it is happening I guess they do multi threading.
In case you are asking why it is happening, it is for the ajax requests or for repsonses that have to be submitted immediately

Resources