@Test @SuppressWarnings("deprecation") public void testProduce_WithUsernamePassword_BadCredentials() throws Exception { String threadName = Thread.currentThread().getName(); Thread.currentThread().setName(getName()); ConfigurableSecurityHandler csh = new ConfigurableSecurityHandler(); HashLoginServiceFactory hsl = new HashLoginServiceFactory("InterlokJetty", PROPERTIES.getProperty(HttpConsumerTest.JETTY_USER_REALM)); csh.setLoginService(hsl); SecurityConstraint securityConstraint = new SecurityConstraint(); securityConstraint.setMustAuthenticate(true); securityConstraint.setRoles("user"); csh.setSecurityConstraints(Arrays.asList(securityConstraint)); HttpConnection jc = HttpHelper.createConnection(); jc.setSecurityHandler(csh); MockMessageProducer mockProducer = new MockMessageProducer(); JettyMessageConsumer consumer = JettyHelper.createConsumer(HttpHelper.URL_TO_POST_TO); Channel channel = JettyHelper.createChannel(jc, consumer, mockProducer); HttpAuthenticator auth = getAuthenticator(getName(), getName()); StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(channel)); stdHttp.setIgnoreServerResponseCode(false); stdHttp.registerConnection(new NullConnection()); stdHttp.setAuthenticator(auth); try { start(channel); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT); start(stdHttp); AdaptrisMessage reply = stdHttp.request(msg); fail(); } catch (ProduceException expected) { } finally { stop(stdHttp); HttpHelper.stopChannelAndRelease(channel); Thread.currentThread().setName(threadName); } }
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();   }