Search in sources :

Example 6 with WSDLModel

use of com.sun.xml.ws.api.model.wsdl.WSDLModel in project metro-jax-ws by eclipse-ee4j.

the class FODTest method testFreezeFOD.

// OrderProcessorService service = null;
public void testFreezeFOD() throws Exception {
    /*
		 * Verify that we can get messages from a port type by walking the model.
		 * 
		 */
    // File f = new File("testcases/fromwsdl/freeze/concrete.wsdl");
    // System.out.println(f.getAbsolutePath());
    // URL wsdl = new URL("file:/scratch/bnaugle/bugs/fod/v2/concrete.wsdl");
    // URL wsdl = new URL("file:/scratch/bnaugle/bugs/fod/FusionOrderDemoShared/services/orderbooking/output/concrete.wsdl");
    String WSDL_NAME = "concrete.wsdl";
    Source wsdlSource = getSource(WSDL_NAME);
    WSDLModel model = RuntimeWSDLParser.parse(getURL(WSDL_NAME), wsdlSource, XmlUtil.createDefaultCatalogResolver(), true, Container.NONE, new WSDLParserExtension[] {});
    Map<QName, ? extends WSDLPortType> portTypes = model.getPortTypes();
    Set<QName> keySet = portTypes.keySet();
    for (QName name : keySet) {
        WSDLPortType pt = portTypes.get(name);
        System.out.println(name.toString() + portTypes.get(name));
        Iterable<? extends WSDLOperation> operations = pt.getOperations();
        for (WSDLOperation operation : operations) {
            assertNotNull(operation.getInput().getMessage());
        }
    }
}
Also used : WSDLPortType(com.sun.xml.ws.api.model.wsdl.WSDLPortType) QName(javax.xml.namespace.QName) WSDLModel(com.sun.xml.ws.api.model.wsdl.WSDLModel) WSDLOperation(com.sun.xml.ws.api.model.wsdl.WSDLOperation) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source)

Example 7 with WSDLModel

use of com.sun.xml.ws.api.model.wsdl.WSDLModel 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);
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) WSDLModel(com.sun.xml.ws.api.model.wsdl.WSDLModel) EntityResolver(org.xml.sax.EntityResolver) BoundEndpoint(com.sun.xml.ws.api.server.BoundEndpoint) URL(java.net.URL) WebServiceException(jakarta.xml.ws.WebServiceException) JAXBException(jakarta.xml.bind.JAXBException) WSDLPort(com.sun.xml.ws.api.model.wsdl.WSDLPort) Container(com.sun.xml.ws.api.server.Container) WSEndpoint(com.sun.xml.ws.api.server.WSEndpoint) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) WSDLService(com.sun.xml.ws.api.model.wsdl.WSDLService) Module(com.sun.xml.ws.api.server.Module)

Example 8 with WSDLModel

use of com.sun.xml.ws.api.model.wsdl.WSDLModel in project metro-jax-ws by eclipse-ee4j.

the class SDODatabindingTestBase method createProxy.

