You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Conficio <Ka...@Conficio.com> on 2010/11/12 02:26:17 UTC

separate CXFServlet for private API's

Hi there,
I want to use two CXFServlets in my web.xml, one for public and one for
private services.

I tried to define


  <servlet>
    <servlet-name>CXFPrivateServlet</servlet-name>
    <servlet-class>
        org.apache.cxf.transport.servlet.CXFServlet
    </servlet-class>
    <init-param>
      <param-name>config-location</param-name>
      <param-value>/WEB-INF/private.xml</param-value>    
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>CXFPrivateServlet</servlet-name>
    <url-pattern>/services/private/*</url-pattern>
  </servlet-mapping>
<servlet>
    <servlet-name>CXFPubicServlet</servlet-name>
    <servlet-class>
        org.apache.cxf.transport.servlet.CXFServlet
    </servlet-class>
    <init-param>
      <param-name>config-location</param-name>
      <param-value>/WEB-INF/public.xml</param-value>    
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>CXFPublicServlet</servlet-name>
    <url-pattern>/services/public/*</url-pattern>
  </servlet-mapping>


This does not seem to work. If I have two servlets like this it loops in the
service endpoint publishing.

If I only define a single config-location and servler-mapping, then the
servlet endpoints are published in the startup, but the servlet does not
serve the WSDL or overview page.

Is there a better way to achieve that?

K<o>
P.S.: This is all part of a spring configured container. When I define a
global include of the endpoint beans and a CXFServlet w/o any
config-location, then the services are deployed, but all under a single URI.
-- 
View this message in context: http://cxf.547215.n5.nabble.com/separate-CXFServlet-for-private-API-s-tp3261355p3261355.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: separate CXFServlet for private API's

Posted by Sergey Beryozkin <sb...@gmail.com>.
Can you have two servlets referring to the same Spring configuration (via
the context parameter) which defines two endpoints (possibly reusing the
same service bean) ?

cheers, Sergey


On Fri, Nov 12, 2010 at 4:59 PM, Conficio <Ka...@conficio.com> wrote:

>
> Thanks Willem for the reply.
>
> I'm not sure how I make the Servlets start one by one. I certainly don't
> want to make them single threaded ;-)
>
> As mentioned I can't even get the single Servlet with a
>
>   <init-param>
>      <param-name>config-location</param-name>
>      <param-value>/WEB-INF/private.xml</param-value>
>    </init-param>
>
> working. It does not seem to publish any services, despite the fact that it
> does log about publishing the services.
>
> I was thinking if multiple bus IDs would be a solution/workaround. It
> appears the Abstract Servlet does accept a bus.id as init param. In that
> case would I need to create each bus in the spring config in order to give
> it it's ID?
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/separate-CXFServlet-for-private-API-s-tp3261355p3262404.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>

Re: separate CXFServlet for private API's

Posted by Conficio <Ka...@Conficio.com>.
Thanks Willem for the reply.

I'm not sure how I make the Servlets start one by one. I certainly don't
want to make them single threaded ;-)

As mentioned I can't even get the single Servlet with a 

   <init-param>
      <param-name>config-location</param-name>
      <param-value>/WEB-INF/private.xml</param-value>    
    </init-param>

working. It does not seem to publish any services, despite the fact that it
does log about publishing the services.

I was thinking if multiple bus IDs would be a solution/workaround. It
appears the Abstract Servlet does accept a bus.id as init param. In that
case would I need to create each bus in the spring config in order to give
it it's ID?
-- 
View this message in context: http://cxf.547215.n5.nabble.com/separate-CXFServlet-for-private-API-s-tp3261355p3262404.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: separate CXFServlet for private API's

Posted by Willem Jiang <wi...@gmail.com>.
Not sure what mess up the QueryHandlerRegistry of the bus, may be you 
need to make these servlets are started on by on.


On 11/12/10 9:26 AM, Conficio wrote:
>
> Hi there,
> I want to use two CXFServlets in my web.xml, one for public and one for
> private services.
>
> I tried to define
>
>
>    <servlet>
>      <servlet-name>CXFPrivateServlet</servlet-name>
>      <servlet-class>
>          org.apache.cxf.transport.servlet.CXFServlet
>      </servlet-class>
>      <init-param>
>        <param-name>config-location</param-name>
>        <param-value>/WEB-INF/private.xml</param-value>
>      </init-param>
>      <load-on-startup>1</load-on-startup>
>    </servlet>
>
>    <servlet-mapping>
>      <servlet-name>CXFPrivateServlet</servlet-name>
>      <url-pattern>/services/private/*</url-pattern>
>    </servlet-mapping>
> <servlet>
>      <servlet-name>CXFPubicServlet</servlet-name>
>      <servlet-class>
>          org.apache.cxf.transport.servlet.CXFServlet
>      </servlet-class>
>      <init-param>
>        <param-name>config-location</param-name>
>        <param-value>/WEB-INF/public.xml</param-value>
>      </init-param>
>      <load-on-startup>1</load-on-startup>
>    </servlet>
>
>    <servlet-mapping>
>      <servlet-name>CXFPublicServlet</servlet-name>
>      <url-pattern>/services/public/*</url-pattern>
>    </servlet-mapping>
>
>
> This does not seem to work. If I have two servlets like this it loops in the
> service endpoint publishing.
>
> If I only define a single config-location and servler-mapping, then the
> servlet endpoints are published in the startup, but the servlet does not
> serve the WSDL or overview page.
>
> Is there a better way to achieve that?
>
> K<o>
> P.S.: This is all part of a spring configured container. When I define a
> global include of the endpoint beans and a CXFServlet w/o any
> config-location, then the services are deployed, but all under a single URI.


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang

Re: separate CXFServlet for private API's (solution?)

Posted by Conficio <Ka...@Conficio.com>.
Thanks Dan,
2.4.1 does seem to improve things a lot.

I got it working as you hint on and did not need to subclass CXFServlet.

Here is web.xml
{code}
<web-app>
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>WEB-INF/globalContext.xml</param-value>
	</context-param>
 	<listener>
		<listener-class>
			org.springframework.web.context.ContextLoaderListener
		</listener-class>
	</listener>

	<servlet>
		<servlet-name>PublicCXFServlet</servlet-name>
		<display-name>Public CXF Servlet</display-name>
		<servlet-class>
			org.apache.cxf.transport.servlet.CXFServlet
		</servlet-class>
		<init-param>
      		<param-name>config-location</param-name>
      		<param-value>/WEB-INF/beans-public.xml</param-value>    
    	</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>PublicCXFServlet</servlet-name>
		<url-pattern>/public/*</url-pattern>
	</servlet-mapping>

	<servlet>
		<servlet-name>PrivateCXFServlet</servlet-name>
		<display-name>Private CXF Servlet</display-name>
		<servlet-class>
			org.apache.cxf.transport.servlet.CXFServlet
		</servlet-class>
		<init-param>
      		<param-name>config-location</param-name>
      		<param-value>/WEB-INF/beans-private.xml</param-value>    
    	</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>PrivateCXFServlet</servlet-name>
		<url-pattern>/private/*</url-pattern>
	</servlet-mapping>
</web-app>
{/code}
and here my public beans as an example
{code}
	<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" />

	<cxf:bus name="public"/>
	
	<jaxws:endpoint 
	  id="helloWorld" 
	  implementor="demo.spring.HelloWorldImpl" 
	  address="/HelloWorld" />
{/code}
I even found that it appears the <cxf:bus .../> clause is optional. It
appears to be working (in the sample derived from java-first-spring) with
all services being on the default bus "cxf". Is there any advantage to
separate the busses?

K<o>
P.S.: Would you like me to submit my example for inclusion in the CXF
samples?

--
View this message in context: http://cxf.547215.n5.nabble.com/separate-CXFServlet-for-private-API-s-tp3261355p4634799.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: separate CXFServlet for private API's

Posted by Conficio <Ka...@Conficio.com>.
I created https://issues.apache.org/jira/browse/CXF-3688 for the missing
jetty-* jars

--
View this message in context: http://cxf.547215.n5.nabble.com/separate-CXFServlet-for-private-API-s-tp3261355p4634493.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: separate CXFServlet for private API's

Posted by Conficio <Ka...@Conficio.com>.
Also missing jetty-xml

--
View this message in context: http://cxf.547215.n5.nabble.com/separate-CXFServlet-for-private-API-s-tp3261355p4633400.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: separate CXFServlet for private API's

Posted by Conficio <Ka...@Conficio.com>.
Dan, 
o.k. I'll give that a try.
In order to get the java first with spring samples to run (in Eclipse and
not through maven), the jetty-webapp and jetty-servlet jars are missing in
the lib folder (2.4.1)

K<o>

--
View this message in context: http://cxf.547215.n5.nabble.com/separate-CXFServlet-for-private-API-s-tp3261355p4633380.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: separate CXFServlet for private API's

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

With 2.4.1, this may be easier to achieve than before, but it's not quite 
there.

With 2.4.x, support for multiple bus's has been greatly enhanced.  Thus, with 
a little work, you may be able to have  a context with 2 bus objects, one for 
the secure and one for the insecure.   Then have a servlet work for each.

<cxf:bus name="secure"/>
<cxf:bus name="insecure"/>


<jaxws:endpoint bus="secure" address="/secure/MyService" ..../>
<jaxws:endpoint bus="insecure" address="/insecure/MyService" ..../>
.....

Looking at the code, you would need a subclass of CXFServlet that would 
override the 
    protected void loadBus(ServletConfig sc);

method to look at a servlet init-param to have it lookup the appropriate 
spring bean.      Actually, if you want to post a patch, a patch to CXFServlet 
that would allow configuring the bus id to use would be great (and likely 
pretty easy)

Let me know how that works for you.


Dan




On Monday, July 25, 2011 10:59:57 AM Conficio wrote:
> Dan,
> just wondering if you like my example or if there is anything else I could
> provide?
> 
> Is there any idea of an alternative (like starting some service per
> CXFServlet and others per Java class?
> 
> Kaj
> Still hoping to make multiple CXFServlet configs work.
> 
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/separate-CXFServlet-for-private-API-s-tp326
> 1355p4631755.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: separate CXFServlet for private API's

Posted by Conficio <Ka...@Conficio.com>.
Dan,
just wondering if you like my example or if there is anything else I could
provide?

Is there any idea of an alternative (like starting some service per
CXFServlet and others per Java class?

Kaj
Still hoping to make multiple CXFServlet configs work.

--
View this message in context: http://cxf.547215.n5.nabble.com/separate-CXFServlet-for-private-API-s-tp3261355p4631755.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: separate CXFServlet for private API's

Posted by Conficio <Ka...@Conficio.com>.
Hi Daniel,
I hope you had a good thanks giving holiday.

Did you get a chance to look at this issue? Is the hello world example
helpful?

I'd like to help any way I can. Could you point me to some architectural
documentation of the CXFServlet so I could effectively debug the issue?

Do you know of any workaround?

Thanks

K<o>
-- 
View this message in context: http://cxf.547215.n5.nabble.com/separate-CXFServlet-for-private-API-s-tp3261355p3284441.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: separate CXFServlet for private API's

Posted by Conficio <Ka...@Conficio.com>.
I guess this is pointing to the same issue?
https://issues.apache.org/jira/browse/CXF-2838
-- 
View this message in context: http://cxf.547215.n5.nabble.com/separate-CXFServlet-for-private-API-s-tp3261355p3265976.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: separate CXFServlet for private API's

Posted by Conficio <Ka...@Conficio.com>.
Thank Daniel,
here is my sample, based of java first with spring support

/webapp/WEB-INF/beans-private.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
	Licensed to the Apache Software Foundation (ASF) under one
	or more contributor license agreements. See the NOTICE file
	distributed with this work for additional information
	regarding copyright ownership. The ASF licenses this file
	to you under the Apache License, Version 2.0 (the
	"License"); you may not use this file except in compliance
	with the License. You may obtain a copy of the License at
	
	http://www.apache.org/licenses/LICENSE-2.0
	
	Unless required by applicable law or agreed to in writing,
	software distributed under the License is distributed on an
	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
	KIND, either express or implied. See the License for the
	specific language governing permissions and limitations
	under the License.
-->
<!-- START SNIPPET: beans -->
<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.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="helloWorld" 
	  implementor="demo.spring.HelloWorldImpl" 
	  address="/HelloWorldPrivate" />
	  
</beans>
<!-- END SNIPPET: beans -->

/webapp/WEB-INF/beans.xml 

... as is ... 

/webapp/WEB-INF/empty.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
	Licensed to the Apache Software Foundation (ASF) under one
	or more contributor license agreements. See the NOTICE file
	distributed with this work for additional information
	regarding copyright ownership. The ASF licenses this file
	to you under the Apache License, Version 2.0 (the
	"License"); you may not use this file except in compliance
	with the License. You may obtain a copy of the License at
	
	http://www.apache.org/licenses/LICENSE-2.0
	
	Unless required by applicable law or agreed to in writing,
	software distributed under the License is distributed on an
	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
	KIND, either express or implied. See the License for the
	specific language governing permissions and limitations
	under the License.
-->
<!-- START SNIPPET: beans -->
<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.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="helloWorld" 
	  implementor="demo.spring.HelloWorldImpl" 
	  address="/HelloWorld" />
-->	  
</beans>
<!-- END SNIPPET: beans -->

/webapp/WEB-INF/web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<!--
	Licensed to the Apache Software Foundation (ASF) under one
	or more contributor license agreements. See the NOTICE file
	distributed with this work for additional information
	regarding copyright ownership. The ASF licenses this file
	to you under the Apache License, Version 2.0 (the
	"License"); you may not use this file except in compliance
	with the License. You may obtain a copy of the License at
	
	http://www.apache.org/licenses/LICENSE-2.0
	
	Unless required by applicable law or agreed to in writing,
	software distributed under the License is distributed on an
	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
	KIND, either express or implied. See the License for the
	specific language governing permissions and limitations
	under the License.
-->
<!-- START SNIPPET: webxml -->
<web-app>
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>WEB-INF/empty.xml</param-value>
	</context-param>
	<listener>
		<listener-class>
			org.springframework.web.context.ContextLoaderListener
		</listener-class>
	</listener>

	<servlet>
		<servlet-name>CXFServletPrivate</servlet-name>
		<display-name>CXF Servlet Private</display-name>
		<servlet-class>
			org.apache.cxf.transport.servlet.CXFServlet
		</servlet-class>
		<init-param>
      		<param-name>config-location</param-name>
      		<param-value>beans-private.xml</param-value>    
    	</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>CXFServletPrivate</servlet-name>
		<url-pattern>/private/*</url-pattern>
	</servlet-mapping>
	<servlet>
		<servlet-name>CXFServletPublic</servlet-name>
		<display-name>CXF Servlet Public</display-name>
		<servlet-class>
			org.apache.cxf.transport.servlet.CXFServlet
		</servlet-class>
		<init-param>
      		<param-name>config-location</param-name>
      		<param-value>beans.xml</param-value>    
    	</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>CXFServletPublic</servlet-name>
		<url-pattern>/public/*</url-pattern>
	</servlet-mapping>
</web-app>
<!-- END SNIPPET: webxml -->


I don't see the endless loop of loading those contexts in this simple Jetty
example (My app uses tomcat and a lot of other things, incl. spring 3.0)

But with this config I'd expect http://localhost:9002/public/ to present me
with the usual service list or http://localhost:9002/private/ for that
matter and also http://localhost:9002/public/HelloWorld?wsdl should present
the WSDL.

Let me know if I'm doing anything wrong here.

Kaj
P.S.: Even if I do simply config the public service in web.xml, I get no
services listed at http://localhost:9002/public/
-- 
View this message in context: http://cxf.547215.n5.nabble.com/separate-CXFServlet-for-private-API-s-tp3261355p3265972.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: separate CXFServlet for private API's

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

Any chance you could take a hello world thing and create a sample of this 
issue?  I really don't know what would cause this, but if we can reproduce, we 
can at least debug it.

Dan


On Thursday 11 November 2010 8:26:17 pm Conficio wrote:
> Hi there,
> I want to use two CXFServlets in my web.xml, one for public and one for
> private services.
> 
> I tried to define
> 
> 
>   <servlet>
>     <servlet-name>CXFPrivateServlet</servlet-name>
>     <servlet-class>
>         org.apache.cxf.transport.servlet.CXFServlet
>     </servlet-class>
>     <init-param>
>       <param-name>config-location</param-name>
>       <param-value>/WEB-INF/private.xml</param-value>
>     </init-param>
>     <load-on-startup>1</load-on-startup>
>   </servlet>
> 
>   <servlet-mapping>
>     <servlet-name>CXFPrivateServlet</servlet-name>
>     <url-pattern>/services/private/*</url-pattern>
>   </servlet-mapping>
> <servlet>
>     <servlet-name>CXFPubicServlet</servlet-name>
>     <servlet-class>
>         org.apache.cxf.transport.servlet.CXFServlet
>     </servlet-class>
>     <init-param>
>       <param-name>config-location</param-name>
>       <param-value>/WEB-INF/public.xml</param-value>
>     </init-param>
>     <load-on-startup>1</load-on-startup>
>   </servlet>
> 
>   <servlet-mapping>
>     <servlet-name>CXFPublicServlet</servlet-name>
>     <url-pattern>/services/public/*</url-pattern>
>   </servlet-mapping>
> 
> 
> This does not seem to work. If I have two servlets like this it loops in
> the service endpoint publishing.
> 
> If I only define a single config-location and servler-mapping, then the
> servlet endpoints are published in the startup, but the servlet does not
> serve the WSDL or overview page.
> 
> Is there a better way to achieve that?
> 
> K<o>
> P.S.: This is all part of a spring configured container. When I define a
> global include of the endpoint beans and a CXFServlet w/o any
> config-location, then the services are deployed, but all under a single
> URI.

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

Re: separate CXFServlet for private API's

Posted by Conficio <Ka...@Conficio.com>.
I should have mentioned I'm working with JDK 1.6 and cxf 2.2.10 
-- 
View this message in context: http://cxf.547215.n5.nabble.com/separate-CXFServlet-for-private-API-s-tp3261355p3261362.html
Sent from the cxf-user mailing list archive at Nabble.com.