Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CWWWC0002W warning message coming out when using mpGraphQL features #29691

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*******************************************************************************
* Copyright (c) 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package com.ibm.ws.io.smallrye.graphql.component;

import javax.servlet.ServletContext;

public interface GraphQLSecurityInitializer {
public void onStartup(ServletContext ctx);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020 IBM Corporation and others.
* Copyright (c) 2020, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -31,6 +31,14 @@
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

import org.eclipse.microprofile.graphql.ConfigKey;
import org.jboss.jandex.IndexView;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.component.annotations.ReferencePolicyOption;

import com.ibm.websphere.ras.Tr;
import com.ibm.websphere.ras.TraceComponent;
import com.ibm.ws.container.service.app.deploy.ModuleInfo;
Expand All @@ -41,7 +49,6 @@
import com.ibm.wsspi.logging.Introspector;

import graphql.schema.GraphQLSchema;

import io.smallrye.graphql.bootstrap.Bootstrap;
import io.smallrye.graphql.cdi.config.GraphQLConfig;
import io.smallrye.graphql.execution.ExecutionService;
Expand All @@ -52,19 +59,27 @@
import io.smallrye.graphql.servlet.IndexInitializer;
import io.smallrye.graphql.servlet.SchemaServlet;

import org.eclipse.microprofile.graphql.ConfigKey;
import org.osgi.service.component.annotations.Component;
import org.jboss.jandex.IndexView;

@Component(property = { "service.vendor=IBM" })
public class GraphQLServletContainerInitializer implements ServletContainerInitializer, Introspector {
private static final TraceComponent tc = Tr.register(GraphQLServletContainerInitializer.class);

private static Map<ClassLoader, DiagnosticsBag> diagnostics = new WeakHashMap<ClassLoader, DiagnosticsBag>();
private GraphQLSecurityInitializer securityInitializer;
public static final String EXECUTION_SERVLET_NAME = "ExecutionServlet";
public static final String SCHEMA_SERVLET_NAME = "SchemaServlet";
public static final String UI_SERVLET_NAME = "UIServlet";

@Reference(cardinality = ReferenceCardinality.OPTIONAL, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY)
public void setSecurityInitializer(GraphQLSecurityInitializer secInitializer) {
securityInitializer = secInitializer;
}

public void unsetSecurityInitializer(GraphQLSecurityInitializer secInitializer) {
if (securityInitializer == secInitializer) {
securityInitializer = null;
}
}

@FFDCIgnore({Throwable.class})
public void onStartup(Set<Class<?>> classes, ServletContext ctx) throws ServletException {
if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
Expand Down Expand Up @@ -118,6 +133,25 @@ public void onStartup(Set<Class<?>> classes, ServletContext ctx) throws ServletE
}
diagBag.webinfClassesUrl = webinfClassesUrl;


GraphQLSchema graphQLSchema = null;
try {
IndexInitializer indexInitializer = new IndexInitializer();
IndexView index = indexInitializer.createIndex(Collections.singleton(webinfClassesUrl));
Schema schema = SchemaBuilder.build(index);
if (schema == null || (!schema.hasQueries() && !schema.hasMutations())) {
// not a GraphQL app as far as we can tell - trace and exit:
if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
Tr.debug(tc, "No GraphQL components found in app: " + ctx.getServletContextName());
}
diagnostics.remove(ctx.getClassLoader());
return;
}
diagBag.modelSchema = schema;
} catch (Throwable t) {
Tr.error(tc, "ERROR_GENERATING_SCHEMA_CWMGQ0001E", ctx.getServletContextName());
throw new ServletException(t);
}
GraphQLConfig config = new GraphQLConfig() {
@Override
public String getDefaultErrorMessage() {
Expand Down Expand Up @@ -178,25 +212,8 @@ public Optional<List<String>> getUnwrapExceptions() {
};
diagBag.config = config;

GraphQLSchema graphQLSchema = null;
try {
IndexInitializer indexInitializer = new IndexInitializer();
IndexView index = indexInitializer.createIndex(Collections.singleton(webinfClassesUrl));
Schema schema = SchemaBuilder.build(index);
if (schema == null || (!schema.hasQueries() && !schema.hasMutations())) {
// not a GraphQL app as far as we can tell - trace and exit:
if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
Tr.debug(tc, "No GraphQL components found in app: " + ctx.getServletContextName());
}
diagnostics.remove(ctx.getClassLoader());
return;
}
diagBag.modelSchema = schema;
graphQLSchema = Bootstrap.bootstrap(schema, config);
} catch (Throwable t) {
Tr.error(tc, "ERROR_GENERATING_SCHEMA_CWMGQ0001E", ctx.getServletContextName());
throw new ServletException(t);
}
graphQLSchema = Bootstrap.bootstrap(diagBag.modelSchema, config);

diagBag.graphQLSchema = graphQLSchema;

if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
Expand All @@ -218,6 +235,10 @@ public Optional<List<String>> getUnwrapExceptions() {
ServletRegistration.Dynamic schemaServletReg = ctx.addServlet(SCHEMA_SERVLET_NAME, new SchemaServlet(printer));
schemaServletReg.addMapping(path + "/schema.graphql");

if (securityInitializer != null) {
securityInitializer.onStartup(ctx);
}

boolean enableGraphQLUIServlet = ConfigFacade.getOptionalValue("io.openliberty.enableGraphQLUI", boolean.class)
.orElse(false);
if (enableGraphQLUIServlet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ public void checkForStartFailureMessage() throws Exception {

@AfterClass
public static void afterClass() throws Exception {
server.stopServer("CWWWC0001W", "SRVE0190E", "CWMGQ0001E", "CWWWC0002W");
server.stopServer("CWWWC0001W", "SRVE0190E", "CWMGQ0001E");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,33 @@
package com.ibm.ws.microprofile.graphql.authorization.component;

import java.util.EnumSet;
import java.util.Set;

import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.osgi.service.component.annotations.Component;

import com.ibm.websphere.ras.Tr;
import com.ibm.websphere.ras.TraceComponent;
import com.ibm.ws.io.smallrye.graphql.component.GraphQLSecurityInitializer;
import com.ibm.ws.io.smallrye.graphql.component.GraphQLServletContainerInitializer;

import org.osgi.service.component.annotations.Component;

@Component(property = { "service.vendor=IBM" })
public class GraphQLAuthorizationServletContainerInitializer implements ServletContainerInitializer {
private static final TraceComponent tc = Tr.register(GraphQLAuthorizationServletContainerInitializer.class);
public class GraphQLAuthorizationInitializer implements GraphQLSecurityInitializer {
private static final TraceComponent tc = Tr.register(GraphQLAuthorizationInitializer.class);
private static final String AUTH_FILTER_NAME = "AuthorizationFilter";

public void onStartup(Set<Class<?>> classes, ServletContext ctx) throws ServletException {
if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
Tr.entry(tc, "onStartup", new Object[] {classes, ctx, ctx.getServletContextName(), ctx.getContextPath()});
public void onStartup(ServletContext ctx) {
if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
Tr.entry(tc, "onStartup", new Object[] {ctx, ctx.getServletContextName(), ctx.getContextPath()});
}

// add servlet filter for ExecutionServlet
FilterRegistration.Dynamic filterReg = ctx.addFilter(AUTH_FILTER_NAME, AuthorizationFilter.getInstance());
filterReg.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST), true,
GraphQLServletContainerInitializer.EXECUTION_SERVLET_NAME);
if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
Tr.exit(tc, "onStartup");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,13 @@ public static void tearDown() throws Exception {
if (RepeatTestFilter.isRepeatActionActive(COMPAT_OL_FEATURES)) {
toleratedWarnErrors = new String[] { "SRVE0280E", // TODO: SRVE0280E tracked by OpenLiberty issue #4857
"CWWKS5207W", // The remaining ones relate to config not done for the server / app
"CWWWC0002W",
"CWMOT0010W",
"TRAS4352W" // Only happens when running with WebSphere Liberty image due to an auto feature
};

} else if (RepeatTestFilter.isRepeatActionActive(COMPAT_WL_FEATURES)) {
toleratedWarnErrors = new String[] { "SRVE0280E", // TODO: SRVE0280E tracked by OpenLiberty issue #4857
"CWWKS5207W", // The remaining ones relate to config not done for the server / app
"CWWWC0002W",
"CWMOT0010W",
"CWWKG0033W", // related to missing config for collectives
"CWSJY0035E", // wmqJmsClient.rar.location variable not in the server.xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ public static void tearDown() throws Exception {
if (RepeatTestFilter.isRepeatActionActive(COMPAT_OL_FEATURES)) {
toleratedWarnErrors = new String[] { "SRVE0280E", // TODO: SRVE0280E tracked by OpenLiberty issue #4857
"CWWKS5207W", // The remaining ones relate to config not done for the server / app
"CWWWC0002W",
"CWMOT0010W",
"CWWKE0701E", // TODO: Fix this or verify that it is expected
"TRAS4352W" // Only happens when running with WebSphere Liberty image due to an auto feature
Expand All @@ -137,7 +136,6 @@ public static void tearDown() throws Exception {
} else if (RepeatTestFilter.isRepeatActionActive(COMPAT_WL_FEATURES)) {
toleratedWarnErrors = new String[] { "SRVE0280E", // TODO: SRVE0280E tracked by OpenLiberty issue #4857
"CWWKS5207W", // The remaining ones relate to config not done for the server / app
"CWWWC0002W",
"CWMOT0010W",
"CWWKE0701E", // TODO: Fix this or verify that it is expected
"CWWKG0033W", // related to missing config for collectives
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,13 @@ public static void tearDown() throws Exception {
if (RepeatTestFilter.isRepeatActionActive(COMPAT_OL_FEATURES)) {
toleratedWarnErrors = new String[] { "SRVE0280E", // TODO: SRVE0280E tracked by OpenLiberty issue #4857
"CWWKS5207W", // The remaining ones relate to config not done for the server / app
"CWWWC0002W",
"CWMOT0010W",
"TRAS4352W" // Only happens when running with WebSphere Liberty image due to an auto feature
};

} else if (RepeatTestFilter.isRepeatActionActive(COMPAT_WL_FEATURES)) {
toleratedWarnErrors = new String[] { "SRVE0280E", // TODO: SRVE0280E tracked by OpenLiberty issue #4857
"CWWKS5207W", // The remaining ones relate to config not done for the server / app
"CWWWC0002W",
"CWMOT0010W",
"CWWKG0033W", // related to missing config for collectives
"CWSJY0035E", // wmqJmsClient.rar.location variable not in the server.xml
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*******************************************************************************
* Copyright (c) 2020, 2021 IBM Corporation and others.
* Copyright (c) 2020, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
Expand Down Expand Up @@ -272,10 +272,7 @@ public void testMP33plusStandalone() throws Exception {
server.startServer();
runGetMethod(200, "/helloworld/helloworld", MESSAGE);
} finally {
//I think CWWWC0002W is a configuration error and should not appear
//Should be removed by issue 15496
server.stopServer("CWMOT0010W", //CWMOT0010W: OpenTracing cannot track JAX-RS requests because an OpentracingTracerFactory class was not provided or client libraries for tracing backend are not in the class path.
"CWWWC0002W");//CWWWC0002W: No servlet definition is found for the ExecutionServlet servlet name in the AuthorizationFilter filter mapping.
server.stopServer("CWMOT0010W"); //CWMOT0010W: OpenTracing cannot track JAX-RS requests because an OpentracingTracerFactory class was not provided or client libraries for tracing backend are not in the class path.
}
}

Expand All @@ -299,10 +296,7 @@ public void testMP40plusStandalone() throws Exception {
server.startServer();
runGetMethod(200, "/helloworld/helloworld", MESSAGE);
} finally {
//I think CWWWC0002W is a configuration error and should not appear
//Should be removed by issue 15496
server.stopServer("CWMOT0010W", //CWMOT0010W: OpenTracing cannot track JAX-RS requests because an OpentracingTracerFactory class was not provided or client libraries for tracing backend are not in the class path.
"CWWWC0002W");//CWWWC0002W: No servlet definition is found for the ExecutionServlet servlet name in the AuthorizationFilter filter mapping.
server.stopServer("CWMOT0010W"); //CWMOT0010W: OpenTracing cannot track JAX-RS requests because an OpentracingTracerFactory class was not provided or client libraries for tracing backend are not in the class path.
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ public static void setUp() throws Exception {

@AfterClass
public static void cleanUp() throws Exception {
//I think CWWWC0002W is a mpGraphQL-1.0 bug and should not appear
//See issue 15496
MPCompatibilityTestUtils.cleanUp(server, "CWWWC0002W");
MPCompatibilityTestUtils.cleanUp(server);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ public static void setUp() throws Exception {

@AfterClass
public static void cleanUp() throws Exception {
//I think CWWWC0002W is a mpGraphQL-1.0 bug and should not appear
//See issue 15496
MPCompatibilityTestUtils.cleanUp(server, "CWWWC0002W");
MPCompatibilityTestUtils.cleanUp(server);
}

/**
Expand Down