use of javax.wsdl.Definition 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 javax.wsdl.Definition 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 javax.wsdl.Definition in project tomee by apache.
the class CommonsSchemaLoader method loadSchema.
public XmlSchemaCollection loadSchema() throws OpenEJBException {
Definition definition = readWsdl(wsdlUri);
addImportsFromDefinition(definition);
return xmlSchemaCollection;
}
use of javax.wsdl.Definition in project tomcat by apache.
the class ServiceRefFactory method getObjectInstance.
/**
* Create a new serviceref instance.
*
* @param obj The reference object describing the webservice
*/
@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
if (obj instanceof ServiceRef) {
ServiceRef ref = (ServiceRef) obj;
// ClassLoader
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
if (tcl == null) {
tcl = this.getClass().getClassLoader();
}
ServiceFactory factory = ServiceFactory.newInstance();
javax.xml.rpc.Service service = null;
// Service Interface
RefAddr tmp = ref.get(ServiceRef.SERVICE_INTERFACE);
String serviceInterface = null;
if (tmp != null) {
serviceInterface = (String) tmp.getContent();
}
// WSDL
tmp = ref.get(ServiceRef.WSDL);
String wsdlRefAddr = null;
if (tmp != null) {
wsdlRefAddr = (String) tmp.getContent();
}
// PortComponent
Hashtable<String, QName> portComponentRef = new Hashtable<>();
// Create QName object
QName serviceQname = null;
tmp = ref.get(ServiceRef.SERVICE_LOCAL_PART);
if (tmp != null) {
String serviceLocalPart = (String) tmp.getContent();
tmp = ref.get(ServiceRef.SERVICE_NAMESPACE);
if (tmp == null) {
serviceQname = new QName(serviceLocalPart);
} else {
String serviceNamespace = (String) tmp.getContent();
serviceQname = new QName(serviceNamespace, serviceLocalPart);
}
}
Class<?> serviceInterfaceClass = null;
// Create service object
if (serviceInterface == null) {
if (serviceQname == null) {
throw new NamingException("Could not create service-ref instance");
}
try {
if (wsdlRefAddr == null) {
service = factory.createService(serviceQname);
} else {
service = factory.createService(new URL(wsdlRefAddr), serviceQname);
}
} catch (Exception e) {
NamingException ex = new NamingException("Could not create service");
ex.initCause(e);
throw ex;
}
} else {
// Loading service Interface
try {
serviceInterfaceClass = tcl.loadClass(serviceInterface);
} catch (ClassNotFoundException e) {
NamingException ex = new NamingException("Could not load service Interface");
ex.initCause(e);
throw ex;
}
if (serviceInterfaceClass == null) {
throw new NamingException("Could not load service Interface");
}
try {
if (wsdlRefAddr == null) {
if (!Service.class.isAssignableFrom(serviceInterfaceClass)) {
throw new NamingException("service Interface should extend javax.xml.rpc.Service");
}
service = factory.loadService(serviceInterfaceClass);
} else {
service = factory.loadService(new URL(wsdlRefAddr), serviceInterfaceClass, new Properties());
}
} catch (Exception e) {
NamingException ex = new NamingException("Could not create service");
ex.initCause(e);
throw ex;
}
}
if (service == null) {
throw new NamingException("Cannot create service object");
}
serviceQname = service.getServiceName();
serviceInterfaceClass = service.getClass();
if (wsdlRefAddr != null) {
try {
WSDLFactory wsdlfactory = WSDLFactory.newInstance();
WSDLReader reader = wsdlfactory.newWSDLReader();
reader.setFeature("javax.wsdl.importDocuments", true);
Definition def = reader.readWSDL((new URL(wsdlRefAddr)).toExternalForm());
javax.wsdl.Service wsdlservice = def.getService(serviceQname);
// Can't change the API
@SuppressWarnings("unchecked") Map<String, ?> ports = wsdlservice.getPorts();
Method m = serviceInterfaceClass.getMethod("setEndpointAddress", new Class[] { java.lang.String.class, java.lang.String.class });
for (String portName : ports.keySet()) {
Port port = wsdlservice.getPort(portName);
String endpoint = getSOAPLocation(port);
m.invoke(service, new Object[] { port.getName(), endpoint });
portComponentRef.put(endpoint, new QName(port.getName()));
}
} catch (Exception e) {
if (e instanceof InvocationTargetException) {
Throwable cause = e.getCause();
if (cause instanceof ThreadDeath) {
throw (ThreadDeath) cause;
}
if (cause instanceof VirtualMachineError) {
throw (VirtualMachineError) cause;
}
}
NamingException ex = new NamingException("Error while reading Wsdl File");
ex.initCause(e);
throw ex;
}
}
ServiceProxy proxy = new ServiceProxy(service);
// Use port-component-ref
for (int i = 0; i < ref.size(); i++) {
if (ServiceRef.SERVICEENDPOINTINTERFACE.equals(ref.get(i).getType())) {
String serviceendpoint = "";
String portlink = "";
serviceendpoint = (String) ref.get(i).getContent();
if (ServiceRef.PORTCOMPONENTLINK.equals(ref.get(i + 1).getType())) {
i++;
portlink = (String) ref.get(i).getContent();
}
portComponentRef.put(serviceendpoint, new QName(portlink));
}
}
proxy.setPortComponentRef(portComponentRef);
// Instantiate service with proxy class
Class<?>[] serviceInterfaces = serviceInterfaceClass.getInterfaces();
Class<?>[] interfaces = Arrays.copyOf(serviceInterfaces, serviceInterfaces.length + 1);
interfaces[interfaces.length - 1] = javax.xml.rpc.Service.class;
Object proxyInstance = null;
try {
proxyInstance = Proxy.newProxyInstance(tcl, interfaces, proxy);
} catch (IllegalArgumentException e) {
proxyInstance = Proxy.newProxyInstance(tcl, serviceInterfaces, proxy);
}
// Use handler
if (ref.getHandlersSize() > 0) {
HandlerRegistry handlerRegistry = service.getHandlerRegistry();
List<String> soaproles = new ArrayList<>();
while (ref.getHandlersSize() > 0) {
HandlerRef handlerRef = ref.getHandler();
HandlerInfo handlerInfo = new HandlerInfo();
// Loading handler Class
tmp = handlerRef.get(HandlerRef.HANDLER_CLASS);
if ((tmp == null) || (tmp.getContent() == null)) {
break;
}
Class<?> handlerClass = null;
try {
handlerClass = tcl.loadClass((String) tmp.getContent());
} catch (ClassNotFoundException e) {
break;
}
// Load all datas relative to the handler : SOAPHeaders, config init element,
// portNames to be set on
List<QName> headers = new ArrayList<>();
Hashtable<String, String> config = new Hashtable<>();
List<String> portNames = new ArrayList<>();
for (int i = 0; i < handlerRef.size(); i++) {
if (HandlerRef.HANDLER_LOCALPART.equals(handlerRef.get(i).getType())) {
String localpart = "";
String namespace = "";
localpart = (String) handlerRef.get(i).getContent();
if (HandlerRef.HANDLER_NAMESPACE.equals(handlerRef.get(i + 1).getType())) {
i++;
namespace = (String) handlerRef.get(i).getContent();
}
QName header = new QName(namespace, localpart);
headers.add(header);
} else if (HandlerRef.HANDLER_PARAMNAME.equals(handlerRef.get(i).getType())) {
String paramName = "";
String paramValue = "";
paramName = (String) handlerRef.get(i).getContent();
if (HandlerRef.HANDLER_PARAMVALUE.equals(handlerRef.get(i + 1).getType())) {
i++;
paramValue = (String) handlerRef.get(i).getContent();
}
config.put(paramName, paramValue);
} else if (HandlerRef.HANDLER_SOAPROLE.equals(handlerRef.get(i).getType())) {
String soaprole = "";
soaprole = (String) handlerRef.get(i).getContent();
soaproles.add(soaprole);
} else if (HandlerRef.HANDLER_PORTNAME.equals(handlerRef.get(i).getType())) {
String portName = "";
portName = (String) handlerRef.get(i).getContent();
portNames.add(portName);
}
}
// Set the handlers informations
handlerInfo.setHandlerClass(handlerClass);
handlerInfo.setHeaders(headers.toArray(new QName[0]));
handlerInfo.setHandlerConfig(config);
if (!portNames.isEmpty()) {
for (String portName : portNames) {
initHandlerChain(new QName(portName), handlerRegistry, handlerInfo, soaproles);
}
} else {
Enumeration<QName> e = portComponentRef.elements();
while (e.hasMoreElements()) {
initHandlerChain(e.nextElement(), handlerRegistry, handlerInfo, soaproles);
}
}
}
}
return proxyInstance;
}
return null;
}
use of javax.wsdl.Definition in project carbon-apimgt by wso2.
the class APIMWSDLReaderTest method testGetWSDL.
@Test
public void testGetWSDL() throws Exception {
doMockStatics();
APIMWSDLReader wsdlReader = new APIMWSDLReader("");
byte[] content = IOUtils.toByteArray(Thread.currentThread().getContextClassLoader().getResourceAsStream("wsdls/stockQuote.wsdl"));
Definition definition = wsdlReader.getWSDLDefinitionFromByteContent(content, false);
Assert.assertNotNull(new String(wsdlReader.getWSDL(definition)));
}
Aggregations