Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
modules/server/src/main/java/org/jboss/wsf/stack/cxf/JAXRSServletExt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2016, Red Hat Middleware LLC, and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.jboss.wsf.stack.cxf; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.ServletConfig; | ||
import javax.servlet.ServletContext; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet; | ||
import org.jboss.wsf.spi.deployment.ServletDelegate; | ||
import org.jboss.wsf.stack.cxf.client.configuration.JBossWSBusFactory; | ||
|
||
/** | ||
* An extension to the CXF servlet | ||
* | ||
* @author alessio.soldano@jboss.com | ||
* | ||
* @since 19-Jan-2016 | ||
*/ | ||
public class JAXRSServletExt extends CXFNonSpringJaxrsServlet implements ServletDelegate | ||
{ | ||
private static final long serialVersionUID = 670827645417313373L; | ||
|
||
@Override | ||
public void init(ServletConfig sc) throws ServletException { | ||
super.init(sc); | ||
} | ||
|
||
@Override | ||
protected void loadBus(ServletConfig servletConfig) | ||
{ | ||
this.bus = JBossWSBusFactory.getClassLoaderDefaultBus(Thread.currentThread().getContextClassLoader()); //if this is not the dep classloader, pass it through ServletDelegate | ||
this.bus.setExtension(Thread.currentThread().getContextClassLoader(), ClassLoader.class); | ||
} | ||
|
||
@Override | ||
public void doHead(HttpServletRequest request, HttpServletResponse response, ServletContext context) | ||
throws ServletException, IOException | ||
{ | ||
this.doHead(request, response); | ||
} | ||
|
||
@Override | ||
public void doGet(HttpServletRequest request, HttpServletResponse response, ServletContext context) | ||
throws ServletException, IOException | ||
{ | ||
this.doGet(request, response); | ||
} | ||
|
||
@Override | ||
public void doPost(HttpServletRequest request, HttpServletResponse response, ServletContext context) | ||
throws ServletException, IOException | ||
{ | ||
this.doPost(request, response); | ||
} | ||
|
||
@Override | ||
public void doPut(HttpServletRequest request, HttpServletResponse response, ServletContext context) | ||
throws ServletException, IOException | ||
{ | ||
this.doPut(request, response); | ||
} | ||
|
||
@Override | ||
public void doDelete(HttpServletRequest request, HttpServletResponse response, ServletContext context) | ||
throws ServletException, IOException | ||
{ | ||
this.doDelete(request, response); | ||
} | ||
|
||
@Override | ||
public void service(HttpServletRequest request, HttpServletResponse response, ServletContext context) | ||
throws ServletException, IOException | ||
{ | ||
this.service(request, response); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
...ver/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/JAXRSBusDeploymentAspect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright 2016, Red Hat Middleware LLC, and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.jboss.wsf.stack.cxf.deployment.aspect; | ||
|
||
import javax.xml.ws.spi.Provider; | ||
|
||
import org.apache.cxf.Bus; | ||
import org.apache.cxf.BusFactory; | ||
import org.apache.cxf.transport.http.HttpDestinationFactory; | ||
import org.apache.cxf.transport.servlet.ServletDestinationFactory; | ||
import org.jboss.ws.common.integration.AbstractDeploymentAspect; | ||
import org.jboss.wsf.spi.deployment.Deployment; | ||
import org.jboss.wsf.stack.cxf.client.configuration.JBossWSBusFactory; | ||
|
||
/** | ||
* A deployment aspect that creates the CXF Bus early and attaches it to the deployment | ||
* | ||
* @author alessio.soldano@jboss.com | ||
*/ | ||
//TODO!!! unify with JAXWS handling | ||
public class JAXRSBusDeploymentAspect extends AbstractDeploymentAspect | ||
{ | ||
|
||
@Override | ||
public void start(final Deployment dep) | ||
{ | ||
if (BusFactory.getDefaultBus(false) == null) | ||
{ | ||
//Make sure the default bus is created and set for client side usage | ||
//(i.e. no server side integration contribution in it) | ||
//TODO!!! think about this... is it still fine for the default bus to be created like this? | ||
JBossWSBusFactory.getDefaultBus(Provider.provider().getClass().getClassLoader()); | ||
} | ||
startDeploymentBus(dep); | ||
} | ||
|
||
@Override | ||
public void stop(final Deployment dep) | ||
{ | ||
final Bus bus = dep.removeAttachment(Bus.class); | ||
if (bus != null) | ||
{ | ||
bus.shutdown(true); | ||
} | ||
} | ||
|
||
private void startDeploymentBus(final Deployment dep) | ||
{ | ||
BusFactory.setThreadDefaultBus(null); | ||
ClassLoader origClassLoader = SecurityActions.getContextClassLoader(); | ||
try | ||
{ | ||
//at least for now, we use the classloader-bus association as a shortcut for bus retieval in the servlet... | ||
Bus bus = JBossWSBusFactory.getClassLoaderDefaultBus(dep.getClassLoader()); | ||
//Force servlet transport to prevent CXF from using Jetty / http server or other transports | ||
bus.setExtension(new ServletDestinationFactory(), HttpDestinationFactory.class); | ||
//let's leave the resources and such creations in the CXF servlet for now; we'll later move that here and use a different servlet | ||
dep.addAttachment(Bus.class, bus); | ||
} | ||
finally | ||
{ | ||
BusFactory.setThreadDefaultBus(null); | ||
SecurityActions.setContextClassLoader(origClassLoader); | ||
} | ||
} | ||
|
||
} |