Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -228,31 +228,36 @@ private JFieldRef setCookies(ExecutableElement executableElement, RestHolder res
* that it behaves as it did previous to this feature.
*/
private void insertRestTryCatchBlock(RestHolder holder, JBlock body, JExpression returnCall, boolean methodReturnVoid) {
JTryBlock tryBlock = body._try();
JBlock returnCallBody = body;

if (methodReturnVoid) {
tryBlock.body().add((JInvocation) returnCall);
} else {
tryBlock.body()._return(returnCall);
}
if (holder.getRestErrorHandlerField() != null) {
JTryBlock tryBlock = body._try();
returnCallBody = tryBlock.body();

JCatchBlock jCatch = tryBlock._catch(classes().REST_CLIENT_EXCEPTION);

JCatchBlock jCatch = tryBlock._catch(classes().REST_CLIENT_EXCEPTION);
JBlock catchBlock = jCatch.body();
JConditional conditional = catchBlock._if(JOp.ne(holder.getRestErrorHandlerField(), JExpr._null()));
JVar exceptionParam = jCatch.param("e");

JBlock catchBlock = jCatch.body();
JConditional conditional = catchBlock._if(JOp.ne(holder.getRestErrorHandlerField(), JExpr._null()));
JVar exceptionParam = jCatch.param("e");
JBlock thenBlock = conditional._then();

JBlock thenBlock = conditional._then();
// call the handler method if it was set.
thenBlock.add(holder.getRestErrorHandlerField().invoke("onRestClientExceptionThrown").arg(exceptionParam));

// call the handler method if it was set.
thenBlock.add(holder.getRestErrorHandlerField().invoke("onRestClientExceptionThrown").arg(exceptionParam));
// return null if exception was caught and handled.
if (!methodReturnVoid) {
thenBlock._return(JExpr._null());
}

// return null if exception was caught and handled.
if (!methodReturnVoid) {
thenBlock._return(JExpr._null());
// re-throw the exception if handler wasn't set.
conditional._else()._throw(exceptionParam);
}

// re-throw the exception if handler wasn't set.
conditional._else()._throw(exceptionParam);
if (methodReturnVoid) {
returnCallBody.add((JInvocation) returnCall);
} else {
returnCallBody._return(returnCall);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ private void implementSetErrorHandler(List<ExecutableElement> methods) {
JMethod setErrorHandlerMethod = codeModelHelper.implementMethod(this, methods, "setRestErrorHandler", TypeKind.VOID.toString(), RestErrorHandler.class.getName());

if (setErrorHandlerMethod != null) {
setRestErrorHandlerField();
setErrorHandlerMethod.body().assign(_this().ref(getRestErrorHandlerField()), setErrorHandlerMethod.params().get(0));
}
}
Expand Down Expand Up @@ -256,9 +257,7 @@ private void setAuthenticationField() {
}

public JFieldVar getRestErrorHandlerField() {
if (restErrorHandlerField == null) {
setRestErrorHandlerField();
}
// restErrorHandlerField is created only if the method setRestErrorHandler is implemented
return restErrorHandlerField;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@
import org.androidannotations.annotations.rest.Post;
import org.androidannotations.annotations.rest.Put;
import org.androidannotations.annotations.rest.Rest;
import org.androidannotations.api.rest.RestClientErrorHandling;
import org.androidannotations.api.rest.RestErrorHandler;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

// if defined, the rootUrl will be added as a prefix to every request
@Rest(rootUrl = "http://company.com/ajax/services", converters = { MappingJacksonHttpMessageConverter.class }, interceptors = { RequestInterceptor.class })
public interface HttpMethodsService {
public interface HttpMethodsService extends RestClientErrorHandling {

@Delete("/delete/")
void delete();
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.