我定义了这条简单的路线:
from("file:" + recoverableErrorsFolder +"?
delete=true&consumer.initialDelay=0&consumer.delay="+redeliveryDelay)
.to("bean:myBean");
我以这种方式定义myBean:
public void process(Exchange exchange) throws Exception {
ReceivedPlazasInfo receiv =exchange.getIn().getBody(ReceivedPlazasInfo.class);
}
但是当我运行它时,处理过的文件永远不会被删除。
如果我将过程功能更改为
String receiv =exchange.getIn().getBody(String.class);
它工作正常。
会发生什么?
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;
}
}
答案 0 :(得分:0)
当您将POJO类与JAXB注释(例如ReceivedParkingInfo
一起使用)并且希望让Apache Camel能够通过JAXB自动将XML转换为此POJO时,您需要添加camel-jaxb
到类路径。
这可以解释在您尝试
时永远不会删除该文件ReceivedPlazasInfo receiv =exchange.getIn().getBody(ReceivedPlazasInfo.class);
因为类路径上没有camel-jaxb,所以Camel无法将文件转换为此POJO类,而是返回null,或者抛出有关转换的异常。
所以你应该记得将camel-jaxb
添加到类路径中。