Search in sources :

Example 21 with WebServiceFeature

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

the class ServerImpl method registerCallback.

public String registerCallback(W3CEndpointReference callback) {
    try {
        WebServiceFeature[] wfs = new WebServiceFeature[] {};
        CallbackPortType port = (CallbackPortType) callback.getPort(CallbackPortType.class, wfs);
        System.out.println("Invoking callback object");
        String resp = port.serverSayHi(System.getProperty("user.name"));
        System.out.println("Response from callback object: " + resp);
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
    return "registerCallback called";
}
Also used : CallbackPortType(org.apache.callback.CallbackPortType) WebServiceFeature(javax.xml.ws.WebServiceFeature)

Example 22 with WebServiceFeature

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

the class EndpointReferenceTest method testProviderGetPort.

@Test
public void testProviderGetPort() throws Exception {
    BusFactory.setDefaultBus(getBus());
    GreeterImpl greeter1 = new GreeterImpl();
    try (EndpointImpl endpoint = new EndpointImpl(getBus(), greeter1, (String) null)) {
        endpoint.publish("http://localhost:8080/test");
        ProviderImpl provider = new ProviderImpl();
        InputStream is = getClass().getResourceAsStream("resources/hello_world_soap_http_infoset.xml");
        Document doc = StaxUtils.read(is);
        DOMSource erXML = new DOMSource(doc);
        EndpointReference endpointReference = EndpointReference.readFrom(erXML);
        WebServiceFeature[] wfs = new WebServiceFeature[] {};
        Greeter greeter = provider.getPort(endpointReference, Greeter.class, wfs);
        String response = greeter.greetMe("John");
        assertEquals("Hello John", response);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) InputStream(java.io.InputStream) Greeter(org.apache.hello_world_soap_http.Greeter) GreeterImpl(org.apache.hello_world_soap_http.GreeterImpl) WebServiceFeature(javax.xml.ws.WebServiceFeature) ProviderImpl(org.apache.cxf.jaxws.spi.ProviderImpl) Document(org.w3c.dom.Document) EndpointReference(javax.xml.ws.EndpointReference) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) Test(org.junit.Test)

Example 23 with WebServiceFeature

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

the class ServiceImpl method createDispatch.

public <T> Dispatch<T> createDispatch(QName portName, Class<T> type, JAXBContext context, Mode mode, WebServiceFeature... features) {
    // using this instead of JaxWsClientFactoryBean so that handlers are configured
    JaxWsProxyFactoryBean clientFac = new JaxWsProxyFactoryBean();
    // Initialize Features.
    configureObject(portName.toString() + ".jaxws-client.proxyFactory", clientFac);
    final AbstractServiceFactoryBean sf;
    try {
        DataBinding db;
        if (context != null) {
            db = new JAXBDataBinding(context);
        } else {
            db = new SourceDataBinding(type);
        }
        sf = createDispatchService(db);
    } catch (ServiceConstructionException e) {
        throw new WebServiceException(e);
    }
    JaxWsEndpointImpl endpoint = getJaxwsEndpoint(portName, sf, features);
    // if the client factory has properties specified, then set those into the endpoint
    if (clientFac.getProperties() != null) {
        endpoint.putAll(clientFac.getProperties());
    }
    // add all the client factory features onto the endpoint feature list
    endpoint.getFeatures().addAll(clientFac.getFeatures());
    // if the client factory has a bus specified (other than the thread default),
    // then use that for the client.  Otherwise use the bus from this service.
    Bus clientBus = getBus();
    if (clientFac.getBus() != BusFactory.getThreadDefaultBus(false) && clientFac.getBus() != null) {
        clientBus = clientFac.getBus();
    }
    @SuppressWarnings("rawtypes") List<Handler> hc = clientFac.getHandlers();
    // CXF-3956
    hc.addAll(handlerResolver.getHandlerChain(portInfos.get(portName)));
    endpoint.getJaxwsBinding().setHandlerChain(hc);
    // create the client object, then initialize the endpoint features against it
    Client client = new ClientImpl(clientBus, endpoint, clientFac.getConduitSelector());
    for (Feature af : endpoint.getFeatures()) {
        af.initialize(client, clientBus);
    }
    // CXF-2822
    initIntercepors(client, clientFac);
    if (executor != null) {
        client.getEndpoint().setExecutor(executor);
    }
    // then try to get it from the wsdl
    if (!StringUtils.isEmpty(clientFac.getAddress())) {
        client.getEndpoint().getEndpointInfo().setAddress(clientFac.getAddress());
    } else {
        // Set the the EPR's address in EndpointInfo
        PortInfoImpl portInfo = portInfos.get(portName);
        if (portInfo != null && !StringUtils.isEmpty(portInfo.getAddress())) {
            client.getEndpoint().getEndpointInfo().setAddress(portInfo.getAddress());
        }
    }
    Dispatch<T> disp = new DispatchImpl<>(client, mode, context, type);
    configureObject(disp);
    return disp;
}
Also used : AbstractServiceFactoryBean(org.apache.cxf.service.factory.AbstractServiceFactoryBean) Bus(org.apache.cxf.Bus) WebServiceException(javax.xml.ws.WebServiceException) Handler(javax.xml.ws.handler.Handler) ClientImpl(org.apache.cxf.endpoint.ClientImpl) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) Feature(org.apache.cxf.feature.Feature) WebServiceFeature(javax.xml.ws.WebServiceFeature) JaxWsEndpointImpl(org.apache.cxf.jaxws.support.JaxWsEndpointImpl) DataBinding(org.apache.cxf.databinding.DataBinding) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) PortInfoImpl(org.apache.cxf.jaxws.handler.PortInfoImpl) Client(org.apache.cxf.endpoint.Client)

Example 24 with WebServiceFeature

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

the class JaxWsServiceFactoryBean method setMTOMFeatures.

private void setMTOMFeatures(DataBinding databinding) {
    if (this.wsFeatures != null) {
        for (WebServiceFeature wsf : this.wsFeatures) {
            if (wsf instanceof MTOMFeature) {
                databinding.setMtomEnabled(true);
                MTOMFeature f = (MTOMFeature) wsf;
                if (f.getThreshold() > 0) {
                    databinding.setMtomThreshold(((MTOMFeature) wsf).getThreshold());
                }
            }
        }
    }
}
Also used : MTOMFeature(javax.xml.ws.soap.MTOMFeature) WebServiceFeature(javax.xml.ws.WebServiceFeature)

Example 25 with WebServiceFeature

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

the class EjbRuntimeEndpointInfo method prepareInvocation.

public Object prepareInvocation(boolean doPreInvoke) throws Exception {
    ComponentInvocation inv = null;
    AdapterInvocationInfo adapterInvInfo = new AdapterInvocationInfo();
    // init'ing jaxws is done here - this sequence is important
    if (adapter == null) {
        synchronized (this) {
            if (adapter == null) {
                try {
                    // Set webservice context here
                    // If the endpoint has a WebServiceContext with @Resource then
                    // that has to be used
                    EjbDescriptor ejbDesc = endpoint.getEjbComponentImpl();
                    Iterator<ResourceReferenceDescriptor> it = ejbDesc.getResourceReferenceDescriptors().iterator();
                    while (it.hasNext()) {
                        ResourceReferenceDescriptor r = it.next();
                        if (r.isWebServiceContext()) {
                            Iterator<InjectionTarget> iter = r.getInjectionTargets().iterator();
                            boolean matchingClassFound = false;
                            while (iter.hasNext()) {
                                InjectionTarget target = iter.next();
                                if (ejbDesc.getEjbClassName().equals(target.getClassName())) {
                                    matchingClassFound = true;
                                    break;
                                }
                            }
                            if (!matchingClassFound) {
                                continue;
                            }
                            try {
                                javax.naming.InitialContext ic = new javax.naming.InitialContext();
                                wsCtxt = (WebServiceContextImpl) ic.lookup("java:comp/env/" + r.getName());
                            } catch (Throwable t) {
                                if (logger.isLoggable(Level.FINE)) {
                                    logger.log(Level.FINE, LogUtils.ERROR_EREI, t.getCause());
                                }
                            }
                        }
                    }
                    if (wsCtxt == null) {
                        wsCtxt = new WebServiceContextImpl();
                    }
                } catch (Throwable t) {
                    LogHelper.log(logger, Level.SEVERE, LogUtils.CANNOT_INITIALIZE, t, endpoint.getName());
                    return null;
                }
            }
        }
    }
    if (doPreInvoke) {
        inv = container.startInvocation();
        adapterInvInfo.setInv(inv);
    }
    // Now process handlers and init jaxws RI
    synchronized (this) {
        if (!handlersConfigured && doPreInvoke) {
            try {
                WsUtil wsu = new WsUtil();
                String implClassName = endpoint.getEjbComponentImpl().getEjbClassName();
                Class clazz = container.getEndpointClassLoader().loadClass(implClassName);
                // Get the proper binding using BindingID
                String givenBinding = endpoint.getProtocolBinding();
                // Get list of all wsdls and schema
                SDDocumentSource primaryWsdl = null;
                Collection docs = null;
                if (endpoint.getWebService().hasWsdlFile()) {
                    WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
                    ApplicationRegistry appRegistry = wscImpl.getApplicationRegistry();
                    ApplicationInfo appInfo = appRegistry.get(endpoint.getBundleDescriptor().getApplication().getRegistrationName());
                    URI deployedDir = appInfo.getSource().getURI();
                    URL pkgedWsdl;
                    if (deployedDir != null) {
                        if (endpoint.getBundleDescriptor().getApplication().isVirtual()) {
                            pkgedWsdl = deployedDir.resolve(endpoint.getWebService().getWsdlFileUri()).toURL();
                        } else {
                            String moduleUri1 = endpoint.getBundleDescriptor().getModuleDescriptor().getArchiveUri();
                            // Fix for issue 7024099
                            // Only replace the last "." with "_" for moduleDescriptor's archive uri
                            String moduleUri = FileUtils.makeFriendlyFilenameExtension(moduleUri1);
                            pkgedWsdl = deployedDir.resolve(moduleUri + "/" + endpoint.getWebService().getWsdlFileUri()).toURL();
                        }
                    } else {
                        pkgedWsdl = endpoint.getWebService().getWsdlFileUrl();
                    }
                    if (pkgedWsdl != null) {
                        primaryWsdl = SDDocumentSource.create(pkgedWsdl);
                        docs = wsu.getWsdlsAndSchemas(pkgedWsdl);
                    }
                }
                // Create a Container to pass ServletContext and also inserting the pipe
                JAXWSContainer container = new JAXWSContainer(null, endpoint);
                // Get catalog info
                java.net.URL catalogURL = clazz.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;
                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 (endpoint.getAddressing() != null) {
                    AddressingFeature addressingFeature = new AddressingFeature(addressing.isEnabled(), addressing.isRequired(), getResponse(addressing.getResponses()));
                    wsFeatures.add(addressingFeature);
                }
                if (wsFeatures.size() > 0) {
                    binding = BindingID.parse(givenBinding).createBinding(wsFeatures.toArray(new WebServiceFeature[wsFeatures.size()]));
                } else {
                    binding = BindingID.parse(givenBinding).createBinding();
                }
                wsu.configureJAXWSServiceHandlers(endpoint, endpoint.getProtocolBinding(), 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
                // #GLASSFISH-21081
                InstanceResolver ir = InstanceResolver.createFromInstanceResolverAnnotation(clazz);
                // 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(clazz);
                }
                // Create the jaxws2.1 invoker and use this
                Invoker invoker = ir.createInvoker();
                WSEndpoint wsep = WSEndpoint.create(// The endpoint class
                clazz, // we do not want JAXWS to process @HandlerChain
                false, // the invoker
                new EjbInvokerImpl(clazz, invoker, webServiceEndpointServant, wsCtxt), // the service QName
                endpoint.getServiceName(), // the port
                endpoint.getWsdlPort(), container, // Derive binding
                binding, // primary WSDL
                primaryWsdl, // Collection of imported WSDLs and schema
                docs, catalogURL);
                String uri = endpoint.getEndpointAddressUri();
                String urlPattern = uri.startsWith("/") ? uri : "/" + uri;
                // All set; Create the adapter
                if (adapterList == null) {
                    adapterList = new ServletAdapterList();
                }
                adapter = adapterList.createAdapter(endpoint.getName(), urlPattern, wsep);
                handlersConfigured = true;
            } catch (Throwable t) {
                LogHelper.log(logger, Level.SEVERE, LogUtils.CANNOT_INITIALIZE, t, endpoint.getName());
                adapter = null;
            }
        }
    }
    // set it using this method
    synchronized (this) {
        addWSContextInfo(wsCtxt);
        if (inv != null && inv instanceof EJBInvocation) {
            EJBInvocation ejbInv = (EJBInvocation) inv;
            ejbInv.setWebServiceContext(wsCtxt);
        }
    }
    adapterInvInfo.setAdapter(adapter);
    return adapterInvInfo;
}
Also used : WSBinding(com.sun.xml.ws.api.WSBinding) AddressingFeature(javax.xml.ws.soap.AddressingFeature) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) URL(java.net.URL) InstanceResolver(com.sun.xml.ws.api.server.InstanceResolver) ApplicationInfo(org.glassfish.internal.data.ApplicationInfo) ArrayList(java.util.ArrayList) URI(java.net.URI) URL(java.net.URL) ApplicationRegistry(org.glassfish.internal.data.ApplicationRegistry) SDDocumentSource(com.sun.xml.ws.api.server.SDDocumentSource) Invoker(com.sun.xml.ws.api.server.Invoker) WSEndpoint(com.sun.xml.ws.api.server.WSEndpoint) ServletAdapterList(com.sun.xml.ws.transport.http.servlet.ServletAdapterList) MTOMFeature(javax.xml.ws.soap.MTOMFeature) WSEndpoint(com.sun.xml.ws.api.server.WSEndpoint) WebServiceFeature(javax.xml.ws.WebServiceFeature) Collection(java.util.Collection) EJBInvocation(org.glassfish.ejb.api.EJBInvocation)

Aggregations

WebServiceFeature (javax.xml.ws.WebServiceFeature)30 ArrayList (java.util.ArrayList)11 MTOMFeature (javax.xml.ws.soap.MTOMFeature)9 QName (javax.xml.namespace.QName)8 URL (java.net.URL)7 WebServiceException (javax.xml.ws.WebServiceException)7 AddressingFeature (javax.xml.ws.soap.AddressingFeature)7 MalformedURLException (java.net.MalformedURLException)6 RespectBindingFeature (javax.xml.ws.RespectBindingFeature)6 LinkedList (java.util.LinkedList)4 Service (javax.xml.ws.Service)4 InputStream (java.io.InputStream)3 NamingException (javax.naming.NamingException)3 DOMSource (javax.xml.transform.dom.DOMSource)3 EndpointReference (javax.xml.ws.EndpointReference)3 Bus (org.apache.cxf.Bus)3 Test (org.junit.Test)3 WSBinding (com.sun.xml.ws.api.WSBinding)2 PrivilegedActionException (java.security.PrivilegedActionException)2 Iterator (java.util.Iterator)2