PDA

View Full Version : Resin and CXF


juszczec
04-12-2011, 12:42 AM
Hi folks

I've been using Resin for maybe about 2 weeks. I'm trying to get an
Apache CXF application running and I've got a question.

This link http://wiki.caucho.com/CXF
gives an explanation of how to create a CXF app and run it under
Resin.

Is this the only way to use CXF and Resin? For instance, the
example shows the web service and client in the same application. Is
this the only way to do it or can I have the service and client in
different war files?

The link also shows the use of "<protocol uri="cxf:"/>" in
resin-web.xml. Are these absolute requirements or can I create a CXF
app without the protocol tag and with a web.xml file instead?

I've got a few other questions, but I'll have to post them after I
recreate the problems at work in the morning.

Mark

reza
04-13-2011, 03:23 PM
juszczec,

That wiki page is fairly outdated. We haven't tested CXF in Resin 4 yet, but you should be able to use it just as you would on any other Servlet container.

Thanks,
Reza

juszczec
04-13-2011, 07:15 PM
reza

Thank you for the reply. I found a more up to date set of instructions at:

http://caucho.com/resin-4.0/examples/remote-hello-world/index.xtp

I stripped out the non cxf stuff from the example, since I'm only interested in Resin and cxf at this point.

The problem is, it doesn't work. I'm not sure what's wrong.

Here are HelloService.java and HelloServiceImpl.java (I made no changes to these and am posting them for completeness):


package example;

public interface HelloService {
/**
* Returns "hello, world".
*/
public String hello();
}



package example;

public class HelloServiceImpl implements HelloService {
/**
* Returns "hello, world".
*/
public String hello()
{
return "hello, world";
}
}

Here is what's left of resin-web.xml. I took a guess and removed what I thought had nothing to do with cxf. Curiously, the <uri> tag said xfire, I assumed in needed to be changed to cxf. Am I correct?


<web-app xmlns="http://caucho.com/ns/resin">

<servlet-mapping url-pattern="/hello/hessian/*"
servlet-class="example.HelloServiceImpl">
<protocol uri="cxf:"/>
</servlet-mapping>

<remote-client interface="example.HelloService" name="soap">
<uri>cxf:url=${webApp.url}/hello/soap/</uri>
</remote-client>

</web-app>


demo.jsp became:


<%@ page import="javax.webbeans.Named" %>
<%@ page import="example.HelloService" %>
<%!
@Named("soap") HelloService _soapHello;
%>
<pre>
From SOAP: <%= _soapHello.hello() %>
</pre>


I also copied demo.jsp to index.jsp, because AFAIK that's the default entry point unless you specify something in web.xml. Resin doesn't have a web.xml, are its functions taken over by resin-web.xml?

I put all this in a web app called cxf2 and when I go to the url http://localhost:18979/cxf2/ (I changed the default port 8080 to 18979) I get
500 Servlet Exception


[show] java.lang.NullPointerException