public static <T> T createProxy(Class<T> proxySEI, DatabindingConfig srvConfig, DatabindingConfig cliConfig, boolean debug) throws Exception {
    Class<?> endpointClass = srvConfig.getEndpointClass();
    // TODO default BindingID
    if (srvConfig.getMappingInfo().getBindingID() == null)
        srvConfig.getMappingInfo().setBindingID(BindingID.parse(endpointClass));
    Databinding srvDb = (Databinding) factory.createRuntime(srvConfig);
    InVmWSDLResolver result = new InVmWSDLResolver();
    WSDLGenInfo wsdlGenInfo = new WSDLGenInfo();
    wsdlGenInfo.setWsdlResolver(result);
    // wsdlGenInfo.setContainer(container);
    wsdlGenInfo.setExtensions(ServiceFinder.find(WSDLGeneratorExtension.class).toArray());
    wsdlGenInfo.setInlineSchemas(true);
    srvDb.generateWSDL(wsdlGenInfo);
    if (debug)
        result.print();
    WSDLModel wsdl = RuntimeWSDLParser.parse(result.getWsdlSource(), result.getEntityResolver(), false, null, new WSDLParserExtension[0]);
    QName serviceName = wsdl.getFirstServiceName();
    WSDLPort wsdlPort = wsdl.getService(serviceName).getFirstPort();
    // ((AbstractSEIModelImpl)((DatabindingImpl)srvDb).getModel()).freeze((WSDLPortImpl)wsdlPort);
    cliConfig.setWsdlPort(wsdlPort);
    cliConfig.getMappingInfo().setServiceName(serviceName);
    Databinding cliDb = (Databinding) factory.createRuntime(cliConfig);
    Class<?>[] intf = { proxySEI };
    WsDatabindingTestFacade h = new WsDatabindingTestFacade(cliDb, srvDb, endpointClass);
    h.wireLog = debug;
    Object proxy = Proxy.newProxyInstance(proxySEI.getClassLoader(), intf, h);
    return proxySEI.cast(proxy);
}
Also used : QName(javax.xml.namespace.QName) WSDLModel(com.sun.xml.ws.api.model.wsdl.WSDLModel) WSDLGenInfo(com.sun.xml.ws.api.databinding.WSDLGenInfo) Databinding(com.sun.xml.ws.api.databinding.Databinding) WSDLPort(com.sun.xml.ws.api.model.wsdl.WSDLPort)

Example 9 with WSDLModel

use of com.sun.xml.ws.api.model.wsdl.WSDLModel in project metro-jax-ws by eclipse-ee4j.

the class WSServiceDelegate method getPortNameFromEPR.

/**
 * @param wsepr EndpointReference from which portName will be extracted.
 *      If EndpointName ( port name) is null in EPR, then it will try to get if from WSDLModel using portType QName
 * @param portTypeName
 *          should be null in dispatch case
 *          should be non null in SEI case
 * @return
 *      port name from EPR after validating various metadat elements.
 *      Also if service instance does n't have wsdl,
 *      then it gets the WSDL metadata from EPR and builds wsdl model.
 */
private QName getPortNameFromEPR(@NotNull WSEndpointReference wsepr, @Nullable QName portTypeName) {
    QName portName;
    WSEndpointReference.Metadata metadata = wsepr.getMetaData();
    QName eprServiceName = metadata.getServiceName();
    QName eprPortName = metadata.getPortName();
    if ((eprServiceName != null) && !eprServiceName.equals(serviceName)) {
        throw new WebServiceException("EndpointReference WSDL ServiceName differs from Service Instance WSDL Service QName.\n" + " The two Service QNames must match");
    }
    if (wsdlService == null) {
        Source eprWsdlSource = metadata.getWsdlSource();
        if (eprWsdlSource == null) {
            throw new WebServiceException(ProviderApiMessages.NULL_WSDL());
        }
        try {
            WSDLModel eprWsdlMdl = parseWSDL(new URL(wsepr.getAddress()), eprWsdlSource, null);
            wsdlService = eprWsdlMdl.getService(serviceName);
            if (wsdlService == null)
                throw new WebServiceException(ClientMessages.INVALID_SERVICE_NAME(serviceName, buildNameList(eprWsdlMdl.getServices().keySet())));
        } catch (MalformedURLException e) {
            throw new WebServiceException(ClientMessages.INVALID_ADDRESS(wsepr.getAddress()));
        }
    }
    portName = eprPortName;
    if (portName == null && portTypeName != null) {
        // get the first port corresponding to the SEI
        WSDLPort port = wsdlService.getMatchingPort(portTypeName);
        if (port == null)
            throw new WebServiceException(ClientMessages.UNDEFINED_PORT_TYPE(portTypeName));
        portName = port.getName();
    }
    if (portName == null)
        throw new WebServiceException(ProviderApiMessages.NULL_PORTNAME());
    if (wsdlService.get(portName) == null)
        throw new WebServiceException(ClientMessages.INVALID_EPR_PORT_NAME(portName, buildWsdlPortNames()));
    return portName;
}
Also used : MalformedURLException(java.net.MalformedURLException) WebServiceException(jakarta.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) WSDLModel(com.sun.xml.ws.api.model.wsdl.WSDLModel) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) URL(java.net.URL) WSDLPort(com.sun.xml.ws.api.model.wsdl.WSDLPort)

