So veröffentlichen Sie eine Mehrteil-/Formulardaten mit Dateien in einer REST -APIJava

Java-Forum
Guest
 So veröffentlichen Sie eine Mehrteil-/Formulardaten mit Dateien in einer REST -API

Post by Guest »

Ich versuche eine REST -API zu schreiben, um einen Anhang hochzuladen. Ich habe die API geschrieben. Aber wenn ich versuche, von Postman anzurufen, wirft es eine Ausnahme aus.

Code: Select all

 @Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(
@FormDataParam("attachment") InputStream uploadedInputStream,
@FormDataParam("attachment") FormDataContentDisposition fileDetail) {
JSONObject response = new JSONObject();
JSONObject jobj = new JSONObject();
if (uploadedInputStream == null) {
response = StringUtil.getErrorResponse("eleave", jobj, null);
} else {
try {
response.put(Constants.RES_success, true);
response = companyService.uploadAttachement(uploadedInputStream, fileDetail);
} catch (JSONException ex) {
_logger.log(Level.SEVERE, "CompanyRestService.changePassword", ex.getMessage());
response = StringUtil.getErrorResponse("e01", jobj, ex.getMessage());
} catch (Exception ex) {
_logger.log(Level.SEVERE, "CompanyRestService.changePassword", ex.getMessage());
response = StringUtil.getErrorResponse("erp25", jobj, ex.getMessage());
}
}
return Response.status(200).entity(response.toString()).build();
}
Ich habe wie unten versucht, aber es wirft eine Ausnahme
< /p>

Antwort: < /strong> < /p>

Code: Select all

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.krawler.eleave.ws.rest.v1.CompanyRestService.uploadFile(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition) 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.krawler.eleave.ws.rest.v1.CompanyRestService,
handlerConstructors=[org.glassfish.jersey.server.model.HandlerConstructor@7aa399f8]},
handlingMethod=public javax.ws.rs.core.Response
com.krawler.eleave.ws.rest.v1.CompanyRestService.uploadFile(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition),
parameters=[Parameter [type=class java.io.InputStream, source=attachment, defaultValue=null],
Parameter [type=class com.sun.jersey.core.header.FormDataContentDisposition, source=attachment, defaultValue=null]],
responseType=class javax.ws.rs.core.Response}, nameBindings=[]}']
< /code>

Abhängigkeiten:  <   / p >   < b r   / >   < b r   / > < c o d e > & l t ; d e p e n d e n c i e s & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; c g l i b & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; c g l i b - n o d e p & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 3 . 1 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; a s m & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; a s m & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 3 . 1 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; c o m . m y c o m p a n y & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; p o i - 3 . 5 - b e t a 6 & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 2 0 0 9 0 6 2 2 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; j a v a x . a c t i v a t i o n & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; a c t i v a t i o n & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 1 . 1 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; b a c k p o r t - u t i l - c o n c u r r e n t & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; b a c k p o r t - u t i l - c o n c u r r e n t & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 3 . 1 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; c o m m o n s - c o d e c & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; c o m m o n s - c o d e c & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 1 . 3 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; c o m m o n s - c o l l e c t i o n s & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; c o m m o n s - c o l l e c t i o n s & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 3 . 1 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; c o m m o n s - d i g e s t e r & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; c o m m o n s - d i g e s t e r & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 2 . 0 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; c o m m o n s - f i l e u p l o a d & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; c o m m o n s - f i l e u p l o a d & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 1 . 2 . 1 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; c o m m o n s - h t t p c l i e n t & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; c o m m o n s - h t t p c l i e n t & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 3 . 0 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; c o m m o n s - i o & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; c o m m o n s - i o & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 1 . 4 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; c o m m o n s - l a n g & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; c o m m o n s - l a n g & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 2 . 4 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; c o m m o n s - l o g g i n g & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; c o m m o n s - l o g g i n g & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 1 . 1 . 1 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; c o m m o n s - l o g g i n g & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; c o m m o n s - l o g g i n g - a p i & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 1 . 0 . 4 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; c o m m o n s - p o o l & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; c o m m o n s - p o o l & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 1 . 1 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; n e t . s f . e z m o r p h & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; e z m o r p h & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 1 . 0 . 4 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; n e t . s f . f l e x j s o n & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; f l e x j s o n & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 3 . 0 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; c h . e t h z . g a n y m e d & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; g a n y m e d - s s h 2 & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; b u i l d 2 1 0 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; o r g . m n o d e . i c a l 4 j & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; i c a l 4 j & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 1 . 0 . 3 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; c o m . l o w a g i e & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; i t e x t & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 2 . 1 . 7 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; o r o & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; o r o & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 2 . 0 . 8 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; n e t . s f . j a s p e r r e p o r t s & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; j a s p e r r e p o r t s & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 4 . 1 . 2 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; c o m . o c t o . c a p t c h a & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; j c a p t c h a - a l l & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 1 . 0 - R C 6 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; j d o m & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; j d o m & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 1 . 1 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; o r g . m o r t b a y . j e t t y & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; j e t t y & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 6 . 1 . 6 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; o r g . m o r t b a y . j e t t y & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; j e t t y - u t i l & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 6 . 1 . 6 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; c o m . u w y n & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; j h i g h l i g h t & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 1 . 0 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; j m i m e m a g i c & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; j m i m e m a g i c & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 0 . 0 . 4 a & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t ; & l t ; d e p e n d e n c y & g t ; & l t ; g r o u p I d & g t ; j o d a - t i m e & l t ; / g r o u p I d & g t ; & l t ; a r t i f a c t I d & g t ; j o d a - t i m e & l t ; / a r t i f a c t I d & g t ; & l t ; v e r s i o n & g t ; 2 . 4 & l t ; / v e r s i o n & g t ; & l t ; / d e p e n d e n c y & g t;javax.servletjstl1.2junitjunit4.11com.mycompanyKrawlerJsonLib1.0com.mycompanykrawlersso1.2log4jlog4j1.2.12org.apache.lucenelucene-core1.9.1javax.mailmail1.4mysqlmysql-connector-java5.1.46org.tmatesoft.svnkitsvnkit1.3.1com.paypal.sdkpaypal-core1.4.3pdfboxpdfbox0.7.3org.apache.poipoi3.7org.apache.poipoi-contrib3.7-beta3org.apache.poipoi-ooxml3.7org.apache.poipoi-ooxml-schemas3.7org.apache.poipoi-scratchpad3.7romerome1.0taglibsstandard1.1.2org.tuckeyurlrewritefilter3.2.0xercesxercesImpl2.8.0org.apache.xmlbeansxmlbeans2.6.0xomxom1.1org.glassfish.jersey.containersjersey-container-servlet${jersey-version}org.glassfish.hk2.externalasm-all-repackagedorg.glassfish.hk2.externalcglibjavax.servletjavax.servlet-api3.1.0org.glassfish.jersey.mediajersey-media-json-jackson${jersey-version}io.jsonwebtokenjjwt0.6.0com.googlecode.json-simplejson-simple1.1org.glassfish.jersey.mediajersey-media-multipart${jersey-version}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post