java.lang.NullPointerException
at _jsp._index__jsp._jspService(index.jsp:7)
at _jsp._index__jsp._jspService(index.jsp:5)
at com.caucho.jsp.JavaPage.service(JavaPage.java:64)
at com.caucho.jsp.Page.pageservice(Page.java:542)
at com.caucho.server.dispatch.PageFilterChain.doFilte r(PageFilterChain.java:194)
at com.caucho.server.webapp.DispatchFilterChain.doFil ter(DispatchFilterChain.java:126)
at com.caucho.server.dispatch.ServletInvocation.servi ce(ServletInvocation.java:287)
at com.caucho.server.webapp.RequestDispatcherImpl.for ward(RequestDispatcherImpl.java:298)
at com.caucho.server.webapp.RequestDispatcherImpl.dis patch(RequestDispatcherImpl.java:141)
at com.caucho.server.dispatch.RewriteDispatchFilterCh ain.doFilter(RewriteDispatchFilterChain.java:91)
at com.caucho.server.webapp.WebAppFilterChain.doFilte r(WebAppFilterChain.java:156)
at com.caucho.server.webapp.AccessLogFilterChain.doFi lter(AccessLogFilterChain.java:95)
at com.caucho.server.dispatch.ServletInvocation.servi ce(ServletInvocation.java:287)
at com.caucho.server.http.HttpRequest.handleRequest(H ttpRequest.java:792)
at com.caucho.network.listen.TcpSocketLink.dispatchRe quest(TcpSocketLink.java:730)
at com.caucho.network.listen.TcpSocketLink.handleRequ est(TcpSocketLink.java:689)
at com.caucho.network.listen.TcpSocketLink.handleRequ estsImpl(TcpSocketLink.java:669)
at com.caucho.network.listen.TcpSocketLink.handleRequ ests(TcpSocketLink.java:617)
at com.caucho.network.listen.AcceptTask.doTask(Accept Task.java:104)
at com.caucho.network.listen.ConnectionReadTask.runTh read(ConnectionReadTask.java:98)
at com.caucho.network.listen.ConnectionReadTask.run(C onnectionReadTask.java:81)
at com.caucho.network.listen.AcceptTask.run(AcceptTas k.java:67)
at com.caucho.env.thread.ResinThread.runTasks(ResinTh read.java:164)
at com.caucho.env.thread.ResinThread.run(ResinThread. java:130)

Resin/4.0.16 Server: 'default'

The offending lines are line 5:
%> (after @Named("soap") HelloService _soapHello;)

and line 7:
From SOAP: <%= _soapHello.hello() %>

Can you, or anyone else reading, suggest where I went wrong?

Mark

reza
04-13-2011, 07:43 PM
Mark,

That example code is way out of date too. I can check to see if it still works if you need me to? Alternatively, I would follow the generic instructions to bootstrap CXF using web.xml (with or without Spring).

As soon as we can, the plan is to integrate CXF via CDI but we haven't gotten there yet (but could bump up the priority for that if it makes sense). We just haven't gotten any requests for it so it is lower priority right now.

Thanks,
Reza

juszczec
04-13-2011, 09:11 PM
reza

When you say the "generic instructions for bootstrapping CXF", do you refer to instructions provided with Resin or CXF? If you mean instructions provided with Resin and can send me a link, I'll be happy to go thru them and let you know the results.

I'll also look at the CXF website and see if I can find any such docs there.

Can you please let me know either way?

Mark

reza
04-13-2011, 09:23 PM
Mark,

I meant the instructions here: http://cxf.apache.org/docs/servlet-transport.html.

Thanks,
Reza

juszczec
04-13-2011, 09:30 PM
Reza

Thanks for the clarification. I understand. I'll give it a try and post the results.

Mark

juszczec
04-13-2011, 10:19 PM
Reza

Can you also try to configure a Spring+CXF web service under Resin as you offered in a previous post?

Perhaps if we work together we can come to a resolution quicker than working separately.

Mark

reza
04-13-2011, 10:40 PM
Mark,

Certainly.

I'll test out where we are with the Resin/CDI specific CXF support/generic CXF support without Spring (it's due for an update anyways as I mentioned). If you can try the CXF+Spring path and run into any Resin specific issues, I can certainly help with that.

Thanks,
Reza

juszczec
04-14-2011, 05:19 PM
Hello

This beans.xml file:


<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">

<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

<jaxws:endpoint
id="sfautils"
implementor="demo.spring.servlet.SFAutilsImpl"
address="/sfautils" />

</beans>


Gave this error:

file:/Users/mark.juszczec/resin-4.0.16/webapps/spring_http/WEB-INF/beans.xml:28:
<beans xmlns="http://www.springframework.org/schema/beans"> is an unexpected
top-level tag.

26: http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
27: http://cxf.apache.org/jaxws
28: http://cxf.apache.org/schemas/jaxws.xsd">
29:
30: <import resource="classpath:META-INF/cxf/cxf.xml" />


