You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by slocum <sl...@weirdrealm.com> on 2011/03/16 17:03:04 UTC

Calling cxf web service from JSP page

I built a JSP page to call my web service. When I run the JSP I get the
following root cause:



javax.xml.ws.WebServiceException: Port
{http://ws.cmps.digitalriver.com}CMPSWebServiceHttpPort not found.

	org.apache.cxf.jaxws.ServiceImpl.getPort(ServiceImpl.java:326)

	org.apache.cxf.jaxws.ServiceImpl.getPort(ServiceImpl.java:317)

	javax.xml.ws.Service.getPort(Service.java:92)


com.digitalriver.cmps.ws.CMPSWebService.getCMPSWebServiceHttpPort(CMPSWebService.java:63)

...



The JSP code is here:



<%

	CMPSWebService service =  new CMPSWebService();

	CMPSWebServicePortType port = service.getCMPSWebServiceHttpPort();

	LookupProductRequestType prdReq = new LookupProductRequestType();

	prdReq.setDivisionID(division);

	prdReq.setDivisionProductID(divOrderID);

	prdReq.setLanguage(lang);

	LookupProductResponseType resp = port.lookupProduct(prdReq);

%>



The relevant section of the WSDL is:


	&lt;wsdl:service name="CMPSWebService"&gt;

		&lt;wsdl:port name="CMPSWebServiceHttpPort"
binding="tns:CMPSWebServiceHttpBinding"&gt;

			&lt;soap:address
location="http://localhost:8080/cmps-1.0/services/CMPSWebService" /&gt;

		&lt;/wsdl:port&gt;

	&lt;/wsdl:service&gt;



Any ideas what I'm doing wrong?


--
View this message in context: http://cxf.547215.n5.nabble.com/Calling-cxf-web-service-from-JSP-page-tp3786341p3786341.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Calling cxf web service from JSP page

Posted by slocum <sl...@weirdrealm.com>.
I used the second method and it got farther. Looks like the service URL in
the addPort() isn't working right.

JSP Code:

	CMPSWebService service =  new CMPSWebService();
	QName portName = new QName("http://ws.cmps.digitalriver.com",
"CMPSWebServiceHttpPort");
	service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING,
"http://localhost:8080/cmps-1.0/services/CMPSWebService");
	CMPSWebServicePortType port = service.getCMPSWebServiceHttpPort();
	LookupProductRequestType prdReq = new LookupProductRequestType();


Error output:

org.apache.jasper.JasperException: An exception occurred processing JSP page
/new_product.jsp at line 138

135: 	prdReq.setDivisionID(division);
136: 	prdReq.setDivisionProductID(divProductID);
137: 	prdReq.setLanguage(lang);
138: 	LookupProductResponseType resp = port.lookupProduct(prdReq);
139: 
140: 	if (resp.getResponseMessage() != null &&
!resp.getResponseMessage().isEmpty() &&
resp.getResponseMessage().equalsIgnoreCase("SUCCESS")) {
141:     	product = resp.getProductInformation();

...

root cause

javax.xml.ws.WebServiceException: Could not send Message.
	org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:135)
	$Proxy69.lookupProduct(Unknown Source)

org.apache.jsp.new_005fproduct_jsp._jspService(new_005fproduct_jsp.java:258)

...

root cause

java.net.ConnectException: ConnectException invoking
http://localhost:8080/cmps-1.0/services/CMPSWebService: Connection refused
	sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	java.lang.reflect.Constructor.newInstance(Constructor.java:513)

org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.mapException(HTTPConduit.java:2058)

org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:2043)
	org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
	org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:639)

org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)

org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:243)
	org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:487)
	org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:313)
	org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:265)
	org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
	org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:124)
	$Proxy69.lookupProduct(Unknown Source)

org.apache.jsp.new_005fproduct_jsp._jspService(new_005fproduct_jsp.java:258)


--
View this message in context: http://cxf.547215.n5.nabble.com/Calling-cxf-web-service-from-JSP-page-tp3786341p3796000.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Calling cxf web service from JSP page

Posted by Daniel Kulp <dk...@apache.org>.
On Wednesday 16 March 2011 2:20:15 PM slocum wrote:
> So I still get the same error with this. Here is the new JSP code:
> 
> 	CMPSWebService service =  new CMPSWebService();
> 	URL wsdlURL =
> service.getClass().getResource("/WEB-INF/classes/cmps-1.0.wsdl");

Can you double check that wsdlURL is not null here?    If getResource doesn't 
find it, it would be null and that would be the equivilent of:

