Search in sources :

Example 1 with WebService

use of jakarta.jws.WebService 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;
}
Also used : MalformedURLException(java.net.MalformedURLException) WebServiceException(jakarta.xml.ws.WebServiceException) WebService(jakarta.jws.WebService) StreamSource(javax.xml.transform.stream.StreamSource) WSDLModel(com.sun.xml.ws.api.model.wsdl.WSDLModel) WSDLService(com.sun.xml.ws.api.model.wsdl.WSDLService) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) URL(java.net.URL)

Example 2 with WebService

use of jakarta.jws.WebService in project metro-jax-ws by eclipse-ee4j.

the class SDODatabindingTestBase method invmSetup.

protected WebServiceFeature[] invmSetup(final URL wsdlURL, final Class sei, final Class seb, final QName serviceName, final QName portName) {
    DatabindingModeFeature dbmf = new DatabindingModeFeature("eclipselink.sdo");
    Class implementorClass = seb;
    boolean handlersSetInDD = false;
    Container container = Container.NONE;
    Map<String, SDDocumentSource> docs = new HashMap<String, SDDocumentSource>();
    SDDocumentSource primaryWSDL = SDDocumentSource.create(wsdlURL);
    docs.put(wsdlURL.toString(), primaryWSDL);
    ExternalMetadataFeature exm = ExternalMetadataFeature.builder().setReader(new com.sun.xml.ws.model.ReflectAnnotationReader() {

        public <A extends Annotation> A getAnnotation(final Class<A> annType, final Class<?> cls) {
            if (WebService.class.equals(annType)) {
                final WebService ws = cls.getAnnotation(WebService.class);
                return (A) new jakarta.jws.WebService() {

                    public Class<? extends Annotation> annotationType() {
                        return WebService.class;
                    }

                    @Override
                    public String endpointInterface() {
                        return sei.getName();
                    }

                    @Override
                    public String name() {
                        return (ws != null) ? ws.name() : null;
                    }

                    @Override
                    public String portName() {
                        return (ws != null) ? ws.portName() : null;
                    }

                    @Override
                    public String serviceName() {
                        return (ws != null) ? ws.serviceName() : null;
                    }

                    @Override
                    public String targetNamespace() {
                        return (ws != null) ? ws.targetNamespace() : null;
                    }

                    @Override
                    public String wsdlLocation() {
                        return (ws != null) ? ws.wsdlLocation() : null;
                    }
                };
            }
            return cls.getAnnotation(annType);
        }
    }).build();
    BindingID bindingID = BindingID.parse(implementorClass);
    WSBinding binding = bindingID.createBinding(dbmf, exm);
    final WSEndpoint<?> endpoint = WSEndpoint.create(implementorClass, !handlersSetInDD, null, serviceName, portName, container, binding, primaryWSDL, docs.values(), XmlUtil.createEntityResolver(null), false);
    ComponentFeature cf = new ComponentFeature(new com.sun.xml.ws.api.Component() {

        public <S> S getSPI(Class<S> spiType) {
            if (TransportTubeFactory.class.equals(spiType))
                return (S) new TransportTubeFactory() {

                    public Tube doCreate(ClientTubeAssemblerContext context) {
                        return new InVmTransportTube(context.getCodec(), context.getBinding(), wsdlURL, endpoint);
                    }
                };
            return null;
        }
    });
    WebServiceFeature[] f = { dbmf, cf };
    return f;
}
Also used : WSBinding(com.sun.xml.ws.api.WSBinding) Tube(com.sun.xml.ws.api.pipe.Tube) HashMap(java.util.HashMap) WebService(jakarta.jws.WebService) DatabindingModeFeature(com.oracle.webservices.api.databinding.DatabindingModeFeature) BindingID(com.sun.xml.ws.api.BindingID) TransportTubeFactory(com.sun.xml.ws.api.pipe.TransportTubeFactory) Container(com.sun.xml.ws.api.server.Container) SDDocumentSource(com.sun.xml.ws.api.server.SDDocumentSource) Annotation(java.lang.annotation.Annotation) ExternalMetadataFeature(com.oracle.webservices.api.databinding.ExternalMetadataFeature) WebService(jakarta.jws.WebService) WebServiceFeature(jakarta.xml.ws.WebServiceFeature) ComponentFeature(com.sun.xml.ws.api.ComponentFeature) ClientTubeAssemblerContext(com.sun.xml.ws.api.pipe.ClientTubeAssemblerContext)

Example 3 with WebService

use of jakarta.jws.WebService in project metro-jax-ws by eclipse-ee4j.

the class EndpointFactory method verifyImplementorClass.

