简体   繁体   English

配置Apache CXF

[英]Configuration Apache CXF

i try to use Apache CXF in my project. 我尝试在我的项目中使用Apache CXF。 So i set up an xml file cxf-client.xml where i put this code : 所以我建立了一个xml文件cxf-client.xml ,在其中放置了以下代码:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
   xsi:schemaLocation="http://cxf.apache.org/transports    /http/configuration
       http://cxf.apache.org/schemas/configuration/http-conf.xsd
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd">

       <import resource="classpath:META-INF/cxf/cxf.xml" />
       <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
       <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

       <http-conf:conduit name="*.http-conduit">
       <http-conf:client ConnectionTimeout="3000" ReceiveTimeout="3000"/>
       </http-conf:conduit>
</beans>

My question is how and where i can read this file to execute correctly my project ? 我的问题是如何以及在哪里可以读取此文件以正确执行我的项目? i need more configuration ? 我需要更多配置?

here is my client class java : 这是我的客户端类java:

@WebServiceClient(name = "name", 
              wsdlLocation = "sourse?wsdl",
              targetNamespace = "myNameSpace") 
public class MyClass extends Service {

public final static URL WSDL_LOCATION;

public final static QName SERVICE = new QName("myNameSpace", "name");
public final static QName MyEndpointServiceImplPort = new QName("myNameSpace", "MyEndpointServiceImplPort");
static {
    URL url = null;
    try {
        String urlString = System.getProperty("webservice.trainmission.url");
        url = new URL(urlString);
    } catch (MalformedURLException e) {
        e.getMessage();
    }
    WSDL_LOCATION = url;
}

public MyClass(URL wsdlLocation, QName serviceName) {       
    super(wsdlLocation, serviceName);
}
@WebEndpoint(name = "MyEndpointServiceImplPort")
public MyEndpointServicePortType getMyEndpointServiceImplPort() {
    return super.getPort(MyEndpointServiceImplPort,    MyEndpointServicePortType.class);
}

here is my web.xml : 这是我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xmlns="http://java.sun.com/xml/ns/javaee"   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com /xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>MyProject</display-name>
<context-param>
  <param-name>contextConfigLocation</param-name>
<param-value>
        classpath:conf/cxf-client.xml
</param-value>
</context-param>
<servlet>
  <description>Apache CXF Endpoint</description>
  <display-name>cxf</display-name>
  <servlet-name>cxf</servlet-name>
  <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-  class>
  <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
  <servlet-name>cxf</servlet-name>
  <url-pattern>/services/*</url-pattern>
</servlet-mapping>

<listener>
  <display-name>Spring Web Context Loader Listener</display-name>
  <listener-class>org.springframework.web.context.ContextLoaderListener
  </listener-class>
</listener>
</web-app>

when i create an instance of MyClass it blocked in this line super(wsdlLocation, serviceName); 当我创建MyClass的实例时,它在此行中被阻止了super(wsdlLocation, serviceName); and it don't use the timeout that i configured it 而且它不使用我配置的超时

It seems your service is blocked when the constructor tries to download the WSDL from wsdlLocaltion. 构造函数尝试从wsdlLocaltion下载WSDL时,似乎服务被阻止。 CXF timeouts does not apply here. CXF超时不适用于此处。 Ensure the URL of wsdlLocation is accesible. 确保wsdlLocation的URL是可访问的。 If not 如果不

1) Point to a local wsdl file. 1) 指向本地wsdl文件。

File wsdlFile = new File(wsdl);
wsdlLocation = wsdlFile.toURI().toURL();

2) Configure a CXF webservice without WDSL 2) 在没有WDSL的情况下配置CXF Web服务

See https://stackoverflow.com/a/19827446/6371459 参见https://stackoverflow.com/a/19827446/6371459

QName qname = new QName("http://thenamespace", "FooService");
FooService service = new FooService(null, qname); // null for ignore WSDL
Foo port = service.getFooPort();
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext()
   .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
   "http://foo.com/soap/fooBean");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM