use of com.sun.xml.ws.api.model.wsdl.WSDLService in project metro-jax-ws by eclipse-ee4j.
the class WSServiceDelegate method getPort.
@Override
public <T> T getPort(Class<T> portInterface, WebServiceFeature... features) {
// get the portType from SEI
QName portTypeName = RuntimeModeler.getPortTypeName(portInterface, getMetadadaReader(new WebServiceFeatureList(features), portInterface.getClassLoader()));
WSDLService tmpWsdlService = this.wsdlService;
if (tmpWsdlService == null) {
// assigning it to local variable and not setting it back to this.wsdlService intentionally
// as we don't want to include the service instance with information gathered from sei
tmpWsdlService = getWSDLModelfromSEI(portInterface);
// still null? throw error need wsdl metadata to create a proxy
if (tmpWsdlService == null) {
throw new WebServiceException(ProviderApiMessages.NO_WSDL_NO_PORT(portInterface.getName()));
}
}
// get the first port corresponding to the SEI
WSDLPort port = tmpWsdlService.getMatchingPort(portTypeName);
if (port == null) {
throw new WebServiceException(ClientMessages.UNDEFINED_PORT_TYPE(portTypeName));
}
QName portName = port.getName();
return getPort(portName, portInterface, features);
}
use of com.sun.xml.ws.api.model.wsdl.WSDLService in project metro-jax-ws by eclipse-ee4j.
the class WSServiceDelegate method getWSDLModelfromSEI.
private WSDLService getWSDLModelfromSEI(final Class sei) {
WebService ws = AccessController.doPrivileged(new PrivilegedAction<>() {
public WebService run() {
return (WebService) sei.getAnnotation(WebService.class);
}
});
if (ws == null || ws.wsdlLocation().equals(""))
return null;
String wsdlLocation = ws.wsdlLocation();
wsdlLocation = JAXWSUtils.absolutize(JAXWSUtils.getFileOrURLName(wsdlLocation));
Source wsdl = new StreamSource(wsdlLocation);
WSDLService service = null;
try {
URL url = wsdl.getSystemId() == null ? null : new URL(wsdl.getSystemId());
WSDLModel model = parseWSDL(url, wsdl, sei);
service = model.getService(this.serviceName);
if (service == null)
throw new WebServiceException(ClientMessages.INVALID_SERVICE_NAME(this.serviceName, buildNameList(model.getServices().keySet())));
} catch (MalformedURLException e) {
throw new WebServiceException(ClientMessages.INVALID_WSDL_URL(wsdl.getSystemId()));
}
return service;
}
use of com.sun.xml.ws.api.model.wsdl.WSDLService in project metro-jax-ws by eclipse-ee4j.
the class EndpointFactory method getWSDLPort.
/**
* Parses the primary WSDL and returns the {@link WSDLPort} for the given service and port names
*
* @param primaryWsdl Primary WSDL
* @param metadata it may contain imported WSDL and schema documents
* @param serviceName service name in wsdl
* @param portName port name in WSDL
* @param container container in which this service is running
* @return non-null wsdl port object
*/
@NotNull
private static WSDLPort getWSDLPort(SDDocumentSource primaryWsdl, Collection<? extends SDDocumentSource> metadata, @NotNull QName serviceName, @NotNull QName portName, Container container, EntityResolver resolver) {
URL wsdlUrl = primaryWsdl.getSystemId();
try {
// TODO: delegate to another entity resolver
WSDLModel wsdlDoc = RuntimeWSDLParser.parse(new Parser(primaryWsdl), new EntityResolverImpl(metadata, resolver), false, container, ServiceFinder.find(WSDLParserExtension.class).toArray());
if (wsdlDoc.getServices().size() == 0) {
throw new ServerRtException(ServerMessages.localizableRUNTIME_PARSER_WSDL_NOSERVICE_IN_WSDLMODEL(wsdlUrl));
}
WSDLService wsdlService = wsdlDoc.getService(serviceName);
if (wsdlService == null) {
throw new ServerRtException(ServerMessages.localizableRUNTIME_PARSER_WSDL_INCORRECTSERVICE(serviceName, wsdlUrl));
}
WSDLPort wsdlPort = wsdlService.get(portName);
if (wsdlPort == null) {
throw new ServerRtException(ServerMessages.localizableRUNTIME_PARSER_WSDL_INCORRECTSERVICEPORT(serviceName, portName, wsdlUrl));
}
return wsdlPort;
} catch (IOException | ServiceConfigurationError | SAXException e) {
throw new ServerRtException("runtime.parser.wsdl", wsdlUrl, e);
} catch (XMLStreamException e) {
throw new ServerRtException("runtime.saxparser.exception", e.getMessage(), e.getLocation(), e);
}
}
use of com.sun.xml.ws.api.model.wsdl.WSDLService in project metro-jax-ws by eclipse-ee4j.
the class MetadataTester method testMultiplePort.
public void testMultiplePort() throws IOException, SAXException, XMLStreamException {
URL url = JAXWSUtils.getFileOrURL(msURL);
com.sun.xml.ws.api.model.wsdl.WSDLModel doc = RuntimeWSDLParser.parse(url, new StreamSource(url.toExternalForm()), getResolver(), true, Container.NONE);
WSDLService service = doc.getService(new QName("http://InteropBaseAddress/interop", "PingService10"));
WSDLPort port1 = service.get(new QName("http://InteropBaseAddress/interop", "X10_IPingService"));
assertTrue(port1 != null);
WSDLPort port2 = service.get(new QName("http://InteropBaseAddress/interop", "X10-NoTimestamp_IPingService"));
assertTrue(port2 != null);
WSDLPort port3 = service.get(new QName("http://InteropBaseAddress/interop", "K10_IPingService"));
assertTrue(port3 != null);
WSDLPort port4 = service.get(new QName("http://InteropBaseAddress/interop", "KD10_IPingService"));
assertTrue(port4 != null);
}
use of com.sun.xml.ws.api.model.wsdl.WSDLService in project metro-jax-ws by eclipse-ee4j.
the class ProviderImpl method createW3CEndpointReference.
public W3CEndpointReference createW3CEndpointReference(String address, QName interfaceName, QName serviceName, QName portName, List<Element> metadata, String wsdlDocumentLocation, List<Element> referenceParameters, List<Element> elements, Map<QName, String> attributes) {
Container container = ContainerResolver.getInstance().getContainer();
if (address == null) {
if (serviceName == null || portName == null) {
throw new IllegalStateException(ProviderApiMessages.NULL_ADDRESS_SERVICE_ENDPOINT());
} else {
// check if it is run in a Java EE Container and if so, get address using serviceName and portName
Module module = container.getSPI(Module.class);
if (module != null) {
List<BoundEndpoint> beList = module.getBoundEndpoints();
for (BoundEndpoint be : beList) {
WSEndpoint wse = be.getEndpoint();
if (wse.getServiceName().equals(serviceName) && wse.getPortName().equals(portName)) {
try {
address = be.getAddress().toString();
} catch (WebServiceException e) {
// May be the container does n't support this
// just ignore the exception
}
break;
}
}
}
// address is still null? may be its not run in a JavaEE Container
if (address == null)
throw new IllegalStateException(ProviderApiMessages.NULL_ADDRESS());
}
}
if ((serviceName == null) && (portName != null)) {
throw new IllegalStateException(ProviderApiMessages.NULL_SERVICE());
}
// Validate Service and Port in WSDL
String wsdlTargetNamespace = null;
if (wsdlDocumentLocation != null) {
try {
EntityResolver er = XmlUtil.createDefaultCatalogResolver();
URL wsdlLoc = new URL(wsdlDocumentLocation);
WSDLModel wsdlDoc = RuntimeWSDLParser.parse(wsdlLoc, new StreamSource(wsdlLoc.toExternalForm()), er, true, container, ServiceFinder.find(WSDLParserExtension.class).toArray());
if (serviceName != null) {
WSDLService wsdlService = wsdlDoc.getService(serviceName);
if (wsdlService == null)
throw new IllegalStateException(ProviderApiMessages.NOTFOUND_SERVICE_IN_WSDL(serviceName, wsdlDocumentLocation));
if (portName != null) {
WSDLPort wsdlPort = wsdlService.get(portName);
if (wsdlPort == null)
throw new IllegalStateException(ProviderApiMessages.NOTFOUND_PORT_IN_WSDL(portName, serviceName, wsdlDocumentLocation));
}
wsdlTargetNamespace = serviceName.getNamespaceURI();
} else {
QName firstService = wsdlDoc.getFirstServiceName();
wsdlTargetNamespace = firstService.getNamespaceURI();
}
} catch (Exception e) {
throw new IllegalStateException(ProviderApiMessages.ERROR_WSDL(wsdlDocumentLocation), e);
}
}
// wcf3.0/3.5 rejected empty metadata element.
if (metadata != null && metadata.size() == 0) {
metadata = null;
}
return new WSEndpointReference(AddressingVersion.fromSpecClass(W3CEndpointReference.class), address, serviceName, portName, interfaceName, metadata, wsdlDocumentLocation, wsdlTargetNamespace, referenceParameters, elements, attributes).toSpec(W3CEndpointReference.class);
}
Aggregations