|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2012, 2022 Oracle and/or its affiliates. All rights reserved. |
3 | 3 | *
|
4 | 4 | * This program and the accompanying materials are made available under the
|
5 | 5 | * terms of the Eclipse Public License v. 2.0, which is available at
|
@@ -79,31 +79,33 @@ public void setEntity(final Object entity) {
|
79 | 79 | public void setWorkers(final MessageBodyWorkers workers) {
|
80 | 80 | super.setWorkers(workers);
|
81 | 81 | final byte[] entityBytes;
|
82 |
| - if (entity != null) { |
83 |
| - final MultivaluedMap<String, Object> myMap = new MultivaluedHashMap<String, Object>(getHeaders()); |
84 |
| - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
85 |
| - OutputStream stream = null; |
86 |
| - try { |
87 |
| - stream = workers.writeTo(entity, entity.getClass(), entityType.getType(), |
88 |
| - new Annotation[0], getMediaType(), |
89 |
| - myMap, |
90 |
| - propertiesDelegate, baos, Collections.<WriterInterceptor>emptyList()); |
91 |
| - } catch (final IOException | WebApplicationException ex) { |
92 |
| - Logger.getLogger(TestContainerRequest.class.getName()).log(Level.SEVERE, null, ex); |
93 |
| - } finally { |
94 |
| - if (stream != null) { |
95 |
| - try { |
96 |
| - stream.close(); |
97 |
| - } catch (final IOException e) { |
98 |
| - // ignore |
| 82 | + if (workers != null) { |
| 83 | + if (entity != null) { |
| 84 | + final MultivaluedMap<String, Object> myMap = new MultivaluedHashMap<String, Object>(getHeaders()); |
| 85 | + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 86 | + OutputStream stream = null; |
| 87 | + try { |
| 88 | + stream = workers.writeTo(entity, entity.getClass(), entityType.getType(), |
| 89 | + new Annotation[0], getMediaType(), |
| 90 | + myMap, |
| 91 | + propertiesDelegate, baos, Collections.<WriterInterceptor>emptyList()); |
| 92 | + } catch (final IOException | WebApplicationException ex) { |
| 93 | + Logger.getLogger(TestContainerRequest.class.getName()).log(Level.SEVERE, null, ex); |
| 94 | + } finally { |
| 95 | + if (stream != null) { |
| 96 | + try { |
| 97 | + stream.close(); |
| 98 | + } catch (final IOException e) { |
| 99 | + // ignore |
| 100 | + } |
99 | 101 | }
|
100 | 102 | }
|
| 103 | + entityBytes = baos.toByteArray(); |
| 104 | + } else { |
| 105 | + entityBytes = new byte[0]; |
101 | 106 | }
|
102 |
| - entityBytes = baos.toByteArray(); |
103 |
| - } else { |
104 |
| - entityBytes = new byte[0]; |
| 107 | + setEntityStream(new ByteArrayInputStream(entityBytes)); |
105 | 108 | }
|
106 |
| - setEntityStream(new ByteArrayInputStream(entityBytes)); |
107 | 109 | }
|
108 | 110 | }
|
109 | 111 |
|
|
0 commit comments