[ https://issues.apache.org/jira/browse/OFBIZ-13152?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17898528#comment-17898528 ]
Sixty One edited comment on OFBIZ-13152 at 11/15/24 8:46 AM: ------------------------------------------------------------- Oh well...I wondered why our API responses are messed up from time to time. Here we are. I easily reproduced the behavior as we heavily use OFBiz with REST. Side note: The swagger-ui is an automatically generated UI to document and test the REST endpoints for RESTful services. Within OFBiz it's available on [http://localhost:8443/docs/swagger-ui.html] when you have the rest-api plugin checked out. I exported the createProject-service for the REST-API on latest trunk: {code:java} diff --git a/applications/workeffort/servicedef/services.xml b/applications/workeffort/servicedef/services.xml index e35d0e7662..3628f44fd3 100644 --- a/applications/workeffort/servicedef/services.xml +++ b/applications/workeffort/servicedef/services.xml @@ -39,7 +39,7 @@ under the License. <override name="description" allow-html="safe"/> </service> <service name="createWorkEffort" default-entity-name="WorkEffort" engine="groovy" invoke="createWorkEffort" - location="component://workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy"> + location="component://workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy" export="true" auth="true" action="POST"> <description>Create a WorkEffort Entity</description> <permission-service service-name="workEffortGenericPermission" main-action="CREATE"/> <implements service="interfaceWorkEffort"/> {code} Grab a fresh JWT: {code:java} $ curl -kX POST "https://localhost:8443/rest/auth/token" -H "accept: application/json" -H "Authorization: Basic YWRtaW46b2ZiaXo=" { "statusCode" : 200, "statusDescription" : "OK", "successMessage" : "Token granted.", "data" : { "access_token" : "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MzE2NTg1MzEsImV4cCI6MTczMTY2MDMzMSwiaXNzIjoiQXBhY2hlT0ZCaXoiLCJ1c2VyTG9naW5JZCI6ImFkbWluIn0.TIhR8pAW9t74oXDiOUWwVuwjQJsBXEpC2duco-M5yevYfkVesn1gA7nc8daYRtwtBqxsfq10Wq5TT3iozMwgnA", "token_type" : "Bearer", "expires_in" : "1800" } } {code} Create a new project: {code:java} $ curl -k -X 'POST' 'https://localhost:8443/rest/services/createWorkEffort' -H 'accept: application/json' -H 'Content-Type: application/json' -H 'Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MzE2NTg1MzEsImV4cCI6MTczMTY2MDMzMSwiaXNzIjoiQXBhY2hlT0ZCaXoiLCJ1c2VyTG9naW5JZCI6ImFkbWluIn0.TIhR8pAW9t74oXDiOUWwVuwjQJsBXEpC2duco-M5yevYfkVesn1gA7nc8daYRtwtBqxsfq10Wq5TT3iozMwgnA' -d '{"workEffortName": "my-first-project", "workEffortTypeId":"PROJECT", "currentStatusId":"PRJ_ACTIVE"}' { "statusCode" : 200, "statusDescription" : "OK", "data" : { "workEffortId" : "10000" } }{code} Provoke an error for the first time - Here we receive the OFBiz service error message: {code:java} $ curl -k -X 'POST' 'https://localhost:8443/rest/services/createWorkEffort' -H 'accept: application/json' -H 'Content-Type: application/json' -H 'Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MzE2NTg1MzEsImV4cCI6MTczMTY2MDMzMSwiaXNzIjoiQXBhY2hlT0ZCaXoiLCJ1c2VyTG9naW5JZCI6ImFkbWluIn0.TIhR8pAW9t74oXDiOUWwVuwjQJsBXEpC2duco-M5yevYfkVesn1gA7nc8daYRtwtBqxsfq10Wq5TT3iozMwgnA' -d '{"workEffortName": "my-first-project", "workEffortTypeId":"PROJECT", "currentStatusId":"PRJs_ACTIVE"}' { "statusCode" : 422, "statusDescription" : "Unprocessable Entity", "errorType" : "GenericEntityException", "errorMessage" : "createWorkEffort execution failed. The request contained invalid information and could not be processed.", "errorDescription" : "StandardException: INSERT on table 'WORK_EFFORT' caused a violation of foreign key constraint 'WK_EFFRT_CURSTTS' for key (PRJs_ACTIVE). The statement has been rolled back." }{code} Main issue: If we once produced an error it looks like we never receive a good error response again, instead a Tomcat 500 HTML style response {code:java} $ curl -k -X 'POST' 'https://localhost:8443/rest/services/createWorkEffort' -H 'accept: application/json' -H 'Content-Type: application/json' -H 'Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MzE2NTg1MzEsImV4cCI6MTczMTY2MDMzMSwiaXNzIjoiQXBhY2hlT0ZCaXoiLCJ1c2VyTG9naW5JZCI6ImFkbWluIn0.TIhR8pAW9t74oXDiOUWwVuwjQJsBXEpC2duco-M5yevYfkVesn1gA7nc8daYRtwtBqxsfq10Wq5TT3iozMwgnA' -d '{"workEffortName": "my-first-project", "workEffortTypeId":"PROsJECT", "currentStatusId":"PRJ_ACTIVE"}' <!doctype html><html lang="en"><head><title>HTTP Status 500 – Internal Server Error</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 500 – Internal Server Error</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Message</b> Internal Server Error</p><p><b>Description</b> The server encountered an unexpected condition that prevented it from fulfilling the request.</p><hr class="line" /><h3>Apache Tomcat/9.0.91</h3></body></html>{code} If we send a valid input again, the service execution is still successful, as are the response code and the response body. If an error then occurs again, we only receive the Tomcat 500 instead of the OFBiz error message. The Service execution within OFBiz works perfectly, I think the error just occurs when we execute services by REST. I'll attach the logs of a failed service request ([^2024-11-15-ofbiz-rest-api-error.log]), from a feeling I'd say we should start to dig into: {code:java} org.glassfish.jersey.server.ServerRuntime$Responder mapException SEVERE: An exception was not mapped due to exception mapper failure. The HTTP 500 response will be returned.{code} BTW: release22.01 doesn't show this behavior! was (Author: JIRAUSER288222): Oh well...I wondered why our API responses are messed up from time to time. Here we are. I easily reproduced the behavior as we heavily use OFBiz with REST. Side note: The swagger-ui is an automatically generated UI to document and test the REST endpoints for RESTful services. Within OFBiz it's available on http://localhost:8443/docs/swagger-ui.html when you have the rest-api plugin checked out. I exported the createProject-service for the REST-API on latest trunk: {code:java} diff --git a/applications/workeffort/servicedef/services.xml b/applications/workeffort/servicedef/services.xml index e35d0e7662..3628f44fd3 100644 --- a/applications/workeffort/servicedef/services.xml +++ b/applications/workeffort/servicedef/services.xml @@ -39,7 +39,7 @@ under the License. <override name="description" allow-html="safe"/> </service> <service name="createWorkEffort" default-entity-name="WorkEffort" engine="groovy" invoke="createWorkEffort" - location="component://workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy"> + location="component://workeffort/src/main/groovy/org/apache/ofbiz/workeffort/workeffort/workeffort/WorkEffortServicesScript.groovy" export="true" auth="true" action="POST"> <description>Create a WorkEffort Entity</description> <permission-service service-name="workEffortGenericPermission" main-action="CREATE"/> <implements service="interfaceWorkEffort"/> {code} Grab a fresh JWT: {code:java} $ curl -kX POST "https://localhost:8443/rest/auth/token" -H "accept: application/json" -H "Authorization: Basic YWRtaW46b2ZiaXo=" { "statusCode" : 200, "statusDescription" : "OK", "successMessage" : "Token granted.", "data" : { "access_token" : "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MzE2NTg1MzEsImV4cCI6MTczMTY2MDMzMSwiaXNzIjoiQXBhY2hlT0ZCaXoiLCJ1c2VyTG9naW5JZCI6ImFkbWluIn0.TIhR8pAW9t74oXDiOUWwVuwjQJsBXEpC2duco-M5yevYfkVesn1gA7nc8daYRtwtBqxsfq10Wq5TT3iozMwgnA", "token_type" : "Bearer", "expires_in" : "1800" } } {code} Create a new project: {code:java} $ curl -k -X 'POST' 'https://localhost:8443/rest/services/createWorkEffort' -H 'accept: application/json' -H 'Content-Type: application/json' -H 'Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MzE2NTg1MzEsImV4cCI6MTczMTY2MDMzMSwiaXNzIjoiQXBhY2hlT0ZCaXoiLCJ1c2VyTG9naW5JZCI6ImFkbWluIn0.TIhR8pAW9t74oXDiOUWwVuwjQJsBXEpC2duco-M5yevYfkVesn1gA7nc8daYRtwtBqxsfq10Wq5TT3iozMwgnA' -d '{"workEffortName": "my-first-project", "workEffortTypeId":"PROJECT", "currentStatusId":"PRJ_ACTIVE"}' { "statusCode" : 200, "statusDescription" : "OK", "data" : { "workEffortId" : "10000" } }{code} Provoke an error for the first time - Here we receive the OFBiz service error message: {code:java} $ curl -k -X 'POST' 'https://localhost:8443/rest/services/createWorkEffort' -H 'accept: application/json' -H 'Content-Type: application/json' -H 'Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MzE2NTg1MzEsImV4cCI6MTczMTY2MDMzMSwiaXNzIjoiQXBhY2hlT0ZCaXoiLCJ1c2VyTG9naW5JZCI6ImFkbWluIn0.TIhR8pAW9t74oXDiOUWwVuwjQJsBXEpC2duco-M5yevYfkVesn1gA7nc8daYRtwtBqxsfq10Wq5TT3iozMwgnA' -d '{"workEffortName": "my-first-project", "workEffortTypeId":"PROJECT", "currentStatusId":"PRJs_ACTIVE"}' { "statusCode" : 422, "statusDescription" : "Unprocessable Entity", "errorType" : "GenericEntityException", "errorMessage" : "createWorkEffort execution failed. The request contained invalid information and could not be processed.", "errorDescription" : "StandardException: INSERT on table 'WORK_EFFORT' caused a violation of foreign key constraint 'WK_EFFRT_CURSTTS' for key (PRJs_ACTIVE). The statement has been rolled back." }{code} Main issue: If we once produced an error it looks like we never receive a good error response again, instead a Tomcat 500 HTML style response {code:java} $ curl -k -X 'POST' 'https://localhost:8443/rest/services/createWorkEffort' -H 'accept: application/json' -H 'Content-Type: application/json' -H 'Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MzE2NTg1MzEsImV4cCI6MTczMTY2MDMzMSwiaXNzIjoiQXBhY2hlT0ZCaXoiLCJ1c2VyTG9naW5JZCI6ImFkbWluIn0.TIhR8pAW9t74oXDiOUWwVuwjQJsBXEpC2duco-M5yevYfkVesn1gA7nc8daYRtwtBqxsfq10Wq5TT3iozMwgnA' -d '{"workEffortName": "my-first-project", "workEffortTypeId":"PROsJECT", "currentStatusId":"PRJ_ACTIVE"}' <!doctype html><html lang="en"><head><title>HTTP Status 500 – Internal Server Error</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 500 – Internal Server Error</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Message</b> Internal Server Error</p><p><b>Description</b> The server encountered an unexpected condition that prevented it from fulfilling the request.</p><hr class="line" /><h3>Apache Tomcat/9.0.91</h3></body></html>{code} If we send a valid input again, the service execution is still successful, as are the response code and the response body. If an error then occurs again, we only receive the Tomcat 500 instead of the OFBiz error message. The Service execution within OFBiz works perfectly, I think the error just occurs when we execute services by REST. I'll attach the logs of a failed service request ([^2024-11-15-ofbiz-rest-api-error.log]), from a feeling I'd say we should start to dig into "org.glassfish.jersey.server.ServerRuntime$Responder mapException SEVERE: An exception was not mapped due to exception mapper failure. The HTTP 500 response will be returned." BTW: release22.01 doesn't show this behavior! > Inconsistent Error Handling for Entity Creation via Exported Service > -------------------------------------------------------------------- > > Key: OFBIZ-13152 > URL: https://issues.apache.org/jira/browse/OFBIZ-13152 > Project: OFBiz > Issue Type: Bug > Components: rest-api > Reporter: Arashpreet Singh > Assignee: Jacques Le Roux > Priority: Major > Attachments: 2024-11-15-ofbiz-rest-api-error.log, trunk-logs.txt > > > There appears to be a problem with the OFBiz error-handling mechanism when > creating an entity using an exported service. Initially, if incorrect input > data is provided, OFBiz correctly returns a meaningful error message from the > backend. However, upon resubmitting the same request without any changes, > instead of returning the same meaningful error, the system responds with a > 500 internal server error and an HTML response. > Interestingly, when OFBiz is restarted, the first request with the same > incorrect data again returns a proper, meaningful error message. But all > subsequent requests with the same data continue to produce a 500 response, > which is not ideal for consistent error reporting. > This issue impacts debugging and error handling for services that rely on > accurate back-end responses. The expected behavior would be to consistently > return the meaningful error for all requests, regardless of whether OFBiz has > been restarted. -- This message was sent by Atlassian Jira (v8.20.10#820010)