@Override public String getBodyClass() { return action.getBodyClass(); }
@Override public Object getBodyParam() { return action.getBodyParam(); }
@Override public List<ContentType> getClientConsumedContentTypes() { return action.getClientConsumedContentTypes(); }
path = builder.template.getPath(); httpMethod = builder.template.getHttpMethod(); queryCount = builder.template.getParameters(Type.QUERY).size(); if (!action.getPath().startsWith(path)) { return false; } else if (!action.getPath().equals(path)) { return false; if (!action.getHttpMethod().equals(httpMethod)) { return false; List<HttpParameter> queryParams = action.getParameters(Type.QUERY); if (queryParams.size() != queryCount) { return false; } else if (useTemplate()) { if (!queryParams.equals(builder.template.getParameters(Type.QUERY))) { return false;
private List<HttpParameter> getParameters(RestAction<?> action, Type type) { List<HttpParameter> queryParams = new ArrayList<>(); queryParams.addAll(globalQueryParams.get(action.getHttpMethod())); queryParams.addAll(action.getParameters(type)); return queryParams; }
private String buildPath(RestAction<?> action) { List<HttpParameter> params = action.getParameters(Type.PATH); String path = action.getPath(); for (HttpParameter param : params) { List<Entry<String, String>> entries = param.getEncodedEntries(); assert entries.size() == 1; Entry<String, String> entry = entries.get(0); path = path.replace("{" + entry.getKey() + "}", entry.getValue()); } return path; }
private SerializedValue getSerializedValue(RestAction<?> action, Object object) throws ActionException { String bodyClass = action.getBodyClass(); if (bodyClass != null) { List<ContentType> contentTypes = action.getClientProducedContentTypes(); Serialization serialization = findSerialization(bodyClass, contentTypes); if (serialization != null) { return serialize(serialization, object, bodyClass, contentTypes); } } throw new ActionException("Unable to serialize request body. No serializer found."); }
private void assignBodyFromSerialization(RequestBuilder requestBuilder, RestAction<?> action) throws ActionException { String data; if (action.hasBodyParam()) { SerializedValue serializedValue = getSerializedValue(action, action.getBodyParam()); ContentType contentType = serializedValue.getContentType(); data = serializedValue.getData(); requestBuilder.setHeader(HttpHeaders.CONTENT_TYPE, contentType.toString()); } else { // Fixes an issue for all IE versions (IE 11 is the latest at this time). If request data is not // explicitly set to 'null', the JS 'undefined' will be sent as the request body on IE. Other // browsers don't send undefined bodies. data = null; } requestBuilder.setRequestData(data); }
private void addActionHeaders(RestAction<?> action, List<HttpParameter> headerParams) { headerParams.addAll(action.getParameters(Type.HEADER)); }
@Override public String getPath() { return action.getPath(); }
@Override public HttpMethod getHttpMethod() { return action.getHttpMethod(); }
@Override public Boolean hasFormParams() { return action.hasFormParams(); }
@Override public String getResultClass() { return action.getResultClass(); }
@Override public List<ContentType> getClientProducedContentTypes() { return action.getClientProducedContentTypes(); }
@Override public Boolean hasBodyParam() { return action.hasBodyParam(); }
@Override public void saveCookiesFromAction(RestAction<?> action) { List<HttpParameter> parameters = action.getParameters(Type.COOKIE); for (HttpParameter parameter : parameters) { assert parameter instanceof CookieParameter; saveCookiesFromParameter((CookieParameter) parameter); } }
private String buildPrefix(RestAction<?> action) { String prefix = ""; if (!isAbsoluteUrl(action.getPath())) { prefix = applicationPathProvider.get(); } return prefix; }
private void addGlobalHeaders(RestAction<?> action, List<HttpParameter> headerParams) { headerParams.addAll(globalParams.get(action.getHttpMethod())); }
@Override public void buildBody(RequestBuilder requestBuilder, RestAction<?> action) throws ActionException { if (action.hasFormParams()) { assignBodyFromForm(requestBuilder, action); } else { assignBodyFromSerialization(requestBuilder, action); } }
private <R> R getDeserializedResponse(RestAction<R> action, Response response) throws ActionException { String resultClass = action.getResultClass(); if (resultClass != null) { ContentType contentType = ContentType.valueOf(response.getHeader(HttpHeaders.CONTENT_TYPE)); Serialization serialization = findSerialization(resultClass, contentType); if (serialization != null) { return deserializeValue(serialization, resultClass, contentType, response.getText()); } } throw new ActionException("Unable to deserialize response. No serializer found."); }