private void initializePorts() { try { Definition def = bus.getExtension(WSDLManager.class).getDefinition(wsdlURL); javax.wsdl.Service serv = def.getService(serviceName); if (serv == null) { throw new WebServiceException("Could not find service named " + serviceName Map<String, Port> wsdlports = CastUtils.cast(serv.getPorts()); for (Port port : wsdlports.values()) { QName name = new QName(serviceName.getNamespaceURI(), port.getName()); = CastUtils.cast(port.getBinding().getExtensibilityElements()); if (!extensions.isEmpty()) { ExtensibilityElement e = extensions.get(0); extensions = CastUtils.cast(port.getExtensibilityElements()); if (!extensions.isEmpty()) { ExtensibilityElement e = extensions.get(0); Service service = sf.create(); for (ServiceInfo si : service.getServiceInfos()) { for (EndpointInfo ei : si.getEndpoints()) { String bindingID = BindingID.getJaxwsBindingID(ei.getTransportId()); addPort(ei.getName(), bindingID, ei.getAddress());
private Map<QName, Operation> getOperations(PortType portType) { Map<QName, Operation> operations = new HashMap<>(); Collection<Operation> pops = CastUtils.cast(portType.getOperations()); for (Operation op : pops) { operations.put(new QName(portType.getQName().getNamespaceURI(), op.getName()), op); } return operations; }
private Map<QName, XNode> getBindings(Service service) { Map<QName, XNode> bindings = new HashMap<>(); if (service.getPorts().values().isEmpty()) { throw new ToolException("Service " + service.getQName() + " does not contain any usable ports"); } Collection<Port> ports = CastUtils.cast(service.getPorts().values()); for (Port port : ports) { Binding binding = port.getBinding(); bindings.put(binding.getQName(), getXNode(service, port)); if (WSDLConstants.NS_WSDL11.equals(binding.getQName().getNamespaceURI())) { throw new ToolException("Binding " + binding.getQName().getLocalPart() + " namespace set improperly."); } } return bindings; }
private static QName getBindingQNameByID(Definition wsdlDef, String repositoryID, WSDLASTVisitor wsdlVisitor) { // We need to find the binding which corresponds with the given repository ID. // This is specified in the schema definition for a custom endpoint // reference type. Collection<Binding> bindings = CastUtils.cast(wsdlDef.getBindings().values()); if (bindings.isEmpty() && !wsdlVisitor.getModuleToNSMapper().isDefaultMapping()) { // If we are not using the default mapping, then the binding definitions are not // located in the current Definition object, but nistead in the root Definition bindings = CastUtils.cast(wsdlVisitor.getDefinition().getBindings().values()); } for (Binding b : bindings) { List<?> extElements = b.getExtensibilityElements(); for (java.lang.Object element : extElements) { if (element instanceof BindingType) { BindingType bt = (BindingType)element; if (bt.getRepositoryID().equals(repositoryID)) { if (wsdlVisitor.getSupportPolymorphicFactories()) { return new QName(b.getQName().getNamespaceURI(), "InferFromTypeId", b.getQName().getPrefix()); } return b.getQName(); } } } } return null; }
private boolean isServiceExisted() { services = CastUtils.cast(wsdlDefinition.getServices()); if (services == null) { return false; } for (Map.Entry<QName, Service> entry : services.entrySet()) { String serviceName = entry.getKey().getLocalPart(); if (serviceName.equals(env.get(ToolConstants.CFG_SERVICE))) { service = entry.getValue(); break; } } return (service == null) ? false : true; }
private boolean isBindingExisted() { Map<QName, Binding> bindings = CastUtils.cast(wsdlDefinition.getBindings()); if (bindings == null) { return false; } for (Entry<QName, Binding> entry : bindings.entrySet()) { String existBindingName = entry.getKey().getLocalPart(); String bindingName = (String)env.get(ToolConstants.CFG_BINDING); if (bindingName.equals(existBindingName)) { binding = entry.getValue(); } } return (binding == null) ? false : true; }
protected void buildBindingOperation(Definition def, Binding binding, Collection<BindingOperationInfo> bindingOperationInfos) { BindingOperation bindingOperation = null; for (BindingOperationInfo bindingOperationInfo : bindingOperationInfos) { bindingOperation = def.createBindingOperation(); addDocumentation(bindingOperation, bindingOperationInfo.getDocumentation()); bindingOperation.setName(bindingOperationInfo.getName().getLocalPart()); for (Operation operation : CastUtils.cast(binding.getPortType().getOperations(), Operation.class)) { if (operation.getName().equals(bindingOperation.getName())) { bindingOperation.setOperation(operation); break; } } buildBindingInput(def, bindingOperation, bindingOperationInfo.getInput()); buildBindingOutput(def, bindingOperation, bindingOperationInfo.getOutput()); buildBindingFault(def, bindingOperation, bindingOperationInfo.getFaults()); addExtensibilityAttributes(def, bindingOperation, bindingOperationInfo.getExtensionAttributes()); addExtensibilityElements(def, bindingOperation, getWSDL11Extensors(bindingOperationInfo)); binding.addBindingOperation(bindingOperation); } }
private boolean queryBinding(QName bqname) { Collection<Binding> bindings = CastUtils.cast(definition.getBindings().values()); for (Binding binding : bindings) { if (binding.getQName().getLocalPart().equals(bqname.getLocalPart())) { return true; } } return false; }
protected EprMetaData getObjectReferenceBinding(Definition wsdlDef, QName bindingName) { EprMetaData info = new EprMetaData(); Binding wsdlBinding = wsdlDef.getBinding(bindingName); // If the binding name does not have a namespace associated with it, then we'll need to // get the list of all bindings and compare their local parts against our name. if (wsdlBinding == null && bindingName.getNamespaceURI().isEmpty() && !bindingName.getLocalPart().isEmpty()) { Collection<Binding> bindingsCollection = CastUtils.cast(wsdlDef.getBindings().values()); for (Binding b : bindingsCollection) { if (b.getQName().getLocalPart().equals(bindingName.getLocalPart())) { wsdlBinding = b; break; } } } if (wsdlBinding != null) { info.setBinding(wsdlBinding); info.setCandidateWsdlDef(wsdlDef); } return info; }
private boolean isPortTypeExisted() { portTypes = CastUtils.cast(wsdlDefinition.getPortTypes()); if (portTypes == null) { return false; } for (Map.Entry<QName, PortType> entry : portTypes.entrySet()) { String existPortName = entry.getKey().getLocalPart(); if (existPortName.equals(env.get(ToolConstants.CFG_PORTTYPE))) { portType = entry.getValue(); break; } } return (portType == null) ? false : true; }
private void fixSchema(Schema sc, String pfx) throws ParserConfigurationException { Document doc = DOMUtils.getEmptyDocument(); Element el = doc.createElementNS(sc.getElementType().getNamespaceURI(), pfx + ":" + sc.getElementType().getLocalPart()); sc.setElement(el); Map<String, List<String>> mp = CastUtils.cast(sc.getImports()); for (Map.Entry<String, List<String>> ent : mp.entrySet()) { Element imp = doc.createElementNS(sc.getElementType().getNamespaceURI(), pfx + ":import"); el.appendChild(imp); imp.setAttribute("namespace", ent.getKey()); } }
@SuppressWarnings("unchecked") public QName getServiceQName(Definition def) { List<Definition> defs = new ArrayList<>(); defs.add(def); Iterator<?> ite1 = def.getImports().values().iterator(); while (ite1.hasNext()) { List<javax.wsdl.Import> defList = CastUtils.cast((List<?>)ite1.next()); for (javax.wsdl.Import importDef : defList) { defs.add(importDef.getDefinition()); } } String serviceName = (String)context.get(ToolConstants.CFG_SERVICENAME); for (Definition definition : defs) { if (serviceName != null) { for (Iterator<QName> ite = definition.getServices().keySet().iterator(); ite.hasNext();) { QName qn = ite.next(); if (qn.getLocalPart().equalsIgnoreCase(serviceName.toLowerCase())) { return qn; } } } } Message msg = new Message("SERVICE_NOT_FOUND", LOG, new Object[] {serviceName}); throw new ToolException(msg); }
protected void processAttachments(SoapMessage message, SoapBodyInfo sbi) { Collection<Attachment> atts = setupAttachmentOutput(message); List<Object> outObjects = CastUtils.cast(message.getContent(List.class)); String partName = mpi.getConcreteName().getLocalPart(); String ct = (String) mpi.getProperty(Message.CONTENT_TYPE); throw new Fault(new org.apache.cxf.common.i18n.Message("ATTACHMENT_NOT_SUPPORTED", LOG, o.getClass()));
private List<PortType> getPortTypeList() throws Exception { Map<QName, PortType> portTypes = CastUtils.cast(def.getAllPortTypes()); List<PortType> intfs = null; if (portTypes == null) { org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message( "No PortTypes defined in wsdl", LOG); throw new Exception(msg.toString()); } PortType portType = null; intfs = new ArrayList<>(); if (portTypes.size() == 1) { portType = portTypes.values().iterator().next(); interfaceNames.add(portType.getQName().getLocalPart()); intfs.add(portType); } else if (portTypes.size() > 1) { if (def.getAllBindings().size() > 0) { throwMultipleMultipleTypeException(CastUtils.cast(def.getAllBindings().keySet(), QName.class)); } for (PortType port : portTypes.values()) { interfaceNames.add(port.getQName().getLocalPart()); intfs.add(port); } } return intfs; }
public Object[] getHeaders(QName name, JAXBContext context, boolean allRoles) { SOAPMessage msg = getMessage(); SOAPHeader header; try { header = msg.getSOAPPart().getEnvelope().getHeader(); if (header == null || !header.hasChildNodes()) { return new Object[0]; } List<Object> ret = new ArrayList<>(); Iterator<SOAPHeaderElement> it = CastUtils.cast(header.examineAllHeaderElements()); while (it.hasNext()) { SOAPHeaderElement she = it.next(); if ((allRoles || roles.contains(she.getActor())) && name.equals(she.getElementQName())) { ret.add(JAXBUtils.unmarshall(context, she)); } } return ret.toArray(new Object[0]); } catch (SOAPException | JAXBException e) { throw new WebServiceException(e); } }
public Binding[] getCorbaBindings() { List<Binding> result = new ArrayList<>(); Map<QName, Binding> bindings = CastUtils.cast(definition.getBindings()); for (Binding binding : bindings.values()) { List<ExtensibilityElement> extElements = CastUtils.cast(binding.getExtensibilityElements()); for (int i = 0; i < extElements.size(); i++) { ExtensibilityElement el = extElements.get(i); if (el.getElementType().equals(CorbaConstants.NE_CORBA_BINDING)) { result.add(binding); break; } } } return result.toArray(new Binding[0]); }
public void handleMessage(Message message) throws Fault { Exchange ex = message.getExchange(); Set<Endpoint> endpoints = CastUtils.cast((Set<?>)ex.get(MultipleEndpointObserver.ENDPOINTS)); Endpoint ep = selectEndpoint(message, endpoints); if (ep == null) { return; } ex.put(Endpoint.class, ep); ex.put(Binding.class, ep.getBinding()); ex.put(Service.class, ep.getService()); InterceptorChain chain = message.getInterceptorChain(); chain.add(ep.getInInterceptors()); chain.add(ep.getBinding().getInInterceptors()); chain.add(ep.getService().getInInterceptors()); chain.setFaultObserver(ep.getOutFaultObserver()); }
/** * {@inheritDoc} */ public Object getInstance(Message m) { if (singletonInstance != null) { return singletonInstance; } ProviderInfo<?> application = m == null ? null : (ProviderInfo<?>)m.getExchange().getEndpoint().get(Application.class.getName()); Map<Class<?>, Object> mapValues = CastUtils.cast(application == null ? null : Collections.singletonMap(Application.class, application.getProvider())); Object[] values = ResourceUtils.createConstructorArguments(c, m, !isSingleton(), mapValues); Object instance = values.length > 0 ? ac.getBean(beanId, values) : ac.getBean(beanId); initInstance(m, instance); return instance; }
/** * While extracting the Message.PROTOCOL_HEADERS property from the Message, * this call ensures that the Message.PROTOCOL_HEADERS property is * set on the Message. If it is not set, an empty map is placed there, and * then returned. * * @param message The outbound message * @return The PROTOCOL_HEADERS map */ public static Map<String, List<String>> getSetProtocolHeaders(final Message message) { Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS)); if (null == headers) { headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); } else if (headers instanceof HashMap) { Map<String, List<String>> headers2 = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); headers2.putAll(headers); headers = headers2; } message.put(Message.PROTOCOL_HEADERS, headers); return headers; }
public void handleMessage(Message message) throws Fault { Fault f = (Fault)message.getContent(Exception.class); if (f == null) { return; SoapVersion soapVersion = (SoapVersion)message.get(SoapVersion.class.getName()); if (soapVersion != null && soapVersion.getVersion() != 1.1) { if (f instanceof SoapFault) { for (Iterator<QName> it = CastUtils.cast(sf.getFault().getFaultSubcodes()); it.hasNext();) { ((SoapFault) f).addSubCode(it.next()); message.setContent(Exception.class, f); throw new Fault(new org.apache.cxf.common.i18n.Message("INVOCATION_TARGET_EXC", BUNDLE), e); } catch (IllegalAccessException | IllegalArgumentException e) { throw new Fault(new org.apache.cxf.common.i18n.Message("COULD_NOT_INVOKE", BUNDLE), e); Service service = message.getExchange().getService(); message.getExchange().getBus()); writer.setSchema(schema); OperationInfo op = message.getExchange().getBindingOperationInfo().getOperationInfo(); QName faultName = getFaultName(fault, cause.getClass(), op); MessagePartInfo part = getFaultMessagePart(faultName, op);