Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace request & httpntlm with axios & axios-ntlm #1146

Merged
merged 2 commits into from
Jul 6, 2021
Merged

replace request & httpntlm with axios & axios-ntlm #1146

merged 2 commits into from
Jul 6, 2021

Conversation

vision10
Copy link
Contributor

This is my attempt to replace request and httpntlm packages with axios and axios-ntlm

Its not perfect yet and there are still some issues that need to be addressed:

  • axios does not handle multipart options.
    • axios recommends to use form-data package for attachments, but I don't know if we should include another package or let the user handle this
  • requestStream method does not return a request stream but a data response as a stream (because axios does not return the request stream, if only has the option to return the response as a stream with options.responseType='stream')
  • a few tests need some rewriting (I have adjusted a few to work with the new packages as best as I knew/could)

I have updated a few packages (those with minor changes)
Some files have a few more changes because of vs code text autoformat (mainly whitespaces)
On a personal note, I don't think Promises mix well together with callbacks, so maybe callbacks should be dropped in a future version if axios is adopted ?

@coveralls
Copy link

coveralls commented May 19, 2021

Coverage Status

Coverage increased (+0.07%) to 95.133% when pulling ade889f on vision10:master into 95fa71f on vpulim:master.

@jsdevel
Copy link
Collaborator

jsdevel commented Jun 1, 2021

@vision10 please get the build to pass.

@jsdevel jsdevel merged commit 5b7dfe2 into vpulim:master Jul 6, 2021
@j0k3r
Copy link

j0k3r commented Jul 7, 2021

Something got broken with version 0.40.0 (I don't know if it's directly related to that PR).
I've tested to update the lib soap-as-promised and tests are failing.

@jsdevel
Copy link
Collaborator

jsdevel commented Jul 7, 2021

@j0k3r can you submit a PR?

@j0k3r
Copy link

j0k3r commented Jul 8, 2021

I didn't take a closer look atm. Maybe @vision10 can have an idea?

@vision10
Copy link
Contributor Author

vision10 commented Jul 8, 2021

I think you need to use createClientAsync in your tests

@renanwilliam
Copy link

with this PR we lost support for sending attachments in MTOM?

@renanwilliam
Copy link

just to inform I have checked and we have a project MTOM attachments working fine on 0.39.0 and after upgrade to 0.40.0 it's stopped to work. This pull request is a breaking change.

@vision10
Copy link
Contributor Author

vision10 commented Jul 28, 2021

Yes, I said it in the beginning, axios does not handle attachments automatically like request did, and a decision is needed if we should include another pachage or let the user handle them

@renanwilliam
Copy link

Ok but isn't better decide it and implement before release it?

@j0k3r
Copy link

j0k3r commented Jul 29, 2021

I agree this is a BC change, but before 1.0.0, everything can be broken.
What you should do @renanwilliam is

  • revert to 0.39.0,
  • add a test unit to ensure MTOM attachements are working
  • let Dependabot create a PR with newest version (and fail for upgrading to 0.40.0)
  • wait until a new version of node-soap pass your test and then you'll be able to merge it

@renanwilliam
Copy link

renanwilliam commented Jul 29, 2021

I still think that isn't make sense release this change considering doesn't have any real benefit that justify a feature loss (it is just a replacement of request by axios). It can be worked in separate branch or a RC release until this open issues are fixed.

Anyway, I think that will be a good mention it in documentation about this BC.

@scagood
Copy link
Contributor

scagood commented Jul 30, 2021

I have just upgraded from 0.39.0 to 0.40.0 and for some reason the ClientSSLSecurity and ClientSSLSecurityPFX dont work anymore.

This I can only assume it is associated to this PR 👀

@olliswe
Copy link

olliswe commented Aug 3, 2021

I have just upgraded from 0.39.0 to 0.40.0 and for some reason the ClientSSLSecurity and ClientSSLSecurityPFX dont work anymore.

This I can only assume it is associated to this PR 👀

Same here...

@wagnerch
Copy link
Contributor

SOAP faults also appear to be broken by this PR.

const soap = require("soap");

(async () => {
    const client = await soap.createClientAsync("http://www.dneonline.com/calculator.asmx?wsdl");

    try {
        const res = await client.AddAsync ({
            "intA": "1",
            "intB": "a"
        });
        console.log(res[0]?.AddResult);
    } catch (error) {
        console.log("ERROR:", error?.message);
    }
}) ();


C:> npm install [email protected]
C:> node .\soap.js
ERROR: Request failed with status code 500

C:> npm install [email protected]
C:> node .\soap.js
ERROR: soap:Client: System.Web.Services.Protocols.SoapException: Server was unable to read request. ---> System.InvalidOperationException: There is an error in XML document (1, 326). ---> System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at System.Xml.XmlConvert.ToInt32(String s)
   at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read1_Add()
   at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer.Deserialize(XmlSerializationReader reader)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
   --- End of inner exception stack trace ---
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
   at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)
   at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
   --- End of inner exception stack trace ---
   at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()
   at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()

@scagood
Copy link
Contributor

scagood commented Aug 12, 2021

I found the same @wagnerch my solution was just to add the following to my entry point:

require('axios').defaults.validateStatus = () => true;

I will note this only work for me as this is the only package in my entire deps tree that uses axios 👀

I will note that any error handling you have will probably not work now also as the errors come formatted differently, but that is at least something we can handle in our client code.

I should probably make a PR to change the request options here also though 👀

@wagnerch
Copy link
Contributor

@scagood Yeah, unfortunately I use axios, and it is also used in Azure which I also use, so setting this as a default wouldn't work for me. Not sure what the scoping of this default would be? I don't think the exception behavior should change because the underlying HTTP engine has changed.

I'll stick on 0.39.0 for now, and see where things go.

@wagnerch
Copy link
Contributor

wagnerch commented Aug 13, 2021

@scagood Thanks for the tip, submitted a PR to fix it. It looks like the requestStream pieces are broken with restoring the status code behavior that requests had, haven't had a chance to investigate it.

@bigplayalman
Copy link

bigplayalman commented Apr 15, 2022

for anyone having an issue with this, since this is using axios you need to change your options

import https from 'https';

const agent = new https.Agent({  
  rejectUnauthorized: false,  
  pfx: 'pfx buffer',  
  passphrase: 'password',  
})

const options = {  
  wsdl_options: {  
    httpsAgent: agent,  
  }  
}

@isaacgrimaldo
Copy link

other way to use it

const agent = new https.Agent({
    cert: certpub,
    key: certpri,
  });

  const options = {
    envelopeKey: 'soapenv',
    wsdl_options: {
      httpsAgent: agent,
    },
  };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants