@Test public void testRequest_GetMethod_WithErrorResponse() throws Exception { MockMessageProducer mock = new MockMessageProducer(); HttpConnection jc = HttpHelper.createConnection(); JettyMessageConsumer mc = createConsumer(HttpHelper.URL_TO_POST_TO); ServiceList services = new ServiceList(); services.add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.UNAUTHORIZED_401))); Channel c = createChannel(jc, createWorkflow(mc, mock, services)); StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));; stdHttp.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethodProvider.RequestMethod.GET)); StandaloneRequestor producer = new StandaloneRequestor(stdHttp); AdaptrisMessage msg = new DefaultMessageFactory().newMessage(ALT_TEXT); try { start(c); start(producer); producer.doService(msg); fail(); } catch (ServiceException expected) { } finally { stop(c); stop(producer); } assertEquals(1, mock.messageCount()); }
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); }
StandardHttpProducer extends HttpProducer<HttpURLConnection, HttpURLConnection> { 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); } }
StandardHttpProducer extends HttpProducer<HttpURLConnection, HttpURLConnection> { 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); } StandardHttpProducer(); }
StandardHttpProducer extends HttpProducer<HttpURLConnection, HttpURLConnection> { 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); } StandardHttpProducer();  }
StandardHttpProducer extends HttpProducer<HttpURLConnection, HttpURLConnection> { 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); } StandardHttpProducer();   }