Search in sources :

Example 6 with Multipart

use of org.apache.cxf.jaxrs.ext.multipart.Multipart in project cxf by apache.

the class WadlGenerator method doWriteParam.

// CHECKSTYLE:OFF
protected void doWriteParam(OperationResourceInfo ori, StringBuilder sb, Parameter pm, Class<?> type, Type genericType, String paramName, Annotation[] anns, boolean isJson) {
    // CHECKSTYLE:ON
    ParameterType pType = pm.getType();
    boolean isForm = isFormParameter(pm, type, anns);
    if (paramName == null && isForm) {
        Multipart m = AnnotationUtils.getAnnotation(anns, Multipart.class);
        if (m != null) {
            paramName = m.value();
        }
    }
    sb.append("<param name=\"").append(paramName).append("\" ");
    String style = ParameterType.PATH == pType ? "template" : isForm ? "query" : ParameterType.REQUEST_BODY == pType ? "plain" : pType.toString().toLowerCase();
    sb.append("style=\"").append(style).append("\"");
    if (pm.getDefaultValue() != null) {
        sb.append(" default=\"").append(xmlEncodeIfNeeded(pm.getDefaultValue())).append("\"");
    }
    if (InjectionUtils.isSupportedCollectionOrArray(type)) {
        type = InjectionUtils.getActualType(genericType);
        sb.append(" repeating=\"true\"");
    }
    String value = XmlSchemaPrimitiveUtils.getSchemaRepresentation(type);
    if (value == null) {
        if (type.isEnum()) {
            value = "xs:string";
        } else if (type == InputStream.class) {
            value = "xs:anyType";
        }
    }
    if (value != null) {
        if (isJson) {
            value = value.substring(3);
        }
        sb.append(" type=\"").append(value).append("\"");
    }
    if (type.isEnum()) {
        sb.append(">");
        handleDocs(anns, sb, DocTarget.PARAM, true, isJson);
        setEnumOptions(sb, type);
        sb.append("</param>");
    } else {
        addDocsAndCloseElement(ori, pm.getIndex(), sb, anns, "param", DocTarget.PARAM, true, isJson);
    }
}
Also used : ParameterType(org.apache.cxf.jaxrs.model.ParameterType) Multipart(org.apache.cxf.jaxrs.ext.multipart.Multipart) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 7 with Multipart

use of org.apache.cxf.jaxrs.ext.multipart.Multipart in project cxf by apache.

the class MultipartProvider method getRootMediaType.

private String getRootMediaType(Annotation[] anns, MediaType mt) {
    String mimeType = mt.getParameters().get("type");
    if (mimeType != null) {
        return mimeType;
    }
    Multipart id = AnnotationUtils.getAnnotation(anns, Multipart.class);
    if (id != null && !MediaType.WILDCARD.equals(id.type())) {
        mimeType = id.type();
    }
    if (mimeType == null) {
        if (PropertyUtils.isTrue(mc.getContextualProperty(Message.MTOM_ENABLED))) {
            mimeType = "text/xml";
        } else {
            mimeType = MediaType.APPLICATION_OCTET_STREAM;
        }
    }
    return mimeType;
}
Also used : Multipart(org.apache.cxf.jaxrs.ext.multipart.Multipart)

Aggregations

Multipart (org.apache.cxf.jaxrs.ext.multipart.Multipart)7 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Consumes (javax.ws.rs.Consumes)2 Attachment (org.apache.cxf.jaxrs.ext.multipart.Attachment)2 File (java.io.File)1 Method (java.lang.reflect.Method)1 URISyntaxException (java.net.URISyntaxException)1 URLClassLoader (java.net.URLClassLoader)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 DataHandler (javax.activation.DataHandler)1 ByteArrayDataSource (javax.mail.util.ByteArrayDataSource)1 FormParam (javax.ws.rs.FormParam)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 QueryParam (javax.ws.rs.QueryParam)1 AsyncResponse (javax.ws.rs.container.AsyncResponse)1