2010-12-14 37 views
0

你好 首先抱歉我的英語不好。沒有Tomcat或Axis的SOAP通訊

我用Eclipse開發。作爲目標平臺,我使用劍魚默認。我想使用SOAP作爲協議,但沒有像Tomcat這樣的exta工具包。我寫了一些WSDL文件。隨着劍魚我建立了一個提供者和消費者。它首先效果很好。但過了一段時間後,協議接口爲空,因爲會話無效。劍魚使所有連接全自動,我還沒有找到我如何手動連接到我的接口。 (使用OSGI的箭魚)如何手動重試連接?

這裏是一些代碼,這將是有用的

import java.util.Timer; 
import java.util.TimerTask; 

import org.apache.commons.logging.Log; 
import org.apache.commons.logging.LogFactory; 
import org.springframework.beans.factory.InitializingBean; 
import org.springframework.util.Assert; 
import org.iecimpl.serverserverprotocoll.ServerServerProtocoll; 

public class ServerServerProtocollClientInvoker implements InitializingBean { 
    private static final Log LOG = LogFactory.getLog(ServerServerProtocollClientInvoker.class); 
private Integer delayBeforeSending = 5000; 
private ServerServerProtocoll serverServerProtocoll; 
public ServerServerProtocoll getServerServerProtocoll() { 
    return serverServerProtocoll; 
} 

public void setServerServerProtocoll(ServerServerProtocoll serverServerProtocoll) { 
    this.serverServerProtocoll = serverServerProtocoll; 
} 

public Integer getDelayBeforeSending() { 
    return delayBeforeSending; 
} 

public void setDelayBeforeSending(Integer delayBeforeSending) { 
    this.delayBeforeSending = delayBeforeSending; 
} 

public void afterPropertiesSet() throws Exception { 
    Assert.notNull(serverServerProtocoll); 
    Timer timer = new Timer(); 
     timer.schedule(new TimerTask() { 
      @Override 
      public void run() { 
       try { 
        performRequest(); 
       } catch (Exception ex) { 
        throw new RuntimeException(ex); 
       } 
      } 


     }, delayBeforeSending); 
    } 
private void performRequest() { 
    LOG.info("Performing invocation on ..."); 
    /*Implementation*/ 
    clienttest.testclienttest(serverServerProtocoll); 
    LOG.info("Result of runing is...."); 
} 
} 

XML文件:

xml under META-INF/spring/jaxws-consumer.xml 
<?xml version="1.0" encoding="UTF-8"?> 

<!-- 
Copyright (c) 2008, 2009 SOPERA GmbH. 
All rights reserved. This program and the accompanying materials 
are made available under the terms of the Eclipse Public License v1.0 
which accompanies this distribution, and is available at 
http://www.eclipse.org/legal/epl-v10.html 

Contributors: 
    SOPERA GmbH - initial API and implementation 
--> 

<spring:beans xmlns:spring="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:osgi="http://www.springframework.org/schema/osgi" 
    xmlns:camel-osgi="ht_tp://activemq.apache.org/camel/schema/osgi" 
    xmlns:http="http://servicemix.apache.org/http/1.0" 
    xmlns:jaxws="http://cxf.apache.org/jaxws" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
    http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd 
    http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd 
    http://servicemix.apache.org/http/1.0 http://servicemix.apache.org/http/1.0/servicemix-http.xsd" 
    xmlns:serviceNamespace="ht_tp://www.IECImpl.org/ServerServerProtocoll/" 
    xmlns="ht-tp://www.IECImpl.org/ServerServerProtocoll/">  

<spring:import resource="classpath:META-INF/cxf/cxf.xml" /> 
<spring:import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> 
<spring:import resource="classpath:META-INF/org/eclipse/swordfish/plugins/cxf/support/nmr-transport.xml" /> 

<jaxws:client id="ServerServerProtocollClient" 
       serviceClass="org.iecimpl.serverserverprotocoll.ServerServerProtocoll" 
       serviceName="serviceNamespace:ServerServerProtocoll" 
       address="nmr:ServerServerProtocoll" /> 
<spring:bean class="org.iecimpl.serverserverprotocoll.sample.ServerServerProtocollClientInvoker"> 
<spring:property name="serverServerProtocoll" ref="ServerServerProtocollClient"/> 
</spring:bean>  


<spring:bean class="org.apache.servicemix.common.osgi.EndpointExporter" /> 

<http:endpoint endpoint="cxfEndpointHttpProvider"     
      service="serviceNamespace:ServerServerProtocoll" 
      locationURI="http://localhost:1001/EnergyServer" 
      soap="true" 
      role="provider"/> 

所有數據定義,但我在這方面newbee。

+0

不是嗎?沒有人? – Muuh 2010-12-14 18:23:16

+0

你想從eclipse IDE手動連接到你的服務嗎? – UVM 2010-12-15 06:56:51

+0

對不起,我沒有看到你有答案。我想在不使用Springmetadata的情況下從Javacode動態連接。 – Muuh 2011-01-11 19:19:40

回答

1

我想知道爲什麼你會「鬆動」serverServerProtocoll的價值? 從您發佈的代碼中,不清楚。如果值「突然」變得無效,必須有一個任務,做那個......

你可以試試這個解決方法: 箭魚作爲內部使用CXF,你可以簡單地創建一個org.apache.cxf.jaxws.JaxWsProxyFactoryBean 你的消費者Spring的配置中。

每當你需要一個客戶端爲你的服務,你可以使用Spring應用程序上下文中定義的工廠bean創建一個。

請參閱:Configuring a Spring Client (Option 2)