Search in sources :

Example 1 with AbstractThresholdOutputStream

use of org.apache.cxf.io.AbstractThresholdOutputStream in project cxf by apache.

the class HTTPConduitURLEasyMockTest method verifyRequestHeaders.

private OutputStream verifyRequestHeaders(Message message, boolean expectHeaders, String method) throws IOException {
    Map<String, List<String>> headers = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
    assertNotNull("expected request headers set", headers);
    assertTrue("expected output stream format", message.getContentFormats().contains(OutputStream.class));
    connection.getRequestMethod();
    EasyMock.expectLastCall().andReturn(method).anyTimes();
    if (!"GET".equals(method)) {
        os = EasyMock.createMock(OutputStream.class);
        connection.getOutputStream();
        EasyMock.expectLastCall().andReturn(os);
    }
    message.put(HTTPConduit.KEY_HTTP_CONNECTION, connection);
    if (expectHeaders) {
        connection.setRequestProperty(EasyMock.eq("Authorization"), EasyMock.eq("Basic Qko6dmFsdWU="));
        EasyMock.expectLastCall();
        connection.setRequestProperty(EasyMock.eq("Content-Type"), EasyMock.eq("text/xml;charset=utf8"));
        EasyMock.expectLastCall();
        connection.setRequestProperty(EasyMock.eq("Accept"), EasyMock.eq("text/xml;charset=utf8,text/plain"));
        EasyMock.expectLastCall();
    }
    connection.getRequestProperties();
    EasyMock.expectLastCall().andReturn(new HashMap<String, List<String>>()).anyTimes();
    control.replay();
    AbstractThresholdOutputStream wrappedOS = (AbstractThresholdOutputStream) message.getContent(OutputStream.class);
    assertNotNull("expected output stream", wrappedOS);
    wrappedOS.write(PAYLOAD.getBytes());
    wrappedOS.unBuffer();
    control.verify();
    control.reset();
    return wrappedOS;
}
Also used : AbstractThresholdOutputStream(org.apache.cxf.io.AbstractThresholdOutputStream) HashMap(java.util.HashMap) OutputStream(java.io.OutputStream) AbstractThresholdOutputStream(org.apache.cxf.io.AbstractThresholdOutputStream) MessageContentsList(org.apache.cxf.message.MessageContentsList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 AbstractThresholdOutputStream (org.apache.cxf.io.AbstractThresholdOutputStream)1 MessageContentsList (org.apache.cxf.message.MessageContentsList)1