2016-08-08 35 views
0

Ich versuche, Apache CXF in meinem Projekt zu verwenden. Also habe ich eine XML-Datei auf cxf-client.xml, wo ich diesen Code setzen:Konfiguration Apache CXF

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

Meine Frage ist, wie und wo ich diese Datei mein Projekt ausführen lesen richtig? Ich brauche mehr Konfiguration?

hier ist meine Client-Klasse 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); 
} 

hier ist mein 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> 

, wenn ich eine Instanz von MyClass es in dieser Linie blockierte super(wsdlLocation, serviceName); und das nicht verwenden Timeout, dass ich es konfigurierte

+0

Dieser ist eine 'Spring' Konfigurationsdatei. Ich empfehle Ihnen, ein Tutorial über den Frühling zu lesen, um zu wissen, wie Sie es in Ihrem Projekt verwenden können. – pedrofb

+0

danke für Ihre Antwort! Ich habe diese Klasse in meiner 'web.xml' als Klassenpfad aufgerufen. hast du eine idee, wenn ich so mehr konfiguration brauche oder es gut ist? – josef

+0

Sie müssen ContextLoaderListener konfigurieren. Überprüfen Sie diese http://stackoverflow.com/questions/6451377/loading-context-in-spring-using-web-xml – pedrofb

Antwort

0

Es scheint, dass Ihr Dienst blockiert ist, wenn der Konstruktor versucht, die WSDL von WSDLLocaltio herunterladen n. CXF Timeouts gelten hier nicht. Stellen Sie sicher, dass die URL von wsdlLocation zugänglich ist. Wenn nicht

1) Zeigen Sie auf eine lokale WSDL-Datei.

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

2) Konfigurieren eines CXF Webservice ohne WDSL

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"); 
+0

Danke für Ihre Antwort! In Wirklichkeit finde ich eine einfache Lösung, wie Sie es in der Antwort – josef

+0

sehen können Also haben Sie schließlich die Endpunktadresse mit 'BindingProvider' konfiguriert? – pedrofb

+0

Entschuldigung, weil ich meine Antwort nicht veröffentlichen kann! Ich weiß nicht, was das Problem ist! aber sag dir, ich habe eine einfache lösung benutzt. Es ist URLConenction. Ich habe diese Lösung verwendet, um meine URL zu steuern, bevor ich meinen Dienst anrufe: try { URL testUrl = neue URL (MyURL); URLConnection testConnection = testUrl.openConnection(); testConnection.setConnectTimeout (TIMEOUT_VALUE); testConnection.setReadTimeout (TIMEOUT_VALUE); } catch (SocketTimeoutException e) { System.out.println ("Mehr als" + TIMEOUT_VALUE + "verstrichen."); } – josef