Search in sources :

Example 1 with RespectBindingFeature

use of javax.xml.ws.RespectBindingFeature in project cxf by apache.

the class JaxWsEndpointImpl method checkRespectBindingFeature.

private void checkRespectBindingFeature(List<ExtensibilityElement> bindingExtensors) {
    if (bindingExtensors != null) {
        Iterator<ExtensibilityElement> extensionElements = bindingExtensors.iterator();
        while (extensionElements.hasNext()) {
            ExtensibilityElement ext = extensionElements.next();
            if (ext instanceof UnknownExtensibilityElement && Boolean.TRUE.equals(ext.getRequired()) && this.wsFeatures != null) {
                for (WebServiceFeature feature : this.wsFeatures) {
                    if (feature instanceof RespectBindingFeature && feature.isEnabled()) {
                        org.apache.cxf.common.i18n.Message message = new org.apache.cxf.common.i18n.Message("UNKONWN_REQUIRED_WSDL_BINDING", LOG);
                        LOG.severe(message.toString());
                        throw new WebServiceException(message.toString());
                    }
                }
            }
        }
    }
}
Also used : Message(org.apache.cxf.message.Message) WebServiceException(javax.xml.ws.WebServiceException) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) UnknownExtensibilityElement(javax.wsdl.extensions.UnknownExtensibilityElement) RespectBindingFeature(javax.xml.ws.RespectBindingFeature) WebServiceFeature(javax.xml.ws.WebServiceFeature)

Example 2 with RespectBindingFeature

use of javax.xml.ws.RespectBindingFeature 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 3 with RespectBindingFeature

use of javax.xml.ws.RespectBindingFeature in project cxf by apache.

the class RespectBindingFeatureClientServerTest method testOperationInputRespectBindingFeature.

@Test
public void testOperationInputRespectBindingFeature() throws Exception {
    startServers("/wsdl_systest/cxf_operation_input_respectbing.wsdl");
    try {
        GreeterRPCLit greeter = service.getPort(portName, GreeterRPCLit.class, new RespectBindingFeature(true));
        updateAddressPort(greeter, PORT);
        greeter.greetMe("hello");
        fail("WebServiceException is expected");
    } catch (Exception ex) {
        assertTrue("WebServiceException is expected", ex instanceof javax.xml.ws.WebServiceException);
        assertTrue("RespectBindingFeature message is expected: " + ex.getMessage(), ex.getMessage().indexOf("extension with required=true attribute") > -1);
    }
}
Also used : GreeterRPCLit(org.apache.hello_world_rpclit.GreeterRPCLit) RespectBindingFeature(javax.xml.ws.RespectBindingFeature) Test(org.junit.Test)

Example 4 with RespectBindingFeature

use of javax.xml.ws.RespectBindingFeature in project Payara by payara.

the class WSServletContextListener method registerEndpoint.

