2

I am trying to get call an api with the HTTP logic app within Azure

I am able to make the call successful through post man. see my post man configuration

Post Man Configuration

I can see the http code from postman as this, I am using this to make the logic app to be formatted similar to what post man has.

POST /dcma/rest/initiateOcrClassifyExtract HTTP/1.1

Host: godemo.ephesoft.com

Authorization: Basic NDU=??????

Cache-Control: no-cache

Postman-Token: 3baf23e7-6b46-a5f4-094b-3df1879bbe21

Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="000001.pdf"; filename="000001.pdf"
Content-Type: application/pdf


------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="batchClassIdentifier"

BC590

------WebKitFormBoundary7MA4YWxkTrZu0gW--

below is the actual logic app http configuration.

Logic App config

the logs on the server show the below error

    2017-09-07 20:12:51,784 [ajp-apr-8009-exec-3] ERROR org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/dcma].[DispatcherServlet]- Servlet.service() for servlet [DispatcherServlet] in context with path [/dcma] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadException: Header section has more than 10240 bytes (maybe it is not properly terminated)] with root cause
org.apache.commons.fileupload.MultipartStream$MalformedStreamException: Header section has more than 10240 bytes (maybe it is not properly terminated)
    at org.apache.commons.fileupload.MultipartStream.readHeaders(MultipartStream.java:541)
    at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.findNextItem(FileUploadBase.java:999)
    at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:965)
    at org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:331)
    at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:351)
    at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
    at org.springframework.web.multipart.commons.CommonsMultipartResolver.parseRequest(CommonsMultipartResolver.java:158)
    at org.springframework.web.multipart.commons.CommonsMultipartResolver.resolveMultipart(CommonsMultipartResolver.java:142)
    at org.springframework.web.servlet.DispatcherServlet.checkMultipart(DispatcherServlet.java:1070)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:912)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at com.ephesoft.dcma.webapp.AuthenticationFilter.doFilter(AuthenticationFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at com.ephesoft.dcma.webapp.SessionTimeoutFilter.doFilter(SessionTimeoutFilter.java:43)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:230)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at com.ephesoft.dcma.webapp.HTTPHeaderFilter.doFilter(HTTPHeaderFilter.java:75)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
1
  • Does my answer helps you? Any Progress? Commented Sep 25, 2017 at 4:23

3 Answers 3

3

For multipart/form-data there is now an example in the official documentation:

https://learn.microsoft.com/bs-latn-ba/azure/connectors/connectors-native-http#content-with-multipartform-data-type

"body": {
   "$content-type": "multipart/form-data",
   "$multipart": [
      {
         "body": "<output-from-trigger-or-previous-action>",
         "headers": {
            "Content-Disposition": "form-data; name=file; filename=<file-name>"
         }
      }
   ]
}

And if there are other form fields to send, just add similar objects with correct form field names.

The Content-Disposition header will need escaped quotes for the name and filename field if you are not using the TriggerBody from a previous step.

"Content-Disposition": "form-data; name=\"file\"; filename=\"<file-name>\""
Sign up to request clarification or add additional context in comments.

Comments

1

From the log message you offered, I found that you used the apache.commons.fileupload library in the backend. So,I created a simple servlet web project which contains the core code as below with the apache.commons.fileupload library to process uploaded files.

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

@WebServlet("/HelloWorldByPostman")
public class HelloWorldByPostman extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public HelloWorldByPostman() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

//      String savePath = this.getServletContext().getRealPath("/WEB-INF/upload");

        boolean isMultipart = ServletFileUpload.isMultipartContent(request); 
        System.out.println(isMultipart);

        if(isMultipart){  
            FileItemFactory factory = new DiskFileItemFactory();  
            ServletFileUpload upload = new ServletFileUpload(factory);  
            List<FileItem> items = null;  
            try {
                items=upload.parseRequest(request);
                System.out.println(items.toString());  
            } catch (FileUploadException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }  
            Iterator<FileItem> iterator = items.iterator();  
            while(iterator.hasNext()){  
                FileItem item = iterator.next();  
                if(item.isFormField()){  
                    System.out.println("is txt........"+item.getFieldName());  
                }else{  
                    System.out.println("is file..........."+item.getFieldName());  
                }  
            }  
        }  

        response.getWriter().append("Served at: ").append("jaygong");
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

Then,I deployed the project to Azure Web App so that I can upload files via http request.

Postman:

enter image description here

enter image description here

Result: enter image description here

Logic App:

enter image description here

Result:

enter image description here

When the action is post and Content-Type type is multipart/form-data, the browser will take the form to control unit segmentation, and for each part plus Content-Disposition (form-data or file), Content-Type (default is text/plain), name (name control) and other information, and add a boundary.

The Content-Type attribute is already included in Body part so you could remove the Content-Type setting in Header part and retry your post request.

Hope it helps you.

1 Comment

Could you share the function.json of HelloWorldByPostman please?
0

you need to pass the data like In body

{
  "$Content-Type": "application/x-www-form-urlencoded",
  "$formdata": [
    {
      "key": "grant_type",
      "value": "client_credentials"
    },
    {
      "key": "client_id",
      "value": "your clientid"
    },
    {
      "key": "client_secret",
      "value": "your client secret"
    }
  ]
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.