如何在 soap 客户端中获取 Http 响应代码?
How to get an Http response code in a soap client?
有一个肥皂网络服务和一个客户端。使用 Apache CXF / Spring 包。
客户:
public class MyWebServiceClientFactoryCXF {
public MyWebServiceAPI getMyWebServiceClient(String URI, String username, String password) throws MalformedURLException {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(MyWebServiceAPI.class);
factory.setAddress(URI);
factory.setUsername(username);
factory.setPassword(password);
factory.setDataBinding(new AegisDatabinding());
return (MyWebServiceAPI) factory.create();
}
}
Spring 上下文:
<bean id="myWebServiceClientFactory" class="mypakg.MyWebServiceClientFactoryCXF"/>
<bean id="myWebServiceClient" factory-bean="myWebServiceClientFactory" factory-method="getMyWebServiceClient">
<constructor-arg index="0" type="java.lang.String" value="${ws.url}"/>
<constructor-arg index="1" type="java.lang.String" value="${ws.login}"/>
<constructor-arg index="2" type="java.lang.String" value="${ws.pwd}"/>
</bean>
使用:
public class App {
@Autowired
private MyWebServiceAPI wsClient;
public void someMethod() {
wsClient.getSomeInfo();
// Need to know http response code from `wsClient.getSomeInfo()`
}
}
如何从 soap 网络服务获取响应代码?
我可以为 JaxWsProxyFactoryBean
指定一个拦截器,但是如何将值从拦截器传递给 App.someMethod()
方法?
考虑以下代码:
import org.apache.cxf.message.Message;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.endpoint.Client;
public void someMethod() {
try {
wsClient.getSomeInfo(); //exception here for non-2xx http status by default
} finally {
Client client = ClientProxy.getClient(wsClient);
Integer responseCode = client.getResponseContext().get(Message.RESPONSE_CODE);
}
另请参阅:
有一个肥皂网络服务和一个客户端。使用 Apache CXF / Spring 包。
客户:
public class MyWebServiceClientFactoryCXF {
public MyWebServiceAPI getMyWebServiceClient(String URI, String username, String password) throws MalformedURLException {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(MyWebServiceAPI.class);
factory.setAddress(URI);
factory.setUsername(username);
factory.setPassword(password);
factory.setDataBinding(new AegisDatabinding());
return (MyWebServiceAPI) factory.create();
}
}
Spring 上下文:
<bean id="myWebServiceClientFactory" class="mypakg.MyWebServiceClientFactoryCXF"/>
<bean id="myWebServiceClient" factory-bean="myWebServiceClientFactory" factory-method="getMyWebServiceClient">
<constructor-arg index="0" type="java.lang.String" value="${ws.url}"/>
<constructor-arg index="1" type="java.lang.String" value="${ws.login}"/>
<constructor-arg index="2" type="java.lang.String" value="${ws.pwd}"/>
</bean>
使用:
public class App {
@Autowired
private MyWebServiceAPI wsClient;
public void someMethod() {
wsClient.getSomeInfo();
// Need to know http response code from `wsClient.getSomeInfo()`
}
}
如何从 soap 网络服务获取响应代码?
我可以为 JaxWsProxyFactoryBean
指定一个拦截器,但是如何将值从拦截器传递给 App.someMethod()
方法?
考虑以下代码:
import org.apache.cxf.message.Message;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.endpoint.Client;
public void someMethod() {
try {
wsClient.getSomeInfo(); //exception here for non-2xx http status by default
} finally {
Client client = ClientProxy.getClient(wsClient);
Integer responseCode = client.getResponseContext().get(Message.RESPONSE_CODE);
}
另请参阅: