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

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

Related

IllegalThreadStateException when starting an Apache Camel Route with resequencer

I have an Spring Boot application which uses Apache Camel for routing along with ActiveMQ as a message broker. I also use Hawtio for routing monitorization and to stop/start the routes.
Everything is working great except for one single route, the one that has a resequencer used to sort a batch of messages before processing them. I can stop this route from Hawtio, but when I try to start the route again, Hawtio gives me this error:
{
"request": {
"mbean": "org.apache.camel:context=camel,name=\"MAIL_READER\",type=routes",
"attribute": "LastError",
"type": "read"
},
"value": {
"exception": {
"routeId": "MAIL_READER",
"localizedMessage": "Failed to start route MAIL_READER because of Route(MAIL_READER)[From[activemq:queue:MAIL_READER...",
"cause": {
"localizedMessage": "java.lang.IllegalThreadStateException",
"cause": {
"localizedMessage": null,
"cause": null,
"suppressed": [],
"message": null
},
"suppressed": [],
"message": "java.lang.IllegalThreadStateException"
},
"suppressed": [],
"message": "Failed to start route MAIL_READER because of Route(MAIL_READER)[From[activemq:queue:MAIL_READER..."
},
"phase": "START"
},
"timestamp": 1608036365,
"status": 200
}
If I remove the resequencer from the route, the stop/start works fine. I can pause/resume the route with the resequencer though, without any kind of problem. This is the Camel route definition in the Spring Boot application:
from("activemq:queue:mail_reader?transacted=true")
.resequence(simple("${header.priority}")).batch().timeout(30000)
.process(mailProcessor)
.to("activemq:queue:processed_mails");
Seems like the resequencer is trying to use the original threads instead creating new ones when I send the route start order. Is there some kind of known problem with the Camel resequencer and threads? I found this, and it seems to be solved...
Thanks in advance.

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?

Getting a 404 to this API

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.

Google Logging API - What service name to use when writing entries from non-Google application?

I am trying to use Google Cloud Logging API to write log entries from a web application I'm developing (happens to be .net).
To do this, I must use the logging.projects.logs.entries.write request. This request dictates that I provide a serviceName argument:
{
"entries": [
{
"textPayload": "test",
"metadata":
{
"serviceName": "compute.googleapis.com"
"projectId": "...",
"region": "us-central1",
"zone": "us-central1-a",
"severity": "DEFAULT",
"timestamp": "2015-01-13T19:17:01Z",
"userId": "",
}
}]
}
Unless I specify "compute.googleapis.com" as the serviceName I get an error 400 response:
{
"error":
{
"code": 400,
"message": "Unsupported service specified",
"status": "INVALID_ARGUMENT"
}
}
For now using "compute.googleapis.com" seems to work but I'm asking - what service name should I give, given that I'm not using Google Compute Engine or Google App Engine here?
The Cloud Logging API currently only officially supports Google resources, so the best course of action is to continue to use "compute.googleapis.com" as the service and supply the labels "compute.googleapis.com/resource_type" and "compute.googleapis.com/resource_id", which are used for indexing and visible in the UI drop-downs.
We also currently permit the service name "custom.googleapis.com" with index labels "custom.googleapis.com/primary_key" and "custom.googleapis.com/secondary_key" but that is not officially supported and subject to change in a future release.

Resources