use of java.io.ByteArrayInputStream in project camel by apache.
the class PGPDataFormatTest method readSecretKey.
static PGPSecretKey readSecretKey() throws Exception {
InputStream input = new ByteArrayInputStream(getSecKeyRing());
PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(input), new BcKeyFingerprintCalculator());
@SuppressWarnings("rawtypes") Iterator keyRingIter = pgpSec.getKeyRings();
while (keyRingIter.hasNext()) {
PGPSecretKeyRing keyRing = (PGPSecretKeyRing) keyRingIter.next();
@SuppressWarnings("rawtypes") Iterator keyIter = keyRing.getSecretKeys();
while (keyIter.hasNext()) {
PGPSecretKey key = (PGPSecretKey) keyIter.next();
if (key.isSigningKey()) {
return key;
}
}
}
throw new IllegalArgumentException("Can't find signing key in key ring.");
}
use of java.io.ByteArrayInputStream in project camel by apache.
the class AbstractPGPDataFormatTest method doRoundTripEncryptionTests.
protected void doRoundTripEncryptionTests(String endpoint) throws Exception {
MockEndpoint encrypted = setupExpectations(context, 3, "mock:encrypted");
MockEndpoint unencrypted = setupExpectations(context, 3, "mock:unencrypted");
String payload = "Hi Alice, Be careful Eve is listening, signed Bob";
Map<String, Object> headers = getHeaders();
template.sendBodyAndHeaders(endpoint, payload, headers);
template.sendBodyAndHeaders(endpoint, payload.getBytes(), headers);
template.sendBodyAndHeaders(endpoint, new ByteArrayInputStream(payload.getBytes()), headers);
assertMocksSatisfied(encrypted, unencrypted, payload);
}
use of java.io.ByteArrayInputStream in project camel by apache.
the class CryptoDataFormatTest method doRoundTripEncryptionTests.
private void doRoundTripEncryptionTests(String endpoint, Map<String, Object> headers) throws Exception {
MockEndpoint encrypted = setupExpectations(context, 3, "mock:encrypted");
MockEndpoint unencrypted = setupExpectations(context, 3, "mock:unencrypted");
String payload = "Hi Alice, Be careful Eve is listening, signed Bob";
template.sendBodyAndHeaders(endpoint, payload, headers);
template.sendBodyAndHeaders(endpoint, payload.getBytes(), headers);
template.sendBodyAndHeaders(endpoint, new ByteArrayInputStream(payload.getBytes()), headers);
assertMocksSatisfied(encrypted, unencrypted, payload);
}
use of java.io.ByteArrayInputStream in project camel by apache.
the class DefaultCxfMessageMapperTest method setupCamelExchange.
private Exchange setupCamelExchange(String requestURI, String requestPath, HttpServletRequest request) {
org.apache.camel.Message camelMessage = EasyMock.createMock(org.apache.camel.Message.class);
Exchange camelExchange = EasyMock.createMock(Exchange.class);
camelExchange.getProperty(CamelTransportConstants.CXF_EXCHANGE, org.apache.cxf.message.Exchange.class);
EasyMock.expectLastCall().andReturn(new ExchangeImpl());
camelExchange.hasOut();
EasyMock.expectLastCall().andReturn(false);
camelExchange.getIn();
EasyMock.expectLastCall().andReturn(camelMessage).times(3);
camelMessage.getHeaders();
EasyMock.expectLastCall().andReturn(Collections.emptyMap()).times(2);
camelMessage.getHeader(Exchange.CONTENT_TYPE, String.class);
EasyMock.expectLastCall().andReturn(null);
camelMessage.getHeader("Accept", String.class);
EasyMock.expectLastCall().andReturn(null);
camelMessage.getHeader(Exchange.HTTP_CHARACTER_ENCODING, String.class);
EasyMock.expectLastCall().andReturn(null);
camelMessage.getHeader(Exchange.CHARSET_NAME, String.class);
EasyMock.expectLastCall().andReturn(null);
camelMessage.getHeader(Exchange.HTTP_URI, String.class);
EasyMock.expectLastCall().andReturn(requestURI);
camelMessage.getHeader(Exchange.HTTP_PATH, String.class);
EasyMock.expectLastCall().andReturn(requestPath);
camelMessage.getHeader(Exchange.HTTP_BASE_URI, String.class);
EasyMock.expectLastCall().andReturn(requestPath);
camelMessage.getHeader(Exchange.HTTP_METHOD, String.class);
EasyMock.expectLastCall().andReturn("GET");
camelMessage.getHeader(Exchange.HTTP_QUERY, String.class);
EasyMock.expectLastCall().andReturn("");
camelMessage.getHeader(Exchange.HTTP_SERVLET_REQUEST);
EasyMock.expectLastCall().andReturn(request);
camelMessage.getHeader(Exchange.HTTP_SERVLET_RESPONSE);
EasyMock.expectLastCall().andReturn(null);
camelMessage.getBody(InputStream.class);
EasyMock.expectLastCall().andReturn(new ByteArrayInputStream("".getBytes()));
EasyMock.replay(camelExchange, camelMessage);
return camelExchange;
}
use of java.io.ByteArrayInputStream in project camel by apache.
the class PGPDataFormatTest method createSignature.
private void createSignature(OutputStream out) throws Exception {
PGPSecretKey pgpSec = readSecretKey();
PGPPrivateKey pgpPrivKey = pgpSec.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider(getProvider()).build("sdude".toCharArray()));
PGPSignatureGenerator sGen = new PGPSignatureGenerator(new JcaPGPContentSignerBuilder(pgpSec.getPublicKey().getAlgorithm(), HashAlgorithmTags.SHA1).setProvider(getProvider()));
sGen.init(PGPSignature.BINARY_DOCUMENT, pgpPrivKey);
BCPGOutputStream bOut = new BCPGOutputStream(out);
InputStream fIn = new ByteArrayInputStream("Test Signature".getBytes("UTF-8"));
int ch;
while ((ch = fIn.read()) >= 0) {
sGen.update((byte) ch);
}
fIn.close();
sGen.generate().encode(bOut);
}
Aggregations