new CMPSWebService(null, serviceName);

and thus thus wsdl wouldn't be used.   


THAT said, if there is nothing in the wsdl that is really needed (like 
policies and such), you can do something like:
service = new CMPSWebService();
QName portName = new QName("http://ws.cmps.digitalriver.com",
               "CMPSWebServiceHttpPort");
service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, 
                          "http://localhost:8080/path/to/service");


Dan


> 	QName serviceName = new QName("http://ws.cmps.digitalriver.com",
> "CMPSWebService");
> 	service = new CMPSWebService(wsdlURL, serviceName);
> 	CMPSWebServicePortType port = service.getCMPSWebServiceHttpPort();
> 
> 
> For reference, here is the top of the web service implementation code:
> 
> @WebService(name = "CMPSServiceImpl",
> 			serviceName = "CMPSWebService",
> 			portName = "CMPSWebServiceHttpPort",
> 			wsdlLocation="classpath:cmps-1.0.wsdl",
> 			endpointInterface = 
"com.digitalriver.cmps.ws.CMPSWebServicePortType",
> 			targetNamespace = "http://ws.cmps.digitalriver.com")
> public class CMPSServiceImpl implements CMPSWebServicePortType {
> 
>     public CMPSServiceImpl() {
>     	this(Application.getInstance().getSessionFactory());
>     }
> 
>     public CMPSServiceImpl(SessionFactory factory) {
>         sessionFactory = factory;
>         try {
>           Application.getInstance().loadProperties();
>           logger.debug("Loaded application props!!!!!!!");
>         }
>         catch(Exception e) {
>             e.printStackTrace();
>         }
>     }
> ...
> }
> 
> Daniel  Kulp wrote:
> > It would depend on where you stick the WSDL.   A common place is in WEB-
> > INF/wsdl in which case it would be something like:
> > 
> > URL wsdlURL =
> > service.getClass().getResource("/WEB-INF/wsdl/myWsdl.wsdl"); QName
> > serviceName = new QName(http://ws.cmps.digitalriver.com"",
> > "CMPSWebService");
> > service = new CMPSWebService(wsdlURL, serviceName);
> 
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/Calling-cxf-web-service-from-JSP-page-tp37
> 86341p3791853.html Sent from the cxf-user mailing list archive at
> Nabble.com.

-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog
Talend - http://www.talend.com

Re: Calling cxf web service from JSP page

Posted by slocum <sl...@weirdrealm.com>.
So I still get the same error with this. Here is the new JSP code:

	CMPSWebService service =  new CMPSWebService();
	URL wsdlURL =
service.getClass().getResource("/WEB-INF/classes/cmps-1.0.wsdl");
	QName serviceName = new QName("http://ws.cmps.digitalriver.com",
"CMPSWebService");
	service = new CMPSWebService(wsdlURL, serviceName);
	CMPSWebServicePortType port = service.getCMPSWebServiceHttpPort();


For reference, here is the top of the web service implementation code:

@WebService(name = "CMPSServiceImpl",
			serviceName = "CMPSWebService",
			portName = "CMPSWebServiceHttpPort",
			wsdlLocation="classpath:cmps-1.0.wsdl",
			endpointInterface = "com.digitalriver.cmps.ws.CMPSWebServicePortType",
			targetNamespace = "http://ws.cmps.digitalriver.com")
public class CMPSServiceImpl implements CMPSWebServicePortType {

    public CMPSServiceImpl() {
    	this(Application.getInstance().getSessionFactory());
    }
    
