@Override public String getMediaType(){ MimeType contentType = getContentType(); return null == contentType ? null : contentType.getMediaType(); }
protected boolean isSupportedProduce(String produce) { for(ResponseFormat format : supportedProduces) { if(null != format.getPrimaryMimeType() && format.getPrimaryMimeType().getMediaType().equalsIgnoreCase(produce)) { return true; } } return false; }
protected void preConfigure(RestdContext context, RouteBuilder route, FuncActionBuilder action, MApiOperationBuilder mo) { if(null == mo) { return; } for(String consume : mo.getConsumes()) { for(RequestFormat format : supportedConsumes) { if(null != format.getPrimaryMimeType() && format.getPrimaryMimeType().getMediaType().equalsIgnoreCase(consume)) { action.addConsume(format); break; } } } for(String produce : mo.getProduces()) { for(ResponseFormat format : supportedProduces) { if(null != format.getPrimaryMimeType() && format.getPrimaryMimeType().getMediaType().equalsIgnoreCase(produce)) { action.addProduce(format); break; } } } }
@Override public THttpResponse send() { String url = buildRequestUrl(); try { initRequest(url); log.debug("Sending '{}' request to '{}'...", method, url); OkTHttpResponse response = new OkTHttpResponse(this, httpClient.newCall(request.build()).execute()); if(log.isDebugEnabled()) { log.debug("Response result : [status={}, content-type='{}', content-length={}]", response.getStatus(), response.getContentType(), response.getContentLength()); MimeType contentType = response.getContentType(); if(null != contentType && ContentTypes.isText(contentType.getMediaType())) { log.debug("Content -> \n{}", Strings.abbreviate(response.getContent(), 200)); } } return response; } catch (Exception e) { throw new HttpException("Error send http request : " + e.getMessage(),e); } }