Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to solve this seneraio in Java web applications?  RSS feed

 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

I am working on a Java Web application which has two types of client web(web Browser) and mobile(Android,IOS)

So far I have maked logic for server side is

1)Request for page to page Controller
2)Get the data require from DAO
3)Set data on request using request.getParameter("ObjName",data);
4)Get the data in JSP page and parse using Tag Library

so far I am thinking and this is working fine

Now problem is here
I am also making its android app so I can't pass same Object as I pass for JSP page to android app.So I have to use JSON format for web and mobile to transfer data.

So I am thinking logic like this

1)Web client->request for page controller->page controller get data and convert it to JSON->use request.getRequestDispatcher("")->Parse JSON in jsp

2)Mobile Client->request for get or Post to a URL->URL performs its work->send JSON to mobile client->Mobile client get status


now
suppose I request for some URL

"/someURL"

both web and mobile are calling it how can differentiate request whethar comming from android app or web browser because I can't write same code for two url request because one is request.getRequestDispatcher("") and other is simple mobile client for JSON parse.

hope my point is clear









 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kishor Joshi wrote:3)Set data on request using request.getParameter("ObjName",data);

There is no getParameter method on the request. Did you mean setAttribute?

I am also making its android app so I can't pass same Object as I pass for JSP page to android app.So I have to use JSON format for web and mobile to transfer data.

No you don't. A one-size-fits-all approach is doomed to fail. If you are going to continue to use JSP, you shouldn't try to shoehorn a different approach into it.

For the mobile app, develop a RESTful API.

If you'd rather not support both approaches, drop the JSP approach and write the web app as a JavaScript SPA (single-page application) that consumes the same RESTful API.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean to say

seprate logic for mobile and web client

Mean JSP logic is same

I need to develop seprate Restful APIs for mobile clients?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kishor Joshi wrote:Mean JSP logic is same

Yes. Trying to make a JSP do handstands to accept JSON rather than scoped variables would be high folly, in my opinion.

I need to develop seprate Restful APIs for mobile clients?

"Need" is a strong word. It's the way I would approach it, however. And, I'd approach a new web app as a JavaScript SPA rather than use JSP, so I could use the same RESTful API for both applications.

Or, if you want to stay with a traditional JSP application, there's nothing that says that your servlet controllers can't use the RESTful API as the model. I do that with one of the applications I am currently supporting.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got my solution

I think developing Restful APIs seprate for client other than JSP will work for me
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I have one more question realted to Rest Client Verfication


suppose my URL is like this

http://myIPAddress:myPort/myURL


and I am using this from Android App and IOS app or other clients

so this URL is hard coded in my web application
so anyone who renginner my code can get that URL and can make a application which communicate in exactly same way as my application

so this is security hole
so how can I verfiy a REST clients that request is comming from trusted source?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Authentication and authorization, just like any other server-side service. Do you not secure your backends now?
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes I want to secure backends
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!