Skip to content

Commit

Permalink
fixes #17
Browse files Browse the repository at this point in the history
  • Loading branch information
hoegertn committed Aug 26, 2013
1 parent 281e948 commit 3ab5709
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.restdoc.server.impl.annotations;
package org.restdoc.annotations;

/*
* #%L Java Server implementation %% Copyright (C) 2012 RestDoc org %% Licensed under the Apache License, Version 2.0 (the "License"); you
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.restdoc.server.impl.annotations;
package org.restdoc.annotations;

/*
* #%L Java Server implementation %% Copyright (C) 2012 RestDoc org %% Licensed under the Apache License, Version 2.0 (the "License"); you
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.restdoc.server.impl.annotations;
package org.restdoc.annotations;

/*
* #%L Java Server implementation %% Copyright (C) 2012 RestDoc org %% Licensed under the Apache License, Version 2.0 (the "License"); you
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.restdoc.server.impl.annotations;
package org.restdoc.annotations;

/*
* #%L Java Server implementation %% Copyright (C) 2012 RestDoc org %% Licensed under the Apache License, Version 2.0 (the "License"); you
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.restdoc.server.impl.annotations;
package org.restdoc.annotations;

/*
* #%L Java Server implementation %% Copyright (C) 2012 RestDoc org %% Licensed under the Apache License, Version 2.0 (the "License"); you
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.restdoc.server.impl.annotations;
package org.restdoc.annotations;

/*
* #%L Java Server implementation %% Copyright (C) 2012 RestDoc org %% Licensed under the Apache License, Version 2.0 (the "License"); you
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.restdoc.server.impl.annotations;
package org.restdoc.annotations;

/*
* #%L Java Server implementation %% Copyright (C) 2012 RestDoc org %% Licensed under the Apache License, Version 2.0 (the "License"); you
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.restdoc.server.impl.annotations;
package org.restdoc.annotations;

/*
* #%L Java Server implementation %% Copyright (C) 2012 RestDoc org %% Licensed under the Apache License, Version 2.0 (the "License"); you
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.restdoc.server.impl.annotations;
package org.restdoc.annotations;

/*
* #%L Java Server implementation %% Copyright (C) 2012 RestDoc org %% Licensed under the Apache License, Version 2.0 (the "License"); you
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.restdoc.server.impl.annotations;
package org.restdoc.annotations;

/*
* #%L Java Server implementation %% Copyright (C) 2012 RestDoc org %% Licensed under the Apache License, Version 2.0 (the "License"); you
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.restdoc.server.impl.annotations;
package org.restdoc.annotations;

/*
* #%L Java Server implementation %% Copyright (C) 2012 RestDoc org %% Licensed under the Apache License, Version 2.0 (the "License"); you
Expand Down
68 changes: 34 additions & 34 deletions src/main/java/org/restdoc/server/impl/RestDocGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
*/

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -28,16 +30,21 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;

