You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by imiten <im...@yahoo.com> on 2012/04/13 12:06:58 UTC
dispatch api cannot find port
Hi,
I created a client server for dispatch provider based web service. Below
are its code and error. I used eclipse WebService (STP) plugin to write the
service and generate the wsdl and client. I modified client as per the cxf
web site sample.
The webservice is deployed to tomcat and its log are are below.
Web Service
-----------
package com.mkyong.webservice;
import javax.jws.WebService;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.Provider;
import javax.xml.ws.ServiceMode;
import javax.xml.ws.Service;
import javax.xml.ws.WebServiceProvider;
@WebService(targetNamespace = "http://webservice.mkyong.com/", portName =
"ProductWebServicePort", serviceName = "ProductWebServiceService")
@WebServiceProvider
@ServiceMode(value=Service.Mode.PAYLOAD)
public class ProductWebService implements Provider<SOAPMessage> {
public SOAPMessage invoke(SOAPMessage request) {
// TODO Auto-generated method stub
SOAPMessage response = null;
try {
System.out.println("Incoming Client Request as a SOAPMessage");
System.out.println(request);
} catch (Exception ex) {
ex.printStackTrace();
}
return response;
}
}
Client:
-------
/**
* Please modify this class to meet your needs
* This class is not complete
*/
package com.mkyong.webservice;
import java.io.InputStream;
import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPMessage;
import javax.xml.transform.dom.DOMSource;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
/**
* This class was generated by Apache CXF 2.5.2
* 2012-04-13T13:43:44.952+05:30
* Generated source version: 2.5.2
*
*/
public class ProductWebService_PortTypeClient {
public static void main(String[] args) throws Exception {
QName serviceName = new QName("http://webservice.mkyong.com/",
"ProductWebServiceService");
QName portName = new QName("http://webservice.mkyong.com/",
"ProductWebServicePort");
Service service = Service.create(serviceName);
Dispatch<SOAPMessage> dispatch = service.createDispatch(portName,
SOAPMessage.class, Service.Mode.PAYLOAD);
InputStream is1 =
Service.class.getResourceAsStream("CreateProduct.xml");
if (is1 == null) {
System.err.println("Failed to create input stream from file "
+ "CreateProduct.xml, please check");
System.exit(-1);
}
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage soapReq1 = factory.createMessage(null, is1);
System.out.println("Invoking server through Dispatch interface using
SOAPMessage");
SOAPMessage soapResp = dispatch.invoke(soapReq1);
System.out.println("Response from server: " +
soapResp.getSOAPBody().getTextContent());
}
}
Client run error:
-----------------
Apr 13, 2012 2:45:25 PM
org.apache.cxf.service.factory.ReflectionServiceFactoryBean
buildServiceFromClass
INFO: Creating Service
{http://webservice.mkyong.com/}ProductWebServiceService from class
org.apache.cxf.jaxws.support.DummyImpl
Exception in thread "main" javax.xml.ws.WebServiceException: Port
{http://webservice.mkyong.com/}ProductWebServicePort not found.
at org.apache.cxf.jaxws.ServiceImpl.getJaxwsEndpoint(ServiceImpl.java:254)
at org.apache.cxf.jaxws.ServiceImpl.createDispatch(ServiceImpl.java:634)
at org.apache.cxf.jaxws.ServiceImpl.createDispatch(ServiceImpl.java:609)
at org.apache.cxf.jaxws.ServiceImpl.createDispatch(ServiceImpl.java:601)
at javax.xml.ws.Service.createDispatch(Service.java:352)
at
com.mkyong.webservice.ProductWebService_PortTypeClient.main(ProductWebService_PortTypeClient.java:30)
tomcat log:
-----------
Apr 13, 2012 2:44:13 PM
org.springframework.beans.factory.support.DefaultListableBeanFactory
preInstantiateSingletons
INFO: Pre-instantiating singletons in
org.springframework.beans.factory.support.DefaultListableBeanFactory@106b5f4:
defining beans
[cxf,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,productwebservice];
root of factory hierarchy
Apr 13, 2012 2:44:13 PM
org.apache.cxf.service.factory.ReflectionServiceFactoryBean
buildServiceFromWSDL
INFO: Creating Service
{http://webservice.mkyong.com/}ProductWebServiceService from WSDL:
wsdl/productwebservice.wsdl
Apr 13, 2012 2:44:14 PM org.apache.cxf.endpoint.ServerImpl initDestination
INFO: Setting the server's publish address to be /ProductWebServicePort
Apr 13, 2012 2:44:14 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/WebServiceProject] is completed
Regards,
Miten.
--
View this message in context: http://cxf.547215.n5.nabble.com/dispatch-api-cannot-find-port-tp5637843p5637843.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: dispatch api cannot find port
Posted by Daniel Kulp <dk...@apache.org>.
On Friday, April 13, 2012 04:21:27 AM imiten wrote:
> Hi,
>
> Its working !
>
> I added url in dispatcher client code as:
> Service service = Service.create(new
> URL("http://localhost:8080/WebServiceProject/wsdl/productwebservice.wsdl")
> , serviceName);
>
> Now it fetches wsdl and invokes service fine. I also changed mode from
> payload to message.
>
> I have few questions below.
>
> 1) will I have to hardcode the wsdl url, qname in servlet if I have to
> invoke the webservice from web page ? Actually I wanted to have web page
> on submit, triggers servlet which then contacts web service. I would
> want form submit directly trigger web service but not sure how to handle
> soap communication in html client. need ajax ?
CXF does have a Javascript based client. You can run wsdl2js to generate a
Javascript client that can be used for very basic SOAP things directly.
That said, enabling a REST based interface with CXF's JAX-RS implementation
and using that from the HTML client is likely the better option for most
things.
That said, your original code may have worked if you added a addPort call in
there:
Service service = Service.create(serviceName);
service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING,
"http://servername.com/foo")
Dispatch<SOAPMessage> dispatch = service.createDispatch(portName,
SOAPMessage.class, Service.Mode.PAYLOAD);
> 2) When I try payload mode it complains (I made the request to but xml
> message removing soap tags):
> SOAPMessage is not valid in PAYLOAD mode with SOAP/HTTP binding.
> It seems I need to change service provider type to use DOMSource instead
> of SOAPMessage. any ideas ?
A SOAPMessage always represents the entire message and thus must be MESSAGE
mode. If you just want the payload (contents of the Body), you need a type
that can represent just that such as DOMSource (or just Source).
> 3) eclipse is generating WebServiceProject with the web service wizard
> from my implementation (provider) class. will it generate such generic
> names ? I was wanting to use some ant script etc. to generate war and was
> hoping that eclipse will help me with that ? any idea if its possible ?
No idea on that one.
Dan
>
> Regards,
>
> Miten.
>
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/dispatch-api-cannot-find-port-tp5637843p5
> 638013.html Sent from the cxf-user mailing list archive at Nabble.com.
--
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com
Re: dispatch api cannot find port
Posted by imiten <im...@yahoo.com>.
Hi,
Its working !
I added url in dispatcher client code as:
Service service = Service.create(new
URL("http://localhost:8080/WebServiceProject/wsdl/productwebservice.wsdl"),
serviceName);
Now it fetches wsdl and invokes service fine. I also changed mode from
payload to message.
I have few questions below.
1) will I have to hardcode the wsdl url, qname in servlet if I have to
invoke the webservice from web page ? Actually I wanted to have web page on
submit, triggers servlet which then contacts web service. I would want form
submit directly trigger web service but not sure how to handle soap
communication in html client. need ajax ?
2) When I try payload mode it complains (I made the request to but xml
message removing soap tags):
SOAPMessage is not valid in PAYLOAD mode with SOAP/HTTP binding.
It seems I need to change service provider type to use DOMSource instead of
SOAPMessage. any ideas ?
3) eclipse is generating WebServiceProject with the web service wizard from
my implementation (provider) class. will it generate such generic names ? I
was wanting to use some ant script etc. to generate war and was hoping that
eclipse will help me with that ? any idea if its possible ?
Regards,
Miten.
--
View this message in context: http://cxf.547215.n5.nabble.com/dispatch-api-cannot-find-port-tp5637843p5638013.html
Sent from the cxf-user mailing list archive at Nabble.com.