Search in sources :

Example 6 with com.gw2auth.oauth2.server

use of com.gw2auth.oauth2.server in project lighty-netconf-simulator by PANTHEONtech.

the class ResetActionProcessor method execute.

@SuppressWarnings({ "rawtypes", "unchecked", "checkstyle:IllegalCatch" })
@Override
protected CompletableFuture<Response> execute(final Element requestXmlElement, final ActionDefinition paramActionDefinition) {
    this.actionDefinition = paramActionDefinition;
    final XmlNodeConverter xmlNodeConverter = getNetconfDeviceServices().getXmlNodeConverter();
    try {
        final XmlElement xmlElement = XmlElement.fromDomElement(requestXmlElement);
        final Element actionElement = findInputElement(xmlElement, this.actionDefinition.getQName());
        final Reader readerFromElement = RPCUtil.createReaderFromElement(actionElement);
        final ContainerNode deserializedNode = (ContainerNode) xmlNodeConverter.deserialize(this.actionDefinition.getInput(), readerFromElement);
        final Input input = this.adapterSerializer.fromNormalizedNodeActionInput(Reset.class, deserializedNode);
        final String key = findNameElement(xmlElement);
        Preconditions.checkNotNull(key);
        final Class listItem = Server.class;
        final Identifier listKey = new ServerKey(key);
        final KeyedInstanceIdentifier<Server, ServerKey> keydIID = (KeyedInstanceIdentifier<Server, ServerKey>) InstanceIdentifier.create(Collections.singletonList(IdentifiableItem.of(listItem, listKey)));
        final ListenableFuture<RpcResult<Output>> outputFuture = this.resetAction.invoke(keydIID, input);
        final CompletableFuture<Response> completableFuture = new CompletableFuture<>();
        Futures.addCallback(outputFuture, new FutureCallback<RpcResult<Output>>() {

            @Override
            public void onSuccess(final RpcResult<Output> result) {
                final NormalizedNode domOutput = ResetActionProcessor.this.adapterSerializer.toNormalizedNodeActionOutput(Reset.class, result.getResult());
                final List<NormalizedNode> list = new ArrayList<>();
                list.add(domOutput);
                completableFuture.complete(new ResponseData(list));
            }

            @Override
            public void onFailure(final Throwable throwable) {
            }
        }, Executors.newSingleThreadExecutor());
        return completableFuture;
    } catch (final TransformerException | DocumentedException | DeserializationException e) {
        throw new RuntimeException(e);
    }
}
Also used : Server(org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.Server) XmlElement(org.opendaylight.netconf.api.xml.XmlElement) Element(org.w3c.dom.Element) Reader(java.io.Reader) DeserializationException(io.lighty.codecs.util.exception.DeserializationException) ServerKey(org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.ServerKey) Input(org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.server.reset.Input) CompletableFuture(java.util.concurrent.CompletableFuture) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) Identifier(org.opendaylight.yangtools.yang.binding.Identifier) DocumentedException(org.opendaylight.netconf.api.DocumentedException) Output(org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.server.reset.Output) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Reset(org.opendaylight.yang.gen.v1.urn.example.data.center.rev180807.server.Reset) TransformerException(javax.xml.transform.TransformerException) ResponseData(io.lighty.netconf.device.response.ResponseData) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Response(io.lighty.netconf.device.response.Response) XmlElement(org.opendaylight.netconf.api.xml.XmlElement) XmlNodeConverter(io.lighty.codecs.util.XmlNodeConverter) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier)

Example 7 with com.gw2auth.oauth2.server

use of com.gw2auth.oauth2.server in project liferay-ide by liferay.

the class LiferayTomcatServerBehavior method moveContextToAutoDeployDir.