import org.restdoc.annotations.RestDocAccept;
import org.restdoc.annotations.RestDocHeader;
import org.restdoc.annotations.RestDocIgnore;
import org.restdoc.annotations.RestDocParam;
import org.restdoc.annotations.RestDocResponse;
import org.restdoc.annotations.RestDocReturnCode;
import org.restdoc.annotations.RestDocReturnCodes;
import org.restdoc.annotations.RestDocType;
import org.restdoc.annotations.RestDocValidation;
import org.restdoc.api.GlobalHeader;
import org.restdoc.api.HeaderDefinition;
import org.restdoc.api.MethodDefinition;
Expand All @@ -49,15 +56,6 @@
import org.restdoc.api.RestResource;
import org.restdoc.api.Schema;
import org.restdoc.api.util.RestDocParser;
import org.restdoc.server.impl.annotations.RestDocAccept;
import org.restdoc.server.impl.annotations.RestDocHeader;
import org.restdoc.server.impl.annotations.RestDocIgnore;
import org.restdoc.server.impl.annotations.RestDocParam;
import org.restdoc.server.impl.annotations.RestDocResponse;
import org.restdoc.server.impl.annotations.RestDocReturnCode;
import org.restdoc.server.impl.annotations.RestDocReturnCodes;
import org.restdoc.server.impl.annotations.RestDocType;
import org.restdoc.server.impl.annotations.RestDocValidation;
import org.restdoc.server.impl.util.MediaTypeResolver;
import org.restdoc.server.impl.util.SchemaResolver;
import org.slf4j.Logger;
Expand Down Expand Up @@ -157,11 +155,7 @@ private void addResourcesOfClass(final Class<?> apiClass, final String baseURI)
// find methods
final Method[] methods = apiClass.getMethods();
for (final Method method : methods) {
if (method.isAnnotationPresent(Path.class) || //
method.isAnnotationPresent(GET.class) || //
method.isAnnotationPresent(POST.class) || //
method.isAnnotationPresent(PUT.class) || //
method.isAnnotationPresent(DELETE.class)) {
if (method.isAnnotationPresent(Path.class) || (RestDocGenerator.getHTTPVerb(method) != null)) {
this.logger.debug("Generating RestDoc of method: " + method.toString());
this.addResourceMethod(basepath, method);
}
Expand All @@ -176,7 +170,7 @@ private void addResourceMethod(final String basepath, final Method method) {

// get needed annotations from method
final String methodType = RestDocGenerator.getHTTPVerb(method);
final org.restdoc.server.impl.annotations.RestDoc docAnnotation = method.getAnnotation(org.restdoc.server.impl.annotations.RestDoc.class);
final org.restdoc.annotations.RestDoc docAnnotation = method.getAnnotation(org.restdoc.annotations.RestDoc.class);
final Path pathAnnotation = method.getAnnotation(Path.class);

String path = basepath;
Expand Down Expand Up @@ -205,24 +199,11 @@ private void addResourceMethod(final String basepath, final Method method) {
path += "{?" + string + "}";
}

String id;
final String id;
if ((docAnnotation != null) && (docAnnotation.id() != null) && !docAnnotation.id().isEmpty()) {
id = docAnnotation.id();
} else {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] digest = md.digest(path.getBytes("UTF-8"));
BigInteger bigInt = new BigInteger(1, digest);
String hashtext = bigInt.toString(16);
// Now we need to zero pad it if you actually want the full 32 chars.
while (hashtext.length() < 32) {
hashtext = "0" + hashtext;
}
id = hashtext;
} catch (Exception e) {
this.logger.warn("Failed to generate MD5 sum", e);
id = method.getName();
}
id = this.getDefaultResourceId(method, path);
}
final String resourceDescription = (docAnnotation != null) ? docAnnotation.resourceDescription() : null;

Expand Down Expand Up @@ -261,6 +242,25 @@ private void addResourceMethod(final String basepath, final Method method) {
this.ext.newMethod(restResource, def, method);
}

private String getDefaultResourceId(final Method method, String path) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] digest = md.digest(path.getBytes("UTF-8"));
BigInteger bigInt = new BigInteger(1, digest);
String hashtext = bigInt.toString(16);
// Now we need to zero pad it if you actually want the full 32 chars.
while (hashtext.length() < 32) {
hashtext = "0" + hashtext;
}
return hashtext;
} catch (NoSuchAlgorithmException e) {
this.logger.warn("Failed to generate MD5 sum", e);
} catch (UnsupportedEncodingException e) {
this.logger.warn("Failed to generate MD5 sum", e);
}
return method.getName();
}

/**
* @param queryParams
* @param methodRequestHeader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import java.util.Collection;
import java.util.Map;

import org.restdoc.annotations.RestDocSchema;
import org.restdoc.api.Schema;
import org.restdoc.api.util.RestDocParser;
import org.restdoc.server.impl.IRestDocGeneratorExtension;
import org.restdoc.server.impl.RestDocException;
import org.restdoc.server.impl.annotations.RestDocSchema;

import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/restdoc/server/impl/Msg.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* and limitations under the License. #L%
*/

import org.restdoc.server.impl.annotations.RestDocSchema;
import org.restdoc.annotations.RestDocSchema;

/**
*
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/restdoc/server/impl/MyDeepRes.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

import org.restdoc.server.impl.annotations.RestDocIgnore;
import org.restdoc.server.impl.annotations.RestDocReturnCode;
import org.restdoc.server.impl.annotations.RestDocReturnCodes;
import org.restdoc.annotations.RestDocIgnore;
import org.restdoc.annotations.RestDocReturnCode;
import org.restdoc.annotations.RestDocReturnCodes;

@Produces("text/plain")
@Consumes("text/plain")
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/org/restdoc/server/impl/MyRSBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response.Status;

import org.restdoc.annotations.RestDoc;
import org.restdoc.annotations.RestDocHeader;
import org.restdoc.annotations.RestDocParam;
import org.restdoc.annotations.RestDocResponse;
import org.restdoc.annotations.RestDocReturnCode;
import org.restdoc.annotations.RestDocReturnCodes;
import org.restdoc.server.ext.oauth2.Scopes;
import org.restdoc.server.impl.annotations.RestDoc;
import org.restdoc.server.impl.annotations.RestDocHeader;
import org.restdoc.server.impl.annotations.RestDocParam;
import org.restdoc.server.impl.annotations.RestDocResponse;
import org.restdoc.server.impl.annotations.RestDocReturnCode;
import org.restdoc.server.impl.annotations.RestDocReturnCodes;

import com.google.common.collect.Maps;

Expand Down

0 comments on commit 3ab5709

Please sign in to comment.