Announcement

Collapse
No announcement yet.

Send Json to Rest WebService

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Send Json to Rest WebService

    I'm trying to send a json generated in my transformer.

    This Json is already validated, and accepted on my client, but via mirth the same displays Invalid Json error.

    I'm sending the channel attached, could you give me an aid on this case?

    Thank you,
    Leandro
    Attached Files
    Last edited by lgiuriollo; 01-24-2017, 01:33 AM.

  • #2
    What is the error?
    Best,

    Kirby

    Mirth Certified|Epic Bridges Certified|Cloverleaf Level 2 Certified

    Appliance Version 3.11.4
    Mirth Connect Version 3.8.0
    Java Version 1.6.0_45-b06
    Java (64 bit) Version 1.6.0_45-b06
    Java 7 (64 bit) Version 1.7.0_151-b15
    Java 8 (64 bit) Version 1.8.0_181-b13
    PostgreSQL Version 9.6.8

    Comment


    • #3
      Originally posted by kirbykn2 View Post
      What is the error?
      HTTP Sender error
      ERROR MESSAGE: JSON or XML content is obligatory for fulfilment of this request.


      But i'm have a validated Json with PostMan... =/

      Comment


      • #4
        Are you sure you are passing the JSON as payload to the URL? Did you check whether it is empty?
        HL7v2.7 Certified Control Specialist!

        Comment


        • #5
          Originally posted by siddharth View Post
          Are you sure you are passing the JSON as payload to the URL? Did you check whether it is empty?

          Mirth send charset in header:

          POST http://127.0.0.1:8888/api/receiver/request HTTP/1.1
          charset:
          Content-Type: application/json; charset=windows-1252
          Content-Length: 427
          Host: 127.0.0.1:8888
          Connection: Keep-Alive
          User-Agent: Apache-HttpClient/4.5.1 (Java/1.8.0_121)
          Accept-Encoding: gzip,deflate

          if i remove charset=windows-1252 the process is ok...

          but i don't know remove charset in mirth...
          Attached Files

          Comment


          • #6
            It looks like an error with the server you're sending to. It's probably coded poorly and is checking for a Content-Type that literally matches "application/json" without correctly parsing out elements of the header value.
            Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

            Nicholas Rupley
            Work: 949-237-6069
            Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


            - How do I foo?
            - You just bar.

            Comment


            • #7
              i'm tryed send json in webservice, using this code:


              function RISToDeliveryReport(JsonFile, URL) {

              try {

              var data = JsonFile;

              // Create url object
              var url = new java.net.URL(URL);

              // Open connection to url
              var conn = url.openConnection();


              conn.setDoOutput(true);
              conn.setDoInput(true);
              conn.setRequestMethod("POST");
              conn.setRequestProperty("Content-length", data.length());
              conn.setRequestProperty("Content-type", "application/json");

              logger.info("teste1");


              // Send request
              var outStream = conn.getOutputStream();
              var outWriter = new java.io.OutputStreamWriter(outStream);
              outWriter.write(data);
              outWriter.close();

              logger.info("teste2");

              // Get response
              var inputStream = conn.getInputStream();
              logger.info("teste3");
              var streamReader = new java.io.InputStreamReader(inputStream);
              var respStream = new java.io.BufferedReader(streamReader);

              logger.info("teste4");

              //create variable to hold return data
              var buffer = new java.lang.StringBuffer();
              var line = null;
              while ((line = respStream.readLine()) != null) {
              buffer.append(line + 'n');
              }
              respStream.close();

              logger.info("teste5");

              // Store response in channelMap
              var response = buffer.toString();
              channelMap.put('response', response);

              }//catch(exception){
              //throw exception
              //}

              finally {

              }
              }


              and a have problem in var inputStream = conn.getInputStream();

              return this error:


              ERROR (com.mirth.connect.server.userutil.DatabaseConnect ionFactory:165): Error initializing DatabaseConnectionFactory driver: null
              java.lang.NullPointerException
              at java.lang.Class.forName0(Native Method)
              at java.lang.Class.forName(Unknown Source)
              at com.mirth.connect.server.userutil.DatabaseConnecti onFactory.initializeDriverAndGetInfo(DatabaseConne ctionFactory.java:155)
              at com.mirth.connect.server.userutil.DatabaseConnecti onFactory.getCustomDriverInfo(DatabaseConnectionFa ctory.java:163)
              at com.mirth.connect.server.userutil.DatabaseConnecti onFactory.createDatabaseConnection(DatabaseConnect ionFactory.java:53)
              at sun.reflect.GeneratedMethodAccessor42.invoke(Unkno wn Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
              at java.lang.reflect.Method.invoke(Unknown Source)
              at org.mozilla.javascript.MemberBox.invoke(MemberBox. java:126)
              at org.mozilla.javascript.NativeJavaMethod.call(Nativ eJavaMethod.java:225)
              at org.mozilla.javascript.Interpreter.interpretLoop(I nterpreter.java:1479)
              at org.mozilla.javascript.Interpreter.interpret(Inter preter.java:815)
              at org.mozilla.javascript.InterpretedFunction.call(In terpretedFunction.java:109)
              at org.mozilla.javascript.ContextFactory.doTopCall(Co ntextFactory.java:393)
              at org.mozilla.javascript.ScriptRuntime.doTopCall(Scr iptRuntime.java:3280)
              at org.mozilla.javascript.InterpretedFunction.exec(In terpretedFunction.java:120)
              at com.mirth.connect.server.util.javascript.JavaScrip tTask.executeScript(JavaScriptTask.java:142)
              at com.mirth.connect.connectors.js.JavaScriptDispatch er$JavaScriptDispatcherTask.doCall(JavaScriptDispa tcher.java:149)
              at com.mirth.connect.connectors.js.JavaScriptDispatch er$JavaScriptDispatcherTask.doCall(JavaScriptDispa tcher.java:122)
              at com.mirth.connect.server.util.javascript.JavaScrip tTask.call(JavaScriptTask.java:113)
              at java.util.concurrent.FutureTask.run(Unknown Source)
              at java.util.concurrent.ThreadPoolExecutor.runWorker( Unknown Source)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source)
              at java.lang.Thread.run(Unknown Source)




              any ideia for this problem?


              Thank's,
              Leandro

              Comment

              Working...
              X