Я хочу иметь очень простой загрузчик в сервисе отдыха, который не работает с html-формой, и получать файлы с устройства Android.
это мой код:
@Path("test")
@POST
@Consumes({MediaType.MULTIPART_FORM_DATA})
public String testing(@FormDataParam("img") InputStream fileInputStream,
@FormDataParam("img") FormDataContentDisposition contentDispositionHeader ){
String SERVER_UPLOAD_LOCATION_FOLDER = "/var/lib/openshift/57a83e6f0c1e66920000005a/"
+ "app-root/runtime/repo/downloads/users/";
String filePath = SERVER_UPLOAD_LOCATION_FOLDER + contentDispositionHeader.getFileName();
saveFile(fileInputStream, filePath);
String output = "File saved to server location : " + filePath;
return output;
}
private void saveFile(InputStream uploadedInputStream,
String serverLocation) {
try {
OutputStream outpuStream = new FileOutputStream(new File(serverLocation));
int read = 0;
byte[] bytes = new byte[1024];
outpuStream = new FileOutputStream(new File(serverLocation));
while ((read = uploadedInputStream.read(bytes)) != -1) {
outpuStream.write(bytes, 0, read);
}
outpuStream.flush();
outpuStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
но когда я нажимаю этот код, все мои остальные службы отключаются и выдают ошибку 500 (я имею в виду другой путь uri). например, если я хочу получить доступ к myserviceuri/resturi/login
, он тоже выдает ошибку 500.
HTTP Status 500 - Servlet.init() for servlet restService.restStarter threw exception
type Exception report
message Servlet.init() for servlet restService.restStarter threw exception
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet.init() for servlet restService.restStarter threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:683)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1042)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
root cause
java.lang.IllegalStateException: The resource configuration is not modifiable in this context.
org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:274)
org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:221)
org.glassfish.jersey.server.ResourceConfig.register(ResourceConfig.java:453)
org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:387)
org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:177)
org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:369)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:683)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1042)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.54 logs.
Apache Tomcat/7.0.54
примечание: restService.restStarter — мой первый файл, в котором есть:
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
/**
*
* @author Seyed Ali
*/
@ApplicationPath("RestApi")
public class restStarter extends Application {
}
Я понял, что это две строки:
@FormDataParam("img") InputStream fileInputStream,
@FormDataParam("img") FormDataContentDisposition contentDispositionHeader
вызывает ошибку, и когда я удаляю это из своего тестового файла, другие файлы работают хорошо.
пожалуйста помогите мне.
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.54 logs
? Можете ли вы опубликовать полную трассировку стека? - person Jim Garrison   schedule 09.08.2016