Friday 26 May 2017

Binary Support for API Integrations with Amazon API Gateway - multipart/form-data, application/octet-stream


Binary Support for API Integrations with Amazon API Gateway


Create an API and POST method to support binary, eg: multipart/form-data, application/octet-stream








For API name , enter ‘Thumbnail’, add a description, and choose Create API.



In the created API, choose Resources Actions , and Create Method.








To create the method, choose POST and select the checkmark.














To set up the POST method, for Integration type , select HTTP , enter ‘https://${stageVariables.environmentUrl}’ for Endpoint URL. Choose Save.








Set up the integration

Now, you are ready to set up the integration. In the main page, open Integration Request.















On the Integration Request page, check Use HTTP Proxy integration.For Content Handling , choose Passthrough.















Specify which media types need to be handled as binary. Choose [API name]Binary Support.










Choose Edit , specify the media type (such as “multipart/form-data”) to be handled as binary, and then choose Save.






Choose Edit , specify the media type (such as “application/octet-stream”) to be handled as binary, and then choose Save.




Deployment

Now that the API is configured, you need to deploy it. On the thumbnail Resources page, choose Action , Deploy API.






Testing

Now, you are ready to test the newly created API. 







Reference:
https://aws.amazon.com/blogs/compute/binary-support-for-api-integrations-with-amazon-api-gateway/


Tuesday 16 February 2016

