Normally, you would subclass the CXFNonSpringServlet, override the init(..) method, call super.init(..), then publish your services using the JaxWsServerFactoryBean or similar, but make sure you use the right "bus" object (from getBus() call on the CXFNonSpringServlet).
Dan On Mar 8, 2013, at 4:09 PM, dhogan <[email protected]> wrote: > Hi- > *I am having difficulty transitioning from the CXFServlet based deployment, > to a CXFNonSpringServlet deployment, and am hoping for some insight. > > * > *The scenario: I am exposing a web-service that programmatically publishes > additional web-services - in this case, SecurityTokenService instances. > That all works fine in a Spring-based deployment. Here’s the relevant state > that works great in a Spring-based deployment: > > web.xml > > <servlet> > <servlet-name>new_sts</servlet-name> > > <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> > </servlet> > <servlet-mapping> > <servlet-name>new_sts</servlet-name> > <url-pattern>/new_sts/*</url-pattern> > </servlet-mapping> > > cxf-servlet.xml > > <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://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd > http://www.springframework.org/schema/beans > http://www.springframework.org/schema/beans/spring-beans.xsd" >> > > <jaxws:endpoint id="STSPublish" > implementor="org.forgerock.openam.sts.publish.web.STSPublishImpl" > address="/sts_publish"> > </jaxws:endpoint> > </beans> > > The STSPublishImpl is a pojo with a SEI with a bare @WebService annotation, > and the STSPublishImpl with an annotation that looks like: > @WebService( > endpointInterface="org.forgerock.openam.sts.publish.web.STSPublish", > serviceName="STSPublishService", > portName = "STSPublishPort", > targetNamespace = "http://org.forgerock.openam.sts.publish") > > The STSPublishImpl has the following code: (the spec object is passed as a > parameter, and is the same regardless of invocation context. Likewise, the > getProperties() sets the Crypto state for various SecurityPolicy bindings). > > JaxWsServerFactoryBean serverFactoryBean = new > JaxWsServerFactoryBean(); > serverFactoryBean.setWsdlLocation(spec.getWsdlLocation()); > serverFactoryBean.setAddress(uriElement); > serverFactoryBean.setServiceBean(new > AMSecurityTokenServiceProvider()); > serverFactoryBean.setServiceName(spec.getServiceQName()); > serverFactoryBean.setEndpointName(spec.getPortQName()); > serverFactoryBean.setBindingId(SOAPBinding.SOAP12HTTP_BINDING); > serverFactoryBean.setProperties(getProperties()); > serverFactoryBean.create(); > > If I invoke this code with a uriElement of e.g. Instance444, I can happily > invoke my sts on http://host:8080/openam/new_sts/Instance444 (openam is the > name of the .war file that all of this is bundled in) > > Now here is the non-functioning CXFNonSpringServlet context:* > * > web.xml > > <servlet> > <servlet-name>new_sts</servlet-name> > > <servlet-class>org.apache.cxf.transport.servlet.CXFNonSpringServlet</servlet-class> > </servlet> > <servlet-mapping> > <servlet-name>new_sts</servlet-name> > <url-pattern>/new_sts/*</url-pattern> > </servlet-mapping> > > Because the cxf-servlet.xml seems to have to start with the beans element, > which seems to require the CXFServlet (it is ignored by the > CXFNonSpringServlet), I have tried to deploy my STS-instance creation > functionality two ways: 1. as a programatically created web-service, > published from a ServletContextListener, and 2. as a simple servlet. > > Here is the simple code publish my STSPublishImpl web-service, run in my > ServletContextListener > > JaxWsServerFactoryBean serverFactoryBean = new > JaxWsServerFactoryBean(); > serverFactoryBean.setAddress("/sts_publish"); > serverFactoryBean.setServiceBean(new STSPublishImpl()); > serverFactoryBean.create(); > or > > Endpoint.publish("/sts_publish", new STSPublishImpl()); > > In either case, the logs report: > > Mar 8, 2013 9:23:37 AM > org.apache.cxf.service.factory.ReflectionServiceFactoryBe > an buildServiceFromClass > INFO: Creating Service {http://org.forgerock.openam.sts.publish > }STSPublishServic > e from class org.forgerock.openam.sts.publish.web.STSPublish > Mar 8, 2013 9:23:37 AM org.apache.cxf.endpoint.ServerImpl initDestination > INFO: Setting the server's publish address to be /sts_publish > > but when I want to hit the wsdl, I get the dreaded > > Mar 8, 2013 9:24:34 AM org.apache.cxf.transport.servlet.ServletController > invoke > WARNING: Can't find the the request for > http://macbook.dirk.internal.forgerock.com:8080/openam/new_sts/sts_publish'sObserver > > So I deployed my STS-instance publish code as a simple Servlet, to avoid > having to create a web-service that allows me to create STS instances. I > also had hoped that the publishing of my web-service failed because I was > performing the publish in a ServletContextListener. But if I write a > servlet, which executes the exact same JaxWsServerFactory bean code > (specified above) which successfully publishes STS instances when run in a > Spring-based web-service, I get the following log messages: > > Mar 8, 2013 11:18:30 AM > org.apache.cxf.service.factory.ReflectionServiceFactoryBean > buildServiceFromWSDL > INFO: Creating Service { > http://docs.oasis-open.org/ws-sx/ws-trust/200512/}sts_service from WSDL: > sts_ut.wsdl > Mar 8, 2013 11:18:31 AM org.apache.cxf.endpoint.ServerImpl initDestination > INFO: Setting the server's publish address to be /newSTS > Mar 8, 2013 11:18:57 AM org.apache.cxf.transport.servlet.ServletController > invoke > WARNING: Can't find the the request for > http://macbook.dirk.internal.forgerock.com:8080/openam/new_sts/newSTS'sObserver > > Note the first 4 lines of the log snippet immediately above is exactly the > same as those logged when I run the code from within the Spring-based > web-service (which is successful - I don't get the final two lines in the > log). > > I’d really appreciate any help, as I am out of ideas.* > * > * > *Thanks* > * > * > *Dirk* > > > On Thu, Mar 7, 2013 at 2:08 PM, Daniel Kulp [via CXF] < > [email protected]> wrote: > >> >> On Mar 7, 2013, at 4:59 PM, dhogan <[hidden >> email]<http://user/SendEmail.jtp?type=node&node=5724283&i=0>> >> wrote: >> >>> Dan- >>> Is it possible to deploy and enforce wsdl-first web-services with >>> SecurityPolicy references without Spring? >> >> Yes. >> >>> Is it largely a function of >>> adding the WSS4J interceptors to one's endpoint? >> >> Ideally, no. The basic WSS4J interceptors don't handle the security >> policy things. >> >>> Searching this forum >>> yields contradictory indications regarding the feature-set of CXF >> without >>> Spring, though it does seem that the later posts indicate that most >>> everything you can do with Spring, you can do without (with the possible >>> exception of JMS). Is this correct? I can't seem to find any samples or >>> system tests that use the CXFNonSpringServlet - are there any? >> >> If you use the JaxWsServerFactoryBean from within whatever method you use >> to setup the services, then you would just need to set the wsdlLocation >> appropriately as well as the various properties. There are methods for that >> right on the factory bean. >> >> If you want to use the JAX-WS Endpoint.pushlish(…) API's, it's certainly a >> bit more complicated. It's not too bad if you fill in the wsdlLocation >> attribute of the @WebService annotation on the impl. In that case, you can >> do: >> >> Map<String, Object> props = new HashMap<..>(); >> props.put("ws.security…..", "…."); >> Endpoint ep = Endpoint.create(impl); >> ep.setProperties(props); >> ep.publish("/myService"); >> >> If you cannot stick the wsdlLocation on the attribute, I strongly suggest >> just going with either the JaxWsServerFactoryBean or casting the Endpoint >> returned from the create method there to a CXF specific EndpointImpl and >> calling setWsdlLocation(…) on it. Dealing with the JAX-WS >> Endpoint.setMetadata(..) calls sucks for this. >> >> Hope that helps. >> >> Dan >> >> >> >>> >>> Thanks >>> >>> Dirk >>> >>> >>> On Thu, Mar 7, 2013 at 11:37 AM, Daniel Kulp [via CXF] < >>> [hidden email] <http://user/SendEmail.jtp?type=node&node=5724283&i=1>> >> wrote: >>> >>>> >>>> What does your web.xml look like? Does it still reference the >>>> CXFServlet? Did you update it to change it to CXFNonSpringServlet? >>>> >>>> Dan >>>> >>>> >>>> >>>> >>>> On Mar 7, 2013, at 2:28 PM, dhogan <[hidden email]< >> http://user/SendEmail.jtp?type=node&node=5724272&i=0>> >>>> wrote: >>>> >>>>> Thanks for the prompt response. >>>>> >>>>> I have explicitly removed the spring maven dependencies. I had a set >> of >>>>> pretty sophisticated services running (based on CXF's >>>>> SecurityTokenService), with spring-web as a mvn dependency. I had a >>>> basic >>>>> web-service that allowed me to publish STS instances. This endpoint >> was >>>>> published via a cxf-servlet.xml: >>>>> jaxws:endpoint id="STSPublish" >>>>> implementor="org.forgerock.openam.sts.publish.web.STSPublishImpl" >>>>> address="/sts_publish"> >>>>> </jaxws:endpoint> >>>>> >>>>> We are already using Guice in our project, and I would prefer not to >>>>> include Spring - fewer moving parts = less complexity. When the wsdl >>>>> corresponding to this service was hit, in a .war without Spring jars, >> I >>>>> would get the NoClassDefFoundError mentioned in the previous post. It >>>>> appears that the cxf-servlet.xml file has to have a <beans> root >>>> element, >>>>> which may be responsible for pulling in Spring, so I tried to publish >>>> the >>>>> same service programmatically, but I appear to get the same error. >>>>> >>>>> Thanks for your help. >>>>> >>>>> Dirk >>>>> >>>>> >>>>> On Thu, Mar 7, 2013 at 11:16 AM, Jose María Zaragoza [via CXF] < >>>>> [hidden email] <http://user/SendEmail.jtp?type=node&node=5724272&i=1>> >> >>>> wrote: >>>>> >>>>>>> >>>>>>> java.lang.ClassNotFoundException: >>>>>>> org.springframework.context.ApplicationListener >>>>>>> >>>>>> >>>>>> >>>>>> Which Spring JAR do you have added to your project ? Or mvn >>>> dependencies >>>>>> ... >>>>>> >>>>>> >>>>>> ------------------------------ >>>>>> If you reply to this email, your message will be added to the >>>> discussion >>>>>> below: >>>>>> >>>>>> >>>> >>>>>> . >>>>>> NAML< >>>> >> http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> >> >>>> >>>>>> >>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> View this message in context: >>>> >> http://cxf.547215.n5.nabble.com/JaxWsServerFactoryBean-without-Spring-tp5724258p5724271.html >>>>> Sent from the cxf-user mailing list archive at Nabble.com. >>>> >>>> -- >>>> Daniel Kulp >>>> [hidden email] <http://user/SendEmail.jtp?type=node&node=5724272&i=2> >> - >>>> http://dankulp.com/blog >>>> >>>> Talend Community Coder - http://coders.talend.com >>>> >>>> >>>> >>>> ------------------------------ >>>> If you reply to this email, your message will be added to the >> discussion >>>> below: >>>> >>>> >> >>>> . >>>> NAML< >> http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> >> >>>> >>> >>> >>> >>> >>> -- >>> View this message in context: >> http://cxf.547215.n5.nabble.com/JaxWsServerFactoryBean-without-Spring-tp5724258p5724281.html >> >>> Sent from the cxf-user mailing list archive at Nabble.com. >> >> -- >> Daniel Kulp >> [hidden email] <http://user/SendEmail.jtp?type=node&node=5724283&i=2> - >> http://dankulp.com/blog >> Talend Community Coder - http://coders.talend.com >> >> >> >> ------------------------------ >> If you reply to this email, your message will be added to the discussion >> below: >> >> http://cxf.547215.n5.nabble.com/JaxWsServerFactoryBean-without-Spring-tp5724258p5724283.html >> To unsubscribe from JaxWsServerFactoryBean without Spring, click >> here<http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5724258&code=ZGlyay5ob2dhbkBmb3JnZXJvY2suY29tfDU3MjQyNTh8NDEzODQ2MjQw> >> . >> NAML<http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> >> > > > > > -- > View this message in context: > http://cxf.547215.n5.nabble.com/JaxWsServerFactoryBean-without-Spring-tp5724258p5724321.html > Sent from the cxf-user mailing list archive at Nabble.com. -- Daniel Kulp [email protected] - http://dankulp.com/blog Talend Community Coder - http://coders.talend.com
