use of javax.wsdl.Definition in project tomcat70 by apache.
the class ServiceRefFactory method getObjectInstance.
// ----------------------------------------------------------- Constructors
// -------------------------------------------------------------- Constants
// ----------------------------------------------------- Instance Variables
// --------------------------------------------------------- Public Methods
// -------------------------------------------------- ObjectFactory Methods
/**
* Crete 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) {
Reference ref = (Reference) 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<String, QName>();
// 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 (Iterator<String> i = ports.keySet().iterator(); i.hasNext(); ) {
String portName = i.next();
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<?>[] interfaces = null;
Class<?>[] serviceInterfaces = serviceInterfaceClass.getInterfaces();
interfaces = new Class[serviceInterfaces.length + 1];
for (int i = 0; i < serviceInterfaces.length; i++) {
interfaces[i] = serviceInterfaces[i];
}
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 (((ServiceRef) ref).getHandlersSize() > 0) {
HandlerRegistry handlerRegistry = service.getHandlerRegistry();
ArrayList<String> soaproles = new ArrayList<String>();
while (((ServiceRef) ref).getHandlersSize() > 0) {
HandlerRef handlerRef = ((ServiceRef) 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
ArrayList<QName> headers = new ArrayList<QName>();
Hashtable<String, String> config = new Hashtable<String, String>();
ArrayList<String> portNames = new ArrayList<String>();
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[headers.size()]));
handlerInfo.setHandlerConfig(config);
if (!portNames.isEmpty()) {
Iterator<String> iter = portNames.iterator();
while (iter.hasNext()) initHandlerChain(new QName(iter.next()), 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 tesb-studio-se by Talend.
the class BaseNodeAdapter method generateDefinition.
public Definition generateDefinition(String inputWsdlLocation) throws InvocationTargetException, WSDLException {
String wsdl = getExpressionParamValue(inputWsdlLocation);
setupSSLIfNeeded();
Definition definition = WSDLHelper.load(wsdl, node.getUniqueName());
setNamespacePrefixes(definition);
return definition;
}
use of javax.wsdl.Definition in project tesb-studio-se by Talend.
the class WebServiceUIPresenter method retrieveData.
public void retrieveData(String wsdlLocation) throws WSDLException, InvocationTargetException {
String wsdlLocationTemp = TalendQuoteUtils.removeQuotesIfExist(wsdlLocation);
Definition definition = nodeAdapter.generateDefinition(wsdlLocationTemp);
currentSetting.setWsdlLocation(TalendQuoteUtils.addQuotes(wsdlLocationTemp));
currentSetting.setDefinition(definition);
List<Function> functionsAvailable = new ArrayList<Function>();
for (ServiceInfo serviceInfo : ComponentBuilder.buildModel(definition)) {
for (OperationInfo oper : serviceInfo.getOperations()) {
Function f = new Function(serviceInfo, oper);
functionsAvailable.add(f);
}
}
portFunctionsMap = new LinkedHashMap<String, List<Function>>();
for (Function f : functionsAvailable) {
List<Function> functions = portFunctionsMap.get(f.getPortName());
if (functions == null) {
functions = new ArrayList<Function>();
portFunctionsMap.put(f.getPortName(), functions);
}
functions.add(f);
}
}
use of javax.wsdl.Definition in project tesb-studio-se by Talend.
the class LocalWSDLEditor method saveModel.
private void saveModel() throws CoreException {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
Definition definition = WSDLUtils.getDefinition(serviceItem);
// changed for TDI-18005
Map<String, String> portNameIdMap = new HashMap<String, String>();
Map<String, EMap<String, String>> portAdditionalMap = new HashMap<String, EMap<String, String>>();
Map<String, String> operNameIdMap = new HashMap<String, String>();
Map<String, String> operJobMap = new HashMap<String, String>();
EList<ServicePort> oldServicePorts = ((ServiceConnection) serviceItem.getConnection()).getServicePort();
// get old service port item names and operation names under them
HashMap<String, ArrayList<String>> oldPortItemNames = new HashMap<String, ArrayList<String>>();
for (ServicePort servicePort : oldServicePorts) {
// keep id
portNameIdMap.put(servicePort.getName(), servicePort.getId());
// keep additional infos
portAdditionalMap.put(servicePort.getId(), servicePort.getAdditionalInfo());
EList<ServiceOperation> operations = servicePort.getServiceOperation();
ArrayList<String> operationNames = new ArrayList<String>();
for (ServiceOperation operation : operations) {
operNameIdMap.put(operation.getName(), operation.getId());
operationNames.add(operation.getLabel());
// record assigned job
operJobMap.put(operation.getId(), operation.getReferenceJobId());
}
oldPortItemNames.put(servicePort.getName(), operationNames);
}
((ServiceConnection) serviceItem.getConnection()).getServicePort().clear();
for (Object obj : definition.getAllPortTypes().values()) {
PortType portType = (PortType) obj;
if (portType.isUndefined()) {
continue;
}
ServicePort port = ServicesFactory.eINSTANCE.createServicePort();
String portName = portType.getQName().getLocalPart();
port.setName(portName);
// set port id
String id = portNameIdMap.get(portName);
if (id != null) {
port.setId(id);
// restore additional infos
port.getAdditionalInfo().putAll(portAdditionalMap.get(id));
} else {
port.setId(factory.getNextId());
}
@SuppressWarnings("unchecked") List<Operation> list = portType.getOperations();
for (Operation operation : list) {
if (operation.isUndefined()) {
// means the operation has been removed already ,why ?
continue;
}
ServiceOperation serviceOperation = ServicesFactory.eINSTANCE.createServiceOperation();
serviceOperation.setName(operation.getName());
Iterator<String> operationIterator = operNameIdMap.keySet().iterator();
while (operationIterator.hasNext()) {
String oldOperationName = operationIterator.next();
String operationId = operNameIdMap.get(oldOperationName);
if (oldOperationName.equals(operation.getName())) {
serviceOperation.setId(operationId);
// re-assign job
String jobId = operJobMap.get(operationId);
if (jobId != null) {
serviceOperation.setReferenceJobId(jobId);
}
}
}
if (serviceOperation.getId() == null || serviceOperation.getId().equals("")) {
serviceOperation.setId(factory.getNextId());
}
if (operation.getDocumentationElement() != null) {
serviceOperation.setDocumentation(operation.getDocumentationElement().getTextContent());
}
boolean hasAssignedjob = false;
ArrayList<String> operationNames = oldPortItemNames.get(portName);
String referenceJobId = serviceOperation.getReferenceJobId();
if (operationNames != null && referenceJobId != null) {
IRepositoryViewObject repObj = null;
try {
repObj = factory.getLastVersion(referenceJobId);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (repObj != null) {
for (String name : operationNames) {
if (name.equals(operation.getName() + '-' + repObj.getLabel())) {
serviceOperation.setLabel(name);
hasAssignedjob = true;
break;
}
}
}
}
if (!hasAssignedjob) {
serviceOperation.setLabel(operation.getName());
}
serviceOperation.setInBinding(WSDLUtils.isOperationInBinding(definition, portName, operation.getName()));
port.getServiceOperation().add(serviceOperation);
}
((ServiceConnection) serviceItem.getConnection()).getServicePort().add(port);
}
}
use of javax.wsdl.Definition in project tesb-studio-se by Talend.
the class ServiceExportManager method createBlueprint.
@SuppressWarnings("unchecked")
public void createBlueprint(File outputFile, Map<ServicePort, Map<String, String>> ports, Map<String, String> additionalInfo, IFile wsdl, String studioServiceName) throws IOException, CoreException {
// TODO: support multiport
Entry<ServicePort, Map<String, String>> studioPort = ports.entrySet().iterator().next();
Definition def = WSDLUtils.getDefinition(wsdl);
QName serviceQName = null;
String endpointAddress = null;
String endpointName = null;
Map<QName, Service> services = def.getServices();
ServicePort servicePort = studioPort.getKey();
for (Entry<QName, Service> serviceEntry : services.entrySet()) {
// TODO: support multi-services
Service service = serviceEntry.getValue();
// TODO: support multi-ports
Collection<Port> servicePorts = service.getPorts().values();
for (Port port : servicePorts) {
if (servicePort.getName().equals(port.getBinding().getPortType().getQName().getLocalPart())) {
serviceQName = serviceEntry.getKey();
endpointName = port.getName();
endpointAddress = WSDLUtils.getPortAddress(port);
if (null != endpointAddress) {
// http://jira.talendforge.org/browse/TESB-3638
final URI uri = URI.create(endpointAddress);
endpointAddress = uri.getPath();
if (endpointAddress == null) {
endpointAddress = uri.getRawSchemeSpecificPart();
int interrogationMark = endpointAddress.indexOf('?');
if (interrogationMark > 0) {
endpointAddress = endpointAddress.substring(0, interrogationMark);
}
}
if (endpointAddress.equals("/services/") || endpointAddress.equals("/services")) {
// pass as is
endpointAddress = endpointAddress;
} else if (endpointAddress.startsWith("/services/")) {
// remove forwarding "/services/" context as required by runtime
// leave
endpointAddress = endpointAddress.substring("/services/".length() - 1);
// forwarding
// slash
} else if (endpointAddress.length() == 1) {
// empty path
endpointAddress += studioServiceName;
}
}
break;
}
}
}
Map<String, Object> endpointInfo = new HashMap<String, Object>();
// $NON-NLS-1$
endpointInfo.put("namespace", serviceQName.getNamespaceURI());
// $NON-NLS-1$
endpointInfo.put("service", serviceQName.getLocalPart());
// $NON-NLS-1$
endpointInfo.put("port", endpointName);
// $NON-NLS-1$
endpointInfo.put("address", endpointAddress);
// $NON-NLS-1$
endpointInfo.put("studioName", studioServiceName);
// $NON-NLS-1$
endpointInfo.put("wsdlLocation", wsdl.getName());
Map<String, String> operation2job = new HashMap<String, String>();
for (Map.Entry<ServicePort, Map<String, String>> port : ports.entrySet()) {
// TODO: actual port work
for (Map.Entry<String, String> operation : port.getValue().entrySet()) {
operation2job.put(operation.getKey(), operation.getValue());
}
}
// $NON-NLS-1$
endpointInfo.put("operation2job", operation2job);
boolean isStudioEEVersion = isStudioEEVersion();
boolean useRegistry = isStudioEEVersion && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.USE_SERVICE_REGISTRY));
boolean useSL = Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.USE_SL));
boolean useSAM = !useRegistry && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.USE_SAM));
boolean useSecurityToken = !useRegistry && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.SECURITY_BASIC));
boolean useSecuritySAML = !useRegistry && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.SECURITY_SAML));
boolean useAuthorization = !useRegistry && isStudioEEVersion && useSecuritySAML && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.AUTHORIZATION));
boolean useEncryption = !useRegistry && isStudioEEVersion && useSecuritySAML && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.ENCRYPTION));
boolean logMessages = Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.LOG_MESSAGES));
boolean wsdlSchemaValidation = isStudioEEVersion && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.WSDL_SCHEMA_VALIDATION));
boolean useBusinessCorrelation = !useRegistry && Boolean.valueOf(additionalInfo.get(ServiceMetadataDialog.USE_BUSINESS_CORRELATION));
// $NON-NLS-1$
endpointInfo.put("useSL", useSL);
// $NON-NLS-1$
endpointInfo.put("useSAM", useSAM);
// $NON-NLS-1$
endpointInfo.put("useSecurityToken", useSecurityToken);
// $NON-NLS-1$
endpointInfo.put("useSecuritySAML", useSecuritySAML);
// $NON-NLS-1$
endpointInfo.put("useAuthorization", useAuthorization);
// $NON-NLS-1$
endpointInfo.put("useEncryption", useEncryption);
// $NON-NLS-1$
endpointInfo.put("useServiceRegistry", useRegistry);
// $NON-NLS-1$
endpointInfo.put("logMessages", logMessages);
// $NON-NLS-1$
endpointInfo.put("useWsdlSchemaValidation", wsdlSchemaValidation);
// $NON-NLS-1$
endpointInfo.put("useBusinessCorrelation", useBusinessCorrelation);
Map<String, String> slCustomProperties = new HashMap<String, String>();
if (useSL) /* && !useRegistry */
{
for (Map.Entry<String, String> prop : additionalInfo.entrySet()) {
if (prop.getKey().startsWith(ServiceMetadataDialog.SL_CUSTOM_PROP_PREFIX)) {
slCustomProperties.put(prop.getKey().substring(ServiceMetadataDialog.SL_CUSTOM_PROP_PREFIX.length()), prop.getValue());
}
}
}
// $NON-NLS-1$
endpointInfo.put("slCustomProps", slCustomProperties);
// $NON-NLS-1$
endpointInfo.put(// $NON-NLS-1$
"samlConfig", // $NON-NLS-1$
serviceQName.toString().replaceAll("\\W+", "_").substring(1));
// $NON-NLS-1$
TemplateProcessor.processTemplate(// $NON-NLS-1$
"DATA_SERVICE_BLUEPRINT_CONFIG", endpointInfo, outputFile, getClass().getResourceAsStream(TEMPLATE_BLUEPRINT));
}
Aggregations