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

Unable to update the records on your server #40

Open
pavan3202 opened this issue Dec 11, 2015 · 0 comments
Open

Unable to update the records on your server #40

pavan3202 opened this issue Dec 11, 2015 · 0 comments

Comments

@pavan3202
Copy link

I am trying to update the record in the FHIR server it is throwing me following exception with 500 status. I am not sure some this is missing.
Below is the Exception I am getting

" Exception in thread "main" java.io.IOException: Server returned HTTP response code: 500 for URL: http://fhir.dev.aimsplatform.com/Patient/1272431_format=xml
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at com.test.HttpURLConnectionExample.updatePatientRecord(HttpURLConnectionExample.java:157)
at com.test.HttpURLConnectionExample.main(HttpURLConnectionExample.java:30)"

Following is the code snippet I am using. Please help me on this

//update particular patient record
private void updatePatientRecord(int PatientID) throws Exception {

        String url = "http://fhir.dev.aimsplatform.com/Patient/" + PatientID +"_format=xml";            
        //PUT https://example.com/path/{resourceType}/{id}

        URL obj = new URL(url);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();

         String authStr = "client"+":"+"secret";
            System.out.println("Original String is " + authStr);

        // encode data on your side using BASE64
            byte[] bytesEncoded = Base64.getEncoder().encode(authStr .getBytes());
            String authEncoded = new String(bytesEncoded);
            con.setRequestProperty("Authorization", "Basic "+authEncoded);  
        // optional default is PUT
        con.setRequestMethod("PUT");  


        con.setDoOutput(true);
        con.setDoInput(true);
        con.setRequestProperty("Content-Type", "application/json");
        con.setRequestProperty("Accept", "application/json");             

        JSONObject details = new JSONObject();      

        details.put("city","california");
        details.put("country","usa");

        OutputStreamWriter wr= new OutputStreamWriter(con.getOutputStream());
        wr.write(details.toString());;
        wr.flush(); 


         InputStream ins = con.getInputStream();
         InputStreamReader isr = new InputStreamReader(ins);
         BufferedReader in = new BufferedReader(isr);

         //output the information        

         String inputLine;
         while ((inputLine = in.readLine()) != null)
         {
             System.out.println(inputLine);
         }
         in.close();
    }

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

No branches or pull requests

1 participant