<beans xmlns="http://caucho.com/ns/resin">,
<beans xmlns="http://java.sun.com/xml/ns/javaee"> or
<beans xmlns=""> are expected.

Syntax: (<beans> | <beans> | <beans>)

Which is somewhat troubling. Am I correct in assuming Resin only permits the xmlns= lines shown above?

Mark

juszczec
04-14-2011, 05:30 PM
Never mind the question at the end of the last post.

I guess beans.xml has some significance in Resin. When I renamed beans.xml to applicationContext.xml and changed web.xml to use it instead, then everything started to work just fine.

Mark

reza
04-14-2011, 06:26 PM
Mark,

The file needs to be called something other than beans.xml and/or moved to another location besides WEB-INF/beans.xml or META-INF/beans.xml. Both of those files are assumed to be CDI deployment descriptors as defined by JSR 299: http://jcp.org/en/jsr/detail?id=299. In case you are not aware of it, CDI is the dependency injection standard for Java EE which Resin supports: http://www.caucho.com/resin/candi/.

Thanks,
Reza

reza
04-14-2011, 06:29 PM
Mark,

Great, glad it worked out - so do you need anything else from me/us at this point?

Thanks,
Reza

juszczec
04-15-2011, 06:16 PM
Reza

Actually, there is...

Can you tell me how I determine what jars, taglibs and other resources are provided with Resin?

Here's my problem. My shop is using Resin Pro 4.0.13. I've created a little tiny simple web app and I'm getting a NullPointerException on:

<jsp:useBean id="user" class="user.UserData" scope="session"/>

The class is present, so I'm at a loss.

The confusing this is, I don't have this problem on my local system. So I'm assuming there's some kind of difference between open source Resin on my local system and the Pro version installed on the other server.

Mark

reza
04-15-2011, 06:27 PM
Mark,

You really should not need to dig around the system classpath all that much. Most jars in the system classpath come from RESIN-HOME/lib. There is definitely no class named user.UserData in the system classpath.

I would turn up log levels and see what is really going on (or post the complete stack trace here).

Thanks,
Reza

juszczec
04-15-2011, 06:31 PM
Here's the stack trace:
java.lang.NullPointerException
at _jsp._SaveName__jsp._jspService(SaveName.jsp:11)
at _jsp._SaveName__jsp._jspService(_SaveName__jsp.jav a:28)
at com.caucho.jsp.JavaPage.service(JavaPage.java:64)
at com.caucho.jsp.Page.pageservice(Page.java:542)
at com.caucho.server.dispatch.PageFilterChain.doFilte r(PageFilterChain.java:194)
at com.caucho.server.webapp.WebAppFilterChain.doFilte r(WebAppFilterChain.java:183)
at com.caucho.server.webapp.AccessLogFilterChain.doFi lter(AccessLogFilterChain.java:95)
at com.caucho.server.dispatch.ServletInvocation.servi ce(ServletInvocation.java:287)
at com.caucho.server.http.HttpRequest.handleRequest(H ttpRequest.java:792)
at com.caucho.network.listen.TcpSocketLink.dispatchRe quest(TcpSocketLink.java:675)
at com.caucho.network.listen.TcpSocketLink.handleRequ estsImpl(TcpSocketLink.java:637)
at com.caucho.network.listen.TcpSocketLink.handleRequ ests(TcpSocketLink.java:588)
at com.caucho.network.listen.TcpSocketLink$AcceptTask .doTask(TcpSocketLink.java:1175)
at com.caucho.network.listen.TcpSocketLink$Connection ReadTask.runThread(TcpSocketLink.java:1108)
at com.caucho.network.listen.TcpSocketLink$AcceptTask .run(TcpSocketLink.java:1142)
at com.caucho.env.thread.ResinThread.runTasks(ResinTh read.java:182)
at com.caucho.env.thread.ResinThread.run(ResinThread. java:126)



