简体   繁体   中英

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:

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:

@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.

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.

So you should remember to add camel-jaxb to the classpath.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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