public IStatus moveContextToAutoDeployDir(IModule module, IPath deployDir, IPath baseDir, IPath autoDeployDir, boolean noPath, boolean serverStopped) {
    // $NON-NLS-1$
    IPath confDir = baseDir.append("conf");
    // $NON-NLS-1$
    IPath serverXml = confDir.append("server.xml");
    try (InputStream newInputStream = Files.newInputStream(serverXml.toFile().toPath())) {
        Factory factory = new Factory();
        // $NON-NLS-1$
        factory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
        Server publishedServer = (Server) factory.loadDocument(newInputStream);
        ServerInstance publishedInstance = new ServerInstance(publishedServer, null, null);
        IPath contextPath = null;
        if (autoDeployDir.isAbsolute()) {
            contextPath = autoDeployDir;
        } else {
            contextPath = baseDir.append(autoDeployDir);
        }
        File contextDir = contextPath.toFile();
        if (!contextDir.exists()) {
            contextDir.mkdirs();
        }
        Context context = publishedInstance.createContext(-1);
        // $NON-NLS-1$
        context.setReloadable("true");
        final String moduleName = module.getName();
        final String requiredSuffix = ProjectUtil.getRequiredSuffix(module.getProject());
        String contextName = moduleName;
        if (!moduleName.endsWith(requiredSuffix)) {
            contextName = moduleName + requiredSuffix;
        }
        // $NON-NLS-1$
        context.setSource("org.eclipse.jst.jee.server:" + contextName);
        if (// $NON-NLS-1$
        Boolean.valueOf(context.getAttributeValue("antiResourceLocking")).booleanValue()) {
            // $NON-NLS-1$ //$NON-NLS-2$
            context.setAttributeValue("antiResourceLocking", "false");
        }
        // $NON-NLS-1$
        File contextFile = new File(contextDir, contextName + ".xml");
        if (!LiferayTomcatUtil.isExtProjectContext(context)) {
            // If requested, remove path attribute
            if (noPath) {
                // $NON-NLS-1$
                context.removeAttribute("path");
            }
            // need to fix the doc base to contain entire path to help autoDeployer for Liferay
            context.setDocBase(deployDir.toOSString());
            // context.setAttributeValue("antiJARLocking", "true");
            // check to see if we need to move from conf folder
            // IPath existingContextPath = confDir.append("Catalina/localhost").append(contextFile.getName());
            // if (existingContextPath.toFile().exists()) {
            // existingContextPath.toFile().delete();
            // }
            DocumentBuilder builder = XMLUtil.getDocumentBuilder();
            Document contextDoc = builder.newDocument();
            contextDoc.appendChild(contextDoc.importNode(context.getElementNode(), true));
            XMLUtil.save(contextFile.getAbsolutePath(), contextDoc);
        }
    } catch (Exception e) {
        // confDir.toOSString() + ": " + e.getMessage());
        return new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorPublishConfiguration, new String[] { e.getLocalizedMessage() }), e);
    } finally {
    // monitor.done();
    }
    return Status.OK_STATUS;
}
Also used : Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IPath(org.eclipse.core.runtime.IPath) Server(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server) IServer(org.eclipse.wst.server.core.IServer) DocumentBuilder(javax.xml.parsers.DocumentBuilder) InputStream(java.io.InputStream) Factory(org.eclipse.jst.server.tomcat.core.internal.xml.Factory) ServerInstance(org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance) Document(org.w3c.dom.Document) File(java.io.File) CoreException(org.eclipse.core.runtime.CoreException)

Example 8 with com.gw2auth.oauth2.server

use of com.gw2auth.oauth2.server in project webtools.servertools by eclipse.

the class TomcatVersionHelper method publishCatalinaContextConfig.

/**
 * Add context configuration found in META-INF/context.xml files
 * present in projects to published server.xml.  Used by
 * Tomcat 4.1, 5.0, and 5.5 which support use of META-INF/context.xml
 * in some form.
 *
 * @param baseDir absolute path to catalina instance directory
 * @param webappsDir absolute path to deployment directory
 * @param monitor a progress monitor or null
 * @return result of operation
 */
public static IStatus publishCatalinaContextConfig(IPath baseDir, IPath webappsDir, IProgressMonitor monitor) {
    if (Trace.isTraceEnabled())
        Trace.trace(Trace.FINER, "Apply context configurations");
    IPath confDir = baseDir.append("conf");
    try {
        monitor = ProgressUtil.getMonitorFor(monitor);
        monitor.beginTask(Messages.publishConfigurationTask, 300);
        monitor.subTask(Messages.publishContextConfigTask);
        Factory factory = new Factory();
        factory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
        Server publishedServer = (Server) factory.loadDocument(new FileInputStream(confDir.append("server.xml").toFile()));
        ServerInstance publishedInstance = new ServerInstance(publishedServer, null, null);
        monitor.worked(100);
        boolean modified = false;
        MultiStatus ms = new MultiStatus(TomcatPlugin.PLUGIN_ID, 0, Messages.publishContextConfigTask, null);
        Context[] contexts = publishedInstance.getContexts();
        if (contexts != null) {
            for (int i = 0; i < contexts.length; i++) {
                Context context = contexts[i];
                monitor.subTask(NLS.bind(Messages.checkingContextTask, new String[] { context.getPath() }));
                if (addCatalinaContextConfig(webappsDir, context, ms)) {
                    modified = true;
                }
            }
        }
        monitor.worked(100);
        if (modified) {
            monitor.subTask(Messages.savingContextConfigTask);
            factory.save(confDir.append("server.xml").toOSString());
        }
        // If problem(s) occurred adding context configurations, return error status
        if (ms.getChildren().length > 0) {
            return ms;
        }
        if (Trace.isTraceEnabled())
            Trace.trace(Trace.FINER, "Server.xml updated with context.xml configurations");
        return Status.OK_STATUS;
    } catch (Exception e) {
        Trace.trace(Trace.WARNING, "Could not apply context configurations to published Tomcat configuration from " + confDir.toOSString() + ": " + e.getMessage());
        return new Status(IStatus.ERROR, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorPublishConfiguration, new String[] { e.getLocalizedMessage() }), e);
    } finally {
        monitor.done();
    }
}
Also used : Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IPath(org.eclipse.core.runtime.IPath) Server(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server) Factory(org.eclipse.jst.server.tomcat.core.internal.xml.Factory) MultiStatus(org.eclipse.core.runtime.MultiStatus) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) ServerInstance(org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance)

Example 9 with com.gw2auth.oauth2.server

use of com.gw2auth.oauth2.server in project webtools.servertools by eclipse.

the class TomcatVersionHelper method getCatalinaServerInstance.

/**
 * Gets a ServerInstance for the specified server.xml, Service name,
 * and Host name.  Returns null if server.xml does not exist
 * or an error occurs.
 *
 * @param serverXml path to previously published server.xml
 * @param serviceName name of Service to be used by this instance or null
 * @param hostName name of Host to be used by this instance or null
 * @return ServerInstance for specified server.xml using specified
 * Service and Host names.  null if server.xml does not exist.
 * @throws FileNotFoundException should not occur since existence is tested
 * @throws IOException if there is an error reading server.xml
 * @throws SAXException if there is a syntax error in server.xml
 */
public static ServerInstance getCatalinaServerInstance(IPath serverXml, String serviceName, String hostName) throws FileNotFoundException, IOException, SAXException {
    ServerInstance serverInstance = null;
    Factory factory = new Factory();
    factory.setPackageName("org.eclipse.jst.server.tomcat.core.internal.xml.server40");
    File serverFile = serverXml.toFile();
    if (serverFile.exists()) {
        Server server = (Server) factory.loadDocument(new FileInputStream(serverFile));
        serverInstance = new ServerInstance(server, serviceName, hostName);
        IPath contextPath = serverInstance.getContextXmlDirectory(serverXml.removeLastSegments(1));
        File contextDir = contextPath.toFile();
        if (contextDir.exists()) {
            Map<File, Context> projectContexts = new HashMap<File, Context>();
            loadSeparateContextFiles(contextPath.toFile(), factory, projectContexts);
            // add any separately saved contexts
            Host host = serverInstance.getHost();
            Collection contexts = projectContexts.values();
            Iterator iter = contexts.iterator();
            while (iter.hasNext()) {
                Context context = (Context) iter.next();
                host.importNode(context.getElementNode(), true);
            }
        // TODO Add handling for non-project contexts when there removal can be addressed
        }
    }
    return serverInstance;
}
Also used : Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) Server(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server) IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Iterator(java.util.Iterator) Factory(org.eclipse.jst.server.tomcat.core.internal.xml.Factory) Collection(java.util.Collection) Host(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Host) ServerInstance(org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance) JarFile(java.util.jar.JarFile) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 10 with com.gw2auth.oauth2.server

use of com.gw2auth.oauth2.server in project webtools.servertools by eclipse.

the class XmlTestCase method testServerInstance2.

/**
 * Test behavior of ServerInstance
 */
