Repository: cxf Updated Branches: refs/heads/master f49b63e54 -> 05a7ad32b
Fixing build Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/05a7ad32 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/05a7ad32 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/05a7ad32 Branch: refs/heads/master Commit: 05a7ad32b06dc800d31cffbb39df5be16f847849 Parents: f49b63e Author: Colm O hEigeartaigh <[email protected]> Authored: Mon Apr 20 16:50:25 2015 +0100 Committer: Colm O hEigeartaigh <[email protected]> Committed: Mon Apr 20 16:50:25 2015 +0100 ---------------------------------------------------------------------- .../java/demo/jaxrs/search/server/Catalog.java | 19 +++---------------- .../java/demo/jaxrs/search/server/Storage.java | 17 ++--------------- .../main/java/demo/throttling/client/Client.java | 2 +- .../java/demo/throttling/server/Customer.java | 8 +++++--- .../server/CustomerMetricsInterceptor.java | 2 +- 5 files changed, 12 insertions(+), 36 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/05a7ad32/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Catalog.java ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Catalog.java b/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Catalog.java index 1f66ecb..87bd2c4 100644 --- a/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Catalog.java +++ b/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Catalog.java @@ -233,18 +233,11 @@ public class Catalog { return new StreamingOutput() { @Override public void write(final OutputStream out) throws IOException, WebApplicationException { - InputStream in = null; - - try { - in = storage.getDocument(source); + try (InputStream in = storage.getDocument(source)) { out.write(IOUtils.readBytesFromStream(in)); } catch (final FileNotFoundException ex) { throw new NotFoundException("Document does not exist: " + source); - } finally { - if (in != null) { - try { in.close(); } catch (IOException ex) { /* do nothing */ } - } - } + } } }; } @@ -304,9 +297,7 @@ public class Catalog { private void storeAndIndex(final LuceneDocumentMetadata metadata, final byte[] content) throws IOException { - BufferedInputStream in = null; - try { - in = new BufferedInputStream(new ByteArrayInputStream(content)); + try (BufferedInputStream in = new BufferedInputStream(new ByteArrayInputStream(content))) { final Document document = extractor.extract(in, metadata); if (document != null) { @@ -320,10 +311,6 @@ public class Catalog { writer.close(); } } - } finally { - if (in != null) { - try { in.close(); } catch (IOException ex) { /* do nothing */ } - } } } } http://git-wip-us.apache.org/repos/asf/cxf/blob/05a7ad32/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Storage.java ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Storage.java b/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Storage.java index c35a416..aa3ef2c 100644 --- a/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Storage.java +++ b/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Storage.java @@ -44,15 +44,8 @@ public class Storage { } public void addDocument(final String name, final byte[] content) throws IOException { - InputStream in = null; - - try { - in = new ByteArrayInputStream(content); + try (InputStream in = new ByteArrayInputStream(content)) { addDocument(name, in); - } finally { - if (in != null) { - try { in.close(); } catch (IOException ex) { /* do nothing */ } - } } } @@ -63,16 +56,10 @@ public class Storage { throw new IOException("Unable to delete FS file:" + f.getAbsolutePath()); } - OutputStream out = null; - try { - out = new BufferedOutputStream(new FileOutputStream(f)); + try (OutputStream out = new BufferedOutputStream(new FileOutputStream(f))) { out.write(IOUtils.readBytesFromStream(in)); f.deleteOnExit(); - } finally { - if (out != null) { - try { out.close(); } catch (IOException ex) { /* do nothing */ } - } } } http://git-wip-us.apache.org/repos/asf/cxf/blob/05a7ad32/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/client/Client.java ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/client/Client.java b/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/client/Client.java index 85979be..925740e 100644 --- a/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/client/Client.java +++ b/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/client/Client.java @@ -70,7 +70,7 @@ public final class Client implements Runnable { x++; } while (x < 10000); } catch (javax.xml.ws.WebServiceException wse) { - if (wse.getCause().getMessage().contains("429")){ + if (wse.getCause().getMessage().contains("429")) { //exceeded are allowable number of requests exceeded = true; } else { http://git-wip-us.apache.org/repos/asf/cxf/blob/05a7ad32/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/Customer.java ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/Customer.java b/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/Customer.java index 8436ded..d2e978d 100644 --- a/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/Customer.java +++ b/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/Customer.java @@ -38,7 +38,7 @@ public abstract class Customer { MetricsContext getMetricsContext(MetricRegistry registry) { if (metrics == null) { - metrics = new CodahaleMetricsContext("demo.server:customer=" + name +",type=Customer,", registry); + metrics = new CodahaleMetricsContext("demo.server:customer=" + name + ",type=Customer,", registry); } return metrics; } @@ -59,7 +59,8 @@ public abstract class Customer { super(n); } public void throttle(ThrottleResponse m) { - //System.out.println("p " + metrics.getTotals().getOneMinuteRate() + " " + metrics.getTotals().getCount()); + //System.out.println("p " + metrics.getTotals().getOneMinuteRate() + // + " " + metrics.getTotals().getCount()); //Preferred customers are unthrottled until they hit 100req/sec, then start delaying by .05 seconds //(drops to max of 50req/sec until below the 100req/sec rate) if (metrics.getTotals().getOneMinuteRate() > 100) { @@ -89,7 +90,8 @@ public abstract class Customer { super(n); } public void throttle(ThrottleResponse m) { - //System.out.println("ch " + metrics.getTotals().getOneMinuteRate() + " " + metrics.getTotals().getCount()); + //System.out.println("ch " + metrics.getTotals().getOneMinuteRate() + // + " " + metrics.getTotals().getCount()); //Cheap customers are always get a .1 sec delay long delay = 100; //Then they get futher throttled dependending on rates http://git-wip-us.apache.org/repos/asf/cxf/blob/05a7ad32/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/CustomerMetricsInterceptor.java ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/CustomerMetricsInterceptor.java b/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/CustomerMetricsInterceptor.java index 8339ad3..5d05678 100644 --- a/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/CustomerMetricsInterceptor.java +++ b/distribution/src/main/release/samples/throttling/src/main/java/demo/throttling/server/CustomerMetricsInterceptor.java @@ -49,7 +49,7 @@ public class CustomerMetricsInterceptor extends AbstractPhaseInterceptor<Message public void handleMessage(Message message) throws Fault { ExchangeMetrics m = message.getExchange().get(ExchangeMetrics.class); if (m != null) { - Map<String, List<String>> h = CastUtils.cast((Map<?,?>)message.get(Message.PROTOCOL_HEADERS)); + Map<String, List<String>> h = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS)); String auth = h.get("Authorization").toString(); auth = auth.substring(auth.indexOf(' ') + 1); try {
