Search in sources :

Example 1 with Module

use of com.sun.xml.ws.api.server.Module in project Payara by payara.

the class JAXWSContainer method getSPI.

@Override
@SuppressWarnings("unchecked")
public <T> T getSPI(Class<T> spiType) {
    if (ServletContext.class.isAssignableFrom(spiType)) {
        return (T) servletContext;
    }
    if (ServerPipelineHook.class.isAssignableFrom(spiType)) {
        ServiceLocator h = Globals.getDefaultHabitat();
        ServerPipeCreator s = h.getService(ServerPipeCreator.class);
        s.init(endpoint);
        return ((T) s);
    }
    if (ResourceInjector.class.isAssignableFrom(spiType)) {
        // Give control of injection time only for servlet endpoints
        if (endpoint.implementedByWebComponent()) {
            return (T) new ResourceInjectorImpl(endpoint);
        }
    }
    if (Module.class.isAssignableFrom(spiType)) {
        if (module != null) {
            return ((T) spiType.cast(module));
        } else {
            return ((T) spiType.cast(new Module() {

                @Override
                public List<BoundEndpoint> getBoundEndpoints() {
                    return new ArrayList<BoundEndpoint>() {

                        private static final long serialVersionUID = 1L;

                        @Override
                        public boolean add(BoundEndpoint e) {
                            return true;
                        }
                    };
                }
            }));
        }
    }
    return null;
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) List(java.util.List) ArrayList(java.util.ArrayList) Module(com.sun.xml.ws.api.server.Module) BoundEndpoint(com.sun.xml.ws.api.server.BoundEndpoint)

Example 2 with Module

use of com.sun.xml.ws.api.server.Module 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 3 with Module

use of com.sun.xml.ws.api.server.Module in project metro-jax-ws by eclipse-ee4j.

the class HttpAdapter method writeWebServicesHtmlPage.

/*
     * Generates the listing of all services.
     */
private void writeWebServicesHtmlPage(WSHTTPConnection con) throws IOException {
    if (!publishStatusPage) {
        return;
    }
    // TODO: resurrect the ability to localize according to the current request.
    con.getInput().close();
    // standard browsable page
    con.setStatus(WSHTTPConnection.OK);
    con.setContentTypeResponseHeader("text/html; charset=utf-8");
    PrintWriter out = new PrintWriter(new OutputStreamWriter(con.getOutput(), StandardCharsets.UTF_8));
    out.println("<html>");
    out.println("<head><title>");
    // out.println("Web Services");
    out.println(WsservletMessages.SERVLET_HTML_TITLE());
    out.println("</title></head>");
    out.println("<body>");
    // out.println("<h1>Web Services</h1>");
    out.println(WsservletMessages.SERVLET_HTML_TITLE_2());
    // what endpoints do we have in this system?
    Module module = getEndpoint().getContainer().getSPI(Module.class);
    List<BoundEndpoint> endpoints = Collections.emptyList();
    if (module != null) {
        endpoints = module.getBoundEndpoints();
    }
    if (endpoints.isEmpty()) {
        // out.println("<p>No JAX-WS context information available.</p>");
        out.println(WsservletMessages.SERVLET_HTML_NO_INFO_AVAILABLE());
    } else {
        out.println("<table width='100%' border='1'>");
        out.println("<tr>");
        out.println("<td>");
        // out.println("Endpoint");
        out.println(WsservletMessages.SERVLET_HTML_COLUMN_HEADER_PORT_NAME());
        out.println("</td>");
        out.println("<td>");
        // out.println("Information");
        out.println(WsservletMessages.SERVLET_HTML_COLUMN_HEADER_INFORMATION());
        out.println("</td>");
        out.println("</tr>");
        for (BoundEndpoint a : endpoints) {
            String endpointAddress = a.getAddress(con.getBaseAddress()).toString();
            out.println("<tr>");
            out.println("<td>");
            out.println(WsservletMessages.SERVLET_HTML_ENDPOINT_TABLE(a.getEndpoint().getServiceName(), a.getEndpoint().getPortName()));
            out.println("</td>");
            out.println("<td>");
            out.println(WsservletMessages.SERVLET_HTML_INFORMATION_TABLE(endpointAddress, a.getEndpoint().getImplementationClass().getName()));
            out.println("</td>");
            out.println("</tr>");
        }
        out.println("</table>");
    }
    out.println("</body>");
    out.println("</html>");
    out.close();
}
Also used : OutputStreamWriter(java.io.OutputStreamWriter) Module(com.sun.xml.ws.api.server.Module) BoundEndpoint(com.sun.xml.ws.api.server.BoundEndpoint) PrintWriter(java.io.PrintWriter)

Aggregations

BoundEndpoint (com.sun.xml.ws.api.server.BoundEndpoint)3 Module (com.sun.xml.ws.api.server.Module)3 WSEndpointReference (com.sun.xml.ws.api.addressing.WSEndpointReference)1 WSDLModel (com.sun.xml.ws.api.model.wsdl.WSDLModel)1 WSDLPort (com.sun.xml.ws.api.model.wsdl.WSDLPort)1 WSDLService (com.sun.xml.ws.api.model.wsdl.WSDLService)1 Container (com.sun.xml.ws.api.server.Container)1 WSEndpoint (com.sun.xml.ws.api.server.WSEndpoint)1 JAXBException (jakarta.xml.bind.JAXBException)1 WebServiceException (jakarta.xml.ws.WebServiceException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 QName (javax.xml.namespace.QName)1 StreamSource (javax.xml.transform.stream.StreamSource)1 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)1 EntityResolver (org.xml.sax.EntityResolver)1