Sunday, April 19, 2020

Very good reference on using Jersey:
https://dennis-xlc.gitbooks.io/restful-java-with-jax-rs-2-0-en/cn/part1/chapter8/building_and_invoking_requests.html


Do note: need to do a string:
Response resp = invocationBuilder.post(Entity.entity(jsonObjectBody.toString(), MediaType.APPLICATION_JSON)); 

or else json
{"method":"Logon","payload":{"strLogin":"aaa_offers","strPassword":"gL(8KKw3L)\\\"g)BKR","elemParameters":{}},"schema":"xtk:session","securityToken":"","sessionToken":""}


will be converted to like NVP:

{
               "method": {
      "chars": "Logon",
      "string": "Logon",
      "valueType": "STRING"
    },
    "payload": {    
      "strLogin": {
        "chars": "aaa_offers",
        "string": "aaa_offers",
        "valueType": "STRING"
      },
      "strPassword": {
        "chars": "**** password here ****",
        "string": "**** password here ****",
        "valueType": "STRING"
      },
                 "elemParameters": {}
    },
    "schema": {
      "chars": "xtk:session",
      "string": "xtk:session",
      "valueType": "STRING"
    },
    "securityToken": {
      "chars": "",
      "string": "",
      "valueType": "STRING"
    },
    "sessionToken": {
      "chars": "",
      "string": "",
      "valueType": "STRING"
    }
  }

Saturday, April 18, 2020

Jersey Logging

Not easy to do with Jersey 2 but here's a good one to start with:
https://www.javaguides.net/2018/06/jersey-rest-logging-using-loggingfeature.html

And here is how to bridge it to log4j:
https://stackoverflow.com/questions/15437043/how-to-use-log4j-to-see-into-jersey

https://xiaozhoutech.wordpress.com/2013/08/02/log4j-working-on-jersey/

http://jersey.576304.n2.nabble.com/Enable-Logging-td7581002.html


OK folks, this one works:
https://www.logicbig.com/tutorials/misc/java-logging/jul-to-slf4j-log4j2.html

Will post code later

Getting started on Maven

Trying this out now, coz I realised this is the easiest way to ensure I am using the latest jars that I need for my development work.

See this for starters: https://www.vogella.com/tutorials/EclipseMaven/article.html

If you get the error "maven could not resolve archetype", try the suggestions in these 2 links:
https://stackoverflow.com/questions/15506043/create-a-maven-project-in-eclipse-complains-could-not-resolve-archetype
https://stackoverflow.com/questions/18499931/eclipse-java-ee-new-maven-project-could-not-resolve-archetype

To setup Eclipse with M2E:

Way 1: Maven Eclipse plugin installation step by step:
  1. Open Eclipse IDE
  2. Click Help -> Install New Software...
  3. Click Add button at top right corner
  4. Now click OK
After that installation would be started.
Way 2: Another way to install Maven plug-in for Eclipse by "Eclipse Marketplace":
  1. Open Eclipse
  2. Go to Help -> Eclipse Marketplace
  3. Search by Maven
  4. Click "Install" button at "Maven Integration for Eclipse" section
  5. Follow the instruction step by step
After successful installation do the followings in Eclipse:
  1. Go to Window --> Preferences
  2. Observe, Maven is enlisted at left panel
Finally,
  1. Click on an existing project
  2. Select Configure -> Convert to Maven Project

Sunday, July 17, 2016

javax.naming.NoInitialContextException: Unable to find the InitialContextFactory com.sun.jndi.fscontext.RefFSContextFactory.

I'm trying to use MQ bindings when I get the error:
javax.naming.NoInitialContextException: Unable to find the InitialContextFactory com.sun.jndi.fscontext.RefFSContextFactory


Check this out:
http://www-01.ibm.com/support/docview.wss?uid=swg21552830).

Saturday, July 2, 2016

Using maven to include dependency jars in export

Here's a good example Maven Assembly Plugin

http://www.mkyong.com/maven/create-a-fat-jar-file-maven-assembly-plugin/

Setting up maven in eclipse

Here's what you do to open a maven project in eclipse:

1. Install maven (m2e) plugin:
http://stackoverflow.com/questions/8620127/maven-in-eclipse-step-by-step-installation
http://o7planning.org/web/fe/default/en/document/5189/install-maven-into-eclipse
http://www.vogella.com/tutorials/EclipseMaven/article.html


2. In eclipse, choose File-> Import -> Maven -> Existing Maven Projects, and then Enter

3. Root Directory -> Browse and choose the directory where the pom.xml file exists

4. Finish

And you are done! (build the project as the next step via Run As -> Maven Build)

Why do I get “must override a superclass method” with @Override?

Do note, if you get this error, most likely your compiler compliance is not set to at least 1.6.

If using eclipse, check the project's properties and verify that Java Compiler -> Compiler compliance level is set to 1.6.