Link to home
Start Free TrialLog in
Avatar of ChaseITServices
ChaseITServices

asked on

Query about using PostURL with PB10.2

I need to pass a SOAP instruction from a PB application to a 3rd party product, including a Word document.   Using base64 encoding and geturl, I can do this, but it is very slow and our suppliers recommend passing this as a binary stream.  They are unable to provide much assistance with their API, but have provided some Java code, that they say does the trick, as follows...
      public static String rkyvCallWithStream(String sSoap, byte[] data) throws Exception
      {

            Vector results = new Vector(3);
            StringBuffer rtn = new StringBuffer();
            String inputLine;
            BufferedReader in = null;

            OutputStream out = null;
            HttpURLConnection connection = null;

            try {

                  String urlString = "http://" + RKYVMACHINENAME + "/servlets/servlets.CH_CherryServlet?Soap_Message=" + sSoap;
                  URL url = new URL(urlString);
                  System.out.println(urlString);

                  connection = (HttpURLConnection) url.openConnection();
                  connection.setRequestMethod("POST");
                  connection.setRequestProperty("content-type", "text/xml");
                  connection.setUseCaches(false);
                  connection.setDoOutput(true);

                  out = connection.getOutputStream();

                  System.out.println("Writing binary array...");

                  out.write(data, 0, data.length);
                  out.flush();
                  out.close();

                  in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                  while ((inputLine = in.readLine()) != null) {
                        rtn.append(inputLine);
                  }

                  in.close();
                  connection.disconnect();
            } finally {
                  try {
                        out.flush();
                        out.close();
                        in.close();
                  } catch (Exception e) {
                  }
                  connection.disconnect();
            }
            return rtn.toString();
      }
I've had no joy in getting Powerbuilder to do something similar using PostURL.  I suspect that Java is doing something hidden in the way of headers etc.
Our suppliers say they've never heard of anybody using this calling with non-Java clients and helpfully suggest that we recode our application in Java.
Can anybody offer any other suggestions on this?  We are running PB10.2 and don't use PFC or EAServer

SOLUTION
Avatar of Vikas_Dixit
Vikas_Dixit
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ChaseITServices
ChaseITServices

ASKER

Using the above code, I include the string parameters of the soap message with ls_url and pass the Word document as a blob in lblb_args.  I get the following error message back from the Apache server
java.lang.StringIndexOutOfBoundsException: String index out of range
Our suppliers say that this is probably due to the soap message being badly formed rather than, say the contents of the soap message being invalid.  I have also tried converting the soap message to a blob, concatenating it with the Word document and passing it in lblb_args, but get the same error.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I tried an empty request - this caused the soap server to respond with an empty string between the usual response tags.
I then tried sending a 60 character text file, instead of the word document that I'd been using before and got the same StringIndexOutOfBoundsException as before.
sSoap is a set of XML instructions to the server.   Our suppliers think that the syntax we're using should work.  It is a small variation on the syntax that we use for successfull base64 loads.
Do you think I should be sending this as a multi-part form?  Our suppliers basically don't know, but it's not something they normally do.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your reply.  Prior to receiving this we settled upon the method of calling java routines to do the posting (this also saves the necessity of reading the binary document into Powerbuilder first).   This works pretty well.
I'll bear your reply in mind should the issue arise again.