@Override public String getMediaType() { return delegate.getMediaType(); }
@Override public String getMediaType() { return delegate.getMediaType(); }
/** * Returns the qname of the element that has the first parameter as the namespace, the second as the element. * * @param list The arguments. * @return The qname. */ public Object exec(List list) throws TemplateModelException { if (list.size() < 1) { throw new TemplateModelException("The MediaTypeForMethod must have a entity as a parameter."); } TemplateModel from = (TemplateModel) list.get(0); Object unwrapped = DeepUnwrap.unwrap(from); if (unwrapped instanceof Entity) { List<? extends MediaTypeDescriptor> mediaTypes = ((Entity) unwrapped).getMediaTypes(); if (mediaTypes != null && !mediaTypes.isEmpty()) { for (MediaTypeDescriptor mediaType : mediaTypes) { if (mediaType.getMediaType().contains("xml")) { return mediaType.getMediaType(); } } } } return "application/xml"; }
/** * Returns the qname of the element that has the first parameter as the namespace, the second as the element. * * @param list The arguments. * @return The qname. */ public Object exec(List list) throws TemplateModelException { if (list.size() < 1) { throw new TemplateModelException("The MediaTypeForMethod must have a entity as a parameter."); } TemplateModel from = (TemplateModel) list.get(0); Object unwrapped = DeepUnwrap.unwrap(from); if (unwrapped instanceof Entity) { List<? extends MediaTypeDescriptor> mediaTypes = ((Entity) unwrapped).getMediaTypes(); if (mediaTypes != null && !mediaTypes.isEmpty()) { for (MediaTypeDescriptor mediaType : mediaTypes) { if (mediaType.getMediaType().contains("json")) { return mediaType.getMediaType(); } } } } return "application/json"; }
/** * Returns the qname of the element that has the first parameter as the namespace, the second as the element. * * @param list The arguments. * @return The qname. */ public Object exec(List list) throws TemplateModelException { if (list.size() < 1) { throw new TemplateModelException("The MediaTypeForMethod must have a entity as a parameter."); } TemplateModel from = (TemplateModel) list.get(0); Object unwrapped = DeepUnwrap.unwrap(from); if (unwrapped instanceof Entity) { List<? extends MediaTypeDescriptor> mediaTypes = ((Entity) unwrapped).getMediaTypes(); if (mediaTypes != null && !mediaTypes.isEmpty()) { for (MediaTypeDescriptor mediaType : mediaTypes) { if (mediaType.getMediaType().contains("xml")) { return mediaType.getMediaType(); } } } } return "application/xml"; }
/** * Returns the qname of the element that has the first parameter as the namespace, the second as the element. * * @param list The arguments. * @return The qname. */ public Object exec(List list) throws TemplateModelException { if (list.size() < 1) { throw new TemplateModelException("The MediaTypeForMethod must have a entity as a parameter."); } TemplateModel from = (TemplateModel) list.get(0); Object unwrapped = DeepUnwrap.unwrap(from); if (unwrapped instanceof Entity) { List<? extends MediaTypeDescriptor> mediaTypes = ((Entity) unwrapped).getMediaTypes(); if (mediaTypes != null && !mediaTypes.isEmpty()) { for (MediaTypeDescriptor mediaType : mediaTypes) { if (mediaType.getMediaType().contains("json")) { return mediaType.getMediaType(); } } } } return "application/json"; }
builder.append("Content-Type: ").append(this.responseDescriptor.getMediaType()).append("\n");
@Override public String getResponseHeaders() { int responseCode = "POST".equalsIgnoreCase(this.httpMethod) ? 201 : "PUT".equalsIgnoreCase(this.httpMethod) ? 204 : "DELETE".equalsIgnoreCase(this.httpMethod) ? 204 : 200; List<? extends ResponseCode> statusCodes = this.resourceMethod.getStatusCodes(); if (statusCodes != null && !statusCodes.isEmpty()) { for (ResponseCode code : statusCodes) { if (code.getCode() >= 200 && code.getCode() < 400) { responseCode = code.getCode(); break; } } } String message = "Custom Message"; Response.Status status = Response.Status.fromStatusCode(responseCode); if (status != null) { message = status.getReasonPhrase(); } StringBuilder builder = new StringBuilder("HTTP/1.1 ").append(responseCode).append(' ').append(message).append("\n"); if (this.responseDescriptor != null) { builder.append("Content-Type: ").append(this.responseDescriptor.getMediaType()).append("\n"); } for (String responseHeader : this.resourceMethod.getResponseHeaders().keySet()) { if ("content-type".equalsIgnoreCase(responseHeader) && this.responseDescriptor != null) { continue; } builder.append(responseHeader).append(": ").append("...").append("\n"); } return builder.toString(); }
builder.append("Content-Type: ").append(this.requestDescriptor.getMediaType()).append("\n"); builder.append("Accept: ").append(this.responseDescriptor.getMediaType()).append("\n");
builder.append("Content-Type: ").append(this.requestDescriptor.getMediaType()).append("\n"); builder.append("Accept: ").append(this.responseDescriptor.getMediaType()).append("\n");
public Object exec(List list) throws TemplateModelException { if (list.size() < 1) { throw new TemplateModelException("The uniqueMediaTypesFor method must have a parameter."); } TemplateModel from = (TemplateModel) list.get(0); Object unwrapped = new BeansWrapperBuilder(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS).build().unwrap(from); HashMap<String, MediaTypeDescriptor> uniqueMediaTypes = new HashMap<String, MediaTypeDescriptor>(); if (unwrapped instanceof Entity) { Entity entity = (Entity) unwrapped; List<? extends MediaTypeDescriptor> mts = entity.getMediaTypes(); if (mts != null) { for (MediaTypeDescriptor mt : mts) { uniqueMediaTypes.put(mt.getMediaType(), mt); } } } ArrayList<MediaTypeDescriptor> orderedTypes = new ArrayList<>(uniqueMediaTypes.values()); Collections.sort(orderedTypes, (m1, m2) -> { String syntax1 = m1.getSyntax() == null ? "" : m1.getSyntax(); String syntax2 = m2.getSyntax() == null ? "" : m2.getSyntax(); return syntax1.compareTo(syntax2); }); return orderedTypes; } }
String mt = mediaTypeDescriptor.getMediaType(); if (mt != null) { mt = mt.toLowerCase();
if (mts != null) { for (MediaTypeDescriptor mt : mts) { if (mt.getMediaType().endsWith("json")) { DataTypeReference dataType = mt.getDataType(); if (dataType != null && dataType.getBaseType() == BaseType.object) { String body = example.getBody(); if (body != null) { uniqueMediaTypes.put(mt.getMediaType(), body);
if (typeReference instanceof DataTypeReferenceImpl) { return ((DataTypeReferenceImpl) typeReference).getElementQName(); } else if (associateJsonWithXml && mt.getMediaType().endsWith("json")) { DataType dataType = typeReference.getValue(); if (dataType != null) {
if (typeReference instanceof DataTypeReferenceImpl) { return ((DataTypeReferenceImpl) typeReference).getElementQName(); } else if (associateJsonWithXml && mt.getMediaType().endsWith("json")) { DataType dataType = typeReference.getValue(); if (dataType != null) {