use of org.apache.openejb.jee.HandlerChains$JAXB.writeHandlerChains in project tomee by apache.
the class WsDeployer method getHandlerChains.
public static HandlerChains getHandlerChains(Class<?> declaringClass, final String serviceEndpoint, final ClassLoader classLoader) throws OpenEJBException {
HandlerChain handlerChain = declaringClass.getAnnotation(HandlerChain.class);
if (handlerChain == null && serviceEndpoint != null) {
try {
declaringClass = classLoader.loadClass(serviceEndpoint);
handlerChain = declaringClass.getAnnotation(HandlerChain.class);
} catch (final ClassNotFoundException ignored) {
// no-op
}
}
HandlerChains handlerChains = null;
if (handlerChain != null) {
try {
final URL handlerFileURL = declaringClass.getResource(handlerChain.file());
handlerChains = ReadDescriptors.readHandlerChains(handlerFileURL);
} catch (final Throwable e) {
throw new OpenEJBException("Unable to load handler chain file: " + handlerChain.file(), e);
}
}
return handlerChains;
}
use of org.apache.openejb.jee.HandlerChains$JAXB.writeHandlerChains 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<>();
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.writeHandlerChains 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<>();
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<>();
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);
}
}
}
use of org.apache.openejb.jee.HandlerChains$JAXB.writeHandlerChains in project tomee by apache.
the class ServiceRef$JAXB method _write.
public static final void _write(final XoXMLStreamWriter writer, final ServiceRef serviceRef, RuntimeContext context) throws Exception {
if (serviceRef == null) {
writer.writeXsiNil();
return;
}
if (context == null) {
context = new RuntimeContext();
}
final String prefix = writer.getUniquePrefix("http://java.sun.com/xml/ns/javaee");
if (ServiceRef.class != serviceRef.getClass()) {
context.unexpectedSubclass(writer, serviceRef, ServiceRef.class);
return;
}
context.beforeMarshal(serviceRef, LifecycleCallback.NONE);
// ATTRIBUTE: id
final String idRaw = serviceRef.id;
if (idRaw != null) {
String id = null;
try {
id = Adapters.collapsedStringAdapterAdapter.marshal(idRaw);
} catch (final Exception e) {
context.xmlAdapterError(serviceRef, "id", CollapsedStringAdapter.class, String.class, String.class, e);
}
writer.writeAttribute("", "", "id", id);
}
// ELEMENT: descriptions
Text[] descriptions = null;
try {
descriptions = serviceRef.getDescriptions();
} catch (final Exception e) {
context.getterError(serviceRef, "descriptions", ServiceRef.class, "getDescriptions", e);
}
if (descriptions != null) {
for (final Text descriptionsItem : descriptions) {
if (descriptionsItem != null) {
writer.writeStartElement(prefix, "description", "http://java.sun.com/xml/ns/javaee");
writeText(writer, descriptionsItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(serviceRef, "descriptions");
}
}
}
// ELEMENT: displayNames
Text[] displayNames = null;
try {
displayNames = serviceRef.getDisplayNames();
} catch (final Exception e) {
context.getterError(serviceRef, "displayNames", ServiceRef.class, "getDisplayNames", e);
}
if (displayNames != null) {
for (final Text displayNamesItem : displayNames) {
if (displayNamesItem != null) {
writer.writeStartElement(prefix, "display-name", "http://java.sun.com/xml/ns/javaee");
writeText(writer, displayNamesItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(serviceRef, "displayNames");
}
}
}
// ELEMENT: icon
final LocalCollection<Icon> icon = serviceRef.icon;
if (icon != null) {
for (final Icon iconItem : icon) {
if (iconItem != null) {
writer.writeStartElement(prefix, "icon", "http://java.sun.com/xml/ns/javaee");
writeIcon(writer, iconItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(serviceRef, "icon");
}
}
}
// ELEMENT: serviceRefName
final String serviceRefNameRaw = serviceRef.serviceRefName;
String serviceRefName = null;
try {
serviceRefName = Adapters.collapsedStringAdapterAdapter.marshal(serviceRefNameRaw);
} catch (final Exception e) {
context.xmlAdapterError(serviceRef, "serviceRefName", CollapsedStringAdapter.class, String.class, String.class, e);
}
if (serviceRefName != null) {
writer.writeStartElement(prefix, "service-ref-name", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(serviceRefName);
writer.writeEndElement();
} else {
context.unexpectedNullValue(serviceRef, "serviceRefName");
}
// ELEMENT: serviceInterface
final String serviceInterfaceRaw = serviceRef.serviceInterface;
String serviceInterface = null;
try {
serviceInterface = Adapters.collapsedStringAdapterAdapter.marshal(serviceInterfaceRaw);
} catch (final Exception e) {
context.xmlAdapterError(serviceRef, "serviceInterface", CollapsedStringAdapter.class, String.class, String.class, e);
}
if (serviceInterface != null) {
writer.writeStartElement(prefix, "service-interface", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(serviceInterface);
writer.writeEndElement();
} else {
context.unexpectedNullValue(serviceRef, "serviceInterface");
}
// ELEMENT: serviceRefType
final String serviceRefTypeRaw = serviceRef.serviceRefType;
String serviceRefType = null;
try {
serviceRefType = Adapters.collapsedStringAdapterAdapter.marshal(serviceRefTypeRaw);
} catch (final Exception e) {
context.xmlAdapterError(serviceRef, "serviceRefType", CollapsedStringAdapter.class, String.class, String.class, e);
}
if (serviceRefType != null) {
writer.writeStartElement(prefix, "service-ref-type", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(serviceRefType);
writer.writeEndElement();
}
// ELEMENT: wsdlFile
final String wsdlFileRaw = serviceRef.wsdlFile;
String wsdlFile = null;
try {
wsdlFile = Adapters.collapsedStringAdapterAdapter.marshal(wsdlFileRaw);
} catch (final Exception e) {
context.xmlAdapterError(serviceRef, "wsdlFile", CollapsedStringAdapter.class, String.class, String.class, e);
}
if (wsdlFile != null) {
writer.writeStartElement(prefix, "wsdl-file", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(wsdlFile);
writer.writeEndElement();
}
// ELEMENT: jaxrpcMappingFile
final String jaxrpcMappingFileRaw = serviceRef.jaxrpcMappingFile;
String jaxrpcMappingFile = null;
try {
jaxrpcMappingFile = Adapters.collapsedStringAdapterAdapter.marshal(jaxrpcMappingFileRaw);
} catch (final Exception e) {
context.xmlAdapterError(serviceRef, "jaxrpcMappingFile", CollapsedStringAdapter.class, String.class, String.class, e);
}
if (jaxrpcMappingFile != null) {
writer.writeStartElement(prefix, "jaxrpc-mapping-file", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(jaxrpcMappingFile);
writer.writeEndElement();
}
// ELEMENT: serviceQname
final QName serviceQname = serviceRef.serviceQname;
if (serviceQname != null) {
writer.writeStartElement(prefix, "service-qname", "http://java.sun.com/xml/ns/javaee");
writer.writeQName(serviceQname);
writer.writeEndElement();
}
// ELEMENT: portComponentRef
final List<PortComponentRef> portComponentRef = serviceRef.portComponentRef;
if (portComponentRef != null) {
for (final PortComponentRef portComponentRefItem : portComponentRef) {
if (portComponentRefItem != null) {
writer.writeStartElement(prefix, "port-component-ref", "http://java.sun.com/xml/ns/javaee");
writePortComponentRef(writer, portComponentRefItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(serviceRef, "portComponentRef");
}
}
}
// ELEMENT: handler
final List<Handler> handler = serviceRef.handler;
if (handler != null) {
for (final Handler handlerItem : handler) {
if (handlerItem != null) {
writer.writeStartElement(prefix, "handler", "http://java.sun.com/xml/ns/javaee");
writeHandler(writer, handlerItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(serviceRef, "handler");
}
}
}
// ELEMENT: handlerChains
final HandlerChains handlerChains = serviceRef.handlerChains;
if (handlerChains != null) {
writer.writeStartElement(prefix, "handler-chains", "http://java.sun.com/xml/ns/javaee");
writeHandlerChains(writer, handlerChains, context);
writer.writeEndElement();
}
// ELEMENT: mappedName
final String mappedNameRaw = serviceRef.mappedName;
String mappedName = null;
try {
mappedName = Adapters.collapsedStringAdapterAdapter.marshal(mappedNameRaw);
} catch (final Exception e) {
context.xmlAdapterError(serviceRef, "mappedName", CollapsedStringAdapter.class, String.class, String.class, e);
}
if (mappedName != null) {
writer.writeStartElement(prefix, "mapped-name", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(mappedName);
writer.writeEndElement();
}
// ELEMENT: injectionTarget
final Set<InjectionTarget> injectionTarget = serviceRef.injectionTarget;
if (injectionTarget != null) {
for (final InjectionTarget injectionTargetItem : injectionTarget) {
if (injectionTargetItem != null) {
writer.writeStartElement(prefix, "injection-target", "http://java.sun.com/xml/ns/javaee");
writeInjectionTarget(writer, injectionTargetItem, context);
writer.writeEndElement();
} else {
context.unexpectedNullValue(serviceRef, "injectionTarget");
}
}
}
// ELEMENT: lookupName
final String lookupNameRaw = serviceRef.lookupName;
String lookupName = null;
try {
lookupName = Adapters.collapsedStringAdapterAdapter.marshal(lookupNameRaw);
} catch (final Exception e) {
context.xmlAdapterError(serviceRef, "lookupName", CollapsedStringAdapter.class, String.class, String.class, e);
}
if (lookupName != null) {
writer.writeStartElement(prefix, "lookup-name", "http://java.sun.com/xml/ns/javaee");
writer.writeCharacters(lookupName);
writer.writeEndElement();
}
context.afterMarshal(serviceRef, LifecycleCallback.NONE);
}
use of org.apache.openejb.jee.HandlerChains$JAXB.writeHandlerChains 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());
}
Aggregations