I have a local API service that is under a sub domain:
http://sub.192.168.1.1/api/endpoint
By adding the IP redirect to my machine's Hosts file, I can test and consume the API well when using browser tools like Postman, and even opening them via the browser itself (some don't have security at all and just returns plain JSON). Now I tried adding the IP redirect to my device's hosts file too so it can access the subdomain as well as my dev machine. All goes well and I can directly access the APIs via the browser, but when using the app, the endpoints can't be found.
I'm using Retrofit with OkHttp as of now. Hoping anyone can shed a light with this problem.
Did you try at retrofit object to add slash at the end of URL?
.baseUrl("http://sub.192.168.1.1/api/endpoint/")
.build();
Related
I have a Java Application running on Tomcat. I want to get the details of all machines installed in Microsoft Azure portal by taking user's subscription details as input. Preferably a REST API. I am expecting response same like what we get in azure resource explorer.
I made a request with this url "https://management.core.windows.net/"+subscriptionId+"/services/disks" following this method. It gives me result like this
<Disks xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Disk>
<AttachedTo>
<DeploymentName>TEST1</DeploymentName>
<HostedServiceName>TEST1</HostedServiceName>
<RoleName>TEST1</RoleName>
</AttachedTo><OS>Linux</OS>
<Location>South Central US</Location>
<LogicalDiskSizeInGB>30</LogicalDiskSizeInGB>
<MediaLink>link.vhd</MediaLink>
<Name>TEST1-TEST1-0-20</Name>
<SourceImageName>imageName</SourceImageName>
When I call the same method with
"https://management.azure.com/subscriptions/"+subscriptionid+"/providers/Microsoft.Compute/virtualMachines?api-version=2016-03-30" I am getting 401 error.
I even tried downloading the SDK , ListVirtualMachines.java is listing some 600 images, not the one under my subscription.
How Can I achieve it using JAVA REST API?
Per my experience, this issue is due to the authentication method. I do all the requests that you have made and I get the same results with you.
The 401 error code means "Unauthorized". Your authentication method is right for the old REST API request, but not for new.
The new authentication is handled by Azure Active Directory(AD).
The followings may be useful for you.
You could figure out Virtual Machines Rest API by this URL https://msdn.microsoft.com/en-us/library/mt163647.aspx.
You could understand how to authenticate Azure Resource Manager Request by Azure Active Directory by this URL https://msdn.microsoft.com/en-us/library/dn790557.aspx.
Hope it helps. Any concerns, please feel free to let me know.
I am looking for something similar to this but using JAVA rest API calls.
I want to get the list of all the resources (including virtual machines, storage disks, network devices etc) and their basic properties(like ip address, disk space etc)
I have tried making API calls following this link.
When I make an http request to this url
"https://management.azure.com/subscriptions/"+subscriptionId+"/resourceGroups/"+resourceGroupName+"/providers/Microsoft.Compute/virtualMachines?api-version="+apiVersion
But I am getting a 401 error. Am I calling the right URL ? if not which URL I should be calling ?
But I am getting a 401 error. Am I calling the right URL ? if not
which URL I should be calling ?
You're calling the right URL however you're providing incorrect parameters to the API call. The link you mentioned is for making Azure Service Management API calls however what you need to dod is make Azure Resource Manager (ARM) API calls.
Like Azure Service Management API, ARM API requests need to be authenticated. In case of former, the requests are authenticated by using a management certificate. In case of latter, you would need to use a token that you get by authenticating the user against an Azure AD.
Please see this link for more details on authenticating/authorizing ARM API requests: https://azure.microsoft.com/en-us/documentation/articles/resource-manager-api-authentication/.
In order to list all resources in a resource group, you can definitely make use of ARM REST API. However now SDKs are available for you that you can consume directly. To learn more about these SDKs, please see this link: https://azure.microsoft.com/en-in/blog/azure-resource-manager-preview-sdks/.
I have 2 GAE apps running (GAE1 and GAE2). I have to update the datastore of GAE2 from GAE1. How can I achieve this in Java? Does GAE provide any APIs for cross GAE datastore updates?
Note:
I tried making a PUT request through the browser, by enabling CORS on the source and destination GAEs. Unfortunately CORS works only for GET and HEAD.
This issue is fixed in the following way, (Note my requirement is I should not use Remote API from GAE.)
Open an URL in the destination GAE allow this url alone, if it contains a secure request header.
For example:
public void filter(ContainerRequestContext requestContext) {
if (requestContext.getUriInfo().getPath().contains("intgr")
}
Check for the request header that you pass, if it is present in the destination GAE.
Write your REST service in this url path /intgr and send back the response to the Source GAE.
In addition to the Cloud Datastore API mentioned previously, you can also use the Remote API to access services across different App Engine applications including Datastore.
I have a secure(https:443) application Running on Amazon Web services(AWS) have TOmcat7 and Apache http server to it.The URL looks like this https://ama.its.com/service. This works perfectly.
Their is a new requirement for cost effective alternative to run the development AWS instances of our Application on a non-standard ssl port like "23456". So the URL now becomes https://ama.its.com:23456/service. I have a Servlet implementation in our code. When i do a "request.getRequestURL().toString();"it returns the URL with out Port# https://ama.its.com/service. This is causing problems for my application. I want the URL to include the port# in it.
I googled on this a bit i saw this post. The Post tells that Apache server is masking the PORT and reconstructing the URL with out port. The post suggested a work around for getting the URL from the Request header, but i don't want to go that route now until i find out if their is a fix for it. I also looked in the Apache http logs if something funny is going on their. i couldn't find out anything suspicious.
Is their any way i can tell the server not to exclude the Port# in the URL?
Their is something buggy with Apache HTTP server when using a non standard ssl Port other that 443. When the URL is being sent the Port is stripped out in the request object. Alternatively getting the URL from the Request Header is a good option.
That option did not fit my needs as i have one website to the user but the Content i displayed in the Iframe of the website is actually loading the data on a different tomcat (Which is AWS server). So basically the request header gave the URL of the main URL than the URL of the website running inside of the iframe.
I have a workaround that fits to my project need to store the URL of the website with in the IFrame to get from a properties file and use it .
I am trying to make an upload to YouTube from my Java based web app, I spent a few days to understand what and where is the problem and I cannot get it, for now I am pulling my hair out off my head.
I registered my web app in Google Console, so I got a pair of Client ID and Secret and a possibility to download JSON type file with my config.
So here is the config:
{
"web":{
"auth_uri":"https://accounts.google.com/o/oauth2/auth",
"client_secret":"***",
"token_uri":"https://accounts.google.com/o/oauth2/token",
"client_email":"***",
"redirect_uris":["http://localhost:8080/WEBAPP/youtube-callback.html","http://www.WEBAPP.md/youtube-callback.html"],
"client_x509_cert_url":"***",
"client_id":"***",
"auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs",
"javascript_origins":["http://www.WEBAPP.md/"]
}
}
How is possible that I am getting the default URL from Google?
The redirect URI in the request: http://localhost:8080/Callback did not match a registered redirect URI
It always gives me the default http://localhost:8080/Callback URL instead of mine.
And IDE console shows me that:
Please open the following address in your browser:
https://accounts.google.com/o/oauth2/auth?client_id=***&redirect_uri=http://localhost:8080/Callback&response_type=code&scope=https://www.googleapis.com/auth/youtube.upload
Attempting to open that address in the default browser now...
I am using the last version of dependencies:
google-api-services-youtube v3-rev99-1.17.0-rc and google-api-services-youtubeAnalytics v1-rev35-1.17.0-rc
I think I encountered the same problem as you. I addressed this problem with the following steps:
1) Go to Google Developers Console
2) Set JavaScript origins:
http://localhost
3) Set Redirect URIs:
http://localhost:8080
http://localhost:8080/Callback
When your browser redirects the user to Google's oAuth page, are you passing as a parameter the redirect URI you want Google's server to return to with the token response? Setting a redirect URI in the console is not a way of telling Google where to go when a login attempt comes in, but rather it's a way of telling Google what the allowed redirect URIs are (so if someone else writes a web app with your client ID but a different redirect URI it will be disallowed); your web app should, when someone clicks the "login" button, send the browser to:
https://accounts.google.com/o/oauth2/auth?client_id=XXXXX&redirect_uri=http://localhost:8080/WEBAPP/youtube-callback.html&response_type=code&scope=https://www.googleapis.com/auth/youtube.upload
(the callback URI passed as a parameter must be url-encoded, btw).
When Google's server gets authorization from the user, then, it'll redirect the browser to whatever you sent in as the redirect_uri. It'll include in that request the token as a parameter, so your callback page can then validate the token, get an access token, and move on to the other parts of your app.
If you visit:
http://code.google.com/p/google-api-java-client/wiki/OAuth2#Authorization_Code_Flow
You can see better samples of the java client there, demonstrating that you have to override the getRedirectUri method to specify your callback path so the default isn't used.
The redirect URIs are in the client_secrets.json file for multiple reasons ... one big one is so that the oAuth flow can verify that the redirect your app specifies matches what your app allows.
If you visit https://developers.google.com/api-client-library/java/apis/youtube/v3 You can generate a sample application for yourself that's based directly off your app in the console, in which (again) the getRedirectUri method is overwritten to use your specific callbacks.
I was able to get mine working using the following Client Credentials:
Authorized JavaScript origins
http://localhost
Authorized redirect URIs
http://localhost:8090/oauth2callback
Note: I used port 8090 instead of 8080, but that doesn't matter as long as your python script uses the same port as your client_secret.json file.
Reference: Python Quickstart
You need to go into the developer console and set
http://localhost:8080/WEBAPP/youtube-callback.html
as your callback URL.
This video is slightly outdated, as it shows the older Developer Console instead of the new one, however, the concepts should still apply. You need to find your project in the developer console and register a callback URL.
I thought I had this configured but it turns out I set the URL in the wrong place. I followed the URL provided in the Google error page and added my URL here. Stupid mistake from my part, but easily done. Hope this helps