I'm currently working on a Rest-Service that needs to call another Rest-Method provided on the same server. So for example the method on path /myPath/foo needs to request something from the method at path /myPath/restApi/bar
How can I do that with the Spring RestTemplate (or something else) without using a full path in the RestTemplate.postForObject(...) method (full path can't be used, because the url and port of the artifact aren't known when building the artifact).
Thanks for your help!
Best regards,
Andy
First of all why are you accessing a REST method on the same server (it looks like it is the same application) using URL instead of calling the service method behind that second URL directly? If this is the same servlet container but multiple WAR files than fine.
Back to your question: you do have the host and port. You are saying that when a client tries to access /myPath/foo then the server should access /myPath/restApi/bar. When you are in a controller/action/handler method/whatever your REST framework provides obtain HttpServletRequest somehow. Having request object you can find out which host and port your client used to connect to your first web service. You can use that information to call the second web service on the same server.
Second thought: if this is the same server, can't you just use localhost?
Related
I have a Java JAX-RS REST service which has many endpoints, let's say:
...
POST /api/ops/create
GET /api/items
...
Both of them served under same war file, so if I want to reach them from a client I am using following URLs:
POST http://server.domain.com:8080/the_war_file/api/ops/create
POST http://server.domain.com:8080/the_war_file/api/items
Well, the question begins here. I want to access the GET endpoint from the code behind the POST endpoint.
In other words, I want to send a GET request when I am operating the POST request.
Of course, I can send the request to the full URL with server, port and name of the war file.
However, it seems wrong, because I am already in the war file.
Or, I know I can call the method of the other endpoint directly. Is it rational?
So, are there any efficient methods/solutions to call different endpoint in the same war file? (Like routing etc.)
I know I can call the method of the other endpoint directly. Is it
rational?
Yes, this is perfectly fine where in your code behind one request you will call a method of some class that is used for serving some other request. There is no need to send extra HTTP request unless you have a specific need for invocation of that method to be triggered by HTTP request
I have created a spring boot application. I am using a third party API class for my service response. In my controller I have created a GET method with query parameter and inside the method I am calling the service class. Inside the service class I am using the third party API (to get the response).
The problem here the third party API has one authentication API key to use there API call. And when I am running the spring boot application and calling my API while connected to the VPN then it's throwing APIException:SocketTimeout. But when I disconnect the VPN the response comes as expected. Could anybody please suggest me how to overcome this issue. Or how should I bypass my network proxy.
Thank You
so this means that you have a network issue. Either the domain that you're accessing block your vpn region or from your vpn there is some limitations. Could you please make a curl, and see where you're request got blocked ? If doesn't pass your vpn connection, please discuss with your network admin to add it to some sort of whitelisting.
i have inherited a java app that integrates with desktop QB. There's something in the structure of this whole setup i'm not understanding. This is my first go with the QB api as a developer.
the QB Web Connector 2.2.0.71 is installed and functional. I see the .qwc file and understand it, and it is loaded into the web connector. There is an Application class that publishes an endpoint to the same URL as in the .qwc file and then starts a class named QBWebService. this web service class implements com.intuit.developer.TroubleshootWebServiceFSSoap and has methods authenticate, sendRequestXML, etc. Method sendRequestXML has the code i am testing and attempting to modify. but, before i can do that i need to understand the XML going back and forth.
since i don't know what i don't know, if i'm asking the wrong questions, by all means, please say so.
is it correct, then, that the web connector (on schedule) launches the application class and calls the sendRequestXML method?
i was expecting to find a URL that i could send XML to with something like SOAPui in order to test the XML and examine the response, but that doesn't seem to be how this web service works. is it possible to set it up this way?
perhaps i don't understand what the QB web connector application is doing. what is the purpose of opening up the URL on localhost if it can't accept XML via POST?
thanks in advance for the help
--matt
is it correct, then, that the web connector (on schedule) launches the application class and calls the sendRequestXML method?
Yes, that's correct.
i was expecting to find a URL that i could send XML to with something like SOAPui in order to test the XML and examine the response
You can send requests to your SOAP service (e.g. you can call the sendRequestXML method for example).
You'll get back an XML response that (if you were the Web Connector) you would then relay to QuickBooks. QuickBooks would process the response, and then call the receiveResponseXML method to send the XML response back up to your web service.
perhaps i don't understand what the QB web connector application is doing.
It sounds like you're expecting QuickBooks to provide a SOAP endpoint, which you can then directly send XML requests to to query data directly from QuickBooks.
This is not really how the Web Connector works. The Web Connector sort of works "backwards".
Instead of connecting directly to QuickBooks, the Web Connector connects to you (your SOAP endpoint) and asks you "Hey, give me something to do!" (i.e. send me the request XML you want to run against QuickBooks). You then give it an XML request, which it runs against QuickBooks, gets the response, and then connects to you again and says "here's what QuickBooks responded to your request with" (i.e. here you go, receive this response XML from QuickBooks).
So the Web Connector essentially polls a SOAP endpoint you provide, asking you to give it XML requests to pass through to QuickBooks.
Longer explanation here:
http://www.consolibyte.com/docs/index.php/QuickBooks_Web_Connector_Overview#About_the_QuickBooks_Web_Connector
i have created a Java Restful Web service. Now i want to access it in Android. There are different methods in Webservice. Web service is running on http://192.15.10.62:8080.
how should i call a method named getGreetingMsg() in webservice which take a string argument and return a simple String message.
Web service Details
Project name RestFulWS
package Name rest.ws.server
class Name helloAndroid
Method Name getGreetingMsg(string argument)
any help will be appreciated.
Simply with an HTTP client like AndroidHttpClient.
EDIT: RESTful web service is accessible through URL like:
http://yourserver/someservice/<categoryID>/<objectID>
So, you can test your webservice from a web browser like Internet Explorer or Mozilla Firefox.
Then, on Android, use HTTP Get request and the AndroidHttpClient.
Don't forget to set the INTERNET permission in your AndroidManifest.xml too
It depend on the Web server you are using because each type of server will have its own URL to service hosted on it. If you are using JBOSS server then your URL looks like this
IP:PORT/projectname/webservicename/method name
Sounds like you're not sure how to approach your own API. If your API supports GET, then open a web browser and try some GET commands. Once you have a GET statement working, work through this tutorial: http://sarangasl.blogspot.com/2011/06/android-login-screen-using-httpclient.html.
Once you're set with POST, turn off GET in your webserver.
Good luck!
db
My application neeeds to access a third part web service.
Of late, they have introduced a load balancer, which redirects to the server.
Because of this the webservice gets a 302 - Redirect error as response.
In the SOAPUI, I was able to enable a property called "Follow Redirect", and because of this service followed the redirect and served by the server.
Now is there a similar propety that can be turned on in the code, which would make the webservice follow the request?
(The calling code is java and the webservice is in .net)
This needs to be supported by the library implementing the actual call to the web service, and there is not a generic way of setting this.