Package org.jboss.resteasy.plugins.providers.multipart

Examples of org.jboss.resteasy.plugins.providers.multipart.InputPart


    Iterator<String> partNames = formData.keySet().iterator();

    while(partNames.hasNext())
    {
      final String partName = partNames.next();
      final InputPart part = formData.get(partName);
      final MediaType mediaType = part.getMediaType();

      if(MediaType.TEXT_PLAIN_TYPE.equals(mediaType))
      {
        // RFC2045: Each part has an optional "Content-Type" header
        // that defaults to "text/plain".
        // Can go into process without conversion
        if(mapping.isReserved(partName))
          mapping.directives.put(partName, part.getBodyAsString());
        else
          mapping.processVars.put(partName, part.getBodyAsString());
      }
      else
      {
        // anything else turns into a DataHandler
        final byte[] data = part.getBodyAsString().getBytes();
        DataHandler dh = new DataHandler(
            new DataSource()
            {
              public InputStream getInputStream() throws IOException
              {
View Full Code Here


    Iterator<String> partNames = formData.keySet().iterator();

    while(partNames.hasNext())
    {
      final String partName = partNames.next();
      final InputPart part = formData.get(partName);
      final MediaType mediaType = part.getMediaType();

      String mType = mediaType.getType();
      String mSubtype = mediaType.getSubtype();

      try{
          if("text".equals(mType) && "plain".equals(mSubtype))
          {
            // RFC2045: Each part has an optional "Content-Type" header
            // that defaults to "text/plain".
            // Can go into process without conversion
            if(mapping.isReserved(partName))
              mapping.directives.put(partName, part.getBodyAsString());
            else
              mapping.processVars.put(partName, part.getBodyAsString());
          }
          else
          {
            // anything else turns into a DataHandler
            final byte[] data = part.getBodyAsString().getBytes();
            DataHandler dh = new DataHandler(
                new DataSource()
                {
                  public InputStream getInputStream() throws IOException
                  {
View Full Code Here

    Iterator<String> partNames = formData.keySet().iterator();

    while(partNames.hasNext())
    {
      final String partName = partNames.next();
      final InputPart part = formData.get(partName);
      final MediaType mediaType = part.getMediaType();

      String mType = mediaType.getType();
      String mSubtype = mediaType.getSubtype();

      if("text".equals(mType) && "plain".equals(mSubtype))
      {
        // RFC2045: Each part has an optional "Content-Type" header
        // that defaults to "text/plain".
        // Can go into process without conversion
        if(mapping.isReserved(partName))
          mapping.directives.put(partName, part.getBodyAsString());
        else
          mapping.processVars.put(partName, part.getBodyAsString());
      }
      else
      {
        // anything else turns into a DataHandler
        final byte[] data = part.getBodyAsString().getBytes();
        DataHandler dh = new DataHandler(
            new DataSource()
            {
              public InputStream getInputStream() throws IOException
              {
View Full Code Here

    Iterator<String> partNames = formData.keySet().iterator();

    while(partNames.hasNext())
    {
      final String partName = partNames.next();
      final InputPart part = formData.get(partName);
      final MediaType mediaType = part.getMediaType();

      if(MediaType.TEXT_PLAIN_TYPE.equals(mediaType))
      {
        // RFC2045: Each part has an optional "Content-Type" header
        // that defaults to "text/plain".
        // Can go into process without conversion
        if(mapping.isReserved(partName))
          mapping.directives.put(partName, part.getBodyAsString());
        else
          mapping.processVars.put(partName, part.getBodyAsString());
      }
      else
      {
        // anything else turns into a DataHandler
        final byte[] data = part.getBodyAsString().getBytes();
        DataHandler dh = new DataHandler(
            new DataSource()
            {
              public InputStream getInputStream() throws IOException
              {
View Full Code Here

    Iterator<String> partNames = formData.keySet().iterator();

    while(partNames.hasNext())
    {
      final String partName = partNames.next();
      final InputPart part = formData.get(partName);
      final MediaType mediaType = part.getMediaType();

      if(MediaType.TEXT_PLAIN_TYPE.equals(mediaType))
      {
        // RFC2045: Each part has an optional "Content-Type" header
        // that defaults to "text/plain".
        // Can go into process without conversion
        processVars.put(partName, part.getBodyAsString());
      }
      else
      {
        // anything else turns into a DataHandler
        final byte[] data = part.getBodyAsString().getBytes();
        DataHandler dh = new DataHandler(
            new DataSource()
            {
              public InputStream getInputStream() throws IOException
              {
View Full Code Here

            null, importRecordCurator, null, null, null, null, null,
            null, null, null, contentOverrideValidator,
            serviceLevelValidator, null);

        MultipartInput input = mock(MultipartInput.class);
        InputPart part = mock(InputPart.class);
        File archive = mock(File.class);
        List<InputPart> parts = new ArrayList<InputPart>();
        parts.add(part);
        MultivaluedMap<String, String> mm = new MultivaluedMapImpl<String, String>();
        List<String> contDis = new ArrayList<String>();
        contDis.add("form-data; name=\"upload\"; filename=\"test_file.zip\"");
        mm.put("Content-Disposition", contDis);

        when(input.getParts()).thenReturn(parts);
        when(part.getHeaders()).thenReturn(mm);
        when(part.getBody(any(GenericType.class))).thenReturn(archive);
        when(importer.loadExport(eq(owner), any(File.class), any(ConflictOverrides.class)))
            .thenReturn(new HashMap<String, Object>());

        thisOwnerResource.importManifest(owner.getKey(), new String [] {}, input);
        List<ImportRecord> records = importRecordCurator.findRecords(owner);
View Full Code Here

            null, importRecordCurator, null, null, null, null, null,
            null, null, null, contentOverrideValidator,
            serviceLevelValidator, null);

        MultipartInput input = mock(MultipartInput.class);
        InputPart part = mock(InputPart.class);
        File archive = mock(File.class);
        List<InputPart> parts = new ArrayList<InputPart>();
        parts.add(part);
        MultivaluedMap<String, String> mm = new MultivaluedMapImpl<String, String>();
        List<String> contDis = new ArrayList<String>();
        contDis.add("form-data; name=\"upload\"; filename=\"test_file.zip\"");
        mm.put("Content-Disposition", contDis);

        when(input.getParts()).thenReturn(parts);
        when(part.getHeaders()).thenReturn(mm);
        when(part.getBody(any(GenericType.class))).thenReturn(archive);
        when(importer.loadExport(eq(owner), any(File.class), any(ConflictOverrides.class)))
            .thenThrow(new ImporterException("Bad import"));

        try {
            thisOwnerResource.importManifest(owner.getKey(), new String [] {}, input);
View Full Code Here

      @Consumes(MediaType.MULTIPART_FORM_DATA)
      @Produces(MediaType.TEXT_PLAIN)
      public Response testDefaultContentType(MultipartInput input) throws IOException
      {
         List<InputPart> parts = input.getParts();
         InputPart part = parts.get(0);
         String s1 = part.getBody(String.class, null);
         String s2 = part.getBodyAsString();
         String result = part.getMediaType() + ":" + s1 + ":" + s2;
         System.out.println("server response: " + result);
         return Response.ok(result, part.getMediaType()).build();
      }
View Full Code Here

      @Consumes(MediaType.MULTIPART_FORM_DATA)
      @Produces(MediaType.TEXT_PLAIN)
      public Response testInputPartSetMediaType(@QueryParam("contentType") String mediaType, MultipartInput input) throws IOException
      {
         List<InputPart> parts = input.getParts();
         InputPart part = parts.get(0);
         part.setMediaType(MediaType.valueOf(mediaType));
         String s1 = part.getBody(String.class, null);
         String s2 = part.getBodyAsString();
         String result = part.getMediaType() + ":" + s1 + ":" + s2;
         System.out.println("server response: " + result);
         return Response.ok(result, part.getMediaType()).build();
      }
View Full Code Here

      @Consumes(MediaType.WILDCARD)
      @Produces(MediaType.APPLICATION_OCTET_STREAM)
      public Response testByteArray(MultipartInput input) throws IOException
      {
         List<InputPart> parts = input.getParts();
         InputPart part = parts.get(0);
         byte[] b = part.getBody(byte[].class, null);
         return Response.ok(b).build();
      }
View Full Code Here

TOP

Related Classes of org.jboss.resteasy.plugins.providers.multipart.InputPart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.