首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >骆驼CXFRS -空附件

骆驼CXFRS -空附件
EN

Stack Overflow用户
提问于 2014-10-10 15:40:54
回答 1查看 1K关注 0票数 2

我试图制作一个RESTful WS来上传一个带有CXFRS camel组件的文件,我试图通过getAttachment方法检索上传的文件,但是它始终是空的。

这是我的密码:

EndPoint类: ExposedApi.java

代码语言:javascript
复制
@Path("/test")
public class ExposedApi {
@POST
@Path("/resources/solver")  
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public Response upload(@Multipart(value = "file") Attachment attachments ){
    return null;
   }
}

扩展routebuolder的代码: RouteConf.java

代码语言:javascript
复制
public class RouteConf extends RouteBuilder {
@Override
public void configure() throws Exception {
    // TODO Auto-generated method stub
    getContext().setTracing(true);

    from("cxfrs://http://localhost:9090/test?resourceClasses=org.foo.ExposedApi")
    .streamCaching()
    .process(new Processor() {
        public void process(Exchange exchange) throws Exception {

            Message inMessage = exchange.getIn();      
            String operationName = inMessage.getHeader(CxfConstants.OPERATION_NAME, String.class);          

            if (operationName=="upload"){
                Map<String, DataHandler> names= inMessage.getAttachments();


                exchange.getOut().setBody(inMessage.getAttachmentNames().toString()+ " TEST "+ names.keySet().toString());
                        }

            }
    });
   }
}

卷曲请求:

代码语言:javascript
复制
curl -v -F "file=@/Users/Massimo/Desktop/ic_eb.png" http://localhost:9090/test/test/resources/solver

这是我们的回应

代码语言:javascript
复制
* Adding handle: conn: 0x7f92cb804000
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7f92cb804000) send_pipe: 1, recv_pipe: 0
* About to connect() to localhost port 9090 (#0)
*   Trying ::1...
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 9090 (#0)
> POST /test/test/resources/solver HTTP/1.1
> User-Agent: curl/7.30.0
> Host: localhost:9090
> Accept: */*
> Content-Length: 89280
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------837830fae872
> 
< HTTP/1.1 100 Continue
< HTTP/1.1 200 OK
< Content-Type: application/json
< Date: Fri, 10 Oct 2014 14:54:51 GMT
< Content-Length: 10
* Server Jetty(7.6.9.v20130131) is not blacklisted
< Server: Jetty(7.6.9.v20130131)
< 
* Connection #0 to host localhost left intact
[] TEST []

我做错什么了?我怎样才能找回附加的文件?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-15 10:39:38

经过一番努力,我找到了解决办法。

附件在身体内。

如果您想要检索附件,这一行代码适用于我。

代码语言:javascript
复制
Attachment att = (Attachment)inMessage.getBody(ArrayList.class).get(0);
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26303119

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档