/** * See {@link #setContentLength(int)} for the reasons for proxying. * * @param len * parameter of the proxied method */ @ProxyMethod public void setContentLengthLong(final long len) { contentLengthHeaderModifications.add(new Runnable() { @Override public void run() { wrappedResponse.setContentLengthLong(len); } }); }
@BeforeMethod public void initProxy() throws InvalidProxyDescriptionException { subject = new CorrectProxySubject(); ClassLoader cl = new RenamingClassLoader(this.getClass().getClassLoader(), "moved.", ClassToProxy.class, InterfaceToProxy.class); IProxyBuildPlan plan = ProxyBuildPlanImpl.create(CorrectProxySubject.class, "proxy_" + counter.getAndIncrement(), cl); proxy = builder.createProxyClass(plan).createProxy(subject); }
@Test(expectedExceptions = FileNotFoundException.class) public void testExceptionPassing() throws Throwable { callProxy("throwException"); }
/** * Overrides setContentLength to consume the call and to postpone it. When we inject our script * tag, the content length is not known beforehand. Therefore, in case we perform an injection, * we have to force chunked encoding by not setting any content length. * * @param len * the parameter from the proxied method. */ @ProxyMethod public void setContentLength(final int len) { contentLengthHeaderModifications.add(new Runnable() { @Override public void run() { wrappedResponse.setContentLength(len); } }); }
@ProxyMethod public String sayHello() { return "Hello!"; }
@ProxyMethod(methodName = "doubleInt") public int doubleInt_renamed(int a) { return 2 * a; }
@Override @ProxyMethod public void flush() throws IOException { originalStream.flush(); }
@Override @ProxyMethod public void close() throws IOException { originalStream.close(); }
/** * Proxy method for isReady method of the OutputStream. * * @return the ready state */ @ProxyMethod(isOptional = true) public boolean isReady() { return originalStream.isReady(); }
/** * Proxy method for setting the write listener. * * @param listener * write listener which should get set. */ @ProxyMethod(parameterTypes = { "javax.servlet.WriteListener" }, isOptional = true) public void setWriteListener(Object listener) { originalStream.setWriteListener(listener); }
/** * Response status event. We can capture status here. * * @param version * version * @param status * status * @param reason * reason * @throws IOException * IOException */ @ProxyMethod(parameterTypes = { "org.eclipse.jetty.io.Buffer", "int", "org.eclipse.jetty.io.Buffer" }) public void onResponseStatus(Object version, int status, Object reason) throws IOException { this.status = status; if (null != originalListener) { WHttpEventListenerWrapper.ON_RESPONSE_STATUS.call(originalListener, version, status, reason); } }
@ProxyMethod public void throwException() throws FileNotFoundException { throw new FileNotFoundException("testtext"); }
@ProxyMethod(returnType = "java.lang.StringBuffer") public Object createStringBuffer() { return new StringBuffer(); }
@ProxyMethod(parameterTypes = { "java.lang.StringBuffer", "java.lang.String" }) public void appendToStringBuffer(Object sb, Object stringToAppend) { ((StringBuffer) sb).append((String) stringToAppend); }
/** * Exception occurred. * * @param ex * Throwable */ @ProxyMethod(parameterTypes = "java.lang.Throwable") public void onException(Throwable ex) { handleThrowable(ex); if (null != originalListener) { WHttpEventListenerWrapper.ON_EXCEPTION.call(originalListener, ex); } }
/** * Request committed event. This is earliest place we can start a span. * * @throws IOException * IOException */ @ProxyMethod() public void onRequestCommitted() throws IOException { spanStore.startSpan(); if (null != originalListener) { WHttpEventListenerWrapper.ON_REQUEST_COMMITED.call(originalListener); } }
/** * Connection failed. * * @param ex * Throwable */ @ProxyMethod(parameterTypes = "java.lang.Throwable") public void onConnectionFailed(Throwable ex) { handleThrowable(ex); if (null != originalListener) { WHttpEventListenerWrapper.ON_CONNECTION_FAILED.call(originalListener, ex); } }
@Override @ProxyMethod public void write(byte[] b) throws IOException { byte[] newValue = injector.performInjection(b); if (newValue == null) { originalStream.write(b); } else { originalStream.write(newValue); } }
@Override @ProxyMethod public void write(byte[] b, int off, int len) throws IOException { byte[] newValue = injector.performInjection(b, off, len); if (newValue == null) { originalStream.write(b, off, len); } else { originalStream.write(newValue); } }
@Override @ProxyMethod public void write(int b) throws IOException { byte[] newValue = injector.performInjection(new byte[] { (byte) b }); if (newValue == null) { originalStream.write(b); } else { originalStream.write(newValue); } }