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

Feature/java native codegen #266

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from

Conversation

virenderm01
Copy link

@virenderm01 virenderm01 commented May 30, 2020

Pure Java code generator for issue #155 Issue

The code generator creates snippet in java 8, no other dependencies are required to run the code.

Changes:
Added new code gen with name java-native. All the changes required to generate the code is added under the folder codegen/java-native
The code structure and style is similar to java-okhttp codegen.

Sample Code Snippet

import java.io.*;
import javax.net.ssl.HttpsURLConnection;
import java.net.*;
import java.lang.reflect.*;
import java.util.*;
import java.util.function.BiConsumer;
public class main {
   public static void main(String []args) throws IOException{
      URL obj = new URL("https://postman-echo.com/get");
      URLConnection connection = obj.openConnection();
      HttpURLConnection con = (HttpURLConnection) connection;
      con.setRequestMethod("GET");
      Map<String, String> headers = new HashMap<>();
      BiConsumer<String,String> headerMap = (key,value) -> {
         if(headers.get(key)!=null){
            String val = headers.get(key);
            val = val + ", "+ value;
            headers.put(key, val);
         }else{
            headers.put(key,value) ;
         }
      };
      headerMap.accept("key", "value1");
      headerMap.accept("key", "value2");
      for (Map.Entry<String, String> entry : headers.entrySet()) {
         con.setRequestProperty(entry.getKey(), entry.getValue());
      }con.setRequestProperty("Accept","application/json");
      con.setDoOutput(false);
      BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
      String temp = null;
      StringBuilder response = new StringBuilder();
      while ((temp = in.readLine()) != null) {
         response.append(temp).append(" ");
      }
      System.out.println(response.toString());
      in.close();
   
}
}

Test Configuration
Unit Tests and newman test are all passing, the log for the same can be found in the below link.
Overall Code coverage is above 85% for tests.
Java native code logs are from line 5246
Travis Build Logs

@virenderm01
Copy link
Author

Hi @shreys7 ,
Can you review it once, I see it's been more than a month but no action was taken on this.
I have added all the necessary test cases, please let me know if anything else is required.

@danthe1st
Copy link

danthe1st commented Jul 25, 2020

By the way,

if(connection instanceof HttpsURLConnection){
    con = (HttpsURLConnectionconnection;
}else{
    con = (HttpURLConnectionconnection;
}

cab be simplified to con = (HttpURLConnection) connection; as HttpsURLConnection extends HttpsURLConnection.

@virenderm01
Copy link
Author

@danthe1st
you meant

HttpURLConnection con = (HttpsURLConnection) connection;

I have created another branch and have made the changes. Let me know if I had misinterpreted your comment.

@danthe1st
Copy link

danthe1st commented Jul 28, 2020

You can just cast to HttpURLConnection, even if it is a HttpsURLConnection. You therefore don't need the if.

If you cast a HttpUrlConnection to a HttpsURLConnection, it will not work.

@virenderm01
Copy link
Author

Hi @umeshp7 @shreys7 ,
Can you guys please review this, let me know if there are any changes required or if there are any issues that might have been missed out while creating the pull request.

Regards,
Virender Moudgil

@doej1367
Copy link

doej1367 commented Mar 9, 2022

i'd really like to see this - can we all have a status uptade on this?

@dhwaneetbhatt
Copy link
Contributor

Thanks for the contribution @virenderm01. Could you please pull the latest changes from upstream so we can start the review process?

@virenderm01
Copy link
Author

@dhwaneetbhatt updated the branch, the confilicts are now resolved.

@virenderm01
Copy link
Author

@dhwaneetbhatt any update on merging this ?

@dhwaneetbhatt
Copy link
Contributor

@virenderm01 I'm no longer a maintainer of this repository. Please reach out to Postman Support. They should be able to help you.

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.

4 participants