public void testServerInstance2() {
    Server server = getXml40Server("serverxml.test2");
    assertNotNull(server);
    ServerInstance si = new ServerInstance(server, "Service", "nonexistent_host");
    assertNotNull(si.getService());
    assertNotNull(si.getEngine());
    assertEquals("Engine", si.getEngine().getName());
    assertNull(si.getHost());
    assertEquals("Host \"nonexistent_host\" was not found under Engine \"Engine\" and Service \"Service\".", si.getStatus().getMessage());
    si = new ServerInstance(server, "Service", null);
    assertNotNull(si.getService());
    assertNotNull(si.getEngine());
    assertEquals("Engine", si.getEngine().getName());
    assertNotNull(si.getHost());
    assertEquals("localhost", si.getHost().getName());
    assertEquals((new Path("/Base")).append("Engine").append("localhost"), si.getContextXmlDirectory(new Path("/Base")));
    Context context = si.getContext(0);
    assertNotNull(context);
    assertEquals("/WebApp1", context.getPath());
    context = si.getContext(1);
    assertNotNull(context);
    assertEquals("/WebApp2", context.getPath());
    context = si.getContext(2);
    assertNotNull(context);
    assertEquals("/WebApp3", context.getPath());
    // create new context
    context = si.getContext(3);
    context.setPath("/WebApp4");
    Context[] contexts = si.getContexts();
    assertEquals(4, contexts.length);
    assertEquals("/WebApp1", contexts[0].getPath());
    assertEquals("/WebApp2", contexts[1].getPath());
    assertEquals("/WebApp3", contexts[2].getPath());
    assertEquals("/WebApp4", contexts[3].getPath());
    context = si.createContext(2);
    context.setPath("/WebApp2b");
    contexts = si.getContexts();
    assertEquals(5, contexts.length);
    assertEquals("/WebApp1", contexts[0].getPath());
    assertEquals("/WebApp2", contexts[1].getPath());
    assertEquals("/WebApp2b", contexts[2].getPath());
    assertEquals("/WebApp3", contexts[3].getPath());
    assertEquals("/WebApp4", contexts[4].getPath());
    assertTrue(si.removeContext("WebApp2b"));
    contexts = si.getContexts();
    assertEquals(4, contexts.length);
    assertEquals("/WebApp1", contexts[0].getPath());
    assertEquals("/WebApp2", contexts[1].getPath());
    assertEquals("/WebApp3", contexts[2].getPath());
    assertEquals("/WebApp4", contexts[3].getPath());
    assertTrue(si.removeContext(3));
    contexts = si.getContexts();
    assertEquals(3, contexts.length);
    assertEquals("/WebApp1", contexts[0].getPath());
    assertEquals("/WebApp2", contexts[1].getPath());
    assertEquals("/WebApp3", contexts[2].getPath());
    context = si.getContext("/WebApp1");
    assertNotNull(context);
    assertEquals("/WebApp1", context.getPath());
    assertEquals(new Path("/Base/work/Engine/localhost/WebApp1"), si.getContextWorkDirectory(new Path("/Base"), context));
    context = si.getContext("WebApp2");
    assertNotNull(context);
    assertEquals("/WebApp2", context.getPath());
    assertEquals(new Path("/Base/relative/workdir"), si.getContextWorkDirectory(new Path("/Base"), context));
    context = si.getContext("WebApp3");
    assertNotNull(context);
    assertEquals("/WebApp3", context.getPath());
    assertEquals(new Path("/absolute/workdir"), si.getContextWorkDirectory(new Path("/Base"), context));
    context = si.createContext(3);
    context.setPath("");
    context = si.getContext("");
    assertNotNull(context);
    assertEquals("", context.getPath());
    assertEquals(new Path("/Base/work/Engine/localhost/_"), si.getContextWorkDirectory(new Path("/Base"), context));
    assertEquals(new Path("/Base/work/Engine/localhost"), si.getHostWorkDirectory(new Path("/Base")));
    assertNull(si.getContext("nonexistent"));
    assertEquals("Context with path \"/nonexistent\" was not found under Service \"Service\", Engine \"Engine\", and Host \"localhost\".", si.getStatus().getMessage());
}
Also used : Path(org.eclipse.core.runtime.Path) Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) Server(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server) ServerInstance(org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance)

Aggregations

Server (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server)15 ServerInstance (org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance)10 Context (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context)9 Factory (org.eclipse.jst.server.tomcat.core.internal.xml.Factory)8 IPath (org.eclipse.core.runtime.IPath)6 FileInputStream (java.io.FileInputStream)5 IOException (java.io.IOException)5 IStatus (org.eclipse.core.runtime.IStatus)5 MultiStatus (org.eclipse.core.runtime.MultiStatus)5 Status (org.eclipse.core.runtime.Status)5 Host (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Host)5 Connector (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Connector)4 Engine (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Engine)4 Listener (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Listener)4 Service (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Service)4 FileNotFoundException (java.io.FileNotFoundException)3 SAXException (org.xml.sax.SAXException)3 CustomOAuth2AuthorizationCodeRequestAuthenticationProvider (com.gw2auth.oauth2.server.adapt.CustomOAuth2AuthorizationCodeRequestAuthenticationProvider)2 JWKSet (com.nimbusds.jose.jwk.JWKSet)2 RSAKey (com.nimbusds.jose.jwk.RSAKey)2