public <T> T getPort( EndpointReference endpointReference, Class<T> clazz, WebServiceFeature... webServiceFeatures) { /* final @NotNull MemberSubmissionEndpointReference msepr = EndpointReferenceUtil.transform(MemberSubmissionEndpointReference.class, endpointReference); WSService service = new WSServiceDelegate(msepr.toWSDLSource(), msepr.serviceName.name, Service.class); */ if (endpointReference == null) throw new WebServiceException(ProviderApiMessages.NULL_EPR()); WSEndpointReference wsepr = new WSEndpointReference(endpointReference); WSEndpointReference.Metadata metadata = wsepr.getMetaData(); WSService service; if (metadata.getWsdlSource() != null) service = new WSServiceDelegate(metadata.getWsdlSource(), metadata.getServiceName(), Service.class); else throw new WebServiceException("WSDL metadata is missing in EPR"); return service.getPort(wsepr, clazz, webServiceFeatures); }
public W3CEndpointReference createW3CEndpointReference( String address, QName serviceName, QName portName, List<Element> metadata, String wsdlDocumentLocation, List<Element> referenceParameters) { 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 if (wsdlDocumentLocation != null) { try { EntityResolver er = XmlUtil.createDefaultCatalogResolver(); URL wsdlLoc = new URL(wsdlDocumentLocation); WSDLModelImpl wsdlDoc = RuntimeWSDLParser.parse( wsdlLoc, new StreamSource(wsdlLoc.toExternalForm()), er, false, 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)); } } } catch (Exception e) { throw new IllegalStateException(ProviderApiMessages.ERROR_WSDL(wsdlDocumentLocation), e); } } // Supress writing ServiceName and EndpointName in W3C EPR, // Until the ns for those metadata elements is resolved. return new WSEndpointReference( AddressingVersion.fromSpecClass(W3CEndpointReference.class), address, null /*serviceName*/, null /*portName*/, null, metadata, null /*wsdlDocumentLocation*/, referenceParameters) .toSpec(W3CEndpointReference.class); }