【问题标题】:Camel CXFRS - Empty AttachmentCamel CXFRS - 空附件
【发布时间】:2014-12-05 20:11:55
【问题描述】:

我正在尝试制作一个 RESTful WS 来上传带有 CXFRS 骆驼组件的文件,我正在尝试通过 getAttachment 方法检索上传的文件,但它始终为空。

这是我的代码:

EndPoint 类:ExposedApi.java

@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

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());
                        }

            }
    });
   }
}

卷曲请求:

curl -v -F "file=@/Users/Massimo/Desktop/ic_eb.png" http://localhost:9090/test/test/resources/solver

这是回应

* 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 []

我做错了什么?我怎样才能检索附件?

【问题讨论】:

    标签: java jetty osgi apache-camel cxfrs


    【解决方案1】:

    经过一番努力,我找到了解决方案。

    附件在正文中。

    如果你想检索附件,这行代码对我有用

    Attachment att = (Attachment)inMessage.getBody(ArrayList.class).get(0);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多