Install Eclipse-Che on Ubuntu server

  • Install jdk1.8+ & set JAVA_HOME

  • Install Docker

  • $ which curl
    $ sudo apt-get update
    $ sudo apt-get install curl
    $ curl -sSL https://get.docker.com/ | sh
    
    If you would like to use Docker as a non-root user, you should now consider
    adding your user to the "docker" group with something like:
    $ sudo usermod -aG docker serveradmin
    
    Remember that you will have to log out and back in for this to take effect!
  • Verify docker is installed correctly

  • $ docker run hello-world
    or
    $ sudo docker run hello-world
    
    This command downloads a test image and runs it in a container.
  • Download eclipse-che installation jar

  • The reason why I download the installation jar (JAR Universal Extractor) instead of directly use docker image with following command is that way isn't work for me. It's always showing some error.
    $ docker run -it -p 1104:8080 codenvy/che
    
  • Install eclipse-che

  • $ sudo mkdir /usr/local/eclipse-che-4.0.0-RC3
    $ sudo chown -R serveradmin:serveradmin /usr/local/eclipse-che-4.0.0-RC3
    $ java -jar eclipse-che-latest.jar 
    

    You should select "/usr/local/eclipse-che-4.0.0-RC3" as target installation dir.
  • Add execute permisson to TOMCAT script

  • $ cd /usr/local/eclipse-che-4.0.0-RC3/tomcat/bin
    $ chmod +x *.sh
    
  • Set CHE_HOME

  • $ vi ~/.bashrc
    
    Add the line to it
    export CHE_HOME=/usr/local/eclipse-che-4.0.0-RC3
    
    Reload
    $ source ~/.bashrc
    
    Create link to /usr/bin
    $ sudo ln -s /usr/local/eclipse-che-4.0.0-RC3/bin/che.sh /usr/bin/che
    
    Now,you can start Eclipse-Che by
    $ che start
    








    Friday 12 February 2016

    • Get current running class dir path
    • String jarOrBuildClassDir = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
      

      It will return 'build/classes/main' if you run it on IDE

      /Users/demo/workspace/MyDemo/build/classes/main/
      

      It will return the location of 'jar' file which the class archived if you run it in a jar file

      /Users/demo/workspace/MyDemo/install/MyDemo/lib/MyDemo.jar
      
    • Get special resources file path that copy from 'src/main/java/resources/com/demo/test.xsl'
    • URL xslFileURL = getClass().getResource("/com/demo/test.xsl")
      

      It will return 'build/resources/main' if you run it on IDE

      /Users/demo/workspace/MyDemo/build/resources/main/com/demo/test.xsl
      

      It will return the location of 'jar' file which the class archived if you run it in a jar file

      file:/Users/demo/workspace/MyDemo/install/MyDemo/lib/MyDemo.jar!/com/demo/test.xsl
      

    Wednesday 12 November 2014

    BTrace trace ClassLoader Leaking

    If you want to trace the common ClassLoader leaking, you just probe where to invoke "ClassLoader#defineClass". The BTrace script as follow:
    import com.sun.btrace.AnyType;
    import com.sun.btrace.annotations.*;
    import static com.sun.btrace.BTraceUtils.*;
    
    @BTrace
    public class Trace {
    
       @OnMethod(clazz = "+java.lang.ClassLoader", 
                 method = "defineClass")
        public static void traceClassLoaderLeak(@ProbeClassName String clazz, @ProbeMethodName String method, @TargetInstance Object instance) {
            println("\n==== java.lang.ClassLoader#defineClass ====");
            jstack();
        }
    }
    

    Thursday 8 May 2014

    Java client read content from URL with SSL

    • Java client
    • import javax.net.ssl.HostnameVerifier;
      import javax.net.ssl.HttpsURLConnection;
      import javax.net.ssl.SSLSession;
      import java.io.ByteArrayOutputStream;
      import java.io.IOException;
      import java.io.InputStream;
      import java.net.URISyntaxException;
      import java.net.URL;
      import java.nio.file.Files;
      import java.nio.file.Path;
      import java.nio.file.Paths;
      
      public class PDFTester {
          private static final int FILE_BUFFER_SIZE = 2048;
          public static final String CONTENT_TYPE_PDF = "application/pdf";
          public static byte[] readPDFFromURL(URL url) throws IOException {
              System.setProperty("javax.net.ssl.trustStore", "C:/temp/myCA.jks");
              System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
      
              HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
              httpsURLConnection.setHostnameVerifier(new HostnameVerifier() {
                  public boolean verify(String hostname, SSLSession session) {
                      return true;
                  }
              });
              httpsURLConnection.connect();
      
              byte[] buffer = new byte[FILE_BUFFER_SIZE];
              int lengthOfByteToBeWrite;
              try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                   InputStream inputStream = httpsURLConnection.getInputStream()) {
                  while ((lengthOfByteToBeWrite = inputStream.read(buffer)) != -1) {
                      byteArrayOutputStream.write(buffer, 0, lengthOfByteToBeWrite);
                  }
                  byteArrayOutputStream.flush();
                  return byteArrayOutputStream.toByteArray();
              } catch (IOException e) {
                  throw e;
              }
          }
      
          public static void main(String[] args) throws IOException, URISyntaxException {
              URL url = new URL("https://www.sample.com/pdf");
              byte[] bytes = readPDFFromURL(url);
              Path path = Paths.get("c:/temp/test.pdf");
              Files.write(path, bytes);
          }
      }
      
    • SSL base knowledge:
      Implementing SSL / TLS using Java

    Sunday 6 April 2014

    Hide unnecessary Horizontal Scrollbar on jqgrid

    use this css to remove it.

    
    
    

    Thursday 6 March 2014

    Share value between main report, multi sub reports



    How to shared value between multi crystal report sub report?
    1.       Create two sub reports

    2.       Define Formula Field (defineGlobalPersonName)  in subReport1

    3.       Tricky: This formula field (defineGlobalPersonName) must use in somewhere in sub report (subReport1) where inject value into the shared variable. Otherwise, other sub report where reference the shared value (personName)  can’t get the value when printing records.


    4.       Used shared variable in other sub report (subReport2)
    (a)    Declare another “formula field (retreiveBackPersonName)” to retrieve value from above shared variable (personName)


    (b)   Use this formula field (retreiveBackPersonName)  in your sub report (subReport2)
    5.       Preview final report


    6.       If you want shared value to main report as well.  You just only declare one “formula field (sharedValue)”  in main report. Then you can use it