Here's the jsp:


<%--
Document : SaveName
Created on : Apr 15, 2011, 7:17:04 AM
Author : mark.juszczec
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<jsp:useBean id="user" class="user.UserData" scope="session"/>
<jsp:setProperty name="user" property="*"/>
<HTML>
<BODY>
<A HREF="NextPage.jsp">Continue</A>
</BODY>
</HTML>

Mark

reza
04-15-2011, 07:30 PM
Mark,

Unfortunately, I am unable to replicate the issue. Here is the code I used:

================================================== ========
<jsp:useBean id="testBean" class="qa.TestBean" scope="session" />
<jsp:setProperty name="testBean" property="*" />
<jsp:getProperty name="testBean" property="data" />
================================================== ========

================================================== ========
package qa;

public class TestBean {
private String data;

public void setData(String data) {
this.data = data;
}

public String getData() {
return data;
}
}
================================================== ========

I would turn up the log levels and examine the generated code to see what is actually going wrong, possibly doing remote debugging.

Thanks,
Reza

juszczec
04-15-2011, 08:01 PM
Reza

I took a look at the generated code, and came up with a difference that I don't know how to interpret.

Hopefully you or someone on the list can help.

Here is the jsp that works:


public void
_jspService(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws java.io.IOException, javax.servlet.ServletException
{
javax.servlet.http.HttpSession session = request.getSession(true);
com.caucho.server.webapp.WebApp _jsp_application = _caucho_getApplication();
com.caucho.jsp.PageContextImpl pageContext = _jsp_pageManager.allocatePageContext(this, _jsp_application, request, response, null, session, 8192, true, false);

TagState _jsp_state = null;

try {
_jspService(request, response, pageContext, _jsp_application, session, _jsp_state);


Here's the one that fails:


public void
_jspService(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws java.io.IOException, javax.servlet.ServletException
{
com.caucho.server.webapp.WebApp _jsp_application = _caucho_getApplication();
com.caucho.jsp.PageContextImpl pageContext = _jsp_pageManager.allocatePageContext(this, _jsp_application, request, response, null, null, 8192, true, false);

TagState _jsp_state = null;

try {
_jspService(request, response, pageContext, _jsp_application, _jsp_state);


The calls to _jsp_pageManager.allocatePageContext have different parms.

Here the one that works:
com.caucho.jsp.PageContextImpl pageContext = _jsp_pageManager.allocatePageContext(this,
_jsp_application,
request,
response,
null,
session,
8192,
true,
false);

Parm 6 is "session"

In the one that fails:
com.caucho.jsp.PageContextImpl pageContext =
_jsp_pageManager.allocatePageContext(this,
_jsp_application,
request,
response,
null,
null,
8192,
true,
false);

Parm 6 is "null"

Any idea what that could be caused by?

reza
04-15-2011, 08:57 PM
Mark,

I'm not really sure what to tell you - I tried both 4.0.13 and 4.0.16 (the latest release) and neither produce the code you quoted. Are you sure about the Resin version you are using?

The only way I can reproduce this issue/code you quoted is by explicitly disabling sessions like this:

================================================== ========
<%@ page session="false" %>
<jsp:useBean id="user" class="qa.TestBean" scope="session" />
<jsp:setProperty name="user" property="*" />
<jsp:getProperty name="user" property="data" />
================================================== ========

Are you sure the server you are deploying to does not have sessions disabled for some wonky reason? Try this and see if it works:

================================================== ========
<%@ page session="true" %>
<jsp:useBean id="user" class="qa.TestBean" scope="session" />
<jsp:setProperty name="user" property="*" />
<jsp:getProperty name="user" property="data" />
================================================== ========

Thanks,
Reza

P.S.: Please do me a favor and start a new thread with a more appropriate title. That way, anyone else encountering this issue will be able to easily see it more easily.