private void registerEndpoint(WebServiceEndpoint endpoint, ServletContext servletContext) throws Exception {
    ClassLoader classLoader = servletContext.getClassLoader();
    WsUtil wsu = new WsUtil();
    // Complete all the injections that are required
    Class serviceEndpointClass = Class.forName(endpoint.getServletImplClass(), true, classLoader);
    // Get the proper binding using BindingID
    String givenBinding = endpoint.getProtocolBinding();
    // TODO Rama
    // if(endpoint.getWsdlExposed() != null) {
    // wsdlExposed = Boolean.parseBoolean(endpoint.getWsdlExposed());
    // }
    // Get list of all wsdls and schema
    SDDocumentSource primaryWsdl = null;
    Collection docs = null;
    if (endpoint.getWebService().hasWsdlFile()) {
        URL pkgedWsdl = null;
        try {
            pkgedWsdl = servletContext.getResource('/' + endpoint.getWebService().getWsdlFileUri());
        } catch (MalformedURLException e) {
            logger.log(Level.SEVERE, LogUtils.CANNOT_LOAD_WSDL_FROM_APPLICATION, e.getMessage());
        }
        if (pkgedWsdl == null) {
            pkgedWsdl = endpoint.getWebService().getWsdlFileUrl();
        }
        if (pkgedWsdl != null) {
            primaryWsdl = SDDocumentSource.create(pkgedWsdl);
            docs = wsu.getWsdlsAndSchemas(pkgedWsdl);
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, LogUtils.CREATING_ENDPOINT_FROM_PACKAGED_WSDL, primaryWsdl.getSystemId().toString());
                logger.log(Level.FINE, LogUtils.METADATA_DOCS);
                for (Object source : docs) {
                    logger.log(Level.FINE, ((SDDocumentSource) source).getSystemId().toString());
                }
            }
        }
    }
    // Create a Container to pass ServletContext and also inserting the pipe
    JAXWSContainer container = new JAXWSContainer(servletContext, endpoint);
    // Get catalog info
    java.net.URL catalogURL = servletContext.getResource('/' + endpoint.getBundleDescriptor().getDeploymentDescriptorDir() + File.separator + "jax-ws-catalog.xml");
    // Create Binding and set service side handlers on this binding
    boolean mtomEnabled = wsu.getMtom(endpoint);
    WSBinding binding = null;
    // Only if MTOm is enabled create the Binding with the MTOMFeature
    ArrayList<WebServiceFeature> wsFeatures = new ArrayList<WebServiceFeature>();
    // Only if MTOm is enabled create the Binding with the MTOMFeature
    if (mtomEnabled) {
        int mtomThreshold = endpoint.getMtomThreshold() != null ? Integer.parseInt(endpoint.getMtomThreshold()) : 0;
        MTOMFeature mtom = new MTOMFeature(true, mtomThreshold);
        wsFeatures.add(mtom);
    }
    Addressing addressing = endpoint.getAddressing();
    if (addressing != null) {
        AddressingFeature addressingFeature = new AddressingFeature(addressing.isEnabled(), addressing.isRequired(), getResponse(addressing.getResponses()));
        wsFeatures.add(addressingFeature);
    }
    RespectBinding rb = endpoint.getRespectBinding();
    if (rb != null) {
        RespectBindingFeature rbFeature = new RespectBindingFeature(rb.isEnabled());
        wsFeatures.add(rbFeature);
    }
    if (endpoint.getValidateRequest() != null && Boolean.parseBoolean(endpoint.getValidateRequest())) {
        // enable SchemaValidationFeature
        wsFeatures.add(new SchemaValidationFeature());
    }
    if (endpoint.getStreamAttachments() != null && Boolean.parseBoolean(endpoint.getStreamAttachments())) {
        // enable StreamingAttachmentsFeature
        wsFeatures.add(new StreamingAttachmentFeature());
    }
    if (endpoint.getReliabilityConfig() != null) {
        // TODO Revisit later after Metro provides generic method to pass partial configuration to Metro runtime.
        // Only partial configuration is specified in webservices DD, but the information for creating complete RM feature should be gathered
        // from wsdl policy, annotation or metro configuration file. For ex: RmProtocolVersion would be decided by  policy assertion.
        // For now, the feature would be constructed from default values, overriding any configuration specified in wsdl or metro configuration file..
        ReliabilityConfig rxConfig = endpoint.getReliabilityConfig();
        ReliableMessagingFeatureBuilder rmbuilder = new ReliableMessagingFeatureBuilder(RmProtocolVersion.getDefault());
        if (rxConfig.getInactivityTimeout() != null) {
            rmbuilder.sequenceInactivityTimeout(Long.parseLong(rxConfig.getInactivityTimeout().trim()));
        }
        if (endpoint.getHttpResponseBufferSize() != null) {
            rmbuilder.destinationBufferQuota(Long.parseLong(endpoint.getHttpResponseBufferSize().trim()));
        }
        if (rxConfig.getBaseRetransmissionInterval() != null) {
            rmbuilder.messageRetransmissionInterval(Long.parseLong(rxConfig.getBaseRetransmissionInterval().trim()));
        }
        if (rxConfig.getRetransmissionExponentialBackoff() != null) {
            rmbuilder.retransmissionBackoffAlgorithm(Boolean.parseBoolean(rxConfig.getRetransmissionExponentialBackoff()) ? ReliableMessagingFeature.BackoffAlgorithm.EXPONENTIAL : ReliableMessagingFeature.BackoffAlgorithm.getDefault());
        }
        if (rxConfig.getAcknowledgementInterval() != null) {
            rmbuilder.acknowledgementTransmissionInterval(Long.parseLong(rxConfig.getAcknowledgementInterval().trim()));
        }
        if (rxConfig.getSequenceExpiration() != null) {
            logger.log(Level.INFO, LogUtils.CONFIGURATION_IGNORE_IN_WLSWS, new Object[] { endpoint.getEndpointName(), "<sequence-expiration>" });
        }
        if (rxConfig.getBufferRetryCount() != null) {
            rmbuilder.maxMessageRetransmissionCount(Long.parseLong(rxConfig.getBufferRetryCount().trim()));
        }
        if (rxConfig.getBufferRetryDelay() != null) {
            logger.log(Level.INFO, LogUtils.CONFIGURATION_IGNORE_IN_WLSWS, new Object[] { endpoint.getEndpointName(), "<buffer-retry-delay>" });
        }
        wsFeatures.add(rmbuilder.build());
    } else {
        if (endpoint.getHttpResponseBufferSize() != null) {
            logger.log(Level.WARNING, LogUtils.CONFIGURATION_UNSUPPORTED_IN_WLSWS, new Object[] { endpoint.getEndpointName(), "<http-response-buffersize>" });
        }
    }
    if (wsFeatures.size() > 0) {
        binding = BindingID.parse(givenBinding).createBinding(wsFeatures.toArray(new WebServiceFeature[wsFeatures.size()]));
    } else {
        binding = BindingID.parse(givenBinding).createBinding();
    }
    wsu.configureJAXWSServiceHandlers(endpoint, givenBinding, binding);
    // See if it is configured with JAX-WS extension InstanceResolver annotation like
    // @com.sun.xml.ws.developer.servlet.HttpSessionScope or @com.sun.xml.ws.developer.Stateful
    InstanceResolver ir = InstanceResolver.createFromInstanceResolverAnnotation(serviceEndpointClass);
    // TODO - Implement 109 StatefulInstanceResolver ??
    if (ir == null) {
        // use our own InstanceResolver that does not call @PostConstuct method before
        // @Resource injections have happened.
        ir = new InstanceResolverImpl(serviceEndpointClass);
    }
    Invoker inv = ir.createInvoker();
    WSEndpoint wsep = WSEndpoint.create(// The endpoint class
    serviceEndpointClass, // we do not want JAXWS to process @HandlerChain
    false, inv, // the service QName
    endpoint.getServiceName(), // the port
    endpoint.getWsdlPort(), // Our container with info on security/monitoring pipe
    container, // Derive binding
    binding, // primary WSDL
    primaryWsdl, // Collection of imported WSDLs and schema
    docs, catalogURL);
    // Fix for 6852 Add the ServletAdapter which implements the BoundEndpoint
    // container.addEndpoint(wsep);
    // For web components, this will be relative to the web app
    // context root.  Make sure there is a leading slash.
    String uri = endpoint.getEndpointAddressUri();
    String urlPattern = uri.startsWith("/") ? uri : "/" + uri;
    // The whole web app should have a single adapter list
    // This is to enable JAXWS publish WSDLs with proper addresses
    ServletAdapter adapter;
    synchronized (this) {
        ServletAdapterList list = (ServletAdapterList) servletContext.getAttribute("ADAPTER_LIST");
        if (list == null) {
            list = new ServletAdapterList();
            servletContext.setAttribute("ADAPTER_LIST", list);
        }
        adapter = ServletAdapter.class.cast(list.createAdapter(endpoint.getName(), urlPattern, wsep));
        container.addEndpoint(adapter);
    }
    registerEndpointUrlPattern(urlPattern, adapter);
}
Also used : WSBinding(com.sun.xml.ws.api.WSBinding) MalformedURLException(java.net.MalformedURLException) ReliabilityConfig(com.sun.enterprise.deployment.runtime.ws.ReliabilityConfig) AddressingFeature(javax.xml.ws.soap.AddressingFeature) URL(java.net.URL) ArrayList(java.util.ArrayList) URL(java.net.URL) RespectBindingFeature(javax.xml.ws.RespectBindingFeature) ServletAdapterList(com.sun.xml.ws.transport.http.servlet.ServletAdapterList) ServletAdapter(com.sun.xml.ws.transport.http.servlet.ServletAdapter) MTOMFeature(javax.xml.ws.soap.MTOMFeature) StreamingAttachmentFeature(com.sun.xml.ws.developer.StreamingAttachmentFeature) WebServiceFeature(javax.xml.ws.WebServiceFeature) Collection(java.util.Collection) ReliableMessagingFeatureBuilder(com.sun.xml.ws.rx.rm.api.ReliableMessagingFeatureBuilder) SchemaValidationFeature(com.sun.xml.ws.developer.SchemaValidationFeature)

