eclipse-ee4j / eclipse-ee4j/jersey
Getting HTTP Status 500 while calling a rest service with file upload functionality.
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
I'm getting the following exception with the Jersey libraries, it was recently migrated to the Jersey 2.40 version, but still having issues:
Type Exception Report
Message Servlet.init() for servlet [ASPREST] threw exception
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
javax.servlet.ServletException: Servlet.init() for servlet [ASPREST] threw exception
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.base/java.lang.Thread.run(Thread.java:834)
Root Cause
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 javax.ws.rs.core.Response com.hp.vzw.spc.asp.rest.FeatureMappingRest.apnsFileUpload(java.io.InputStream,org.glassfish.jersey.media.multipart.FormDataContentDisposition) throws java.lang.Exception at index 0.; source='ResourceMethod{httpMethod=POST, consumedTypes=[multipart/form-data], producedTypes=[], suspended=false, suspendTimeout=0, suspendTimeoutUnit=MILLISECONDS, invocable=Invocable{handler=ClassBasedMethodHandler{handlerClass=class com.hp.vzw.spc.asp.rest.FeatureMappingRest, handlerConstructors=[org.glassfish.jersey.server.model.HandlerConstructor@341d331f]}, definitionMethod=public javax.ws.rs.core.Response com.hp.vzw.spc.asp.rest.FeatureMappingRest.apnsFileUpload(java.io.InputStream,org.glassfish.jersey.media.multipart.FormDataContentDisposition) throws java.lang.Exception, parameters=[Parameter [type=class java.io.InputStream, source=file, defaultValue=null], Parameter [type=class org.glassfish.jersey.media.multipart.FormDataContentDisposition, source=file, defaultValue=null]], responseType=class javax.ws.rs.core.Response}, nameBindings=[]}']
org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:375)
org.glassfish.jersey.server.ApplicationHandler.lambda$initialize$1(ApplicationHandler.java:297)
org.glassfish.jersey.internal.Errors.process(Errors.java:292)
org.glassfish.jersey.internal.Errors.process(Errors.java:274)
org.glassfish.jersey.internal.Errors.processWithException(Errors.java:232)
org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:296)
org.glassfish.jersey.server.ApplicationHandler.(ApplicationHandler.java:261)
org.glassfish.jersey.servlet.WebComponent.(WebComponent.java:311)
org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:154)
org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:339)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.base/java.lang.Thread.run(Thread.java:834)
Here are the Jersey libraries added to the project:

