Skip to content

Commit

Permalink
Merge branch 'Issue-3' into github-master
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean Deruelle committed Sep 10, 2015
2 parents 52f2dd9 + 51d9818 commit ab879bd
Show file tree
Hide file tree
Showing 31 changed files with 3,919 additions and 157 deletions.
10 changes: 5 additions & 5 deletions containers/sip-servlets-as8-drop-in/jboss-as-mobicents/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,16 @@
<version>8.2.0.Final</version>
<scope>provided</scope>
</dependency>
<!-- dependency>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-core</artifactId>
<version>1.2.0.Beta9-SNAPSHOT</version>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-servlet</artifactId>
<version>1.2.0.Beta9-SNAPSHOT</version>
</dependency -->
<version>1.1.0.Final</version>
</dependency>

<dependency>
<groupId>org.jboss</groupId>
Expand Down Expand Up @@ -319,4 +319,4 @@
</build>
</profile>
</profiles>
</project>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* TeleStax, Open Source Cloud Communications
* Copyright 2011-2015, Telestax Inc and individual contributors
* by the @authors tag.
*
* This program is free software: you can redistribute it and/or modify
* under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package org.mobicents.as8;

/**
* This class replaces io.undertow.servlet.api.ServletContainerImpl to org.mobicents.io.undertow.servlet.api.ConvergedServletContainerImpl in ServletContainerService during server startup process.
* ConvergedServletContainerImpl will create an org.mobicents.io.undertow.servlet.core.ConvergedDeploymentManager object which can be used to create ConvergedSession instead of plain HttpSession.
*
* @author kakonyi.istvan@alerant.hu
* */
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import io.undertow.servlet.api.ServletContainer;

import org.jboss.as.controller.OperationContext;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.mobicents.io.undertow.servlet.api.ConvergedServletContainer;
import org.wildfly.extension.undertow.ServletContainerService;

