0

i try to use Apache CXF in my project. So i set up an xml file cxf-client.xml where i put this code :

<?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 :

@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 :

<?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); and it don't use the timeout that i configured it

josef
  • 89
  • 2
  • 9
  • This is a `spring` configuration file. I suggest you to read some tutorial about spring to know how to use it in your project – pedrofb Aug 08 '16 at 09:14
  • thanks for your answer! i made a call of this class in my `web.xml` as a classpath. you have an idea if like that i need more configuration or it's good ? – josef Aug 08 '16 at 09:20
  • You need to configure ContextLoaderListener. Check this http://stackoverflow.com/questions/6451377/loading-context-in-spring-using-web-xml – pedrofb Aug 08 '16 at 09:36
  • i did it like i edited my question..you can see it! when i create an instance of `MyClass` it blocked in this line `super(wsdlLocation, serviceName);` and it don't use the timeout that i configured it – josef Aug 08 '16 at 10:11
  • I am confused. Your configuration mix server and client parts. Do you want to publish a server endpoint or to consume a Service? – pedrofb Aug 08 '16 at 10:43
  • i want to consume a Service when i create an instance of my class `MyClass` – josef Aug 08 '16 at 11:55
  • It seems your service is blocked when the constructor tries to download the WSDL from `wsdlLocaltion`. CXF timeouts does not apply here. Ensure the URL of wsdlLocation is accesible. If not, you can point to a local wsdl file – pedrofb Aug 08 '16 at 13:24
  • my `wsdlLocation` is not accesible in this moment that's why i want to put a timeout. In this case, where and how i can make a timeout please ? – josef Aug 08 '16 at 13:41

1 Answers1

0

It seems your service is blocked when the constructor tries to download the WSDL from wsdlLocaltion. CXF timeouts does not apply here. Ensure the URL of wsdlLocation is accesible. If not

1) Point to a local wsdl file.

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

2) Configure a CXF webservice without WDSL

See 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");
Community
  • 1
  • 1
pedrofb
  • 37,271
  • 5
  • 94
  • 142
  • Thanks for your answer! In reality, i find a simple solution like you can see it in answer – josef Aug 10 '16 at 07:32
  • So, finally you have configured the endpoint address using `BindingProvider`? – pedrofb Aug 10 '16 at 08:51
  • Sorry because i can't posted my answer! i don't know what is the problem! but tell you, i used a simple solution. It's URLConenction. I used this solution to controle my URL before i call my service : try { URL testUrl = new URL(MyURL); URLConnection testConnection = testUrl.openConnection(); testConnection.setConnectTimeout(TIMEOUT_VALUE); testConnection.setReadTimeout(TIMEOUT_VALUE); } catch (SocketTimeoutException e) { System.out.println("More than " + TIMEOUT_VALUE + " elapsed."); } – josef Aug 12 '16 at 08:12
  • Ok, you have set a timeout to the wsdl connection. But if the WDSL can not be downloaded then the service will not know the endpoint address and the service won't connect. is not it? – pedrofb Aug 12 '16 at 09:19
  • I set a timeout to the wsdl connection. If i can't connect to the wsdl or i can't read into the wsdl after connecting, i leave the try bloc to the exception..else i execute the try bloc, i forget just to make in my answer here my call for my service when i use my wsdl and endpoint as parametre! so my control is before calling my service – josef Aug 12 '16 at 09:58