|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 Oracle and/or its affiliates. All rights reserved. |
| 3 | + * |
| 4 | + * This program and the accompanying materials are made available under the |
| 5 | + * terms of the Eclipse Public License v. 2.0, which is available at |
| 6 | + * http://www.eclipse.org/legal/epl-2.0. |
| 7 | + * |
| 8 | + * This Source Code may also be made available under the following Secondary |
| 9 | + * Licenses when the conditions for such availability set forth in the |
| 10 | + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, |
| 11 | + * version 2 with the GNU Classpath Exception, which is available at |
| 12 | + * https://www.gnu.org/software/classpath/license.html. |
| 13 | + * |
| 14 | + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 |
| 15 | + */ |
| 16 | + |
| 17 | +package org.glassfish.jersey.netty.connector; |
| 18 | + |
| 19 | +import org.glassfish.jersey.client.ClientConfig; |
| 20 | +import org.glassfish.jersey.server.ResourceConfig; |
| 21 | +import org.glassfish.jersey.test.JerseyTest; |
| 22 | +import org.junit.jupiter.api.Assertions; |
| 23 | +import org.junit.jupiter.api.Test; |
| 24 | + |
| 25 | +import javax.ws.rs.GET; |
| 26 | +import javax.ws.rs.Path; |
| 27 | +import javax.ws.rs.ProcessingException; |
| 28 | +import javax.ws.rs.client.ClientBuilder; |
| 29 | +import javax.ws.rs.client.Entity; |
| 30 | +import javax.ws.rs.core.Application; |
| 31 | +import javax.ws.rs.core.MediaType; |
| 32 | +import javax.ws.rs.core.MultivaluedHashMap; |
| 33 | +import javax.ws.rs.core.MultivaluedMap; |
| 34 | +import javax.ws.rs.core.Response; |
| 35 | +import java.util.Collections; |
| 36 | +import java.util.concurrent.ExecutionException; |
| 37 | +import java.util.logging.Logger; |
| 38 | + |
| 39 | +public class EmptyHeaderTest extends JerseyTest { |
| 40 | + |
| 41 | + private static final Logger LOGGER = Logger.getLogger(EmptyHeaderTest.class.getName()); |
| 42 | + |
| 43 | + public static void main(String[] args) throws ExecutionException, InterruptedException { |
| 44 | + new EmptyHeaderTest().testEmptyHeaders(); |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + protected Application configure() { |
| 49 | + return new ResourceConfig().register(new EmptyHeaderTestResource()); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + public void testEmptyHeaders() throws ExecutionException, InterruptedException { |
| 54 | + MultivaluedMap<String, Object> jersey2Headers = new MultivaluedHashMap(); |
| 55 | + jersey2Headers.put("", Collections.singletonList("sss")); |
| 56 | + |
| 57 | + Entity mData = Entity.entity("{\"dd\":\"ddd\"}", MediaType.APPLICATION_JSON_TYPE); |
| 58 | + |
| 59 | + ClientConfig config = new ClientConfig(); |
| 60 | + config.connectorProvider(new NettyConnectorProvider()); |
| 61 | + try { |
| 62 | + Response r = ClientBuilder.newBuilder() |
| 63 | + .withConfig(config) |
| 64 | + .build() |
| 65 | + .target(target().getUri()) |
| 66 | + .request() |
| 67 | + .headers(jersey2Headers) |
| 68 | + .post(mData); |
| 69 | + Assertions.fail("Processing Exception not thrown for empty header name"); |
| 70 | + } catch (ProcessingException processingException) { |
| 71 | + System.out.println(processingException.getMessage()); |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + @Path("") |
| 76 | + private static class EmptyHeaderTestResource { |
| 77 | + @GET |
| 78 | + public Response ok() { |
| 79 | + return Response.ok().build(); |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments