Search in sources :

Example 6 with ServerRtException

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

the class DeploymentDescriptorParser method parse.

/**
 * Parses the {@code sun-jaxws.xml} file and configures
 * a set of {@link HttpAdapter}s.
 */
@NotNull
public List<A> parse(String systemId, InputStream is) {
    XMLStreamReader reader = null;
    try {
        reader = new TidyXMLStreamReader(XMLStreamReaderFactory.create(systemId, is, true), is);
        XMLStreamReaderUtil.nextElementContent(reader);
        return parseAdapters(reader);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (XMLStreamException e) {
                throw new ServerRtException("runtime.parser.xmlReader", e);
            }
        }
        try {
            is.close();
        } catch (IOException e) {
        // ignore
        }
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) TidyXMLStreamReader(com.sun.xml.ws.streaming.TidyXMLStreamReader) TidyXMLStreamReader(com.sun.xml.ws.streaming.TidyXMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) ServerRtException(com.sun.xml.ws.server.ServerRtException) NotNull(com.sun.istack.NotNull)

Example 7 with ServerRtException

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

the class ServerMgr method createContext.

/*
     * Creates a HttpContext at the given address. If there is already a server
     * it uses that server to create a context. Otherwise, it creates a new
     * HTTP server. This sever is added to servers Map.
     */
/*package*/
HttpContext createContext(String address) {
    try {
        HttpServer server;
        ServerState state;
        URL url = new URL(address);
        int port = url.getPort();
        if (port == -1) {
            port = url.getDefaultPort();
        }
        InetSocketAddress inetAddress = new InetSocketAddress(url.getHost(), port);
        synchronized (servers) {
            state = servers.get(inetAddress);
            if (state == null) {
                ServerState free = null;
                for (ServerState ss : servers.values()) {
                    if (port == ss.getServer().getAddress().getPort()) {
                        free = ss;
                        break;
                    }
                }
                if (inetAddress.getAddress().isAnyLocalAddress() && free != null) {
                    state = free;
                } else {
                    if (LOGGER.isLoggable(Level.FINE)) {
                        LOGGER.fine("Creating new HTTP Server at " + inetAddress);
                    }
                    // Creates server with default socket backlog
                    server = HttpServer.create(inetAddress, 0);
                    server.setExecutor(Executors.newCachedThreadPool());
                    String path = url.toURI().getPath();
                    if (LOGGER.isLoggable(Level.FINE)) {
                        LOGGER.fine("Creating HTTP Context at = " + path);
                    }
                    HttpContext context = server.createContext(path);
                    server.start();
                    // we have to get actual inetAddress from server, which can differ from the original in some cases.
                    // e.g. A port number of zero will let the system pick up an ephemeral port in a bind operation,
                    // or IP: 0.0.0.0 - which is used to monitor network traffic from any valid IP address
                    inetAddress = server.getAddress();
                    if (LOGGER.isLoggable(Level.FINE)) {
                        LOGGER.fine("HTTP server started = " + inetAddress);
                    }
                    state = new ServerState(server, path);
                    servers.put(inetAddress, state);
                    return context;
                }
            }
        }
        server = state.getServer();
        if (state.getPaths().contains(url.getPath())) {
            String err = "Context with URL path " + url.getPath() + " already exists on the server " + server.getAddress();
            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.fine(err);
            }
            throw new IllegalArgumentException(err);
        }
        if (LOGGER.isLoggable(Level.FINE)) {
            LOGGER.fine("Creating HTTP Context at = " + url.getPath());
        }
        HttpContext context = server.createContext(url.getPath());
        state.oneMoreContext(url.getPath());
        return context;
    } catch (Exception e) {
        throw new ServerRtException("server.rt.err", e);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) HttpServer(com.sun.net.httpserver.HttpServer) HttpContext(com.sun.net.httpserver.HttpContext) ServerRtException(com.sun.xml.ws.server.ServerRtException) URL(java.net.URL) ServerRtException(com.sun.xml.ws.server.ServerRtException)

Aggregations

ServerRtException (com.sun.xml.ws.server.ServerRtException)7 URL (java.net.URL)4 TidyXMLStreamReader (com.sun.xml.ws.streaming.TidyXMLStreamReader)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 DatabindingModeFeature (com.oracle.webservices.api.databinding.DatabindingModeFeature)1 NotNull (com.sun.istack.NotNull)1 Nullable (com.sun.istack.Nullable)1 HttpContext (com.sun.net.httpserver.HttpContext)1 HttpServer (com.sun.net.httpserver.HttpServer)1 XMLStreamBufferResult (com.sun.xml.stream.buffer.XMLStreamBufferResult)1 BindingID (com.sun.xml.ws.api.BindingID)1 WebServiceFeatureList (com.sun.xml.ws.binding.WebServiceFeatureList)1 WebServiceException (jakarta.xml.ws.WebServiceException)1 MTOMFeature (jakarta.xml.ws.soap.MTOMFeature)1 InputStream (java.io.InputStream)1 Method (java.lang.reflect.Method)1 InetSocketAddress (java.net.InetSocketAddress)1 MalformedURLException (java.net.MalformedURLException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1