简体   繁体   English

Apache camel from(file)不会删除已处理的一个

[英]Apache camel from(file) doesn't delete processed one

I have this simple route defined : 我定义了以下简单路线:
from("file:" + recoverableErrorsFolder +"? delete=true&consumer.initialDelay=0&consumer.delay="+redeliveryDelay) .to("bean:myBean");

and i have myBean defined this way: 我有这样定义myBean:

public  void process(Exchange exchange)  throws Exception {
    ReceivedPlazasInfo receiv =exchange.getIn().getBody(ReceivedPlazasInfo.class);
}

But when i run it, the processed file is never deleted. 但是当我运行它时,处理过的文件永远不会删除。 If I change the process function to 如果我将流程功能更改为

String receiv =exchange.getIn().getBody(String.class);

it works fine. 它工作正常。

What happens? 怎么了?

The ReceivedPlazasInfo class looks like this: ReceivedPlazasInfo类如下所示:

@XmlRootElement( name = "plazas" )
@XmlAccessorType(XmlAccessType.FIELD)
public class ReceivedPlazasInfo {`

@XmlElement( name = "parking" )
private List<ReceivedParkingInfo> parkingResponse;


/**
 * @return list of parkings
 */
public List<ReceivedParkingInfo> getParkingResponse() {
    return parkingResponse;
}

/**
 * @param parkingResponse : list of parkings
 */
public void setParkingResponse(ArrayList<ReceivedParkingInfo> parkingResponse) {
    this.parkingResponse = parkingResponse;
}

} }

@Entity
@XmlRootElement( name  = "parking" )
@XmlAccessorType(XmlAccessType.FIELD)
public class ReceivedParkingInfo {`

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@XmlElement( name = "idParking" )
private String idParking;

@XmlElement( name = "idType" )
private String idType;

@XmlElement( name = "numPlazas" )
private Integer numPlazas;

@XmlElement( name = "timeStamp" )
private String timeStamp;

/**
 * @return idParking
 */ 
public String getIdParking() {
    return idParking;
}

/**
 * @param idParking
 */
public void setIdParking(String idParking) {
    this.idParking = idParking;
}

/**
 * @return idType
 */
public String getIdType() {
    return idType;
}

/**
 * @param idType
 */
public void setIdType(String idType) {
    this.idType = idType;
}

/**
 * @return numPlazas
 */
public Integer getNumPlazas() {
    return numPlazas;
}

/**
 * @param numPlazas
 */
public void setNumPlazas(Integer numPlazas) {
    this.numPlazas = numPlazas;
}

/** 
 * @return timeStamp
 */
public String getTimeStamp() {
    return timeStamp;
}

/**
 * @param timeStamp
 */
public void setTimeStamp(String timeStamp) {
    this.timeStamp = timeStamp;
}
}

When you use POJO classes with JAXB annotations such as ReceivedParkingInfo and you want to let Apache Camel be able to automatic convert to/from XML to this POJO via JAXB, then you need to add camel-jaxb to the classpath. 当您使用带有JAXB批注的POJO类(例如ReceivedParkingInfo并且希望让Apache Camel能够通过JAXB自动将XML转换为该POJO或从XML转换为该POJO时,则需要将camel-jaxb添加到类路径中。

This can explain that the file is never deleted when you attempted 这可以说明尝试执行此文件时绝不会删除该文件

ReceivedPlazasInfo receiv =exchange.getIn().getBody(ReceivedPlazasInfo.class);

Because there is no camel-jaxb on the classpath, so Camel cannot convert the file to this POJO class, and instead it returns null, or throw an exception about conversion not possible. 因为类路径上没有camel-jaxb,所以Camel无法将文件转换为此POJO类,而是返回null,否则将引发有关转换的异常。

So you should remember to add camel-jaxb to the classpath. 因此,您应该记住将camel-jaxb添加到类路径中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM