You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Leos Literak <li...@centrum.cz> on 2008/04/20 15:22:27 UTC

servlet transport question

Hi,

I want to add soap stack to my web application. I decided for CXF. This 
page http://cwiki.apache.org/CXF20DOC/servlet-transport.html shows it 
could be possible. I set up web.xml and now I want to bind the servlet 
to bus, as specified in documentation:

// cxf is the instance of the CXFServlet
Bus bus = cxf.getBus();
BusFactory.setDefaultBus(bus);
Endpoint.publish("/Greeter", new GreeterImpl());

The question is: how can I get the CXFServlet instance? J2EE's 
getServlet() method is deprecated.

1) I dont want to add spring to my project so I want to use programmatic 
way.
2) My application is a web application running in jetty container, so 
starting jetty within jetty is not good option.
3) Endpoint has no method publish, but EndpointImpl.

Thank you

Leos

PS1 documentation says that to build samples you need ant 1.6. I've got 
CXFServlet, but it fails, that verbose attribute is not supported

PS2 javadoc from installer does not contain CXFServlet

Re: servlet transport question

Posted by Rafael Ribeiro <ra...@gmail.com>.
2008/4/20, literakl@centrum.cz <li...@centrum.cz>:
>
> Rafael,
>
> thank you for your message. Especially the note about FQCN for Endpoint is
> crucial for me! Can somebody update
> http://cwiki.apache.org/CXF20DOC/servlet-transport.html ?
>
>
> >After, I configured CXFNonSpringServlet on my web.xml file and then I had
> >setup a Servlet (it could be a filter as well) with loadonstartup to
> >register the Services I had using: Endpoint.publish. Be careful not to
> >import the wrong Endpoint (right one is from: javax.xml.ws) class.
>
>
> Please put snippet, how to configure the Bus (setup the servlet). The
> web.xml part is clear:
>
>   <servlet>
>     <servlet-name>CXFServlet</servlet-name>
>     <display-name>CXF Servlet</display-name>
>     <servlet-class>
>
>         org.apache.cxf.transport.servlet.CXFServlet
>
>     </servlet-class>
>   </servlet>
>
>   <servlet-mapping>
>     <servlet-name>CXFServlet</servlet-name>
>     <url-pattern>/services/*</url-pattern>
>   </servlet-mapping>
>
> But how to manage this part?
>
>
> // cxf is the instance of the CXFServlet
> Bus bus = cxf.getBus();
> BusFactory.setDefaultBus(bus);


Seems like it is already done inside startup of CXFNonSpringServlet
class...  I think I saw in the sources, so the only thing you need to do is
run Endpoint.publish after CXFNonSpringServlet has been run. So, remember to
have an startupvalue for ur servlet greater than CXFNonSpringServlet to
avoid it being run before CXFs.

How have you solved it? Or is it set up behind the scene automatically in
> 2.0.5 release?
>
> Thank you
>
>
> Leos
>
>

Re: servlet transport question

Posted by Willem Jiang <wi...@gmail.com>.
My suggestion is your endpoint publishing code need be put into the 
AbcCxfServlet, so you could get the full control of the bus.
BTW, CXFNoSpringServlet will replace Jetty http transport factory with 
the servlet transport factory.
You need to call the

BusFactory.setDefaultBus(bus);
just before 
Endpoint.publish(endpointUrl, new UserAccountServiceImpl());

If you call the publishing code in another servlet which could load by another classloader, CXF will create another bus for this endpoint.

The service url should be a related path, such as "/users". CXF don't 
know the application's name, so it will update the endpoint's address 
with the request url and the related path is the best way to resolve 
this problem.

Willem


literakl@centrum.cz wrote:
> Ok,
>
> I made some progress today:
>     <servlet>
>         <servlet-name>CXFServlet</servlet-name>
>         <display-name>CXF Web services Servlet</display-name>
>         <servlet-class>cz.abclinuxu.servlets.ws.AbcCxfServlet</servlet-class>
>         <load-on-startup>1</load-on-startup>
>     </servlet>
>     <servlet-mapping>
>         <servlet-name>CXFServlet</servlet-name>
>         <url-pattern>/services/*</url-pattern>
>     </servlet-mapping>
>
> public class AbcCxfServlet extends CXFNonSpringServlet {
>     public void init(ServletConfig servletConfig) throws ServletException {
>         super.init(servletConfig);
>         Bus bus = this.getBus();
>         BusFactory.setDefaultBus(bus);
>     }
> }
>
> some other servlet loaded later:
>
>         String endpointUrl = "http://"+getHostname()+"/services/users";
>         Endpoint.publish(endpointUrl, new UserAccountServiceImpl());
>
> @WebService(endpointInterface = "cz.abclinuxu.servlets.ws.UserAccountService", serviceName = "Users")
> public class UserAccountServiceImpl implements UserAccountService {
>
> saaj-impl-1.3.jar wsdl4j-1.6.1.jar wstx-asl-3.2.4.jar xml-resolver-1.2.jar
> cxf-2.0.5-incubator.jar                  jaxb-api-2.0.jar     saaj-api-1.3.jar    xml-resolver-1.2.jar
> geronimo-annotation_1.0_spec-1.1.1.jar   jaxb-impl-2.0.5.jar  saaj-impl-1.3.jar   XmlSchema-1.3.2.jar
> geronimo-stax-api_1.0_spec-1.0.1.jar     jaxws-api-2.0.jar    wsdl4j-1.6.1.jar
> geronimo-ws-metadata_2.0_spec-1.1.2.jar  neethi-2.0.2.jar     wstx-asl-3.2.4.jar
>
> When I start jetty:
>
> 24.4.2008 19:04:27 org.apache.cxf.transport.servlet.CXFNonSpringServlet loadBusNoConfig
> INFO: Load the bus without application context
> 24.4.2008 19:04:28 org.apache.cxf.transport.servlet.AbstractCXFServlet replaceDestinationFactory
> INFO: Replaced the http destionFactory with servlet transport factory
> 24.4.2008 19:04:28 org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
> INFO: Creating Service {http://ws.servlets.abclinuxu.cz/}Users from class cz.abclinuxu.servlets.ws.UserAccountServiceImpl
> 24.4.2008 19:04:30 org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
> INFO: {http://ws.servlets.abclinuxu.cz/}arg0 part element name {http://ws.servlets.abclinuxu.cz/}arg0 references element {http://ws.servlets.abclinuxu.cz/}arg0
> {http://ws.servlets.abclinuxu.cz/}arg1 part element name {http://ws.servlets.abclinuxu.cz/}arg1 references element {http://ws.servlets.abclinuxu.cz/}arg1
> 24.4.2008 19:04:30 org.apache.cxf.endpoint.ServerImpl initDestination
> INFO: Setting the server's publish address to be http://localhost/services/users
> 2008-04-24 19:04:42.618::INFO:  Started SocketConnector@127.0.0.1:8080
>
> 24.4.2008 19:04:51 org.apache.cxf.transport.servlet.ServletController invoke
> WARNING: Can't find the the request for http://localhost:8080/services/users's Observer
>
> What's wrong?
>
> Leos
>
>
>   


Re: servlet transport question

Posted by li...@centrum.cz.
Ok,

I made some progress today:
    <servlet>
        <servlet-name>CXFServlet</servlet-name>
        <display-name>CXF Web services Servlet</display-name>
        <servlet-class>cz.abclinuxu.servlets.ws.AbcCxfServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>

public class AbcCxfServlet extends CXFNonSpringServlet {
    public void init(ServletConfig servletConfig) throws ServletException {
        super.init(servletConfig);
        Bus bus = this.getBus();
        BusFactory.setDefaultBus(bus);
    }
}

some other servlet loaded later:

        String endpointUrl = "http://"+getHostname()+"/services/users";
        Endpoint.publish(endpointUrl, new UserAccountServiceImpl());

@WebService(endpointInterface = "cz.abclinuxu.servlets.ws.UserAccountService", serviceName = "Users")
public class UserAccountServiceImpl implements UserAccountService {

saaj-impl-1.3.jar wsdl4j-1.6.1.jar wstx-asl-3.2.4.jar xml-resolver-1.2.jar
cxf-2.0.5-incubator.jar                  jaxb-api-2.0.jar     saaj-api-1.3.jar    xml-resolver-1.2.jar
geronimo-annotation_1.0_spec-1.1.1.jar   jaxb-impl-2.0.5.jar  saaj-impl-1.3.jar   XmlSchema-1.3.2.jar
geronimo-stax-api_1.0_spec-1.0.1.jar     jaxws-api-2.0.jar    wsdl4j-1.6.1.jar
geronimo-ws-metadata_2.0_spec-1.1.2.jar  neethi-2.0.2.jar     wstx-asl-3.2.4.jar

When I start jetty:

24.4.2008 19:04:27 org.apache.cxf.transport.servlet.CXFNonSpringServlet loadBusNoConfig
INFO: Load the bus without application context
24.4.2008 19:04:28 org.apache.cxf.transport.servlet.AbstractCXFServlet replaceDestinationFactory
INFO: Replaced the http destionFactory with servlet transport factory
24.4.2008 19:04:28 org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
INFO: Creating Service {http://ws.servlets.abclinuxu.cz/}Users from class cz.abclinuxu.servlets.ws.UserAccountServiceImpl
24.4.2008 19:04:30 org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
INFO: {http://ws.servlets.abclinuxu.cz/}arg0 part element name {http://ws.servlets.abclinuxu.cz/}arg0 references element {http://ws.servlets.abclinuxu.cz/}arg0
{http://ws.servlets.abclinuxu.cz/}arg1 part element name {http://ws.servlets.abclinuxu.cz/}arg1 references element {http://ws.servlets.abclinuxu.cz/}arg1
24.4.2008 19:04:30 org.apache.cxf.endpoint.ServerImpl initDestination
INFO: Setting the server's publish address to be http://localhost/services/users
2008-04-24 19:04:42.618::INFO:  Started SocketConnector@127.0.0.1:8080

24.4.2008 19:04:51 org.apache.cxf.transport.servlet.ServletController invoke
WARNING: Can't find the the request for http://localhost:8080/services/users's Observer

What's wrong?

Leos


Re: servlet transport question

Posted by Willem Jiang <wi...@gmail.com>.
Hi Leos,

Please see my comments in the mail.

literakl@centrum.cz wrote:
> Rafael,
>
> thank you for your message. Especially the note about FQCN for Endpoint is crucial for me! Can somebody update http://cwiki.apache.org/CXF20DOC/servlet-transport.html ?
>   
Sure, I will take care of it.
>   
>> After, I configured CXFNonSpringServlet on my web.xml file and then I had
>> setup a Servlet (it could be a filter as well) with loadonstartup to
>> register the Services I had using: Endpoint.publish. Be careful not to
>> import the wrong Endpoint (right one is from: javax.xml.ws) class.
>>     
>
> Please put snippet, how to configure the Bus (setup the servlet). The web.xml part is clear:
>
>  <servlet>
>     <servlet-name>CXFServlet</servlet-name>
>     <display-name>CXF Servlet</display-name>
>     <servlet-class>
>         org.apache.cxf.transport.servlet.CXFServlet
>     </servlet-class>
>   </servlet>
>
>   <servlet-mapping>
>     <servlet-name>CXFServlet</servlet-name>
>     <url-pattern>/services/*</url-pattern>
>   </servlet-mapping>
>
> But how to manage this part?
>
> // cxf is the instance of the CXFServlet
> Bus bus = cxf.getBus();
> BusFactory.setDefaultBus(bus); 
>
> How have you solved it? Or is it set up behind the scene automatically in 2.0.5 release? 
>   
Basically, you can extends the CXFNonSpringServlet[1] and  the setup 
default Bus part before you call the endpoint.publish
And you also need to change the web.xml's <servlet-class> with your 
extended servlet :)

> Thank you
>
> Leos
>
>
>   
Willem

Re: servlet transport question

Posted by li...@centrum.cz.
Rafael,

thank you for your message. Especially the note about FQCN for Endpoint is crucial for me! Can somebody update http://cwiki.apache.org/CXF20DOC/servlet-transport.html ?

>After, I configured CXFNonSpringServlet on my web.xml file and then I had
>setup a Servlet (it could be a filter as well) with loadonstartup to
>register the Services I had using: Endpoint.publish. Be careful not to
>import the wrong Endpoint (right one is from: javax.xml.ws) class.

Please put snippet, how to configure the Bus (setup the servlet). The web.xml part is clear:

 <servlet>
    <servlet-name>CXFServlet</servlet-name>
    <display-name>CXF Servlet</display-name>
    <servlet-class>
        org.apache.cxf.transport.servlet.CXFServlet
    </servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>CXFServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>

But how to manage this part?

// cxf is the instance of the CXFServlet
Bus bus = cxf.getBus();
BusFactory.setDefaultBus(bus); 

How have you solved it? Or is it set up behind the scene automatically in 2.0.5 release? 

Thank you

Leos


Re: servlet transport question

Posted by Rafael Ribeiro <ra...@gmail.com>.
Hi Leos,
I managed to get CXF running on Tomcat without Spring... let me try do
describe what I had to do in order for it to work:

First of all I had problems using the cxf-incubator jar with every module
bundled, so, I got the modules separate from modules directory. I remember
that I read somewhere that if jetty libs were in classpath they might
present problems to run on tomcat so that's why I decided not to use the
bundled jar.
After, I configured CXFNonSpringServlet on my web.xml file and then I had
setup a Servlet (it could be a filter as well) with loadonstartup to
register the Services I had using: Endpoint.publish. Be careful not to
import the wrong Endpoint (right one is from: javax.xml.ws) class.

I am sending the list of jars I have on my web application but beaware that
it is mixed with hibernate, jpa, jsf and some seam libs... you might be able
to find out which ones you need by only importing the ones found on cxf
distro:

antlr-2.7.6.jar
asm-attrs.jar
asm.jar
c3p0-0.9.1.jar
cglib-2.1.3.jar
commons-beanutils.jar
commons-collections-2.1.1.jar
commons-collections.jar
commons-digester.jar
commons-lang.jar
commons-logging-1.0.4.jar
commons-logging.jar
concurrent-1.3.2.jar
cxf-api-2.0.5-incubator.jar
cxf-common-utilities-2.0.5-incubator.ja
cxf-rt-bindings-soap-2.0.5-incubator.ja
cxf-rt-core-2.0.5-incubator.jar
cxf-rt-databinding-jaxb-2.0.5-incubator
cxf-rt-frontend-jaxws-2.0.5-incubator.j
cxf-rt-frontend-simple-2.0.5-incubator.
cxf-rt-transports-http-2.0.5-incubator.
cxf-tools-common-2.0.5-incubator.jar
dom4j-1.6.1.jar
ehcache-1.2.3.jar
ejb3-persistence.jar
geronimo-activation_1.1_spec-1.0.2.jar
geronimo-annotation_1.0_spec-1.1.1.jar
geronimo-javamail_1.4_spec-1.2.jar
geronimo-stax-api_1.0_spec-1.0.1.jar
geronimo-ws-metadata_2.0_spec-1.1.2.jar
hibernate-annotations.jar
hibernate-commons-annotations.jar
hibernate-entitymanager.jar
hibernate3.jar
javassist.jar
jaxb-api-2.0.jar
jaxb-impl-2.0.5.jar
jaxen-1.1-beta-6.jar
jaxws-api-2.0.jar
jboss-common.jar
jboss-system.jar
jsf-api.jar
jsf-facelets.jar
jsf-impl.jar
jta.jar
log4j-1.2.11.jar
mysql-connector-java-5.1.6-bin.jar
richfaces-api.jar
richfaces-impl.jar
richfaces-ui.jar
saaj-api-1.3.jar
saaj-impl-1.3.jar
wsdl4j-1.6.1.jar
wstx-asl-3.2.4.jar
xerces-2.6.2.jar
xml-apis-1.3.02.jar
xml-resolver-1.2.jar
XmlSchema-1.3.2.jar

2008/4/20, Glen Mazza <gl...@verizon.net>:
>
>
> 2008-04-20 (日) の 15:22 +0200 に Leos Literak さんは書きました:
>
> > Hi,
> >
> > I want to add soap stack to my web application. I decided for CXF. This
> > page http://cwiki.apache.org/CXF20DOC/servlet-transport.html shows it
> > could be possible. I set up web.xml and now I want to bind the servlet
> > to bus, as specified in documentation:
> >
> > // cxf is the instance of the CXFServlet
> > Bus bus = cxf.getBus();
> > BusFactory.setDefaultBus(bus);
> > Endpoint.publish("/Greeter", new GreeterImpl());
> >
> > The question is: how can I get the CXFServlet instance? J2EE's
> > getServlet() method is deprecated.
> >
> > 1) I dont want to add spring to my project so I want to use programmatic
> > way.
>
>
> There's a CXFNonSpringServlet that you can use that may be of help for
> you, but IIRC it is not in heavy use and therefore not very well
> documented:
>
> [1]
>
> http://www.nabble.com/forum/Search.jtp?forum=16914&local=y&query=cxfnonspringservlet
>
>
>
> > 2) My application is a web application running in jetty container, so
> > starting jetty within jetty is not good option.
>
>
> Here's everything I know for Tomcat:
> http://www.jroller.com/gmazza/date/20080417
>
>
>
> > 3) Endpoint has no method publish, but EndpointImpl.
> >
> > Thank you
> >
> > Leos
> >
> > PS1 documentation says that to build samples you need ant 1.6. I've got
> > CXFServlet, but it fails, that verbose attribute is not supported
> >
> > PS2 javadoc from installer does not contain CXFServlet
>
>
> It's here, but our JavaDoc is pretty weak:
>
> http://incubator.apache.org/cxf/javadoc/latest/org/apache/cxf/transport/servlet/CXFServlet.html
>
>
> Glen
>
>
>

Re: servlet transport question

Posted by Ian Roberts <i....@dcs.shef.ac.uk>.
literakl@centrum.cz wrote:
>>> 3) Endpoint has no method publish, but EndpointImpl.
> 
> This issue is not answeared. I guess that documentation is obsolete and I shall create new instance of org.apache.cxf.endpoint.EndpointImpl, is it correct?

The publish method is on javax.xml.ws.Endpoint, not 
org.apache.cxf.endpoint.Endpoint.

Ian

-- 
Ian Roberts               | Department of Computer Science
i.roberts@dcs.shef.ac.uk  | University of Sheffield, UK

Re: servlet transport question

Posted by li...@centrum.cz.
Glen,

>There's a CXFNonSpringServlet that you can use that may be of help for

thanks for the hint

>> 2) My application is a web application running in jetty container, so 
>> starting jetty within jetty is not good option.
>
>Here's everything I know for Tomcat:
>http://www.jroller.com/gmazza/date/20080417

I looked at it but it does not seem to solve my situation. I still don't know how to fetch servlet instance, so I can set up Endpoint. Probably I will need sample .war to understand how to achieve this functionality. I miss the point. As I understand servlet API, it is not possible. If you have .war, you cannot start embedded jetty. So it makes sense that CXF will utilize CFX*Servlet as its transport. But that Bus binding complicates the thing, because it requires instance of the servlet. But you cannot get it from web application, can you?

>> 3) Endpoint has no method publish, but EndpointImpl.

This issue is not answeared. I guess that documentation is obsolete and I shall create new instance of org.apache.cxf.endpoint.EndpointImpl, is it correct?

>> PS1 documentation says that to build samples you need ant 1.6. I've got
>> CXFServlet, but it fails, that verbose attribute is not supported

Will you guys fix README or common_build.xml?

>> PS2 javadoc from installer does not contain CXFServlet

>It's here, but our JavaDoc is pretty weak:
>http://incubator.apache.org/cxf/javadoc/latest/org/apache/cxf/transport/servlet/CXFServlet.html

I mentioned an issue that javadoc in distribution zip is not complete.

I hope that my notes will help you.

Leos


Re: servlet transport question

Posted by Glen Mazza <gl...@verizon.net>.
2008-04-20 (日) の 15:22 +0200 に Leos Literak さんは書きました:
> Hi,
> 
> I want to add soap stack to my web application. I decided for CXF. This 
> page http://cwiki.apache.org/CXF20DOC/servlet-transport.html shows it 
> could be possible. I set up web.xml and now I want to bind the servlet 
> to bus, as specified in documentation:
> 
> // cxf is the instance of the CXFServlet
> Bus bus = cxf.getBus();
> BusFactory.setDefaultBus(bus);
> Endpoint.publish("/Greeter", new GreeterImpl());
> 
> The question is: how can I get the CXFServlet instance? J2EE's 
> getServlet() method is deprecated.
> 
> 1) I dont want to add spring to my project so I want to use programmatic 
> way.

There's a CXFNonSpringServlet that you can use that may be of help for
you, but IIRC it is not in heavy use and therefore not very well
documented:

[1]
http://www.nabble.com/forum/Search.jtp?forum=16914&local=y&query=cxfnonspringservlet


> 2) My application is a web application running in jetty container, so 
> starting jetty within jetty is not good option.

Here's everything I know for Tomcat:
http://www.jroller.com/gmazza/date/20080417


> 3) Endpoint has no method publish, but EndpointImpl.
> 
> Thank you
> 
> Leos
> 
> PS1 documentation says that to build samples you need ant 1.6. I've got 
> CXFServlet, but it fails, that verbose attribute is not supported
> 
> PS2 javadoc from installer does not contain CXFServlet

It's here, but our JavaDoc is pretty weak:
http://incubator.apache.org/cxf/javadoc/latest/org/apache/cxf/transport/servlet/CXFServlet.html

Glen