Forum Discussion

hyd198471's avatar
hyd198471
Occasional Visitor
3 years ago

multipart/form-data

I have a question regarding multipart/form-data problem in payara 5 server.

 

I have email api  which is generated by swagger. v3:

paths:
/site/{site_id}/email:
post:
tags:
- email
summary: send a email with attachments
description: |
send a email with attachment
Role information:
- Endpoint access: Administrator according to test site
operationId: sendEmail
parameters:
- $ref: "common.yaml#/components/parameters/siteId"
requestBody:
description: email
content:
multipart/form-data:
schema:
$ref: "#/components/schemas/Email"
components:
securitySchemes:
bearerAuth:
$ref: "common.yaml#/components/securitySchemes/bearerAuth"
schemas:
Email:
description: Information about email
type: object
properties:
subject:
type: string
description: email subject
start_time:
description: starting time of test
type: string
format: date-time
end_time:
description: ending time of test
type: string
format: date-time
all_participants_included:
description: including all participants or only test team leaders
type: boolean
text:
type: string
description: email text
attachments:
type: array
items:
type: string
format: binary

 The content-type is multipart-form. 

My Application is running in Payara 5.  I have ResourceConfig class with register

register(MultiPartFeature.class);

EmailApi generated class is like following:

@Consumes({ "multipart/form-data" })
@Produces({ "application/json" })
@ApiOperation(value = "send a email with attachments", tags={ "email" })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "operation successful"),
@ApiResponse(code = 400, message = "parameter error", response = InlineResponse400.class),
@ApiResponse(code = 403, message = "User not allowed to perform this operation"),
@ApiResponse(code = 404, message = "Object with given id was not found in server") })
public void sendEmail(@PathParam("site_id") SiteId siteId, @Multipart(value = "subject", required = false) String subject, @Multipart(value = "start_time", required = false) java.time.ZonedDateTime startTime, @Multipart(value = "end_time", required = false) java.time.ZonedDateTime endTime, @Multipart(value = "all_participants_included", required = false) Boolean allParticipantsIncluded, @Multipart(value = "text", required = false) String text, @Multipart(value = "attachments" , required = false) Attachment attachmentsDetail);

But When I register my impl class EmailApiImpl to ResourceConfig.class 

 

It always throws

[2022-04-08 04:27:06,129] Artifact pgms-ams-backend:war: java.io.IOException: com.sun.enterprise.admin.remote.RemoteFailureException: Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization.
[[FATAL] No injection source found for a parameter of type public void com.bmw.pgms.ams.mail.boundary.EmailApiImpl.sendEmail(generated.model.SiteId,java.lang.String,java.time.ZonedDateTime,java.time.ZonedDateTime,java.lang.Boolean,java.lang.String,org.apache.cxf.jaxrs.ext.multipart.Attachment) at index 1.; source='ResourceMethod{httpMethod=POST, consumedTypes=[multipart/form-data], producedTypes=[application/json], suspended=false, suspendTimeout=0, suspendTimeoutUnit=MILLISECONDS, invocable=Invocable{handler=ClassBasedMethodHandler{handlerClass=class com.bmw.pgms.ams.mail.boundary.EmailApiImpl, handlerConstructors=[org.glassfish.jersey.server.model.HandlerConstructor@5990f0f0]}, definitionMethod=public abstract void generated.api.EmailApi.sendEmail(generated.model.SiteId,java.lang.String,java.time.ZonedDateTime,java.time.ZonedDateTime,java.lang.Boolean,java.lang.String,org.apache.cxf.jaxrs.ext.multipart.Attachment), parameters=[Parameter [type=class generated.model.SiteId, source=site_id, defaultValue=null], Parameter [type=class java.lang.String, source=subject, defaultValue=null], Parameter [type=class java.time.ZonedDateTime, source=start_time, defaultValue=null], Parameter [type=class java.time.ZonedDateTime, source=end_time, defaultValue=null], Parameter [type=class java.lang.Boolean, source=all_participants_included, defaultValue=null], Parameter [type=class java.lang.String, source=text, defaultValue=null], Parameter [type=class org.apache.cxf.jaxrs.ext.multipart.Attachment, source=attachments, defaultValue=null]], responseType=void}, nameBindings=[]}']. Please see server.log for more details.

 

I google a lot but still have no answer. Will someone help me?

 

No RepliesBe the first to reply