Search in sources :

Example 1 with Addressing

use of javax.xml.ws.soap.Addressing in project cxf by apache.

the class JaxWsServiceFactoryBean method loadWSFeatureAnnotation.

private void loadWSFeatureAnnotation(Class<?> serviceClass, Class<?> implementorClass) {
    List<WebServiceFeature> features = new ArrayList<>();
    MTOM mtom = implInfo.getImplementorClass().getAnnotation(MTOM.class);
    if (mtom == null && serviceClass != null) {
        mtom = serviceClass.getAnnotation(MTOM.class);
    }
    if (mtom != null) {
        features.add(new MTOMFeature(mtom.enabled(), mtom.threshold()));
    } else {
        // deprecated way to set mtom
        BindingType bt = implInfo.getImplementorClass().getAnnotation(BindingType.class);
        if (bt != null && (SOAPBinding.SOAP11HTTP_MTOM_BINDING.equals(bt.value()) || SOAPBinding.SOAP12HTTP_MTOM_BINDING.equals(bt.value()))) {
            features.add(new MTOMFeature(true));
        }
    }
    Addressing addressing = null;
    if (implementorClass != null) {
        addressing = implementorClass.getAnnotation(Addressing.class);
    }
    if (addressing == null && serviceClass != null) {
        addressing = serviceClass.getAnnotation(Addressing.class);
    }
    if (addressing != null) {
        features.add(new AddressingFeature(addressing.enabled(), addressing.required(), addressing.responses()));
    }
    RespectBinding respectBinding = implInfo.getImplementorClass().getAnnotation(RespectBinding.class);
    if (respectBinding == null && serviceClass != null) {
        respectBinding = serviceClass.getAnnotation(RespectBinding.class);
    }
    if (respectBinding != null) {
        features.add(new RespectBindingFeature(respectBinding.enabled()));
    }
    if (!features.isEmpty()) {
        wsFeatures = features;
        if (setWsFeatures != null) {
            wsFeatures.addAll(setWsFeatures);
        }
    } else {
        wsFeatures = setWsFeatures;
    }
}
Also used : MTOM(javax.xml.ws.soap.MTOM) AddressingFeature(javax.xml.ws.soap.AddressingFeature) BindingType(javax.xml.ws.BindingType) MTOMFeature(javax.xml.ws.soap.MTOMFeature) RespectBindingFeature(javax.xml.ws.RespectBindingFeature) WebServiceFeature(javax.xml.ws.WebServiceFeature) ArrayList(java.util.ArrayList) RespectBinding(javax.xml.ws.RespectBinding) Addressing(javax.xml.ws.soap.Addressing)

Example 2 with Addressing

use of javax.xml.ws.soap.Addressing in project cxf by apache.

the class JaxWsEndpointImpl method buildWsdlExtensibilities.

private void buildWsdlExtensibilities(BindingInfo bindingInfo) {
    Addressing addressing = getAddressing();
    if (addressing != null) {
        ExtensionRegistry extensionRegistry = getBus().getExtension(WSDLManager.class).getExtensionRegistry();
        try {
            ExtensibilityElement el = extensionRegistry.createExtension(javax.wsdl.Binding.class, JAXWSAConstants.WSAW_USINGADDRESSING_QNAME);
            el.setRequired(addressing.required());
            bindingInfo.addExtensor(el);
            StringBuilder polRefId = new StringBuilder(bindingInfo.getName().getLocalPart());
            polRefId.append("_WSAM_Addressing_Policy");
            UnknownExtensibilityElement uel = new UnknownExtensibilityElement();
            W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
            writer.writeStartElement("wsp", "PolicyReference", URI_POLICY_NS);
            writer.writeAttribute("URI", "#" + polRefId.toString());
            writer.writeEndElement();
            Element pr = writer.getDocument().getDocumentElement();
            uel.setElement(pr);
            uel.setElementType(DOMUtils.getElementQName(pr));
            bindingInfo.addExtensor(uel);
            writer = new W3CDOMStreamWriter();
            writer.writeStartElement("wsp", "Policy", URI_POLICY_NS);
            writer.writeAttribute("wsu", URI_WSU_NS, "Id", polRefId.toString());
            writer.writeStartElement("wsam", "Addressing", JAXWSAConstants.NS_WSAM);
            if (!addressing.required()) {
                writer.writeAttribute("wsp", URI_POLICY_NS, "Optional", "true");
            }
            writer.writeStartElement("wsp", "Policy", URI_POLICY_NS);
            String s = getAddressingRequirement(addressing);
            if (s != null) {
                writer.writeEmptyElement("wsam", s, JAXWSAConstants.NS_WSAM);
            }
            writer.writeEndElement();
            writer.writeEndElement();
            writer.writeEndElement();
            pr = writer.getDocument().getDocumentElement();
            uel = new UnknownExtensibilityElement();
            uel.setElement(pr);
            uel.setElementType(DOMUtils.getElementQName(pr));
            if (bindingInfo.getService().getDescription() == null) {
                DescriptionInfo description = new DescriptionInfo();
                description.setName(bindingInfo.getService().getName());
                bindingInfo.getService().setDescription(description);
            }
            bindingInfo.getService().getDescription().addExtensor(uel);
        } catch (Exception e) {
            // ignore
            e.printStackTrace();
        }
    }
}
Also used : W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) Element(org.w3c.dom.Element) WSDLManager(org.apache.cxf.wsdl.WSDLManager) DescriptionInfo(org.apache.cxf.service.model.DescriptionInfo) Addressing(javax.xml.ws.soap.Addressing) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) WebServiceException(javax.xml.ws.WebServiceException) EndpointException(org.apache.cxf.endpoint.EndpointException) ExtensionRegistry(javax.wsdl.extensions.ExtensionRegistry)

Example 3 with Addressing

use of javax.xml.ws.soap.Addressing in project cxf by apache.

the class JaxWsEndpointImpl method getAddressing.

private Addressing getAddressing() {
    Class<?> serviceClass = implInfo.getImplementorClass();
    if (serviceClass != null) {
        Addressing ad = serviceClass.getAnnotation(Addressing.class);
        if (ad != null) {
            return ad;
        }
    }
    serviceClass = implInfo.getSEIClass();
    if (serviceClass != null) {
        Addressing ad = serviceClass.getAnnotation(Addressing.class);
        if (ad != null) {
            return ad;
        }
    }
    return null;
}
Also used : Addressing(javax.xml.ws.soap.Addressing)

Example 4 with Addressing

use of javax.xml.ws.soap.Addressing in project cxf by apache.

the class JaxWsServiceFactoryBean method buildWSAActions.

private void buildWSAActions(OperationInfo operation, Method method) {
    // nothing
    if (method == null) {
        return;
    }
    Action action = method.getAnnotation(Action.class);
    Addressing addressing = method.getDeclaringClass().getAnnotation(Addressing.class);
    if (action == null && addressing == null) {
        return;
    }
    WebMethod wm = method.getAnnotation(WebMethod.class);
    String inputAction = "";
    if (action != null) {
        inputAction = action.input();
    }
    if (wm != null && StringUtils.isEmpty(inputAction)) {
        inputAction = wm.action();
    }
    if (StringUtils.isEmpty(inputAction)) {
        inputAction = computeAction(operation, "Request");
    }
    if (action == null && addressing != null) {
        operation.getInput().addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, inputAction);
        operation.getInput().addExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME, inputAction);
        if (operation.getOutput() != null) {
            operation.getOutput().addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, computeAction(operation, "Response"));
            operation.getOutput().addExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME, computeAction(operation, "Response"));
        }
    } else {
        MessageInfo input = operation.getInput();
        input.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, inputAction);
        if (!StringUtils.isEmpty(action.input())) {
            input.addExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME, inputAction);
        }
        MessageInfo output = operation.getOutput();
        if (output != null && !StringUtils.isEmpty(action.output())) {
            output.addExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME, action.output());
            output.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, action.output());
        } else if (output != null) {
            output.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, computeAction(operation, "Response"));
        }
        FaultAction[] faultActions = action.fault();
        if (faultActions != null && faultActions.length > 0 && operation.getFaults() != null) {
            for (FaultAction faultAction : faultActions) {
                FaultInfo faultInfo = getFaultInfo(operation, faultAction.className());
                if (faultInfo != null && !StringUtils.isEmpty(faultAction.value())) {
                    faultInfo.addExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME, faultAction.value());
                    faultInfo.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, faultAction.value());
                }
                if (operation.isUnwrappedCapable()) {
                    faultInfo = getFaultInfo(operation.getUnwrappedOperation(), faultAction.className());
                    if (faultInfo != null && !StringUtils.isEmpty(faultAction.value())) {
                        faultInfo.addExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME, faultAction.value());
                        faultInfo.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, faultAction.value());
                    }
                }
            }
        }
    }
    for (FaultInfo fi : operation.getFaults()) {
        if (fi.getExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME) == null) {
            String f = "/Fault/" + fi.getName().getLocalPart();
            fi.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, computeAction(operation, f));
            if (operation.isUnwrappedCapable()) {
                fi = operation.getUnwrappedOperation().getFault(fi.getName());
                fi.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, computeAction(operation, f));
            }
        }
    }
}
Also used : WebMethod(javax.jws.WebMethod) FaultAction(javax.xml.ws.FaultAction) Action(javax.xml.ws.Action) FaultAction(javax.xml.ws.FaultAction) FaultInfo(org.apache.cxf.service.model.FaultInfo) Addressing(javax.xml.ws.soap.Addressing) MessageInfo(org.apache.cxf.service.model.MessageInfo)

Example 5 with Addressing

use of javax.xml.ws.soap.Addressing in project Payara by payara.

the class WebServiceRefHandler method processAWsRef.

protected HandlerProcessingResult processAWsRef(AnnotationInfo annInfo, WebServiceRef annotation) throws AnnotationProcessorException {
    AnnotatedElementHandler annCtx = annInfo.getProcessingContext().getHandler();
    AnnotatedElement annElem = annInfo.getAnnotatedElement();
    Class annotatedType = null;
    Class declaringClass = null;
    InjectionTarget target = null;
    String defaultServiceRefName = null;
    if (annInfo.getElementType().equals(ElementType.FIELD)) {
        // this is a field injection
        Field annotatedField = (Field) annElem;
        // check this is a valid field
        if (annCtx instanceof AppClientContext) {
            if (!Modifier.isStatic(annotatedField.getModifiers())) {
                throw new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.injectionfieldnotstatic", "Injection fields for application clients must be declared STATIC"), annInfo);
            }
        }
        annotatedType = annotatedField.getType();
        declaringClass = annotatedField.getDeclaringClass();
        defaultServiceRefName = declaringClass.getName() + "/" + annotatedField.getName();
        target = new InjectionTarget();
        target.setFieldName(annotatedField.getName());
        target.setClassName(annotatedField.getDeclaringClass().getName());
    } else if (annInfo.getElementType().equals(ElementType.METHOD)) {
        // this is a method injection
        Method annotatedMethod = (Method) annElem;
        validateInjectionMethod(annotatedMethod, annInfo);
        if (annCtx instanceof AppClientContext) {
            if (!Modifier.isStatic(annotatedMethod.getModifiers())) {
                throw new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.injectionmethodnotstatic", "Injection methods for application clients must be declared STATIC"), annInfo);
            }
        }
        annotatedType = annotatedMethod.getParameterTypes()[0];
        declaringClass = annotatedMethod.getDeclaringClass();
        // Derive javabean property name.
        String propertyName = getInjectionMethodPropertyName(annotatedMethod, annInfo);
        // prefixing with fully qualified type name
        defaultServiceRefName = declaringClass.getName() + "/" + propertyName;
        target = new InjectionTarget();
        target.setMethodName(annotatedMethod.getName());
        target.setClassName(annotatedMethod.getDeclaringClass().getName());
    } else if (annInfo.getElementType().equals(ElementType.TYPE)) {
        // name must be specified.
        if (!ok(annotation.name())) {
            throw new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.nonametypelevel", "TYPE-Level annotation  must specify name member."), annInfo);
        }
        // this is a dependency declaration, we need the service interface
        // to be specified
        annotatedType = annotation.type();
        if (annotatedType == null || annotatedType == Object.class) {
            throw new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.typenotfound", "TYPE-level annotation symbol must specify type member."), annInfo);
        }
        declaringClass = (Class) annElem;
    } else {
        throw new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.invalidtype", "annotation not allowed on this element."), annInfo);
    }
    MTOM mtom = null;
    Addressing addressing = null;
    RespectBinding respectBinding = null;
    // Other annotations like SchemaValidation etc to be passed on to
    // ServiceReferenceDescriptor
    Map<Class<? extends Annotation>, Annotation> otherAnnotations = new HashMap<Class<? extends Annotation>, Annotation>();
    for (Annotation a : annElem.getAnnotations()) {
        if (!(a.annotationType().isAnnotationPresent(WebServiceFeatureAnnotation.class)))
            continue;
        if (a instanceof MTOM) {
            mtom = (MTOM) a;
        } else if (a instanceof Addressing) {
            addressing = (Addressing) a;
        } else if (a instanceof RespectBinding) {
            respectBinding = (RespectBinding) a;
        } else {
            if (!otherAnnotations.containsKey(a.getClass())) {
                otherAnnotations.put(a.getClass(), a);
            }
        }
    }
    String serviceRefName = !ok(annotation.name()) ? defaultServiceRefName : annotation.name();
    ServiceReferenceContainer[] containers = null;
    if (annCtx instanceof ServiceReferenceContainerContext) {
        containers = ((ServiceReferenceContainerContext) annCtx).getServiceRefContainers();
    }
    if (containers == null || containers.length == 0) {
        annInfo.getProcessingContext().getErrorHandler().fine(new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.invalidannotationforthisclass", "Illegal annotation symbol for this class will be ignored"), annInfo));
        return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.PROCESSED);
    }
    // now process the annotation for all the containers.
    for (ServiceReferenceContainer container : containers) {
        ServiceReferenceDescriptor aRef = null;
        try {
            aRef = container.getServiceReferenceByName(serviceRefName);
        }// ignore
         catch (Throwable t) {
        }
        if (aRef == null) {
            // time to create it...
            aRef = new ServiceReferenceDescriptor();
            aRef.setName(serviceRefName);
            container.addServiceReferenceDescriptor(aRef);
        }
        // merge other annotations
        Map<Class<? extends Annotation>, Annotation> oa = aRef.getOtherAnnotations();
        if (oa == null)
            aRef.setOtherAnnotations(otherAnnotations);
        else {
            for (Map.Entry<Class<? extends Annotation>, Annotation> entry : otherAnnotations.entrySet()) {
                if (!oa.containsKey(entry.getKey()))
                    oa.put(entry.getKey(), entry.getValue());
            }
        }
        // merge wsdlLocation
        if (!ok(aRef.getWsdlFileUri()) && ok(annotation.wsdlLocation()))
            aRef.setWsdlFileUri(annotation.wsdlLocation());
        if (!aRef.hasMtomEnabled() && mtom != null) {
            aRef.setMtomEnabled(mtom.enabled());
            aRef.setMtomThreshold(mtom.threshold());
        }
        // check Addressing annotation
        if (aRef.getAddressing() == null && addressing != null) {
            aRef.setAddressing(new com.sun.enterprise.deployment.Addressing(addressing.enabled(), addressing.required(), addressing.responses().toString()));
        }
        // check RespectBinding annotation
        if (aRef.getRespectBinding() == null && respectBinding != null) {
            aRef.setRespectBinding(new com.sun.enterprise.deployment.RespectBinding(respectBinding.enabled()));
        }
        // Store mapped name that is specified
        if (!ok(aRef.getMappedName()) && ok(annotation.mappedName()))
            aRef.setMappedName(annotation.mappedName());
        // Store lookup name that is specified
        if (!aRef.hasLookupName() && ok(getLookupValue(annotation, annInfo)))
            aRef.setLookupName(getLookupValue(annotation, annInfo));
        aRef.setInjectResourceType("javax.jws.WebServiceRef");
        if (target != null)
            aRef.addInjectionTarget(target);
        // Read the WebServiceClient annotation for the service name space
        // uri and wsdl (if required)
        WebServiceClient wsclientAnn;
        // of these default values.
        if (!Object.class.equals(annotation.value()) && (!javax.xml.ws.Service.class.equals(annotation.value()))) {
            // port.
            if (aRef.getServiceInterface() == null) {
                aRef.setServiceInterface(annotation.value().getName());
            }
            if (aRef.getPortInfoBySEI(annotatedType.getName()) == null) {
                ServiceRefPortInfo portInfo = new ServiceRefPortInfo();
                portInfo.setServiceEndpointInterface(annotatedType.getName());
                aRef.addPortInfo(portInfo);
            }
            // set the port type requested for injection
            if (aRef.getInjectionTargetType() == null) {
                aRef.setInjectionTargetType(annotatedType.getName());
            }
            wsclientAnn = (WebServiceClient) annotation.value().getAnnotation(WebServiceClient.class);
        } else {
            // no value provided in the annotation
            wsclientAnn = (WebServiceClient) annotatedType.getAnnotation(WebServiceClient.class);
        }
        if (wsclientAnn == null) {
            throw new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.classnotannotated", "Class must be annotated with a {1} annotation\n symbol : {1}\n location: {0}", new Object[] { annotatedType.toString(), WebServiceClient.class.toString() }));
        }
        // annotation, get it from WebServiceClient annotation
        if (aRef.getWsdlFileUri() == null) {
            aRef.setWsdlFileUri(wsclientAnn.wsdlLocation());
        }
        // Set service name space URI and service local part
        if (aRef.getServiceName() == null) {
            aRef.setServiceNamespaceUri(wsclientAnn.targetNamespace());
            aRef.setServiceLocalPart(wsclientAnn.name());
        }
        if (aRef.getServiceInterface() == null) {
            aRef.setServiceInterface(annotatedType.getName());
        }
    }
    // have @HandlerChain but the SEI has one specified through JAXWS customization
    if (annElem.getAnnotation(javax.jws.HandlerChain.class) == null) {
        return (new HandlerChainHandler()).processHandlerChainAnnotation(annInfo, annCtx, annotatedType, declaringClass, false);
    }
    return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.PROCESSED);
}
Also used : HashMap(java.util.HashMap) AnnotatedElement(java.lang.reflect.AnnotatedElement) ServiceReferenceContainer(com.sun.enterprise.deployment.types.ServiceReferenceContainer) Addressing(javax.xml.ws.soap.Addressing) AppClientContext(com.sun.enterprise.deployment.annotation.context.AppClientContext) Field(java.lang.reflect.Field) ServiceReferenceContainerContext(com.sun.enterprise.deployment.annotation.context.ServiceReferenceContainerContext) com.sun.enterprise.deployment(com.sun.enterprise.deployment) MTOM(javax.xml.ws.soap.MTOM) Service(org.jvnet.hk2.annotations.Service) RespectBinding(javax.xml.ws.RespectBinding) Method(java.lang.reflect.Method) WebServiceFeatureAnnotation(javax.xml.ws.spi.WebServiceFeatureAnnotation) Annotation(java.lang.annotation.Annotation) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Addressing (javax.xml.ws.soap.Addressing)5 RespectBinding (javax.xml.ws.RespectBinding)2 MTOM (javax.xml.ws.soap.MTOM)2 com.sun.enterprise.deployment (com.sun.enterprise.deployment)1 AppClientContext (com.sun.enterprise.deployment.annotation.context.AppClientContext)1 ServiceReferenceContainerContext (com.sun.enterprise.deployment.annotation.context.ServiceReferenceContainerContext)1 ServiceReferenceContainer (com.sun.enterprise.deployment.types.ServiceReferenceContainer)1 Annotation (java.lang.annotation.Annotation)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 WebMethod (javax.jws.WebMethod)1 ExtensibilityElement (javax.wsdl.extensions.ExtensibilityElement)1 ExtensionRegistry (javax.wsdl.extensions.ExtensionRegistry)1 UnknownExtensibilityElement (javax.wsdl.extensions.UnknownExtensibilityElement)1 Action (javax.xml.ws.Action)1 BindingType (javax.xml.ws.BindingType)1