Uploaded image for project: 'apiman (API Management)'
  1. apiman (API Management)
  2. APIMAN-1335

ApiKeyPolicy from apikey-policy is throwing an NPE on null connectorConfig using the Vert.x gateway

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 1.4.x, 1.4.1.Final
    • 1.4.0.Final
    • Plugin
    • None

      Given the following test config:

      {
          "apis": [{
              "publicAPI": true,
              "organizationId": "testOrg",
              "apiId": "foo",
              "version": "1",
              "endpoint": "http://google.co.za",
              "endpointType": "rest",
              "endpointContentType": "json",
              "endpointProperties": {},
              "parsePayload": false,
              "apiPolicies": [{
                 "policyJsonConfig": "{ \"requestHeader\" : \"X-API-Key\" }",
                 "policyImpl" : "plugin:io.apiman.plugins:apiman-plugins-apikey-policy:1.4.0.Final:war/io.apiman.plugins.apikey_policy.ApiKeyPolicy"
              }, {
                "policyJsonConfig": "{ \"allowOrigin\" : [ \"*\" ] }",
                "policyImpl" : "plugin:io.apiman.plugins:apiman-plugins-cors-policy:1.4.0.Final:war/io.apiman.plugins.cors_policy.CorsPolicy"
              }]
          }],
          "clients": [{
              "organizationId": "testOrg",
              "clientId": "fooClient",
              "version": "1",
              "apiKey": "12345",
              "contracts": [{
                  "apiOrgId": "testOrg",
                  "apiId": "foo",
                  "apiVersion": "1",
                  "plan": "foo",
                  "policies": [{
                     "policyJsonConfig": "{ \"requestHeader\" : \"X-API-Key\" }",
                     "policyImpl" : "plugin:io.apiman.plugins:apiman-plugins-apikey-policy:1.4.0.Final:war/io.apiman.plugins.apikey_policy.ApiKeyPolicy"
                  }, {
                    "policyJsonConfig": "{ \"allowOrigin\" : [ \"*\" ] }",
                    "policyImpl" : "plugin:io.apiman.plugins:apiman-plugins-cors-policy:1.4.0.Final:war//io.apiman.plugins.cors_policy.CorsPolicy"
                  }]
              }]
          }]
      }
      

      and hitting the following URL: http://localhost:8082/testOrg/foo/1/?apiKey=12345

      results in this exception:

      {
      "responseCode": 500,
      "message": "java.lang.NullPointerException",
      "trace": "java.lang.NullPointerException\n\tat io.apiman.plugins.apikey_policy.ApiKeyPolicy.doApply(ApiKeyPolicy.java:54)\n\tat io.apiman.plugins.apikey_policy.ApiKeyPolicy.doApply(ApiKeyPolicy.java:28)\n\tat io.apiman.gateway.engine.policies.AbstractMappedPolicy.apply(AbstractMappedPolicy.java:70)\n\tat io.apiman.gateway.engine.policy.RequestChain.applyPolicy(RequestChain.java:68)\n\tat io.apiman.gateway.engine.policy.Chain.doApply(Chain.java:148)\n\tat io.apiman.gateway.engine.impl.ApiRequestExecutorImpl.lambda$execute$4(ApiRequestExecutorImpl.java:283)\n\tat io.apiman.gateway.engine.impl.ApiRequestExecutorImpl.lambda$loadPolicies$7(ApiRequestExecutorImpl.java:673)\n\tat io.apiman.gateway.engine.policy.PolicyFactoryImpl.loadPolicy(PolicyFactoryImpl.java:95)\n\tat io.apiman.gateway.engine.impl.ApiRequestExecutorImpl.loadPolicies(ApiRequestExecutorImpl.java:641)\n\tat io.apiman.gateway.engine.impl.ApiRequestExecutorImpl.lambda$execute$6(ApiRequestExecutorImpl.java:404)\n\tat io.apiman.gateway.engine.impl.SecureRegistryWrapper$2.handle(SecureRegistryWrapper.java:189)\n\tat io.apiman.gateway.engine.impl.SecureRegistryWrapper$2.handle(SecureRegistryWrapper.java:171)\n\tat io.apiman.gateway.engine.impl.InMemoryRegistry.getContract(InMemoryRegistry.java:219)\n\tat io.apiman.gateway.engine.impl.SecureRegistryWrapper.getContract(SecureRegistryWrapper.java:171)\n\tat io.apiman.gateway.engine.impl.ApiRequestExecutorImpl.execute(ApiRequestExecutorImpl.java:370)\n\tat io.apiman.gateway.platforms.vertx3.http.HttpPolicyAdapter._execute(HttpPolicyAdapter.java:112)\n\tat io.apiman.gateway.platforms.vertx3.http.HttpPolicyAdapter.execute(HttpPolicyAdapter.java:61)\n\tat io.apiman.gateway.platforms.vertx3.verticles.HttpGatewayVerticle.requestHandler(HttpGatewayVerticle.java:55)\n\tat io.vertx.core.http.impl.ServerConnection.handleRequest(ServerConnection.java:285)\n\tat io.vertx.core.http.impl.ServerConnection.processMessage(ServerConnection.java:429)\n\tat io.vertx.core.http.impl.ServerConnection.handleMessage(ServerConnection.java:131)\n\tat io.vertx.core.http.impl.HttpServerImpl$ServerHandler.doMessageReceived(HttpServerImpl.java:630)\n\tat io.vertx.core.http.impl.HttpServerImpl$ServerHandler.doMessageReceived(HttpServerImpl.java:580)\n\tat io.vertx.core.http.impl.VertxHttpHandler.lambda$channelRead$0(VertxHttpHandler.java:71)\n\tat io.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:335)\n\tat io.vertx.core.impl.ContextImpl.executeFromIO(ContextImpl.java:193)\n\tat io.vertx.core.http.impl.VertxHttpHandler.channelRead(VertxHttpHandler.java:71)\n\tat io.vertx.core.net.impl.VertxHandler.channelRead(VertxHandler.java:122)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:349)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:341)\n\tat io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)\n\tat io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:349)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:341)\n\tat io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:363)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:349)\n\tat io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926)\n\tat io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:129)\n\tat io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:642)\n\tat io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:565)\n\tat io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:479)\n\tat io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:441)\n\tat io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)\n\tat java.lang.Thread.run(Thread.java:748)\n"
      }
      

      See the attached screenshot where the NPE occurs.
      I.e. https://github.com/apiman/apiman-plugins/blob/da5a2e7d6f4a214417cf5bb5d578bfb22994ebd8/apikey-policy/src/main/java/io/apiman/plugins/apikey_policy/ApiKeyPolicy.java#L54 results in an NPE because context.getConnectorConfiguration() is null

              msavy_jira Marc Savy (Inactive)
              donovan.muller_jira Donovan Muller (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: