reversed pull 239 as it broke the build

This commit is contained in:
Adrian Cole 2011-12-13 11:45:49 -08:00
parent 840ee92f07
commit 993cd08bbc
3 changed files with 2 additions and 55 deletions

View File

@ -46,7 +46,7 @@ public class BindS3ObjectMetadataToRequest implements Binder {
@Override @Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) { public <R extends HttpRequest> R bindToRequest(R request, Object input) {
checkArgument(checkNotNull(input, "input") instanceof S3Object, "this binder is only valid for S3Object!"); checkArgument(checkNotNull(input, "input") instanceof S3Object, "this binder is only valid for S3Object!, not %s", input);
checkNotNull(request, "request"); checkNotNull(request, "request");
S3Object s3Object = S3Object.class.cast(input); S3Object s3Object = S3Object.class.cast(input);

View File

@ -944,7 +944,6 @@ public class RestAnnotationProcessor<T> {
public GeneratedHttpRequest<T> decorateRequest(GeneratedHttpRequest<T> request) throws NegativeArraySizeException, public GeneratedHttpRequest<T> decorateRequest(GeneratedHttpRequest<T> request) throws NegativeArraySizeException,
ExecutionException { ExecutionException {
Cache<Integer, Set<Annotation>> indexToParamExtractor = methodToIndexOfParamToParamParserAnnotations.get(request.getJavaMethod());
OUTER: for (Entry<Integer, Set<Annotation>> entry : concat(// OUTER: for (Entry<Integer, Set<Annotation>> entry : concat(//
filterValues(methodToIndexOfParamToBinderParamAnnotation.get(request.getJavaMethod()).asMap(), notEmpty) filterValues(methodToIndexOfParamToBinderParamAnnotation.get(request.getJavaMethod()).asMap(), notEmpty)
.entrySet(), // .entrySet(), //
@ -979,17 +978,7 @@ public class RestAnnotationProcessor<T> {
} }
} }
if (input != null) { if (input != null) {
// Allow the input parameter to be parsed by the ParamParser before binding request = binder.bindToRequest(request, input);
Set<Annotation> extractors = indexToParamExtractor.get(entry.getKey());
Object parsedValue = null;
if (extractors != null && extractors.size() > 0) {
ParamParser extractor = (ParamParser) extractors.iterator().next();
parsedValue = injector.getInstance(extractor.value()).apply(input);
} else {
parsedValue = input;
}
request = binder.bindToRequest(request, parsedValue);
} }
if (shouldBreak) if (shouldBreak)
break OUTER; break OUTER;

View File

@ -2537,48 +2537,6 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
assertEquals(domain.getElem(), "Hello World"); assertEquals(domain.getElem(), "Hello World");
} }
public static class AppendTextParser implements Function<Object, String> {
@Override
public String apply(Object input)
{
return input.toString() + "PARSED";
}
}
public interface TestBindWithParamParser {
@GET
@Path("/foo")
public ListenableFuture<String> bindWithoutParsing(
@BinderParam(BindToStringPayload.class) String param);
@GET
@Path("/bar")
public ListenableFuture<String> bindAfterParsing(
@BinderParam(BindToStringPayload.class) @ParamParser(AppendTextParser.class) String param);
}
@Test
public void testBindWithoutParamParser() throws SecurityException, NoSuchMethodException, IOException {
RestAnnotationProcessor<TestBindWithParamParser> processor = factory(TestBindWithParamParser.class);
Method method = TestBindWithParamParser.class.getMethod("bindWithoutParsing", String.class);
GeneratedHttpRequest<TestBindWithParamParser> request = processor.createRequest(method, "test");
assertRequestLineEquals(request, "GET http://localhost:9999/foo HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, "test", "application/unknown", false);
}
@Test
public void testBindWithParamParser() throws SecurityException, NoSuchMethodException, IOException {
RestAnnotationProcessor<TestBindWithParamParser> processor = factory(TestBindWithParamParser.class);
Method method = TestBindWithParamParser.class.getMethod("bindAfterParsing", String.class);
GeneratedHttpRequest<TestBindWithParamParser> request = processor.createRequest(method, "test");
assertRequestLineEquals(request, "GET http://localhost:9999/bar HTTP/1.1");
assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, "testPARSED", "application/unknown", false);
}
@Test(expectedExceptions = NullPointerException.class) @Test(expectedExceptions = NullPointerException.class)
public void testAddHostNullWithHost() throws Exception{ public void testAddHostNullWithHost() throws Exception{
assertNull(RestAnnotationProcessor.addHostIfMissing(null,null)); assertNull(RestAnnotationProcessor.addHostIfMissing(null,null));