    public CMPSServiceImpl(SessionFactory factory) {
        sessionFactory = factory;
        try {
          Application.getInstance().loadProperties();
          logger.debug("Loaded application props!!!!!!!");
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }
...
}


Daniel  Kulp wrote:
> 
> It would depend on where you stick the WSDL.   A common place is in WEB-
> INF/wsdl in which case it would be something like:
> 
> URL wsdlURL = service.getClass().getResource("/WEB-INF/wsdl/myWsdl.wsdl");
> QName serviceName = new QName(http://ws.cmps.digitalriver.com"", 
> "CMPSWebService");
> service = new CMPSWebService(wsdlURL, serviceName);
> 
> 



--
View this message in context: http://cxf.547215.n5.nabble.com/Calling-cxf-web-service-from-JSP-page-tp3786341p3791853.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Calling cxf web service from JSP page

Posted by Daniel Kulp <dk...@apache.org>.
On Wednesday 16 March 2011 1:58:51 PM slocum wrote:
> Daniel  Kulp wrote:
> > My gut feeling says it's not finding the WSDL properly.
> > 
> > My suggestion is to change:
> > CMPSWebService service =  new CMPSWebService();
> > 
> > to use the constructor that takes the WSDL url and service QName.   Grab
> > the
> > WSDL via getClass().getResource(....) or similar to make sure the WSDL is
> > resolvable.
> 
> What is the name of the resource for the WSDL to supply to getResource()?

It would depend on where you stick the WSDL.   A common place is in WEB-
INF/wsdl in which case it would be something like:

URL wsdlURL = service.getClass().getResource("/WEB-INF/wsdl/myWsdl.wsdl");
QName serviceName = new QName(http://ws.cmps.digitalriver.com"", 
"CMPSWebService");
service = new CMPSWebService(wsdlURL, serviceName);


The wsdl URL could be something like that or even an http URL or file URL, 
etc..


-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog
Talend - http://www.talend.com

Re: Calling cxf web service from JSP page

Posted by slocum <sl...@weirdrealm.com>.
Daniel  Kulp wrote:
> 
> My gut feeling says it's not finding the WSDL properly. 
> 
> My suggestion is to change:
> CMPSWebService service =  new CMPSWebService();
> 
> to use the constructor that takes the WSDL url and service QName.   Grab
> the 
> WSDL via getClass().getResource(....) or similar to make sure the WSDL is 
> resolvable.
> 

What is the name of the resource for the WSDL to supply to getResource()?

And otherwise, it should look something like this?

	CMPSWebService service =  new CMPSWebService();
	URL wsdlURL = service.getClass().getResource("WSDL");
	QName serviceName = service.getServiceName();
	service = new CMPSWebService(wsdlURL, serviceName);



--
View this message in context: http://cxf.547215.n5.nabble.com/Calling-cxf-web-service-from-JSP-page-tp3786341p3791083.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Calling cxf web service from JSP page

Posted by Daniel Kulp <dk...@apache.org>.

My gut feeling says it's not finding the WSDL properly. 

My suggestion is to change:
CMPSWebService service =  new CMPSWebService();

to use the constructor that takes the WSDL url and service QName.   Grab the 
WSDL via getClass().getResource(....) or similar to make sure the WSDL is 
resolvable.

Dan


On Wednesday 16 March 2011 12:03:04 PM slocum wrote:
> I built a JSP page to call my web service. When I run the JSP I get the
> following root cause:
> 
> 
> 
> javax.xml.ws.WebServiceException: Port
> {http://ws.cmps.digitalriver.com}CMPSWebServiceHttpPort not found.
> 
> 	org.apache.cxf.jaxws.ServiceImpl.getPort(ServiceImpl.java:326)
> 
> 	org.apache.cxf.jaxws.ServiceImpl.getPort(ServiceImpl.java:317)
> 
> 	javax.xml.ws.Service.getPort(Service.java:92)
> 
> 
> com.digitalriver.cmps.ws.CMPSWebService.getCMPSWebServiceHttpPort(CMPSWebSe
> rvice.java:63)
> 
> ...
> 
> 
> 
> The JSP code is here:
> 
> 
> 
> <%
> 
> 	CMPSWebService service =  new CMPSWebService();
> 
> 	CMPSWebServicePortType port = service.getCMPSWebServiceHttpPort();
> 
> 	LookupProductRequestType prdReq = new LookupProductRequestType();
> 
> 	prdReq.setDivisionID(division);
> 
> 	prdReq.setDivisionProductID(divOrderID);
> 
> 	prdReq.setLanguage(lang);
> 
> 	LookupProductResponseType resp = port.lookupProduct(prdReq);
> 
> %>
> 
> 
> 
> The relevant section of the WSDL is:
> 
> 
> 	&lt;wsdl:service name="CMPSWebService"&gt;
> 
> 		&lt;wsdl:port name="CMPSWebServiceHttpPort"
> binding="tns:CMPSWebServiceHttpBinding"&gt;
> 
> 			&lt;soap:address
> location="http://localhost:8080/cmps-1.0/services/CMPSWebService" /&gt;
> 
> 		&lt;/wsdl:port&gt;
> 
> 	&lt;/wsdl:service&gt;
> 
> 
> 
> Any ideas what I'm doing wrong?
> 
> 
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/Calling-cxf-web-service-from-JSP-page-tp37
> 86341p3786341.html Sent from the cxf-user mailing list archive at
> Nabble.com.

-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog
Talend - http://www.talend.com