use of org.apache.openejb.jee.HandlerChains$JAXB.readHandlerChains in project tomee by apache.
the class HandlerResolverImplTest method readHandlerChains.
private HandlerChains readHandlerChains(final String filePath) throws Exception {
final URL url = getClass().getResource(filePath);
assertNotNull("Could not find handler chains file " + filePath, url);
final HandlerChains handlerChains = ReadDescriptors.readHandlerChains(url);
return handlerChains;
}
use of org.apache.openejb.jee.HandlerChains$JAXB.readHandlerChains in project tomee by apache.
the class HandlerResolverImplTest method testBasic.
public void testBasic() throws Exception {
final HandlerChains handlerChains = readHandlerChains("/handlers.xml");
assertEquals(3, handlerChains.getHandlerChain().size());
final List<HandlerChainInfo> handlerChainInfos = ConfigurationFactory.toHandlerChainInfo(handlerChains);
final List<HandlerChainData> handlerChainDatas = WsBuilder.toHandlerChainData(handlerChainInfos, getClass().getClassLoader());
final HandlerResolverImpl resolver = new HandlerResolverImpl(handlerChainDatas, null, new InitialContext());
List<Handler> handlers = null;
handlers = resolver.getHandlerChain(new TestPortInfo(null, null, null));
assertEquals(3, handlers.size());
}
use of org.apache.openejb.jee.HandlerChains$JAXB.readHandlerChains in project tomee by apache.
the class HandlerResolverImplTest method testServiceMatching.
public void testServiceMatching() throws Exception {
final HandlerChains handlerChains = readHandlerChains("/handlers_service.xml");
assertEquals(3, handlerChains.getHandlerChain().size());
final List<HandlerChainInfo> handlerChainInfos = ConfigurationFactory.toHandlerChainInfo(handlerChains);
final List<HandlerChainData> handlerChainDatas = WsBuilder.toHandlerChainData(handlerChainInfos, getClass().getClassLoader());
final HandlerResolverImpl resolver = new HandlerResolverImpl(handlerChainDatas, null, new InitialContext());
List<Handler> handlers = null;
handlers = resolver.getHandlerChain(new TestPortInfo(null, null, null));
assertEquals(0, handlers.size());
final QName serviceName1 = new QName("http://java.sun.com/xml/ns/javaee", "Bar");
handlers = resolver.getHandlerChain(new TestPortInfo(null, null, serviceName1));
assertEquals(1, handlers.size());
final QName serviceName2 = new QName("http://java.sun.com/xml/ns/javaee", "Foo");
handlers = resolver.getHandlerChain(new TestPortInfo(null, null, serviceName2));
assertEquals(2, handlers.size());
final QName serviceName3 = new QName("http://java.sun.com/xml/ns/javaee", "FooBar");
handlers = resolver.getHandlerChain(new TestPortInfo(null, null, serviceName3));
assertEquals(1, handlers.size());
final QName serviceName4 = new QName("http://java.sun.com/xml/ns/javaee", "BarFoo");
handlers = resolver.getHandlerChain(new TestPortInfo(null, null, serviceName4));
assertEquals(0, handlers.size());
}
use of org.apache.openejb.jee.HandlerChains$JAXB.readHandlerChains in project tomee by apache.
the class WsDeployer method processPorts.
private void processPorts(final EjbModule ejbModule) throws OpenEJBException {
// map existing webservice port declarations by servlet link
Webservices webservices = ejbModule.getWebservices();
final Map<String, PortComponent> portMap = new TreeMap<String, PortComponent>();
if (webservices != null) {
for (final WebserviceDescription webserviceDescription : webservices.getWebserviceDescription()) {
for (final PortComponent portComponent : webserviceDescription.getPortComponent()) {
final ServiceImplBean serviceImplBean = portComponent.getServiceImplBean();
if (serviceImplBean != null && serviceImplBean.getEjbLink() != null) {
portMap.put(serviceImplBean.getEjbLink(), portComponent);
}
}
}
}
final Map<String, EjbDeployment> deploymentsByEjbName = ejbModule.getOpenejbJar().getDeploymentsByEjbName();
WebserviceDescription webserviceDescription;
for (final EnterpriseBean enterpriseBean : ejbModule.getEjbJar().getEnterpriseBeans()) {
// skip if this is not a webservices endpoint
if (!(enterpriseBean instanceof SessionBean)) {
continue;
}
final SessionBean sessionBean = (SessionBean) enterpriseBean;
if (sessionBean.getSessionType() == SessionType.STATEFUL) {
continue;
}
if (sessionBean.getSessionType() == SessionType.MANAGED) {
continue;
}
if (sessionBean.getServiceEndpoint() == null) {
continue;
}
final EjbDeployment deployment = deploymentsByEjbName.get(sessionBean.getEjbName());
if (deployment == null) {
continue;
}
final Class<?> ejbClass;
try {
ejbClass = ejbModule.getClassLoader().loadClass(sessionBean.getEjbClass());
} catch (final ClassNotFoundException e) {
throw new OpenEJBException("Unable to load ejb class: " + sessionBean.getEjbClass(), e);
}
// for now, skip all non jaxws beans
if (!JaxWsUtils.isWebService(ejbClass)) {
continue;
}
// create webservices dd if not defined
if (webservices == null) {
webservices = new Webservices();
ejbModule.setWebservices(webservices);
}
webserviceDescription = webservices.getWebserviceDescriptionMap().get(JaxWsUtils.getServiceName(ejbClass));
if (webserviceDescription == null) {
webserviceDescription = new WebserviceDescription();
if (JaxWsUtils.isWebService(ejbClass)) {
webserviceDescription.setWebserviceDescriptionName(JaxWsUtils.getServiceName(ejbClass));
}
// TODO else { /* create webserviceDescription name using some sort of jaxrpc data */ }
webservices.getWebserviceDescription().add(webserviceDescription);
}
// add a port component if we don't alrady have one
PortComponent portComponent = portMap.get(sessionBean.getEjbName());
if (portComponent == null) {
portComponent = new PortComponent();
if (webserviceDescription.getPortComponentMap().containsKey(JaxWsUtils.getPortQName(ejbClass).getLocalPart())) {
// when to webservices.xml is defined and when we want to
// publish more than one port for the same implementation by configuration
portComponent.setPortComponentName(sessionBean.getEjbName());
} else {
// JAX-WS Metadata specification default
portComponent.setPortComponentName(JaxWsUtils.getPortQName(ejbClass).getLocalPart());
}
webserviceDescription.getPortComponent().add(portComponent);
final ServiceImplBean serviceImplBean = new ServiceImplBean();
serviceImplBean.setEjbLink(sessionBean.getEjbName());
portComponent.setServiceImplBean(serviceImplBean);
// Checking if MTOM must be enabled
if (portComponent.getProtocolBinding() == null) {
portComponent.setProtocolBinding(JaxWsUtils.getBindingUriFromAnn(ejbClass));
}
configMtomAnnotation(ejbClass, portComponent);
if (SOAPBinding.SOAP12HTTP_MTOM_BINDING.equals(portComponent.getProtocolBinding()) || SOAPBinding.SOAP11HTTP_MTOM_BINDING.equals(portComponent.getProtocolBinding())) {
portComponent.setEnableMtom(true);
}
}
// default portId == deploymentId
if (portComponent.getId() == null) {
portComponent.setId(deployment.getDeploymentId());
}
if (webserviceDescription.getId() == null) {
webserviceDescription.setId(deployment.getDeploymentId());
}
// set service endpoint interface
if (portComponent.getServiceEndpointInterface() == null) {
portComponent.setServiceEndpointInterface(sessionBean.getServiceEndpoint());
}
// default location is /@WebService.serviceName/@WebService.name
if (JaxWsUtils.isWebService(ejbClass)) {
if (portComponent.getWsdlPort() == null) {
portComponent.setWsdlPort(JaxWsUtils.getPortQName(ejbClass));
}
if (webserviceDescription.getWsdlFile() == null) {
webserviceDescription.setWsdlFile(JaxWsUtils.getServiceWsdlLocation(ejbClass, ejbModule.getClassLoader()));
}
if (portComponent.getWsdlService() == null) {
final Definition definition = getWsdl(ejbModule, webserviceDescription.getWsdlFile());
if (definition != null && definition.getServices().size() == 1) {
final QName serviceQName = (QName) definition.getServices().keySet().iterator().next();
portComponent.setWsdlService(serviceQName);
} else {
portComponent.setWsdlService(JaxWsUtils.getServiceQName(ejbClass));
}
}
if (portComponent.getLocation() == null && webserviceDescription.getWsdlFile() != null) {
// set location based on wsdl port
final Definition definition = getWsdl(ejbModule, webserviceDescription.getWsdlFile());
final String locationURI = getLocationFromWsdl(definition, portComponent);
portComponent.setLocation(locationURI);
}
if (portComponent.getProtocolBinding() == null) {
portComponent.setProtocolBinding(JaxWsUtils.getBindingUriFromAnn(ejbClass));
}
// handlers
if (portComponent.getHandlerChains() == null) {
final HandlerChains handlerChains = getHandlerChains(ejbClass, sessionBean.getServiceEndpoint(), ejbModule.getClassLoader());
portComponent.setHandlerChains(handlerChains);
}
}
// TODO else { /* location JAX-RPC services comes from wsdl file */ }
}
}
use of org.apache.openejb.jee.HandlerChains$JAXB.readHandlerChains in project tomee by apache.
the class WsDeployer method processPorts.
private void processPorts(final WebModule webModule) throws OpenEJBException {
// map existing webservice port declarations by servlet link
Webservices webservices = webModule.getWebservices();
final Map<String, PortComponent> portMap = new TreeMap<String, PortComponent>();
if (webservices != null) {
for (final WebserviceDescription webserviceDescription : webservices.getWebserviceDescription()) {
for (final PortComponent portComponent : webserviceDescription.getPortComponent()) {
final ServiceImplBean serviceImplBean = portComponent.getServiceImplBean();
if (serviceImplBean != null && serviceImplBean.getServletLink() != null) {
portMap.put(serviceImplBean.getServletLink(), portComponent);
}
}
}
}
// map existing servlet-mapping declarations
final WebApp webApp = webModule.getWebApp();
final Map<String, ServletMapping> servletMappings = new TreeMap<String, ServletMapping>();
for (final ServletMapping servletMapping : webApp.getServletMapping()) {
servletMappings.put(servletMapping.getServletName(), servletMapping);
}
// add port declarations for Pojo webservices
WebserviceDescription webserviceDescription;
for (final Servlet servlet : webApp.getServlet()) {
// the implementation class will be replaced by the WsServlet in the WsRegistry
final String className = servlet.getServletClass();
// Skip JSPs
if (className == null) {
continue;
}
try {
final Class<?> clazz = webModule.getClassLoader().loadClass(className);
if (JaxWsUtils.isWebService(clazz)) {
// add servlet mapping if not already declared
ServletMapping servletMapping = servletMappings.get(servlet.getServletName());
final String serviceName = JaxWsUtils.getServiceName(clazz);
if (servletMapping == null) {
servletMapping = new ServletMapping();
servletMapping.setServletName(servlet.getServletName());
final String location = "/" + serviceName;
servletMapping.getUrlPattern().add(location);
webApp.getServletMapping().add(servletMapping);
}
// if we don't have a webservices document yet, we're gonna need one now
if (webservices == null) {
webservices = new Webservices();
webModule.setWebservices(webservices);
}
// add web service description element (maps to service)
webserviceDescription = webservices.getWebserviceDescriptionMap().get(serviceName);
if (webserviceDescription == null) {
webserviceDescription = new WebserviceDescription();
webserviceDescription.setWebserviceDescriptionName(serviceName);
webservices.getWebserviceDescription().add(webserviceDescription);
}
// define port if not already declared
PortComponent portComponent = portMap.get(servlet.getServletName());
if (portComponent == null) {
portComponent = new PortComponent();
portComponent.setPortComponentName(clazz.getSimpleName());
final ServiceImplBean serviceImplBean = new ServiceImplBean();
serviceImplBean.setServletLink(servlet.getServletName());
portComponent.setServiceImplBean(serviceImplBean);
webserviceDescription.getPortComponent().add(portComponent);
}
// default portId == host.moduleId.servletName
if (portComponent.getId() == null) {
portComponent.setId(webModule.getHost() + "." + webModule.getModuleId() + "." + servlet.getServletName());
}
if (webserviceDescription.getId() == null) {
webserviceDescription.setId(webModule.getHost() + "." + webModule.getModuleId() + "." + servlet.getServletName());
}
// set port values from annotations if not already set
if (portComponent.getServiceEndpointInterface() == null) {
portComponent.setServiceEndpointInterface(JaxWsUtils.getServiceInterface(clazz));
}
if (portComponent.getWsdlPort() == null) {
portComponent.setWsdlPort(JaxWsUtils.getPortQName(clazz));
}
if (webserviceDescription.getWsdlFile() == null) {
webserviceDescription.setWsdlFile(JaxWsUtils.getServiceWsdlLocation(clazz, webModule.getClassLoader()));
}
if (portComponent.getWsdlService() == null) {
final Definition definition = getWsdl(webModule, webserviceDescription.getWsdlFile());
if (definition != null && definition.getServices().size() == 1) {
final QName serviceQName = (QName) definition.getServices().keySet().iterator().next();
portComponent.setWsdlService(serviceQName);
} else {
portComponent.setWsdlService(JaxWsUtils.getServiceQName(clazz));
}
}
if (portComponent.getProtocolBinding() == null) {
portComponent.setProtocolBinding(JaxWsUtils.getBindingUriFromAnn(clazz));
}
configMtomAnnotation(clazz, portComponent);
if (SOAPBinding.SOAP12HTTP_MTOM_BINDING.equals(portComponent.getProtocolBinding()) || SOAPBinding.SOAP11HTTP_MTOM_BINDING.equals(portComponent.getProtocolBinding())) {
portComponent.setEnableMtom(true);
}
// handlers
if (portComponent.getHandlerChains() == null) {
final HandlerChains handlerChains = getHandlerChains(clazz, portComponent.getServiceEndpointInterface(), webModule.getClassLoader());
portComponent.setHandlerChains(handlerChains);
}
}
} catch (final Exception e) {
throw new OpenEJBException("Unable to load servlet class: " + className, e);
}
}
}
Aggregations