public class ConvergedServletContainerService implements Service<ConvergedServletContainerService> {
public static final ServiceName SERVICE_NAME = ServiceName.of("ConvergedServletContainerService");

private OperationContext context;
private List<ServiceName> servletContainerServiceNames;

public ConvergedServletContainerService(OperationContext context, List<ServiceName> servletContainerServiceNames) {
this.context = context;

if(servletContainerServiceNames==null){
servletContainerServiceNames = new ArrayList<ServiceName>();
}
this.servletContainerServiceNames = servletContainerServiceNames;
}

@Override
public ConvergedServletContainerService getValue() throws IllegalStateException, IllegalArgumentException {
return this;
}

@Override
public void start(StartContext context) throws StartException {
ServletContainer servletContainer = ConvergedServletContainer.ConvergedFactory.newInstance();

for(ServiceName name: this.servletContainerServiceNames){
ServiceController<ServletContainerService> servletContainerServiceController =
(ServiceController<ServletContainerService>) this.context.getServiceRegistry(false).getService(name);

ServletContainerService servletContainerService = servletContainerServiceController.getValue();
//using reflection to get the container:
try{
Field servletContainerField = ServletContainerService.class.getDeclaredField("servletContainer");
servletContainerField.setAccessible(true);
servletContainerField.set(servletContainerService, servletContainer);
servletContainerField.setAccessible(false);
}catch(IllegalAccessException | NoSuchFieldException e){
throw new StartException(e);
}
}
}

@Override
public void stop(StopContext context) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@
*/
package org.mobicents.as8;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.management.MBeanServer;





//import org.jboss.as.clustering.web.DistributedCacheManagerFactory;
import org.jboss.as.controller.AbstractBoottimeAddStepHandler;
import org.jboss.as.controller.OperationContext;
Expand Down Expand Up @@ -52,6 +57,7 @@
import org.mobicents.as8.deployment.UndertowSipDeploymentInfoProcessor;
import org.mobicents.as8.deployment.UndertowSipDeploymentProcessor;
import org.mobicents.ext.javax.sip.dns.DefaultDNSServerLocator;
import org.wildfly.extension.undertow.UndertowService;

/**
* Adds the sip subsystem.
Expand Down Expand Up @@ -240,6 +246,27 @@ protected void performBoottime(OperationContext context, ModelNode operation, Mo
.addDependency(DependencyType.OPTIONAL, ServiceName.JBOSS.append("mbean", "server"), MBeanServer.class,
service.getMbeanServer()).setInitialMode(Mode.ACTIVE).install());


//lets find undertow subsystem's servlet container elements:
//FIXME: kakonyii: maybe we should use global undertow constants instead of hard coded strings:
ModelNode undertowNode = Resource.Tools.readModel(context.readResourceFromRoot(PathAddress.pathAddress("subsystem", "undertow")));
ModelNode servletContainerNode = undertowNode.get("servlet-container");

Set<String> servletContainerNames = servletContainerNode.keys();
List<ServiceName> servletConatinerServiceNames = new ArrayList<>();
for(String name : servletContainerNames){
servletConatinerServiceNames.add(UndertowService.SERVLET_CONTAINER.append(name));
}

//add ConvergedServletContainerService to replace servletContainer to convergedServletContainer during startup:
final ConvergedServletContainerService convergedServletContainerService = new ConvergedServletContainerService(context,servletConatinerServiceNames);
newControllers.add(context
.getServiceTarget()
.addService(ConvergedServletContainerService.SERVICE_NAME, convergedServletContainerService)
//depends on undertow servlet container services:
.addDependencies(servletConatinerServiceNames)
.setInitialMode(Mode.ACTIVE).install());

context.addStep(new AbstractDeploymentChainStep() {
@Override
protected void execute(DeploymentProcessorTarget processorTarget) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.mobicents.as8.deployment;

import io.undertow.servlet.api.Deployment;
import io.undertow.servlet.api.DeploymentInfoFacade;
import org.mobicents.io.undertow.servlet.api.DeploymentInfoFacade;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.mobicents.as8.ConvergedServletContainerService;
import org.mobicents.metadata.sip.spec.SipAnnotationMetaData;
import org.mobicents.metadata.sip.spec.SipMetaData;
import org.wildfly.extension.undertow.Server;
Expand Down Expand Up @@ -74,11 +75,17 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro

final String serverInstanceName = metaData.getServerInstanceName() == null ? defaultServer : metaData
.getServerInstanceName();

//lets find server service:
final ServiceName serverName = UndertowService.SERVER.append(serverInstanceName);
ServiceController<?> serverServiceController = phaseContext.getServiceRegistry().getService(serverName);
Server serverService = (Server) serverServiceController.getValue();

final ServiceName deploymentServiceName = UndertowService.deploymentServiceName(serverInstanceName, hostName, pathName);
final ServiceName deploymentInfoServiceName = deploymentServiceName.append(UndertowDeploymentInfoService.SERVICE_NAME);

// instantiate injector service
final UndertowSipDeploymentInfoService sipDeploymentInfoService = new UndertowSipDeploymentInfoService(deploymentUnit);
final UndertowSipDeploymentInfoService sipDeploymentInfoService = new UndertowSipDeploymentInfoService(deploymentUnit,serverService);
final ServiceName sipDeploymentInfoServiceName = deploymentServiceName
.append(UndertowSipDeploymentInfoService.SERVICE_NAME);
// lets earn that deploymentService will depend on this service:
Expand All @@ -89,6 +96,8 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
final ServiceBuilder<UndertowSipDeploymentInfoService> infoInjectorBuilder = phaseContext.getServiceTarget()
.addService(sipDeploymentInfoServiceName, sipDeploymentInfoService);
infoInjectorBuilder.addDependency(deploymentInfoServiceName);
//this service depends on convergedservletcontainer service:
infoInjectorBuilder.addDependency(ConvergedServletContainerService.SERVICE_NAME);
infoInjectorBuilder.install();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package org.mobicents.as8.deployment;

import io.undertow.servlet.api.DeploymentInfo;
import io.undertow.servlet.api.DeploymentInfoFacade;
import io.undertow.servlet.core.ConvergedSessionManagerFactory;
import org.mobicents.io.undertow.servlet.api.DeploymentInfoFacade;
import org.mobicents.io.undertow.servlet.core.ConvergedSessionManagerFactory;

import javax.servlet.ServletException;

Expand All @@ -33,6 +33,8 @@
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.jboss.msc.value.InjectedValue;
import org.wildfly.extension.undertow.Host;
import org.wildfly.extension.undertow.Server;
import org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService;

/**
Expand All @@ -45,9 +47,11 @@ public class UndertowSipDeploymentInfoService implements Service<UndertowSipDepl

private DeploymentUnit deploymentUnit = null;
private SIPWebContext webContext = null;
private Server server = null;

public UndertowSipDeploymentInfoService(DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
public UndertowSipDeploymentInfoService(DeploymentUnit deploymentUnit, Server server) throws DeploymentUnitProcessingException {
this.deploymentUnit = deploymentUnit;
this.server = server;

// lets init sipWebContext:
this.webContext = new SIPWebContext();
Expand Down Expand Up @@ -82,6 +86,16 @@ public void start(StartContext context) throws StartException {
facade.addDeploymentInfo(info);
facade.setSessionManagerFactory(new ConvergedSessionManagerFactory());
this.deploymentUnit.putAttachment(DeploymentInfoFacade.ATTACHMENT_KEY, facade);

if(server!=null){
this.webContext.setWebServerListeners(server.getListeners());
for(Host host: server.getHosts()){
if(host!=null && host.getName().equals(info.getHostName())){
this.webContext.setHostOfDeployment(host);
break;
}
}
}
} catch (ServletException e) {
throw new StartException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.value.ImmediateValue;
import org.mobicents.as8.ConvergedServletContainerService;
import org.mobicents.metadata.sip.spec.SipAnnotationMetaData;
import org.mobicents.metadata.sip.spec.SipMetaData;
import org.wildfly.extension.undertow.Server;
Expand Down Expand Up @@ -148,6 +149,8 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro

// this service depends on the base undertowdeployment service:
sipDeploymentServiceBuilder.addDependency(deploymentServiceName);
//this service depends on convergedservletcontainer service:
sipDeploymentServiceBuilder.addDependency(ConvergedServletContainerService.SERVICE_NAME);
sipDeploymentServiceBuilder.install();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ public void processSipMetaData(JBossConvergedSipMetaData convergedMetaData, SipC
servletInfo.addSecurityRoleRef(ref.getRoleName(), ref.getRoleLink());
}
}
SipServletImpl wrapper = new SipServletImpl(servletInfo, convergedContext.getServletContext());
wrapper.setupMultipart(convergedContext.getServletContext());
SipServletImpl wrapper = new SipServletImpl(servletInfo, convergedContext.getServletContext().getDelegatedContext());
wrapper.setupMultipart(convergedContext.getServletContext().getDelegatedContext());
wrapper.setServletName(value.getServletName());

convergedContext.getDeploymentInfoFacade().addSipServlets(servletInfo);
Expand Down
20 changes: 16 additions & 4 deletions containers/sip-servlets-as8/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@
<version>8.2.0.Final</version>
<scope>provided</scope>
</dependency>
<!-- dependency>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-core</artifactId>
<version>1.2.0.Beta9-SNAPSHOT</version>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-servlet</artifactId>
<version>1.2.0.Beta9-SNAPSHOT</version>
</dependency -->
<version>1.1.0.Final</version>
</dependency>
<!--dependency>
<groupId>org.jboss.security</groupId>
<artifactId>jbosssx</artifactId>
Expand Down Expand Up @@ -129,6 +129,18 @@
<version>1.0.MOBICENTS</version>
<scope>provided</scope>
</dependency>

<!-- undertow memory session management deps -->
<dependency>
<groupId>org.jboss.xnio</groupId>
<artifactId>xnio-api</artifactId>
<version>3.3.0.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.xnio</groupId>
<artifactId>xnio-nio</artifactId>
<version>3.3.0.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Loading

0 comments on commit ab879bd

Please sign in to comment.