if (payload instanceof JAXBElement) //这条语句恒为false
public boolean handleMessage(LogicalMessageContext ctx) {
Boolean outbound_p = (Boolean)
ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outbound_p) {
LogicalMessage msg = ctx.getMessage();
try {
JAXBContext jaxb_ctx = JAXBContext.newInstance("client");
Object payload = msg.getPayload(jaxb_ctx);
Object obj = ((JAXBElement)payload).getValue();//报错语句,无法强制转换
//GetCountryCityByIp gic=(GetCountryCityByIp)obj;
if (payload instanceof JAXBElement) {
System.out.println("Here's the test.")
}
String test=payload.getClass().toString();
System.out.println(test);
}
按理说强制转换应该是在if语句成立条件下进行的,但测试用的打印却没有运行,后来查看了一下payload的类型,属于类类型,似乎与期望的JAXBElement类型不符
通过if语句,能够输出测试语句,将payload能够转换为JAXBElement类型