we made a HTML5 mobile app, & now we are creating a IOS native App. We want the IOS app to call methods on the Java servlet (with stripes) (running the HTML5 App) so that we can use the same behind-the-scenes logic. Do we need to setup a web service to do this?
I.E we would like to just call the existing Stripes action beans from IOS (as they are already set up to receive ajax requests, but will this violate the cross-domain law)?
Thanks!
Cross-domain isn't an issue if you're making requests from a native app, so it should be possible to make requests to your AJAX ActionBeans directly.
You can directly call the logic by using API and get the response. Do servlet mapping to the url pattern you need. then in servlet extend the HttpServlet and override doGet and doPost method, which has HttpServletRequest and HttpServletResponse as input parameters, which can be used to communicate with your mobile app.
Related
I have made school management software...for the server side I have designed the admin panel using servlet and jsp technology.and have used mysql database and for the client I have created an Android app. I want to perform login and logout authentication and fetch data of that particular user on his app.. but I m unable to integrate. I need to know what are ways through which this thing is done professionally....
Thanks in advance
At your backend side you have your servlet which handles incoming requests GET or POST. So in android app you just need to make call to your servlet and handle the response.
In android
1. Get the user credentials and pass it along with your request.Either make GET request and append your credentials to servlet url or pass the parameters as POST request.2. To make network calls use libraries such as Volley, Retrofit or you can even use android built-in AsyncTask.(If you are a beginner start with AsyncTask first and then upgrade to libraries mentioned).
Professional way is to develop REST apis at your backend and call them from your android app.
I'm adding a simple web interface with the already working backend I wrote in Java for and Android app. I know there is a way for exposing GAE ednpoints to JS. https://cloud.google.com/appengine/docs/java/endpoints/consume_js
Instead I want the calls to the endpoint to be generated from a java servlet and pass them to a JSP so I initialise the UserEndpoint and call it's methods inside the doGet().
Is there anything wrong with this method ?
I have studied the java in app billing code snippet at
https://developers.google.com/in-app-payments/docs/tutorial
and I am unable to use it to make my application capable of doing in app payments.
My first question is how do I set up a servlet to handle payment requests. Do I put the getJWT() method in the servlet and call it from the doPost() method?
My second question is what do I do with the String that getJWT() returns? It should be the json object that holds the purchasing information, but I don't know how the jsp file I have should process it.
I have searched for example code using java servlets and jsps to study but found none. I have found python code, but I can't translate python into java yet. If anyone knows of an example (complete) of google in app billing using java servlets and jsps I would appreciate it if you could post a link also.
Thank you.
On the server you need an HttpServlet derived class that takes the order request (in doPost()), calls the JWT libraries together with the Seller Secret to generate the signed JWT string, then returns the result in the response.
On the client side in the HTML page you can use a templating system (e.g. AppEngine + JSPs) or Ajax calls to your servlet to get the generated JWT.
The generated JWT is one of the paramenters to the goog.payments.inapp.buy() JavaScript API.
Below is a simple AppEngine Python implementation of In-App Payments. You can re-use the client-side code and replace the server-side with the Java implementation:
https://code.google.com/p/iap-python/
I am thinking if its possible to user a GWT RPC Servlet (like MyServiceImpl) as callback URL for oauth? The oauth provider will call the callback URL and then pass URL parameters to that callback, is it possible that capture those URL parameter in the RPC servlet?
It is possible to do something like this. RemoteServlet is just another normal servlet, you can override its doPost() and doGet() methods. You will just need to filter incoming requests, if it is an Oauth callback handle it, if it is GWT-RPC request (you can find this out by checking for specific GWT HTTP headers), just delegate it to the super class.
But in reality it is better to keep those two things separated. There can't be a real reason why one servlet should be handling Oauth callbacks and GWT-RPC requests.
The deserialization that GWT uses would make this pretty tricky. It also has a lot of restrictions through it's whitelisting of the exact way in which data can be read from the request. You would probably be better off to override the 'service' method and intercept any oauth callbacks before GWT gets to them.
I'm developing a servlet that gets a name of a web service and could be forward the request to an external web service, for example: http://www.webservice.com/...
I have build a response wrapper that intercept response output but I can't forward request to an external web service, it works only if I redirect the request to a servlet that is on same server.
Example:
request.getRequestDispatcher("aMyServlet").forward(request, response) // WORKS
request.getRequestDispatcher("http://www.webservice.com/...").forward(request, response)
Doesn't because Tomcat searches http://www.webservice.com/... on the server as a local resource.
How can I do external request?
Thanks
forward method that you are using is used for communicating between server resources, (eg: servlet to servlet as you have found out) If you want to redirect to another location, you can use the HttpServletResponse's sendRedirect method.
Better option is to
Perform your own HTTP request and stream the results back to the
browser. This sounds harder than it is. Basically you create a
java.net.HttpURLConnection with the URL of the web site you want to
"redirect" to. This can actually contain the query parameters (as long as
they're not too large) since it will never be sent to the user's browser
either and will not appear in the browser URL bar. Open the connection, get
the content and write it to the Servlet's OutputStream.
To make any request to an outside service, you'll have to explicitly make a new HTTP request and handle its response. Take a look at the HttpUrlConnection class.
You don't mention what kind of service you want to invoke, but either way, your servlet is functioning as a service client, so you should be looking at service client technologies.
For invoking REST style services, java.net.URL or Apache Commons HttpClient can be used to send a request for a URL and fetch the reponse.
For invoking SOAP services, you can use Apache Axis, or Java WSIT.