Example 10 with WSDLModel

use of com.sun.xml.ws.api.model.wsdl.WSDLModel in project metro-jax-ws by eclipse-ee4j.

the class WSAM_EPRTester method runOptionalEPRTests.

private void runOptionalEPRTests() throws Exception {
    URL res = getClass().getClassLoader().getResource("epr/wsamTest.wsdl");
    // assuming that this is a file:// URL.
    File folder = new File(new File(res.getFile()).getParentFile(), "optional");
    System.out.println("\n\nOptional Tests:\n");
    for (File f : folder.listFiles()) {
        if (!f.getName().endsWith(".xml"))
            continue;
        System.out.println("***************************");
        System.out.println("TestFile: " + f.getParentFile().getName() + "/" + f.getName());
        try {
            InputStream is = new FileInputStream(f);
            StreamSource s = new StreamSource(is);
            EndpointReference epr = EndpointReference.readFrom(s);
            WSEndpointReference wsepr = new WSEndpointReference(epr);
            System.out.println("Address: " + wsepr.getAddress());
            WSEndpointReference.Metadata metadata = wsepr.getMetaData();
            System.out.println("Metadata Valid?: true");
            if (metadata.getPortTypeName() != null)
                System.out.println("InterfaceName: " + metadata.getPortTypeName());
            if (metadata.getServiceName() != null)
                System.out.println("ServiceName: " + metadata.getServiceName());
            if (metadata.getPortName() != null)
                System.out.println("Endpoint: " + metadata.getPortName().getLocalPart());
            String wsdliLocation = metadata.getWsdliLocation();
            if (metadata.getWsdliLocation() != null) {
                System.out.println("wsdli:wsdlLocation: " + wsdliLocation);
                String wsdlLocation = wsdliLocation.substring(wsdliLocation.lastIndexOf(" "));
                WSDLModel wsdlModel = RuntimeWSDLParser.parse(new URL(wsdlLocation), new StreamSource(wsdlLocation), XmlUtil.createDefaultCatalogResolver(), false, Container.NONE, ServiceFinder.find(WSDLParserExtension.class).toArray());
                QName binding = wsdlModel.getBinding(metadata.getServiceName(), metadata.getPortName()).getName();
                System.out.println("Binding from WSDL: " + binding);
            }
            System.out.println("");
        } catch (Exception e) {
            System.out.println("Metadata Valid?: false");
            System.out.println("Reason: " + e.getMessage());
            // e.printStackTrace();
            System.out.println("");
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) WSDLModel(com.sun.xml.ws.api.model.wsdl.WSDLModel) File(java.io.File) URL(java.net.URL) FileInputStream(java.io.FileInputStream) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) EndpointReference(jakarta.xml.ws.EndpointReference)

Aggregations

WSDLModel (com.sun.xml.ws.api.model.wsdl.WSDLModel)10 QName (javax.xml.namespace.QName)8 StreamSource (javax.xml.transform.stream.StreamSource)7 URL (java.net.URL)6 WSDLPort (com.sun.xml.ws.api.model.wsdl.WSDLPort)5 WSEndpointReference (com.sun.xml.ws.api.addressing.WSEndpointReference)4 WSDLService (com.sun.xml.ws.api.model.wsdl.WSDLService)3 WebServiceException (jakarta.xml.ws.WebServiceException)3 Source (javax.xml.transform.Source)3 Databinding (com.sun.xml.ws.api.databinding.Databinding)2 WSDLGenInfo (com.sun.xml.ws.api.databinding.WSDLGenInfo)2 EndpointReference (jakarta.xml.ws.EndpointReference)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 MalformedURLException (java.net.MalformedURLException)2 EntityResolver (org.xml.sax.EntityResolver)2 NotNull (com.sun.istack.NotNull)1 WSDLOperation (com.sun.xml.ws.api.model.wsdl.WSDLOperation)1 WSDLPortType (com.sun.xml.ws.api.model.wsdl.WSDLPortType)1