Unable to fetch the metadata : Failed to execute OData Metadata request - s4sdk

I am trying to read data from S4hana cloud.
I configured the destination in cloud foundry where authentication type is OAuth2SAMLBearerAssertion.
and I wrote a little servlet also to get the data using VDM mechanism.
But I am getting below error when I am calling the endpoint
Caused by: com.sap.cloud.sdk.cloudplatform.connectivity.TokenRequestFailedException: Failed to get access token: no valid JWT bearer found in "Authorization" header of request.
2018-10-09T15:34:52.84+0530 [APP/PROC/WEB/0] OUT at com.sap.cloud.sdk.cloudplatform.connectivity.TokenRequest.getCurrentJwt(TokenRequest.java:308)
2018-10-09T15:34:52.84+0530 [APP/PROC/WEB/0] OUT at com.sap.cloud.sdk.cloudplatform.connectivity.TokenRequest.requestTokenWithUserTokenGrant(TokenRequest.java:352)
2018-10-09T15:34:52.84+0530 [APP/PROC/WEB/0] OUT at com.sap.cloud.sdk.cloudplatform.connectivity.XsuaaService.requestAccessToken(XsuaaService.java:135)
2018-10-09T15:34:52.84+0530 [APP/PROC/WEB/0] OUT at com.sap.cloud.sdk.cloudplatform.connectivity.XsuaaService.getServiceToken(XsuaaService.java:197)
2018-10-09T15:34:52.84+0530 [APP/PROC/WEB/0] OUT at com.sap.cloud.sdk.cloudplatform.connectivity.DestinationServiceCommand.getAccessToken(DestinationServiceCommand.java:109)
2018-10-09T15:34:52.84+0530 [APP/PROC/WEB/0] OUT ... 31 common frames omitted
I have followed https://blogs.sap.com/2018/02/05/deep-dive-8-with-sap-s4hana-cloud-sdk-leverage-principal-propagation-via-oauth-2-when-consuming-a-business-api-from-s4hana-cloud/.

Have you setup security / configured an approuter?
The error message indicates a missing JWT in the request.
See also: https://blogs.sap.com/2017/07/18/step-7-with-sap-s4hana-cloud-sdk-secure-your-application-on-sap-cloud-platform-cloudfoundry/

Related

How to fix this Error parsing HTTPS request header?

[http-nio-6014-exec-2] org.apache.coyote.http11.Http11Processor:175 log - Error parsing HTTP request header
Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Invalid character found in method name
If i creating JARs running in container mode, I am able to access the url but in intelli j, its seems to be not working

Unable to catch logs of a post request to a service

I am making an axios post request to a service and in the xml response from the server, I'm getting a resCode:1008 and response message of system error: please retry, however, from the service, I am unable to see the error logs of the request to the service.

feign-okhttp post request with url query parameters

I currently have replaced httpurlconnection to feign-okhttp in my projects. I use the following edition:
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-okhttp</artifactId>
<version>9.6.0</version>
</dependency>
but I got a problem when I post this url: "http://gclife-platform-service:20000/v1/user/login/log?userId=ea9dd2f707a54b11b03193c35b2ad3a4&error=SUCCESS"
The log from server side as following:
Received [1.1
cache-control: no-cache
...
But "Received [1.1" should be:
Received [POST v1/user/login/log?userId=ea9dd2f707a54b11b03193c35b2ad3a4&error=SUCCESS HTTP/1.1
So this caused the parse problem.
2018-05-05 10:10:04.076 DEBUG 6525 --- [io-20000-exec-9] o.apache.coyote.http11.Http11Processor : Error parsing HTTP request header
java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens
when I post url with no query parameters like "http://gclife-platform-service:20000/v1/message/sms/verifycode/check", I got:
Received [POST /v1/message/sms/verifycode/check HTTP/1.1
This is the correct result.
How can I get the correct log like this? Can anyone help? Thanks.
This exception can occur when you try to execute https request from client on endpoint which isn't https enabled. Client will encrypt request data when server is expecting raw data.
Change https:// to http:// in your client url.
I made the same mistake.
print Feign header and find Content-Length was duplicate definition.

Spring Boot Google Drive Api Connection

I am developing one spring boot application where I have to upload files to the google drive.
I have tried to authenticate using GoogleOAuth2Template. Below is code snippet
GoogleOAuth2Template template = new GoogleOAuth2Template(clientId,
clientSecret);
AccessGrant accessGrant =template.authenticateClient();
But when calling authenticateClient() I am getting 404 error.
org.springframework.web.client.HttpClientErrorException: 400 Bad Request
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:700) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:653) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:613) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:531) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.social.google.connect.GoogleOAuth2Template.postForAccessGrant(GoogleOAuth2Template.java:48) ~[spring-social-google-1.0.0.RELEASE.jar:1.0.0.RELEASE]
at org.springframework.social.oauth2.OAuth2Template.authenticateClient(OAuth2Template.java:194) ~[spring-social-core-1.1.0.RELEASE.jar:1.1.0.RELEASE]
at com.cookwala.controller.GoogleDriveController.connectToAPi(GoogleDriveController.java:26) ~[classes/:?]
at com.cookwala.controller.GoogleDriveController$$FastClassBySpringCGLIB$$ffe75835.invoke(<generated>) ~[classes/:?]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:721) ~[spring-aop-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:97) ~[spring-aop-4.3.7.RELEASE.jar:4.3.7.RELEASE]
Also tired calling overloaded method authenticateClient(String scope) , still getting same error.
I am doing above code to get the instance of org.springframework.social.google.api.Google so that can create directory and upload file to Google Drive.
Am I missing something here or is there any other way to get access token from google to connect to google api.

UnknownHostException: graph.facebook.com

I am trying to login with facebook, with spring-social, but after of login in facebook I got the next error:
ERROR: org.springframework.social.connect.web.ProviderSignInController - Exception while completing OAuth 2 connection:
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://graph.facebook.com/v2.3/oauth/access_token":graph.facebook.com; nested exception is java.net.UnknownHostException: graph.facebook.com
In the rest template class, after doExecute(expanded, method, requestCallback, responseExtractor); appears the error, expanded is https://graph.facebook.com/v2.3/oauth/access_token, method POST.
My code is from spring-social-samples, from github.Maybe the problem is in my account of facebook developer???

Resources