Getting a 404 to this API - spring-boot

I have an API here: https://github.com/BillyCharter87/Tech-O-Dex-API/tree/AddingSpringJPA
I continue to get a 404 on either the /greeting or /health. The application starts up fine and deploys on 8080, I've also tried changing the listener port to something else but to no avail.
My Request:
{
"firstName": "Billy",
"lastName": "Charter"
}
Headers:
Content-Type: application/json
Accept: application/json
Response I get back:
{
"timestamp": "2018-04-22T16:20:30.874+0000",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/greeting"
}
Thanks!

SpringBoot main class scans the folder "below" to find components.
Your Application.java is at the same level as your components, so none of your spring components are found.
Reorganize your project's sources as follow:
com/projectname/Application.java
com/projectname/controller/GreetingController.java
com/projectname/service/GreetingService.java
com/projectname/model/...
com/projectname/dto/...
com/projectname/dao/...
Also, while you're at it, remove the #Component on your DTO.

Related

How To Get Data from Db in intellij in Soring Framework using spring boot?

Postman Screens Browser ScreenshotI want to get employee data but this error showing.
what is the solution for this?
I have included all dependencies
{
"timestamp": "2020-12-21T12:53:24.307+00:00",
"status": 404,
"error": "Not Found",
"message": "",
"path": "/bookme/getEmpById"
}
Have you configured the server.servlet.context-path property? If configured, add it to the port

How to send error response as json in Grpc using envoy-proxy

I am throwing error from grpc service using resonseObserver.onError() but I am not getting messages in json format while hitting REST API from rest client, though the positive scenario is working fine and giving response as json.
I am using envoy as a transcoder, can anyone help me with how to get error response also as json. Currently I am getting BadRequest on error scenarios. The project is in SpringBoot.
TIA
You can use convert_grpc_status: true for do this.
http_filters:
- name: envoy.filters.http.grpc_json_transcoder
typed_config:
"#type": type.googleapis.com/envoy.extensions.filters.http.grpc_json_transcoder.v3.GrpcJsonTranscoder
proto_descriptor: "/tmp/envoy/proto.pb"
services: ["xxxxxxxx"]
convert_grpc_status: true
print_options:
always_print_primitive_fields: true
always_print_enums_as_ints: false
preserve_proto_field_names: false
If you mean return details key like this:
{
"code": 3,
"message": "API call quota depleted",
"details": [
{
"#type": "type.googleapis.com/google.rpc.ResourceInfo",
"resourceType": "xxxxxx",
"resourceName": "",
"owner": "",
"description": ""
}
]
}
You MUST compile you .proto file with:
import "google/rpc/error_details.proto";
because Envoy can't deserialize binary details from your backend server without error types.
Also you can read how you can send detailed error response with Python: How to send error details like as BadRequest

Send custom error response in Spring Cloud Gateway when no route matches

In Spring Cloud Gateway , I want to send a custom error in case a particular predicate match fails . For eg:-
I have a Path and a header predicate. Something like this -
- id: test
uri: http://localhost:8000/
predicates:
- Path=/consignment
- Header=h,h1
So if the path mathces and header doesn't , the request fails with not found error something like by default-
{
"timestamp": "2020-03-08T20:05:42.440+0000",
"path": "/test",
"status": 404,
"error": "Not Found",
"message": null,
"requestId": "6dd2e799"
}
But I want to send a custom response mentioning that the header is not present.
Is there a way to do that?

WEB_HOOK channel unavailable when trying to retrieve Google calendar events

I'm trying to use Push notifications for Google Calendar
Callback endpoint is hosted on Heroku. appname.herokuapp.com is verified in Search Console and added to Google Console APIs & Services Allowed domains list.
Request
POST /calendar/v3/calendars/CALENDAR_ID/events/watch HTTP/1.1
Host: www.googleapis.com
Authorization: Bearer TOKEN
Content-Type: application/json
{
"id":"1",
"type": "web_hook",
"address":"https://APPNAME.herokuapp.com/change"
}
Response
400 Bad Request
{
"error": {
"errors": [
{
"domain": "push",
"reason": "channelUnknown",
"message": "WEB_HOOK channel unavailable for:
{address=https://APPNAME.herokuapp.com/change}"
}
],
"code": 400,
"message": "WEB_HOOK channel unavailable for: {address=https://APPNAME.herokuapp.com/change}"
}
}
What
WEB_HOOK channel unavailable
error means?
EDIT: same result with a top level domain which certificate's Subject matches exactly the domain name.
It appears that this was a temporary issue and is now fixed according to Google. (I also tested and seems to be working for me, now.)

Do Google API keys work for Prediction API?

I am trying to use a Server API Key following the instructions at https://developers.google.com/console/help/new/#generatingdevkeys
I have generated a key and whitelisted my IPs (tried from two different ones so far).
However, every response I send results in 401 Unauthorized. My HTTP request looks like this:
Request from an IP associated with the key
POST https://www.googleapis.com/prediction/v1.6/projects/652546152834/hostedmodels/website/predict?key={MY_API_KEY_IS_HERE} HTTP/1.1
User-Agent: Fiddler
Host: www.googleapis.com
Content-Length: 0
Response
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
Am I missing a step? I'd prefer not to use OAuth since it seems like overkill for my simple scenario, but I'll do that next if there's no solution here.
Your application must use OAuth 2.0 to authorize requests. No other authorization protocols are supported.
Source

Resources