2016-08-08 3 views
0

내 프로젝트에서 Apache CXF를 사용하려고합니다. 어떻게 내가 제대로 내 프로젝트를 실행하려면이 파일을 읽을 수있는구성 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> 

내 질문은 : 그래서 나는이 코드를 넣어 xml 파일 cxf-client.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> 

내가이 줄에서 차단 MyClass의 인스턴스를 만들 때 super(wsdlLocation, serviceName);하고는 사용하지 마십시오 : 여기

@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); 
} 

내이 web.xml입니다 : 여기

내 클라이언트 클래스의 자바입니다 내가 구성한 시간 초과

+0

참조하십시오. 나는 당신의 프로젝트에서 그것을 사용하는 방법을 봄에 관한 튜토리얼을 읽기를 권합니다. – pedrofb

+0

답에 감사드립니다! 나는이 클래스를'web.xml '클래스 패스로 호출했다. 당신은 내가 더 많은 구성이 필요하거나 좋다고 생각한다면? – josef

+0

ContextLoaderListener를 구성해야합니다. 이것을 확인하십시오 http://stackoverflow.com/questions/6451377/loading-context-in-spring-using-web-xml – pedrofb

답변

0

생성자가 wsdlLocaltio에서 WSDL을 다운로드하려고하면 서비스가 차단 된 것 같습니다 엔. CXF 시간 초과는 여기에 적용되지 않습니다. wsdlLocation의 URL이 액세스 가능한지 확인하십시오. 일치하지 않는 경우

1) 로컬 wsdl 파일을 가리 킵니다. WDSL

없이

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

2) 구성합니다 CXF의 웹 서비스

이것은`spring` 구성 파일입니다 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

답변 해 주셔서 감사합니다! 실제로, 당신이 대답을 볼 수있는 간단한 솔루션을 찾을 수 – josef

+0

그래서, 마지막으로 당신은 'BindingProvider'를 사용하여 끝점 주소를 구성 했습니까? – pedrofb

+0

죄송합니다. 내 답변을 게시 할 수 없기 때문에! 나는 그 문제가 뭔지 몰라! 하지만 간단한 해결책을 사용했습니다. URLConenction입니다. 내 서비스를 호출하기 전에이 솔루션을 사용하여 내 URL을 제어했습니다. { URL testUrl = new URL (MyURL); URLConnection testConnection = testUrl.openConnection(); testConnection.setConnectTimeout (TIMEOUT_VALUE); testConnection.setReadTimeout (TIMEOUT_VALUE); } catch (SocketTimeoutException e) { System.out.println ("이상 + TIMEOUT_VALUE +"경과했습니다."); } – josef