Example 5 with RespectBindingFeature

use of javax.xml.ws.RespectBindingFeature in project Payara by payara.

the class WebServiceReferenceManagerImpl method getWebServiceFeatures.

private ArrayList<WebServiceFeature> getWebServiceFeatures(ServiceReferenceDescriptor desc) {
    /**
     * JAXWS 2.2 enables @MTOM, @Addressing @RespectBinding
     * on WebServiceRef
     * If these are present use the
     * Service(url,wsdl,features) constructor
     */
    ArrayList<WebServiceFeature> wsFeatures = new ArrayList<WebServiceFeature>();
    if (desc.isMtomEnabled()) {
        wsFeatures.add(new MTOMFeature(true, desc.getMtomThreshold()));
    }
    com.sun.enterprise.deployment.Addressing add = desc.getAddressing();
    if (add != null) {
        wsFeatures.add(new AddressingFeature(add.isEnabled(), add.isRequired(), getResponse(add.getResponses())));
    }
    com.sun.enterprise.deployment.RespectBinding rb = desc.getRespectBinding();
    if (rb != null) {
        wsFeatures.add(new RespectBindingFeature(rb.isEnabled()));
    }
    Map<Class<? extends Annotation>, Annotation> otherAnnotations = desc.getOtherAnnotations();
    Iterator it = otherAnnotations.values().iterator();
    while (it.hasNext()) {
        wsFeatures.add(getWebServiceFeatureBean((Annotation) it.next()));
    }
    return wsFeatures;
}
Also used : AddressingFeature(javax.xml.ws.soap.AddressingFeature) MTOMFeature(javax.xml.ws.soap.MTOMFeature) ArrayList(java.util.ArrayList) WebServiceFeatureAnnotation(javax.xml.ws.spi.WebServiceFeatureAnnotation) Annotation(java.lang.annotation.Annotation) RespectBindingFeature(javax.xml.ws.RespectBindingFeature) WebServiceFeature(javax.xml.ws.WebServiceFeature) Iterator(java.util.Iterator) com.sun.enterprise.deployment(com.sun.enterprise.deployment)

