Apache Camel CXF 端点 - 如何指定 soap 操作?
Apache Camel CXF Endpoint - how to specify soap operation?
我有一个包含两个 soap 操作的 wsdl。所以,我从中生成了 java 类,现在有一个接口:
@WebService(targetNamespace = "...", name = "...")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface RequestsService {
@WebMethod
@WebResult(name = "sendErrorReportResponse", targetNamespace = "...", partName = "result")
public SendErrorReportResponse sendErrorReport(
@WebParam(partName = "parameters", name = "sendErrorReport", targetNamespace = "...")
SendErrorReport parameters
);
@WebMethod
@WebResult(name = "bookRequestResponse", targetNamespace = "...", partName = "result")
public BookRequestResponse bookRequest(
@WebParam(partName = "parameters", name = "bookRequest", targetNamespace = "...")
ServiceRequestMessage parameters
);
}
然后,我为此接口创建了 CXF 端点:
@Bean
public CxfEndpoint myEndpoint() {
CxfEndpoint cxfEndpoint = new CxfEndpoint();
cxfEndpoint.setAddress("...");
cxfEndpoint.setServiceClass(RequestsService.class);
cxfEndpoint.setDataFormat(DataFormat.POJO);
cxfEndpoint.setLoggingFeatureEnabled(true);
return cxfEndpoint;
}
路线:
public static final String ENDPOINT = "cxf:bean:myEndpoint";
@Autowired
private MyProcessor processor;
@Override
public void configure() throws Exception {
from("quartz2://report?cron=0+*+*+*+*+?")
.process(processor)
.to(ENDPOINT);
}
我的问题是,如何指定调用我的 soap 操作之一 - sendErrorReport 或 bookRequest?
P.S
当我从 wsdl 中删除 sendErrorReport 方法并报告 类 时,此代码适用于 bookRequest 方法。否则会出现这个异常:
Caused by: java.lang.IllegalArgumentException: Part {http://...} parameters should be of type SendErrorReport, not ServiceRequestMessage
at org.apache.cxf.jaxb.io.DataWriterImpl.checkPart(DataWriterImpl.java:292)
at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:220)
...
您可以在端点 URI 中设置操作:
ENDPOINT = "cxf:bean:myEndpoint?defaultOperationName=sendErrorReport"
And/Or 你可以设置 operationName
骆驼 header 到需要的值
.process(processor)
.setHeader("operationName", constant("sendErrorReport"))
.to(ENDPOINT);
请注意,在这两种情况下,您的处理器都需要为用于避免上述异常的操作创建适当参数类型的实例。
我有一个包含两个 soap 操作的 wsdl。所以,我从中生成了 java 类,现在有一个接口:
@WebService(targetNamespace = "...", name = "...")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface RequestsService {
@WebMethod
@WebResult(name = "sendErrorReportResponse", targetNamespace = "...", partName = "result")
public SendErrorReportResponse sendErrorReport(
@WebParam(partName = "parameters", name = "sendErrorReport", targetNamespace = "...")
SendErrorReport parameters
);
@WebMethod
@WebResult(name = "bookRequestResponse", targetNamespace = "...", partName = "result")
public BookRequestResponse bookRequest(
@WebParam(partName = "parameters", name = "bookRequest", targetNamespace = "...")
ServiceRequestMessage parameters
);
}
然后,我为此接口创建了 CXF 端点:
@Bean
public CxfEndpoint myEndpoint() {
CxfEndpoint cxfEndpoint = new CxfEndpoint();
cxfEndpoint.setAddress("...");
cxfEndpoint.setServiceClass(RequestsService.class);
cxfEndpoint.setDataFormat(DataFormat.POJO);
cxfEndpoint.setLoggingFeatureEnabled(true);
return cxfEndpoint;
}
路线:
public static final String ENDPOINT = "cxf:bean:myEndpoint";
@Autowired
private MyProcessor processor;
@Override
public void configure() throws Exception {
from("quartz2://report?cron=0+*+*+*+*+?")
.process(processor)
.to(ENDPOINT);
}
我的问题是,如何指定调用我的 soap 操作之一 - sendErrorReport 或 bookRequest?
P.S 当我从 wsdl 中删除 sendErrorReport 方法并报告 类 时,此代码适用于 bookRequest 方法。否则会出现这个异常:
Caused by: java.lang.IllegalArgumentException: Part {http://...} parameters should be of type SendErrorReport, not ServiceRequestMessage
at org.apache.cxf.jaxb.io.DataWriterImpl.checkPart(DataWriterImpl.java:292)
at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:220)
...
您可以在端点 URI 中设置操作:
ENDPOINT = "cxf:bean:myEndpoint?defaultOperationName=sendErrorReport"
And/Or 你可以设置 operationName
骆驼 header 到需要的值
.process(processor)
.setHeader("operationName", constant("sendErrorReport"))
.to(ENDPOINT);
请注意,在这两种情况下,您的处理器都需要为用于避免上述异常的操作创建适当参数类型的实例。