/** * Clear the actual service Endpoint and use Gateway Endpoint instead of the actual Endpoint. * * @param definition - {@link Definition} - WSDL4j wsdl definition * @throws APIManagementException */ private void setServiceDefinition(Definition definition) throws APIManagementException { Map serviceMap = definition.getAllServices(); Iterator serviceItr = serviceMap.entrySet().iterator(); URL addressURI = null; try { while (serviceItr.hasNext()) { Map.Entry svcEntry = (Map.Entry) serviceItr.next(); Service svc = (Service) svcEntry.getValue(); Map portMap = svc.getPorts(); Iterator portItr = portMap.entrySet().iterator(); while (portItr.hasNext()) { Map.Entry portEntry = (Map.Entry) portItr.next(); Port port = (Port) portEntry.getValue(); List<ExtensibilityElement> extensibilityElementList = port.getExtensibilityElements(); for (int i = 0; i < extensibilityElementList.size(); i++) { ExtensibilityElement extensibilityElement = (ExtensibilityElement) port.getExtensibilityElements().get(i); addressURI = new URL(getAddressUrl(extensibilityElement)); if (addressURI == null) { break; } else { setAddressUrl(extensibilityElement); } } } } } catch (Exception e) { log.error("Error occured while getting the wsdl address location", e); throw new APIManagementException(e); } }
public static String getEndpointURL( Definition wsdlDefinition, String serviceName, String portName, String bindingName, String opName) { Map<?, ?> services = wsdlDefinition.getServices(); Set<?> serviceKeys = services.keySet(); for (Iterator<?> it = serviceKeys.iterator(); it.hasNext(); ) { QName serviceKey = (QName) it.next(); if (serviceName != null && serviceKey.getLocalPart().contentEquals(serviceName)) { Service service = (Service) services.get(serviceKey); Map<?, ?> ports = service.getPorts(); Set<?> portKeys = ports.keySet(); for (Iterator<?> it2 = portKeys.iterator(); it2.hasNext(); ) { String portKey = (String) it2.next(); if (portName != null && portKey.contentEquals(portName)) { Port port = (Port) ports.get(portKey); List<?> elements = port.getExtensibilityElements(); for (Iterator<?> it3 = elements.iterator(); it3.hasNext(); ) { Object element = it3.next(); if (element instanceof SOAPAddress) { SOAPAddress address = (SOAPAddress) element; return address.getLocationURI(); } else if (element instanceof SOAP12Address) { SOAP12Address address = (SOAP12Address) element; return address.getLocationURI(); } } } } } } return null; }
public static boolean isSOAP12(Definition wsdlDefinition, String serviceName, String portName) { Map<?, ?> services = wsdlDefinition.getServices(); Set<?> serviceKeys = services.keySet(); for (Iterator<?> it = serviceKeys.iterator(); it.hasNext(); ) { QName serviceKey = (QName) it.next(); if (serviceName != null && serviceKey.getLocalPart().contentEquals(serviceName)) { Service service = (Service) services.get(serviceKey); Map<?, ?> ports = service.getPorts(); Set<?> portKeys = ports.keySet(); for (Iterator<?> it2 = portKeys.iterator(); it2.hasNext(); ) { String portKey = (String) it2.next(); if (portName != null && portKey.contentEquals(portName)) { Port port = (Port) ports.get(portKey); List<?> extElements = port.getExtensibilityElements(); for (Iterator<?> it3 = extElements.iterator(); it3.hasNext(); ) { ExtensibilityElement element = (ExtensibilityElement) it3.next(); String nsURI = element.getElementType().getNamespaceURI(); if (nsURI.contentEquals(SOAP12_NS_URI)) { return true; } return false; } } } } } return false; }
private void setSoapAddressLocationOn(Port port, String url) { List<?> extensions = port.getExtensibilityElements(); for (Object extension : extensions) { if (extension instanceof SOAP12Address) { ((SOAP12Address) extension).setLocationURI(url); } else if (extension instanceof SOAPAddress) { ((SOAPAddress) extension).setLocationURI(url); } } }
private void convertPort(Port port) throws IOException { String comment = ""; String name = port.getName(); String protocol = "soap"; String location = "socket://localhost:80/"; if (port.getDocumentationElement() != null) { comment = port.getDocumentationElement().getNodeValue(); } List<ExtensibilityElement> extElements = port.getExtensibilityElements(); for (ExtensibilityElement element : extElements) { if (element instanceof SOAPAddress) { location = ((SOAPAddress) element).getLocationURI().toString(); StringBuilder builder = new StringBuilder(); builder .append("soap {\n") .append("\t.wsdl = \"") .append(definition.getDocumentBaseURI()) .append("\";\n") .append("\t.wsdl.port = \"") .append(port.getName()) .append("\"\n}"); protocol = builder.toString(); } else if (element instanceof HTTPAddress) { location = ((HTTPAddress) element).getLocationURI().toString(); protocol = "http"; } } try { URI uri = new URI(location); uri = new URI( "socket", uri.getUserInfo(), uri.getHost(), (uri.getPort() < 1) ? 80 : uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); location = uri.toString(); } catch (URISyntaxException e) { e.printStackTrace(); } Binding binding = port.getBinding(); PortType portType = binding.getPortType(); convertPortType(portType, binding); outputPorts.put( name, new OutputPort(name, location, protocol, portType.getQName().getLocalPart(), comment)); }