package sample;import java.io.StringReader;import javax.jbi.messaging.InOut;
import javax.jbi.messaging.NormalizedMessage;
import javax.xml.namespace.QName;
import javax.xml.transform.stream.StreamSource;import org.apache.servicemix.client.RemoteServiceMixClient;public class Test {
public static void main(String[] args) {
RemoteServiceMixClient client = new RemoteServiceMixClient(
"tcp://localhost:61616");
try {
client.init();
client.start();
InOut exchange = client.createInOutExchange();
QName service = new QName("http://localhost:8193/HelloWorld/","say");
exchange.setService(service); NormalizedMessage request = exchange.getInMessage();
request.setProperty("name", "James");
request.setContent(new StreamSource(new StringReader("<Hello>world</Hello>"))); client.sendSync(exchange); NormalizedMessage response = exchange.getOutMessage();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
client.shutDown();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}SMX已经启动,http://localhost:8193/HelloWorld/是已经部署在总线上的sa,调用外部webservice。通过smx自带的例子cxf-wsdl-first中的client.html测试通过,但是使用java类调用出现如下异常:
log4j:WARN No appenders could be found for logger (org.apache.servicemix.jbi.framework.EndpointRegistry).
log4j:WARN Please initialize the log4j system properly.
javax.jbi.messaging.MessagingException: Could not find route for exchange: InOut[
  id: ID:192.168.1.217-12553e3c464-3:0
  status: Active
  role: provider
  service: {http://localhost:8193/HelloWorld/}say
  in: <?xml version="1.0" encoding="UTF-8"?><Hello>world</Hello>
] for service: {http://localhost:8193/HelloWorld/}say and interface: null
at org.apache.servicemix.jbi.nmr.DefaultBroker.sendExchangePacket(DefaultBroker.java:297)
at org.apache.servicemix.jbi.container.JBIContainer.sendExchange(JBIContainer.java:894)
at org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.doSend(DeliveryChannelImpl.java:396)
at org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.sendSync(DeliveryChannelImpl.java:471)
at org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.sendSync(DeliveryChannelImpl.java:443)
at org.apache.servicemix.client.DefaultServiceMixClient.sendSync(DefaultServiceMixClient.java:156)
at sample.Test.main(Test.java:33)求高人解答,或者告诉我如何使用RemoteServiceMixClient,谢谢!

解决方案 »

  1.   

    1--log4j:WARN No appenders could be found for loggerThe reason why you see this message is that your log4j configuration file(i.e. log4j.xml or log4j.properties) is NOT found in the classpath. Placing the log4j configuration file in the applications classpath should solve the issue.2--log4j:WARN Please initialize the log4j system properly. You have not initialised log4j properly. Try reading the online log4j manual or by adding a log4j.properties file to your classpath (to a directory which is on the classpath to be precise).3--javax.jbi.messaging.MessagingException: Could not find route for exchange: InOut..the problem you don't register your service? 
      

  2.   

    http://www.koders.com/java/fid9D2D0D572F3B1E890B2D9F352BF7F1DA56228F81.aspx
      

  3.   

    我已经将外部的webservice的wsdl封装生成sa部署到smx上了,现在就是想用java代码去连接smx调用sa来使用外部的ws。
    你所说的注册是如何实现的?
      

  4.   

    这是sa的wsdl
    <?xml version="1.0" encoding="UTF-8"?>
    <wsdl:definitions targetNamespace="http://sample" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://sample" xmlns:intf="http://sample" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <!--WSDL created by Apache Axis version: 1.4
    Built on Apr 22, 2006 (06:55:48 PDT)-->
     <wsdl:types>
      <schema elementFormDefault="qualified" targetNamespace="http://sample" xmlns="http://www.w3.org/2001/XMLSchema">
       <element name="say">
        <complexType>
         <sequence>
          <element name="name" type="xsd:string"/>
         </sequence>
        </complexType>
       </element>
       <element name="sayResponse">
        <complexType>
         <sequence>
          <element name="sayReturn" type="xsd:string"/>
         </sequence>
        </complexType>
       </element>
      </schema>
     </wsdl:types>
       <wsdl:message name="sayResponse">
          <wsdl:part element="impl:sayResponse" name="parameters"/>
       </wsdl:message>
       <wsdl:message name="sayRequest">
          <wsdl:part element="impl:say" name="parameters"/>
       </wsdl:message>
       <wsdl:portType name="Hello">
          <wsdl:operation name="say">
             <wsdl:input message="impl:sayRequest" name="sayRequest"/>
             <wsdl:output message="impl:sayResponse" name="sayResponse"/>
          </wsdl:operation>
       </wsdl:portType>
       <wsdl:binding name="HelloSoapBinding" type="impl:Hello">
          <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
          <wsdl:operation name="say">
             <wsdlsoap:operation soapAction=""/>
             <wsdl:input name="sayRequest">
                <wsdlsoap:body use="literal"/>
             </wsdl:input>
             <wsdl:output name="sayResponse">
                <wsdlsoap:body use="literal"/>
             </wsdl:output>
          </wsdl:operation>
       </wsdl:binding>
       <wsdl:service name="HelloServiceProxy">
          <wsdl:port binding="impl:HelloSoapBinding" name="HelloProxy">
             <wsdlsoap:address location="http://localhost:8193/HelloWorld/"/>
          </wsdl:port>
       </wsdl:service>
    </wsdl:definitions>