How can we know the name of the page or service or state of page which has called RESTful API in java file. Something like $state.current.name in AngularJS.
I have created api's in java using #RequestMapping(). In this java file I want to know about the name of page that has called this API. As I want to call same api on different pages and want to log different strings according to the page which has requested the API. I am using $http.get(api) in AngularJS to call API.
We found the most reliable way to achieve knowledge of the current URL/state is to send it as part of the request payload. This gets around issues of HTTP referer header stripping. You already have $state.current.name, so adding this to your API-calling JS service function should be straightforward.
If you need to add this to every request, one option is to use an interceptor to add the metadata into every HTTP request which contains JSON.
Related
I have to request a PHP page with 3 Parameters (e.g. www.test.com/index.php?name=mrTest&no=1&id=10001). I'm using WSDL2JAVA for other Services and am now wondering if it is possible to generate a similar Service for this case. This PHP page Returns an XML. I'm just consumer/client of the Service.
I could also make a simple request and then use JAXB to parse the XML but i would like to implement all my Services the same way.
So, does anybody has already implement a php page consumer using WSDL2JAVA?
Best regards
So from my understanding this is a simple PHP page not a SOAP service. Remember XML is just the protocol used in a SOAP service however a SOAP service consists out of a WSDL that is published describing operations and how to call those operations.
A simple PHP page even if it returns XML data is NOT a SOAP service and thus does NOT have a WSDL. You wont be able to use WSDL2JAVA for that.
This PHP page seems more like a REST type service that returns XML instead of JSON. To be honest it really sounds like a REST service.
Try using the latest SOAPUI to connect to the page and see if you can use the REST project type with this page. If it is a REST service it might have a WADL file. YOu can use the WADL2JAVA cxf utility to generate classes to you. HOwever this is a BIG might as most REST services dont use WADL's yet. See this link on CXF
response getting from server is html response. How can i know whether the reponse is correct? how can i check that in server?
These api urls corresponds to a REST web service and thats why when you call those urls, you are getting data. So you need to create your own REST service api for your site to fetch data first.
For creating dot net based REST Service, Use this link. For creating Java based REST service, follow this link.
I am working on a project that uses Spring MVC, and one of the requirement involves sending request to an external services to handle some transactions.
The problem now is the external services only takes POST method, and I've looked everywhere and could not find a way to forward user to external site as a POST request(similar to form submit).
What we are trying to do:
1) My Controller will receives request and execute some backend thing and construct some parameters to pass on.
2) *Send request to external service via HTTP POST method with some parameters.
(note. User's browser will show URL of the external site.)
I've looked into different return types for Spring MVC and could not find anything that fits.
Any advice would be greatly appreciated.
Thanks!
You can use the Apache HttpComponents library to send HTTP requests from you controller. It's easy to use, and there's plenty of documentation and examples.
Supposed that this is not an issue related the Spring MVC. That's the same solution Which you try to implement such operations in Servlet I think.
First of all, this external site should be an async service and you neednt get the response from it, right? If yes, i think the simplest solution is that you can new URLConnection within your Servlet or Controller, construct the params and set the POST method, and then send out the request. After that, you can response to your local page as you like.
The second solution, a dummy JSP page is needed. The page will post a form to external service and redirect to the target page as you needed. No matter you use a javascript or not, I think the user will see a refresh on the browser.
You won't be able to redirect as that implies a GET.
Since your client is using a web browser, it should be possible to return an HTML document with a form, and then to submit that form (with a method attribute of POST) when the page has loaded.
this is my first post on stackoverflow.
I am quite good at Java SE and client side Java Programming, but new to Java web development.
When I search for Java webframeworks, a huge amount of framework are offered, but nothing really seems to fit my needs.
What I actually want is a dumb server and a smart client.
I want the client to ask for certain information and the server to return the requested information in a xml or json format, so that the client itself manages the data.
In most cases the webframeworks render the html pages etc. on the server side, but I just want for example to use AJAX or the android xml parser to get the information and then fill the UI on the clientside.
I am not sure, if Webservices are the right thing for me, because I want to make several async requests to the server.
Or should I simply use servlets, which just return the right xml on request.
A second thing is how to handle the authorization and authentication of the users, which send the request to the webserver.
I do not want to allow everyone to receive the xml or json, which is generated by the server.
In short:
Is there a java based webframework, which can handle authorization and authentication of users and just returns xml or json to a smart client?
Which java based webframework fits best to my needs?
On the following webpage my aim is described, but unfortunately there is no hint how to implement such a "dumb" server...
http://seng130.wordpress.com/lectures-2/web-application-architecture/
You will likely need to use multiple frameworks. Spring-Security to handle your url intercept based on authority. Then use Servlet with Spring-MVC to handle the request within the Controller methods. Tutorial here: http://static.springsource.org/spring-security/site/tutorial.html You can have those methods return string values of JSON or XML. I would suggest using Jackson to convert your objects to a JSON form on the fly and the javax libraries for XML.
Example of Spring-MVC with Jackson:
http://www.mkyong.com/spring-mvc/spring-3-mvc-and-json-example/
Example with Jersey servlet and Jackson
http://www.mkyong.com/webservices/jax-rs/json-example-with-jersey-jackson/
I want to make a POST HTTP request from a struts2 action to an external URL and send parameters in the request.
I have read that it can be done in this way: External django redirect with POST parameters but I was wondering if it can be done in a different way, let's say, directly from the action and not throgh a JSP.
Thanks for any suggestions.
It depends on what you're actually trying to do.
If you're trying to make a request from your action to another site, then do something with the response and return data to the user without the user knowing the external site was accessed, then you'd need to use something like Apache's HttpClient. That can be done anywhere, bt obviously doesn't belong in a JSP as you state.