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,谢谢!
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,谢谢!
你所说的注册是如何实现的?
<?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>