Here is the rest service with the issue:
@Path("/apnsFileUpload")
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response apnsFileUpload(@FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail) throws Exception {
logger.info("Inside POST");
BufferedReader br = null;
ArrayList resultsList = new ArrayList();
String apnsFileUploadJsonString = null;
Map outputMap = new HashMap();
String arrayString = null;
long mdn;
String apnsMsType;
String apnsInterface;
String apnsTopic;
String uniqueId;
String fileName = "";
try {
br = new BufferedReader(new InputStreamReader(uploadedInputStream));
logger.info("Received Batch Manual Processing request.");
logger.info("Uploading file to default temp folder for parsing.");
ArrayList validMsgToInsert = new ArrayList();
int lineCounter = 1, linesProcessed = 0, linesSkipped = 0;
FeatureMappingCBDAO dao = new FeatureMappingCBImpl();
StringBuilder sb = new StringBuilder();
String line = br.readLine();
logger.info("Starting file parsing:");
new LoadAPNSProbs();
while (line != null) {
boolean invalidLine = false;
Scanner parsedLine = new Scanner(line).useDelimiter("\\|");
mdn = Long.parseLong(parsedLine.next());
apnsMsType = parsedLine.next();
apnsInterface = parsedLine.next();
apnsTopic = parsedLine.next();
uniqueId = parsedLine.next();
// Checking if line is VALID
int mdnLength = (int) (Math.log10(mdn) + 1);
if (mdnLength != 10) {
logger.info("SKIPPING :: Line: " + lineCounter + " Reason: MDN '" + mdn + "' is invalid.");
resultsList.add("Line: " + lineCounter + " SKIPPED :: MDN: " + mdn + " | MS Type: " + apnsMsType
+ " | APNS Interface: " + apnsInterface + " | APNS Topic: " + apnsTopic + " | Unique ID: "
+ uniqueId + ": Invalid MDN.");
invalidLine = true;
linesSkipped++;
}
// Checking if MS Type is on dictionary
if (dao.getMessageId(apnsMsType.trim()) == -1) {
logger.info("SKIPPING :: Line: " + lineCounter + " Reason: MS Type '" + apnsMsType
+ "' NOT in dictionary");
resultsList.add("Line: " + lineCounter + " SKIPPED :: MDN: " + mdn + " | MS Type: " + apnsMsType
+ " | APNS Interface: " + apnsInterface + " | APNS Topic: " + apnsTopic + " | Unique ID: "
+ uniqueId + ": Message Type not in dictionary.");
invalidLine = true;
linesSkipped++;
}
// Checking is APNS is an invalid interface name
if (!apnsInterface.trim().equals(LoadAPNSProbs.getApnsInterf01())
&& !apnsInterface.trim().equals(LoadAPNSProbs.getApnsInterf02())) {
logger.info("SKIPPING :: Line: " + lineCounter + " Reason: APNS Interface '" + apnsInterface
+ "' is INVALID.");
resultsList.add("Line: " + lineCounter + " SKIPPED :: MDN: " + mdn + " | MS Type: " + apnsMsType
+ " | APNS Interface: " + apnsInterface + " | APNS Topic: " + apnsTopic + " | Unique ID: "
+ uniqueId + ": Invalid APNS Interface.");
invalidLine = true;
linesSkipped++;
}
// Checking if APNS Message to be sent from file already exists on
// SPC_APNS_MESSAGES_TO_BE_SENT table
if (dao.checkMsgToBeSentAlreadyExists(mdn, apnsMsType) == true) {
logger.info("SKIPPING :: Line: " + lineCounter
+ " Reason: MDN and Message Type already on messages to be sent list.");
resultsList.add("Line: " + lineCounter + " SKIPPED :: MDN: " + mdn + " | MS Type: " + apnsMsType
+ " | APNS Interface: " + apnsInterface + " | APNS Topic: " + apnsTopic + " | Unique ID: "
+ uniqueId + ": Message already on messages to be sent list.");
invalidLine = true;
linesSkipped++;
}
// Checking if device token is active
if (dao.isTokenActive(mdn) == false) {
logger.info("SKIPPING :: Line: " + lineCounter + " Reason: Device token is not active.");
resultsList.add("Line: " + lineCounter + " SKIPPED :: MDN: " + mdn + " | MS Type: " + apnsMsType
+ " | APNS Interface: " + apnsInterface + " | APNS Topic: " + apnsTopic + " | Unique ID: "
+ uniqueId + ": Device token is not active.");
invalidLine = true;
linesSkipped++;
}
// Checking if OEM Device
if (dao.checkIfValidOEMDevice(mdn).equals("notOEMDevice")) {
logger.info("SKIPPING :: Line: " + lineCounter + " Reason: Not OEM device.");
resultsList.add("Line: " + lineCounter + " SKIPPED :: MDN: " + mdn + " | MS Type: " + apnsMsType
+ " | APNS Interface: " + apnsInterface + " | APNS Topic: " + apnsTopic + " | Unique ID: "
+ uniqueId + ": Not an OEM device.");
invalidLine = true;
linesSkipped++;
}
// Checking if OEM device contains valid APNS token
if (dao.checkIfValidOEMDevice(mdn).equals("ValidOEMWithoutToken")) {
logger.info("SKIPPING :: Line: " + lineCounter + " Reason: Device without APNS token.");
resultsList.add("Line: " + lineCounter + " SKIPPED :: MDN: " + mdn + " | MS Type: " + apnsMsType
+ " | APNS Interface: " + apnsInterface + " | APNS Topic: " + apnsTopic + " | Unique ID: "
+ uniqueId + ": No APNS token registered.");
invalidLine = true;
linesSkipped++;
}
// Checking if ANPS topic exists
if (!dao.checkIfANPSTopicExists(apnsTopic)) {
logger.info("SKIPPING :: Line: " + lineCounter + " Reason: APNS Topic does not exist. ");
resultsList.add("Line: " + lineCounter + " SKIPPED :: MDN: " + mdn + " | MS Type: " + apnsMsType
+ " | APNS Interface: " + apnsInterface + " | APNS Topic: " + apnsTopic + " | Unique ID: "
+ uniqueId + ": No APNS token registered.");
invalidLine = true;
linesSkipped++;
}
// Validating Unique ID
if (apnsTopic.equals("Entitlements")) {
if (!uniqueId.equals("0")) {
logger.info("SKIPPING :: Line: " + lineCounter
+ " Reason: invalid unique ID, should be 0 when APNS Topic = Entitlements.");
resultsList.add("Line: " + lineCounter + " SKIPPED :: MDN: " + mdn + " | MS Type: " + apnsMsType
+ " | APNS Interface: " + apnsInterface + " | APNS Topic: " + apnsTopic
+ " | Unique ID: " + uniqueId + ": No APNS token registered.");
invalidLine = true;
linesSkipped++;
}
}
// Validating if topic is different than "Entitlements" has to have a valid
// "DEVICE_ENTITLEMENTS" entity
if (!apnsTopic.equals("Entitlements")
&& dao.checkIfTopicWithDevEnt(mdn, apnsTopic, uniqueId) == false) {
logger.info("SKIPPING :: Line: " + lineCounter
+ " Reason: invalid DEVICE_ENTITLEMENTS entity, there is not some DevEnt.");
resultsList.add("Line: " + lineCounter + " SKIPPED :: MDN: " + mdn + " | MS Type: " + apnsMsType
+ " | APNS Interface: " + apnsInterface + " | APNS Topic: " + apnsTopic + " | Unique ID: "
+ uniqueId + ": No APNS token registered.");
invalidLine = true;
linesSkipped++;
}
// Validating if ApnsToken is null
if (dao.checkIfApnsTokenIsNull(mdn, apnsTopic) == false) {
logger.info(
"SKIPPING :: Line: " + lineCounter + " Reason: ApnsTopic has not ApnsToken registered.");
resultsList.add("Line: " + lineCounter + " SKIPPED :: MDN: " + mdn + " | MS Type: " + apnsMsType
+ " | APNS Interface: " + apnsInterface + " | APNS Topic: " + apnsTopic + " | Unique ID: "
+ uniqueId + ": No APNS token registered.");
invalidLine = true;
linesSkipped++;
}
// Processing line if line was is valid
if (invalidLine == false) {
// Adding to list of messages that will be inserted in DB after 1000 records
validMsgToInsert.add(line);
}
sb.append(line);
sb.append('\n');
line = br.readLine();
lineCounter++;
// Inserting into DB if list has reached 1000 records
if (validMsgToInsert.size() > 1000) {
logger.info("Going to insert first: " + validMsgToInsert.size() + " records into DB.");
if (!dao.createAPNSMessage(validMsgToInsert).equals("SUCCESS")) {
logger.error("An error occurred while trying to insert into the database.");
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("An error occured while creating batch message in database").build();
}
linesProcessed = linesProcessed + validMsgToInsert.size();
validMsgToInsert = new ArrayList();
}
}
// Inserting into DB if total records received for batch processing are less
// than 1000
if (lineCounter <= 1000 && validMsgToInsert.size() > 0) {
logger.info("Going to insert: " + validMsgToInsert.size() + " records into DB.");
if (!dao.createAPNSMessage(validMsgToInsert).equals("SUCCESS")) {
logger.error("An error occurred while trying to insert into the database.");
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("An error occured while creating batch message in database").build();
}
linesProcessed = linesProcessed + validMsgToInsert.size();
}
logger.info("File parsing completed :: Lines processed = " + linesProcessed + " : Lines Skipped = "
+ linesSkipped);
outputMap.put("uploadMsg", "Batch Manual Processing Completed :: Lines Successfully Processed: "
+ linesProcessed + " Lines Skipped:" + linesSkipped);
outputMap.put("resultsList", resultsList);
ObjectMapper objMapper = new ObjectMapper();
objMapper.enable(SerializationFeature.INDENT_OUTPUT);
apnsFileUploadJsonString = objMapper.writeValueAsString(outputMap);
} catch (Exception e) {
logger.error("An error occurred while trying to parse the uploaded file");
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("An error occured while trying to process the uploaded file: " + e).build();
} finally {
br.close();
}
return Response.status(Response.Status.OK).entity(apnsFileUploadJsonString).build();
}
Does anyone knows something about this issue?
Any help will be greatly appreciated it. Thanks!
Regards,
Sandra H.
Contributor guide
Assessment
This issue has not been assessed yet.