@Test public void shouldParseRequest() throws Exception { final RestRequest req = new RestRequest( "GET", String.format("/r%d/Instance/Class/Member/SubSystem/ServiceCode", RestMessage.PROTOCOL_VERSION), "foo=bar", Arrays.asList( new BasicHeader("X-Road-Client", "Instance/Class/Member/SubSystem"), new BasicHeader("X-Road-Id", "42"), new BasicHeader("X-Road-ServerId", "Instance/Class/Member/ServerCode")), "xid" ); final byte[] msg1 = req.toByteArray(); final RestRequest req2 = new RestRequest(msg1); assertArrayEquals(msg1, req2.getMessageBytes()); }
@Override protected byte[] toByteArray() { try (ByteArrayOutputStream bof = new ByteArrayOutputStream()) { writeString(bof, verb.toString()); bof.write(CRLF); writeString(bof, requestPath); if (query != null) { writeString(bof, "?"); writeString(bof, query); } bof.write(CRLF); serializeHeaders(headers, bof, h -> true); return bof.toByteArray(); } catch (Exception io) { throw new IllegalStateException("Unable to serialize request", io); } }
RestRequest extends RestMessage { @Override protected byte[] toByteArray() { try (ByteArrayOutputStream bof = new ByteArrayOutputStream()) { writeString(bof, verb.toString()); bof.write(CRLF); writeString(bof, requestPath); if (query != null) { writeString(bof, "?"); writeString(bof, query); } bof.write(CRLF); serializeHeaders(headers, bof, h -> true); return bof.toByteArray(); } catch (Exception io) { throw new IllegalStateException("Unable to serialize request", io); } } }
RestRequest extends RestMessage { @Override protected byte[] toByteArray() { try (ByteArrayOutputStream bof = new ByteArrayOutputStream()) { writeString(bof, verb.toString()); bof.write(CRLF); writeString(bof, requestPath); if (query != null) { writeString(bof, "?"); writeString(bof, query); } bof.write(CRLF); serializeHeaders(headers, bof, h -> true); return bof.toByteArray(); } catch (Exception io) { throw new IllegalStateException("Unable to serialize request", io); } } RestRequest(byte[] messageBytes);  RestRequest(String verb, String path, String query, List<Header> headers, String xRequestId); }
RestRequest extends RestMessage { @Override protected byte[] toByteArray() { try (ByteArrayOutputStream bof = new ByteArrayOutputStream()) { writeString(bof, verb.toString()); bof.write(CRLF); writeString(bof, requestPath); if (query != null) { writeString(bof, "?"); writeString(bof, query); } bof.write(CRLF); serializeHeaders(headers, bof, h -> true); return bof.toByteArray(); } catch (Exception io) { throw new IllegalStateException("Unable to serialize request", io); } } RestRequest(byte[] messageBytes);  RestRequest(String verb, String path, String query, List<Header> headers, String xRequestId); @Override byte[] getFilteredMessage(); @Override ClientId getSender(); }
RestRequest extends RestMessage { @Override protected byte[] toByteArray() { try (ByteArrayOutputStream bof = new ByteArrayOutputStream()) { writeString(bof, verb.toString()); bof.write(CRLF); writeString(bof, requestPath); if (query != null) { writeString(bof, "?"); writeString(bof, query); } bof.write(CRLF); serializeHeaders(headers, bof, h -> true); return bof.toByteArray(); } catch (Exception io) { throw new IllegalStateException("Unable to serialize request", io); } } RestRequest(byte[] messageBytes);  RestRequest(String verb, String path, String query, List<Header> headers, String xRequestId); @Override byte[] getFilteredMessage(); @Override ClientId getSender();  }