Aggregations

RespectBindingFeature (javax.xml.ws.RespectBindingFeature)9 GreeterRPCLit (org.apache.hello_world_rpclit.GreeterRPCLit)5 Test (org.junit.Test)5 WebServiceFeature (javax.xml.ws.WebServiceFeature)4 ArrayList (java.util.ArrayList)3 AddressingFeature (javax.xml.ws.soap.AddressingFeature)3 MTOMFeature (javax.xml.ws.soap.MTOMFeature)3 com.sun.enterprise.deployment (com.sun.enterprise.deployment)1 ReliabilityConfig (com.sun.enterprise.deployment.runtime.ws.ReliabilityConfig)1 WSBinding (com.sun.xml.ws.api.WSBinding)1 SchemaValidationFeature (com.sun.xml.ws.developer.SchemaValidationFeature)1 StreamingAttachmentFeature (com.sun.xml.ws.developer.StreamingAttachmentFeature)1 ReliableMessagingFeatureBuilder (com.sun.xml.ws.rx.rm.api.ReliableMessagingFeatureBuilder)1 ServletAdapter (com.sun.xml.ws.transport.http.servlet.ServletAdapter)1 ServletAdapterList (com.sun.xml.ws.transport.http.servlet.ServletAdapterList)1 Annotation (java.lang.annotation.Annotation)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1