use of com.adaptris.core.ProduceException in project interlok by adaptris.
the class SimpleHttpProducer method readResponse.
private void readResponse(HttpSession httpReply, AdaptrisMessage reply) throws IOException, CoreException {
int responseCode = httpReply.getResponseLine().getResponseCode();
if (!ignoreServerResponseCode()) {
if (responseCode < 200 || responseCode > 299) {
throw new ProduceException("Failed to send payload, got " + responseCode);
}
}
if (getEncoder() != null) {
copy(getEncoder().readMessage(httpReply), reply);
} else {
OutputStream out = reply.getOutputStream();
InputStream in = httpReply.getResponseMessage().getInputStream();
StreamUtil.copyStream(in, out);
reply.addMetadata(new MetadataElement(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE, String.valueOf(responseCode)));
out.close();
in.close();
}
return;
}
use of com.adaptris.core.ProduceException in project interlok by adaptris.
the class FtpProducer method doProduce.
@Override
public void doProduce(AdaptrisMessage msg, String endpoint) throws ProduceException {
FileTransferConnection conn = retrieveConnection(FileTransferConnection.class);
FileTransferClient client = null;
FileNameCreator creator = filenameCreatorToUse();
try {
client = conn.connect(endpoint);
String dirRoot = conn.getDirectoryRoot(endpoint);
String fileName = creator.createName(msg);
String destFilename = dirRoot + destDirectory + SLASH + fileName;
String buildFilename = dirRoot + buildDirectory + SLASH + fileName;
if (conn.additionalDebug()) {
log.trace("buildFilename=[{}], destFilename=[{}]", buildFilename, destFilename);
} else {
log.debug("destFilename=[{}]", destFilename);
}
msg.addMetadata(CoreConstants.PRODUCED_NAME_KEY, fileName);
if (getEncoder() != null) {
byte[] bytesToWrite = encode(msg);
client.put(bytesToWrite, buildFilename);
} else {
try (InputStream in = msg.getInputStream()) {
client.put(in, buildFilename);
}
}
client.rename(buildFilename, destFilename);
} catch (Exception e) {
throw new ProduceException(e);
} finally {
conn.disconnect(client);
}
}
use of com.adaptris.core.ProduceException in project interlok by adaptris.
the class StandardHttpProducer method doRequest.
private AdaptrisMessage doRequest(AdaptrisMessage msg, String endpointUrl, long timeout, AdaptrisMessage reply) throws ProduceException {
try {
URL url = new URL(endpointUrl);
authenticator.setup(url.toString(), msg, null);
HttpURLConnection http = configure(configureTimeouts((HttpURLConnection) url.openConnection(), timeout), msg);
if (authenticator instanceof HttpURLConnectionAuthenticator) {
((HttpURLConnectionAuthenticator) authenticator).configureConnection(http);
}
writeData(getMethod(msg), msg, http);
handleResponse(http, reply);
} catch (Exception e) {
throw ExceptionHelper.wrapProduceException(e);
} finally {
authenticator.close();
}
return reply;
}
use of com.adaptris.core.ProduceException in project interlok by adaptris.
the class StandardHttpProducer method fail.
private void fail(int responseCode, InputStreamWithEncoding data) throws ProduceException {
if (log.isTraceEnabled()) {
try {
try (OutputStream slf4j = new Slf4jLoggingOutputStream(log, Slf4jLoggingOutputStream.LogLevel.TRACE);
InputStream in = new BufferedInputStream(data.inputStream);
PrintStream out = data.encoding == null ? new PrintStream(slf4j) : new PrintStream(slf4j, false, data.encoding)) {
out.println("Error Data from remote server :");
IOUtils.copy(in, out);
}
} catch (IOException e) {
log.trace("No Error Data available");
}
}
throw new ProduceException("Failed to send payload, got " + responseCode);
}
use of com.adaptris.core.ProduceException in project interlok by adaptris.
the class FsMessageProducerTest method testProduceWithNoCreateDir.
@Test
public void testProduceWithNoCreateDir() throws Exception {
String subdir = new GuidGenerator().safeUUID();
FsProducer fs = createProducer(subdir);
fs.setCreateDirs(false);
File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
try {
start(fs);
fs.produce(new DefaultMessageFactory().newMessage(TEXT));
fail();
} catch (ProduceException expected) {
} finally {
FileUtils.deleteQuietly(new File(parentDir, subdir));
stop(fs);
}
}
Aggregations