/**
 * Verifies if the endpoint implementor class has @WebService or @WebServiceProvider
 * annotation; passing MetadataReader instance allows to read annotations from
 * xml descriptor instead of class's annotations
 *
 * @return
 *       true if it is a Provider or AsyncProvider endpoint
 *       false otherwise
 * @throws java.lang.IllegalArgumentException
 *      If it doesn't have any one of @WebService or @WebServiceProvider
 *      If it has both @WebService and @WebServiceProvider annotations
 */
public static boolean verifyImplementorClass(Class<?> clz, MetadataReader metadataReader) {
    if (metadataReader == null) {
        metadataReader = new ReflectAnnotationReader();
    }
    WebServiceProvider wsProvider = metadataReader.getAnnotation(WebServiceProvider.class, clz);
    WebService ws = metadataReader.getAnnotation(WebService.class, clz);
    if (wsProvider == null && ws == null) {
        throw new IllegalArgumentException(clz + " has neither @WebService nor @WebServiceProvider annotation");
    }
    if (wsProvider != null && ws != null) {
        throw new IllegalArgumentException(clz + " has both @WebService and @WebServiceProvider annotations");
    }
    if (wsProvider != null) {
        if (Provider.class.isAssignableFrom(clz) || AsyncProvider.class.isAssignableFrom(clz)) {
            return true;
        }
        throw new IllegalArgumentException(clz + " doesn't implement Provider or AsyncProvider interface");
    }
    return false;
}
Also used : WebServiceProvider(jakarta.xml.ws.WebServiceProvider) AsyncProvider(com.sun.xml.ws.api.server.AsyncProvider) WebService(jakarta.jws.WebService) ReflectAnnotationReader(com.sun.xml.ws.model.ReflectAnnotationReader) AsyncProvider(com.sun.xml.ws.api.server.AsyncProvider) Provider(jakarta.xml.ws.Provider) WebServiceProvider(jakarta.xml.ws.WebServiceProvider)

Example 4 with WebService

use of jakarta.jws.WebService in project metro-jax-ws by eclipse-ee4j.

the class HandlerAnnotationProcessor method getSEI.

static Class getSEI(Class<?> clazz, MetadataReader metadataReader) {
    if (metadataReader == null) {
        metadataReader = new ReflectAnnotationReader();
    }
    if (Provider.class.isAssignableFrom(clazz) || AsyncProvider.class.isAssignableFrom(clazz)) {
        // No SEI for Provider Implementation
        return null;
    }
    if (Service.class.isAssignableFrom(clazz)) {
        // No SEI for Service class
        return null;
    }
    WebService webService = metadataReader.getAnnotation(WebService.class, clazz);
    if (webService == null) {
        throw new UtilException("util.handler.no.webservice.annotation", clazz.getCanonicalName());
    }
    String ei = webService.endpointInterface();
    if (ei.length() > 0) {
        clazz = getClass(webService.endpointInterface());
        WebService ws = metadataReader.getAnnotation(WebService.class, clazz);
        if (ws == null) {
            throw new UtilException("util.handler.endpoint.interface.no.webservice", webService.endpointInterface());
        }
        return clazz;
    }
    return null;
}
Also used : AsyncProvider(com.sun.xml.ws.api.server.AsyncProvider) WebService(jakarta.jws.WebService) ReflectAnnotationReader(com.sun.xml.ws.model.ReflectAnnotationReader) AsyncProvider(com.sun.xml.ws.api.server.AsyncProvider) Provider(jakarta.xml.ws.Provider)

Example 5 with WebService

use of jakarta.jws.WebService in project metro-jax-ws by eclipse-ee4j.

the class SeiGenerator method write.

private void write(Port port) {
    JavaInterface intf = port.getJavaInterface();
    String className = Names.customJavaTypeClassName(intf);
    if (donotOverride && GeneratorUtil.classExists(options, className)) {
        log("Class " + className + " exists. Not overriding.");
        return;
    }
    JDefinedClass cls;
    try {
        cls = getClass(className, ClassType.INTERFACE);
    } catch (JClassAlreadyExistsException e) {
        QName portTypeName = (QName) port.getProperty(ModelProperties.PROPERTY_WSDL_PORT_TYPE_NAME);
        Locator loc = null;
        if (portTypeName != null) {
            PortType pt = port.portTypes.get(portTypeName);
            if (pt != null) {
                loc = pt.getLocator();
            }
        }
        receiver.error(loc, GeneratorMessages.GENERATOR_SEI_CLASS_ALREADY_EXIST(intf.getName(), portTypeName));
        return;
    }
    // so skip it.
    if (!cls.methods().isEmpty()) {
        return;
    }
    // write class comment - JAXWS warning
    JDocComment comment = cls.javadoc();
    String ptDoc = intf.getJavaDoc();
    if (ptDoc != null) {
        comment.add(ptDoc);
        comment.add("\n\n");
    }
    comment.addAll(getJAXWSClassComment());
    // @WebService
    JAnnotationUse webServiceAnn = cls.annotate(cm.ref(WebService.class));
    writeWebServiceAnnotation(port, webServiceAnn);
    // @HandlerChain
    writeHandlerConfig(Names.customJavaTypeClassName(port.getJavaInterface()), cls, options);
    // @SOAPBinding
    writeSOAPBinding(port, cls);
    // @XmlSeeAlso
    if (options.target.isLaterThan(Options.Target.V2_1)) {
        writeXmlSeeAlso(cls);
    }
    for (Operation operation : port.getOperations()) {
        JavaMethod method = operation.getJavaMethod();
        // @WebMethod
        JMethod m;
        JDocComment methodDoc;
        String methodJavaDoc = operation.getJavaDoc();
        if (method.getReturnType().getName().equals("void")) {
            m = cls.method(JMod.PUBLIC, void.class, method.getName());
            methodDoc = m.javadoc();
        } else {
            JAXBTypeAndAnnotation retType = method.getReturnType().getType();
            m = cls.method(JMod.PUBLIC, retType.getType(), method.getName());
            retType.annotate(m);
            methodDoc = m.javadoc();
            JCommentPart ret = methodDoc.addReturn();
            ret.add("returns " + retType.getName());
        }
        if (methodJavaDoc != null) {
            methodDoc.add(methodJavaDoc);
        }
        writeWebMethod(operation, m);
        JClass holder = cm.ref(Holder.class);
        for (JavaParameter parameter : method.getParametersList()) {
            JVar var;
            JAXBTypeAndAnnotation paramType = parameter.getType().getType();
            if (parameter.isHolder()) {
                var = m.param(holder.narrow(paramType.getType().boxify()), parameter.getName());
            } else {
                var = m.param(paramType.getType(), parameter.getName());
            }
            // annotate parameter with JAXB annotations
            paramType.annotate(var);
            methodDoc.addParam(var);
            JAnnotationUse paramAnn = var.annotate(cm.ref(WebParam.class));
            writeWebParam(operation, parameter, paramAnn);
        }
        com.sun.tools.ws.wsdl.document.Operation wsdlOp = operation.getWSDLPortTypeOperation();
        for (Fault fault : operation.getFaultsSet()) {
            m._throws(fault.getExceptionClass());
            methodDoc.addThrows(fault.getExceptionClass());
            wsdlOp.putFault(fault.getWsdlFaultName(), fault.getExceptionClass());
        }
        // It should be the last thing to invoke after JMethod is built completely
        extension.writeMethodAnnotations(wsdlOp, m);
    }
}
Also used : JavaInterface(com.sun.tools.ws.processor.model.java.JavaInterface) WebService(jakarta.jws.WebService) QName(javax.xml.namespace.QName) JAXBTypeAndAnnotation(com.sun.tools.ws.processor.model.jaxb.JAXBTypeAndAnnotation) Locator(org.xml.sax.Locator) WebParam(jakarta.jws.WebParam) JavaMethod(com.sun.tools.ws.processor.model.java.JavaMethod) JavaParameter(com.sun.tools.ws.processor.model.java.JavaParameter) PortType(com.sun.tools.ws.wsdl.document.PortType)

Aggregations

WebService (jakarta.jws.WebService)9 JavaInterface (com.sun.tools.ws.processor.model.java.JavaInterface)2 JavaMethod (com.sun.tools.ws.processor.model.java.JavaMethod)2 JavaParameter (com.sun.tools.ws.processor.model.java.JavaParameter)2 JAXBTypeAndAnnotation (com.sun.tools.ws.processor.model.jaxb.JAXBTypeAndAnnotation)2 AsyncProvider (com.sun.xml.ws.api.server.AsyncProvider)2 ReflectAnnotationReader (com.sun.xml.ws.model.ReflectAnnotationReader)2 Provider (jakarta.xml.ws.Provider)2 WebServiceProvider (jakarta.xml.ws.WebServiceProvider)2 QName (javax.xml.namespace.QName)2 DatabindingModeFeature (com.oracle.webservices.api.databinding.DatabindingModeFeature)1 ExternalMetadataFeature (com.oracle.webservices.api.databinding.ExternalMetadataFeature)1 JAnnotationUse (com.sun.codemodel.JAnnotationUse)1 JClass (com.sun.codemodel.JClass)1 JClassAlreadyExistsException (com.sun.codemodel.JClassAlreadyExistsException)1 JCommentPart (com.sun.codemodel.JCommentPart)1 JDefinedClass (com.sun.codemodel.JDefinedClass)1 JDocComment (com.sun.codemodel.JDocComment)1 JMethod (com.sun.codemodel.JMethod)1 JVar (com.sun.codemodel.JVar)1