HTTP.Method method = HTTP.Method.valueOf(name); if (null != method) { parseMethodAndPath(method, expr);
protected HttpRequestBase newRequest(String url) { initRequest(); if (method.equals(Method.GET)) { request = new HttpGet(url); if (method.equals(Method.POST)) { request = new HttpPost(url); if (method.equals(Method.PUT)) { request = new HttpPut(url); if (method.equals(Method.DELETE)) { request = new HttpDelete(url); if (method.equals(Method.PATCH)) { request = new HttpPatch(url); if (method.equals(Method.HEAD)) { request = new HttpHead(url); if (method.equals(Method.OPTIONS)) { request = new HttpOptions(url); throw new IllegalStateException("Http method '" + method.name() + "' not supported now");
String method = op.getMethod().name().toLowerCase();
protected HttpRequestBase newRequest(String url) { initRequest(); if (method.equals(HTTP.Method.GET)) { request = new HttpGet(url); if (method.equals(HTTP.Method.POST)) { request = new HttpPost(url); if (method.equals(HTTP.Method.PUT)) { request = new HttpPut(url); if (method.equals(HTTP.Method.DELETE)) { request = new HttpDelete(url); if (method.equals(HTTP.Method.PATCH)) { request = new HttpPatch(url); if (method.equals(HTTP.Method.HEAD)) { request = new HttpHead(url); if (method.equals(HTTP.Method.OPTIONS)) { request = new HttpOptions(url); throw new IllegalStateException("Http method '" + method.name() + "' not supported now");
public static PathDef parse(String path, String filename) { PathDef pd = new PathDef(); int dotIndex = filename.indexOf('.'); String name = filename.substring(0, dotIndex); int atIndex = name.indexOf("@"); if(atIndex >= 0) { pd.method = HTTP.Method.valueOf(name.substring(atIndex + 1).toUpperCase()); if(atIndex == 0) { String[] parts = Strings.split(path, '/'); if(parts.length > 0) { pd.path = path; pd.name = parts[parts.length - 1]; }else{ pd.path = "/"; pd.name = pd.method.name().toLowerCase(); } }else{ pd.name = name.substring(0, atIndex); pd.path = path + "/" + pd.name; } }else{ pd.name = name; pd.path = path + "/" + pd.name; } return pd; } }
protected MApiParameterBuilder toApiParameter(MetaApi mapi, HTTP.Method method, MetaParameter mp) { MApiParameterBuilder p = new MApiParameterBuilder(); MetaUtils.copyNamed(mp, p); p.setRequired(mp.getRequired()); p.setLocation(mp.getLocation()); p.setFile(mp.isFile()); p.setType(mp.getResolvedType()); if (HTTP.Method.PATCH.equals(method)) { if(p.getType().isComplexTypeOrRef()) { Validators.setPartial(true); p.getOrCreateExtention().setAttribute("partial", true); } } ArgumentValidator validator = Validators.of(mapi, mp); if(null != validator) { p.addValidator(validator); } Validators.removePartial(); return p; }
private void initRequest(String url) { if(null != formBody) { requestBody = formBody.build(); }else if(null != body && body.length > 0) { requestBody = RequestBody.create(null, body); }else if(multipart != null && !multipart.isEmpty()) { requestBody = multipart.buildRequestBody(); } if(null != requestBody && method == null) { method = HTTP.Method.POST; } if(null == requestBody && HttpMethod.requiresRequestBody(method.name())) { requestBody = EMPTY_REQUEST_BODY; } request = new Request.Builder(); request.url(url); request.headers(headers.build()); request.method(method.name(), requestBody); } }
protected String initConnUrl() { String connUrl = url; if(!queryParams.isEmpty()) { connUrl = Urls.appendQueryString(connUrl, queryParams.build()); } if(null == method) { if(form || null != content) { method = HTTP.Method.POST; }else{ method = HTTP.Method.GET; } } //JDK Http Connection does not supports PATCH method. if(method == HTTP.Method.PATCH) { method = HTTP.Method.POST; addHeader(Headers.X_HTTP_METHOD_OVERRIDE, HTTP.Method.PATCH.name()); } return connUrl; }
protected void setApiMethod(ApiMetadataContext context, ApiMetadataBuilder m, Route route, MApiOperationBuilder op) { String method = route.getMethod(); if("*".equals(method)) { boolean hasBodyParameter = false; for(Argument a : route.getAction().getArguments()) { if(a.getLocation() == Location.REQUEST_BODY || a.getLocation() == Location.PART_PARAM) { hasBodyParameter = true; } } if(hasBodyParameter) { op.setMethod(HTTP.Method.POST); }else{ op.setMethod(HTTP.Method.GET); } }else{ op.setMethod(HTTP.Method.valueOf(method)); } }
@Override public void handleRequest(Request request, Response response, OAuth2Params params, Consumer<AuthzAccessToken> callback) throws Throwable { if(!HTTP.Method.valueOf(request.getMethod()).isPost()){ handleError(request,response,params, getOauth2Error(key -> OAuth2Errors.invalidRequestError(request,key,"this grant_type only accept post method."),INVALID_REQUEST_INVALID_HTTP_METHOD,"POST")); return; } AuthzClientCredentials credentials = new SamplingAuthzClientCredentials(params.getClientId(),params.getClientSecret()); AuthzClient client = validateClientSecret(request, response,credentials); if(client == null){ return; } callback.accept(tokenManager.createAccessToken(new SimpleAuthzAuthentication(params, client))); } }
@Override public void handleRequest(Request request, Response response, OAuth2Params params, Consumer<AuthzAccessToken> callback) throws Throwable { if(!HTTP.Method.valueOf(request.getMethod()).isPost()){ handleError(request,response,params, getOauth2Error(key -> OAuth2Errors.invalidRequestError(request,key,"this grant_type only accept post method."),INVALID_REQUEST_INVALID_HTTP_METHOD,"POST")); return; } AuthzClientCredentials credentials = new SamplingAuthzClientCredentials(params.getClientId(),params.getClientSecret()); AuthzClient client = validateClientSecret(request, response,credentials); if(client == null){ return; } callback.accept(tokenManager.createAccessToken(new SimpleAuthzAuthentication(params, client))); } }
public MetaOperation getOperation(String method, String path) { for (MetaOperation o : operations) { if (Strings.equalsIgnoreCase(o.getMethod().name(), method)) { if (Strings.equals(o.getPath(), path)) { return o; } } } return null; }
/** * Returns the matched operation. */ public MApiOperation getOperation(String path, String method) { return getPath(path).getOperation(HTTP.Method.valueOf(method)); }
public MApiOperation getOperation(HTTP.Method method){ for(MApiOperation op : operations) { if(op.getMethod().equals(method)) { return op; } } throw new ObjectNotFoundException("No operation with method '" + method + "' exists!"); } }
protected void writePath(WriteContext context, ApiMetadata m, JsonWriter w, MApiPath p) { w.startObject(); for(MApiOperation o : p.getOperations()) { if (checkProfile(o)) continue; w.property(o.getMethod().name().toLowerCase(), () -> { writeOperation(context, m, w, p, o); }); } w.endObject(); }
protected void setConnParams(HttpURLConnection conn, HTTP.Method m) throws IOException { if(connectTimeout > 0) { conn.setConnectTimeout(connectTimeout); } if(readTimeout > 0) { conn.setReadTimeout(readTimeout); } conn.setRequestMethod(m.name()); conn.setUseCaches(false); conn.setInstanceFollowRedirects(false); }
public MApiOperationBuilder getOperation(String method) { for(MApiOperationBuilder op : operations) { if(op.getMethod().name().equalsIgnoreCase(method)) { return op; } } return null; }