[英]CXF WS-Addressing with Decoupled Endpoint but without Jetty
是否可以僅通過ServletDestination將WS-Addressing與解耦端點一起使用,而無需使用Jetty?
我收到以下異常,並且我的SOAP標頭包含任意的ReplyTo地址:
2014-05-26 17:20:35,733 ERROR [org.apache.cxf.transport.http.HTTPTransportFactory] (server_Worker-1) Cannot find any registered HttpDestinationFactory from the Bus.
2014-05-26 17:20:35,733 WARN [org.apache.cxf.ws.addressing.MAPAggregator] (server_Worker-1) decoupled endpoint creation failed:
java.io.IOException: Cannot find any registered HttpDestinationFactory from the Bus.
at org.apache.cxf.transport.http.HTTPTransportFactory.getDestination(HTTPTransportFactory.java:296)
at org.apache.cxf.ws.addressing.impl.MAPAggregatorImpl.getDestination(MAPAggregatorImpl.java:990)
at org.apache.cxf.ws.addressing.impl.MAPAggregatorImpl.setUpDecoupledDestination(MAPAggregatorImpl.java:961)
at org.apache.cxf.ws.addressing.impl.MAPAggregatorImpl.createDecoupledDestination(MAPAggregatorImpl.java:945)
at org.apache.cxf.ws.addressing.impl.MAPAggregatorImpl.getReplyTo(MAPAggregatorImpl.java:930)
at org.apache.cxf.ws.addressing.impl.MAPAggregatorImpl.addRoleSpecific(MAPAggregatorImpl.java:850)
at org.apache.cxf.ws.addressing.impl.MAPAggregatorImpl.aggregate(MAPAggregatorImpl.java:617)
at org.apache.cxf.ws.addressing.impl.MAPAggregatorImpl.mediate(MAPAggregatorImpl.java:448)
at org.apache.cxf.ws.addressing.impl.MAPAggregatorImpl.handleMessage(MAPAggregatorImpl.java:143)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:565)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:474)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:377)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:330)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:96)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:135)
at $Proxy1106.doServiceWS(Unknown Source)
at fr.edu.rennes.cyclades.pilotage.async.WSJob.executeTask(WSJob.java:116)
at fr.edu.ac_rennes.webfusion.quartz.job.BaseJob.executeInternal(BaseJob.java:101)
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:113)
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)
有效負載:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<Action xmlns="http://www.w3.org/2005/08/addressing">http://api.service.support.cyclades.rennes.edu.fr/QuartzWebService/doServiceWS</Action>
<MessageID xmlns="http://www.w3.org/2005/08/addressing">urn:uuid:34978730-9686-40ec-8e66-dcc68c0be27c</MessageID>
<To xmlns="http://www.w3.org/2005/08/addressing">http://sapdcy1.in.ac-rennes.fr:8280/ws_centre/cxf/DeclarerCentresBatchService</To>
<ReplyTo xmlns="http://www.w3.org/2005/08/addressing">
<Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
</ReplyTo>
</soap:Header>
<soap:Body/>
</soap:Envelope>
有人有線索嗎 ?
我找到了解決問題的方法。 我將decoupled_endpoint設置為相對URL(不是以http:// ...開頭),因此CXF決定使用ServletDestinationFactory而不是JettyDestinationFactory(請參閱org.apache.cxf.transport.http.HTTPTransportFactory.getDestination(EndpointInfo)) )。 然后,我設置了一個CXF攔截器,該構造器構造了一個絕對URL,因此SOAP標頭中的replyTo地址包含一個有效且可調用的HTTP地址。
public class ReplyToInterceptor extends AbstractPhaseInterceptor<Message> {
/** Le logger */
private static final Logger LOGGER = LoggerFactory.getLogger(ReplyToInterceptor.class);
/** Host name */
private String hostName;
/** Host port */
private String hostPort;
/**
* Constructeur par défaut
*/
public ReplyToInterceptor() {
super(Phase.PRE_LOGICAL);
addAfter(MAPAggregator.class.getName());
}
/**
* Ajoute l'adresse de retour asynchrone
* @param message Le message
*/
public void handleMessage(Message message) {
if (message instanceof XMLMessage) {
LOGGER.debug("Ignoring REST message");
return;
}
AddressingProperties maps = ContextUtils.retrieveMAPs(message, false, true, false);
if (maps != null) {
LOGGER.debug("WS-Addressing is enabled");
if (!ContextUtils.isRequestor(message)) {
LOGGER.debug("Ignoring response message");
return;
}
EndpointReferenceType replyTo = maps.getReplyTo();
if (replyTo == null) {
return;
}
AttributedURIType replyToAddress = replyTo.getAddress();
if (replyToAddress.getValue().startsWith("http") && !replyToAddress.getValue().startsWith("http://www.w3.org/2005/08/addressing/")) {
LOGGER.debug("Address is already absolute: {}", replyToAddress.getValue());
return;
}
RequestAttributes currentRequestAttributes = RequestContextHolder.getRequestAttributes();
String contextPath = null;
if (currentRequestAttributes != null) {
LOGGER.debug("HttpServletRequest is accessible");
contextPath = ((ServletRequestAttributes) currentRequestAttributes).getRequest().getContextPath();
} else {
LOGGER.debug("Can't access HttpServletRequest, replyTo address will use default context path");
contextPath = "/a_server";
}
String url = "http://" + this.hostName + ":" + this.hostPort + contextPath + "/cxf/async_endpoint";
LOGGER.debug("Setting replyTo URL to: {}", url);
replyToAddress.setValue(url);
} else {
LOGGER.debug("WS-Addressing is disabled");
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.