Tuesday, December 25, 2018

How to post json string for datatables framework

By default, the Ajax request that DataTables makes to obtain server-side processing data is an HTTP GET request. However, there are times when you might wish to use POST. This is very easily done by using the type option of the ajax initialisation option. Naturally, you might want to post your data as a json string within the body of this ajax call. Here comes the important attributes of the ajax option for that scenario.
1
2
3
4
5
6
7
8
9
$('.my-datatable-div').DataTable( {
  "ajax": {
    "contentType": "application/json",
    "type": "POST",
    "data": function(d) {
      return JSON.stringify({"languages" : ["javascript","golang"]});
    }                     
  }
});

Thursday, July 26, 2018

XML-20116: (Warning) Entity already defined, using the first definition.

I’ve been pulling my hair out seeing the following error message while trying to make a simple XSLT transformation in my spring application.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
XML-20116: (Warning) Entity 'tablemodel' already defined, using the first definition.
 at oracle.xml.parser.v2.XMLError.flushErrorHandler(XMLError.java:425)
 at oracle.xml.parser.v2.XMLError.flushErrors1(XMLError.java:290)
 at oracle.xml.parser.v2.XMLReader.scanNameChars(XMLReader.java:1306)
 at oracle.xml.parser.v2.XMLReader.scanQName(XMLReader.java:2204)
 at oracle.xml.parser.v2.XMLExternalReader.scanQName(XMLExternalReader.java:404)
 at oracle.xml.parser.v2.NonValidatingParser.parseAttrDecl(NonValidatingParser.java:1024)
 at oracle.xml.parser.v2.NonValidatingParser.parseAttlistDecl(NonValidatingParser.java:989)
 at oracle.xml.parser.v2.NonValidatingParser.parseMarkupDecl(NonValidatingParser.java:819)
 at oracle.xml.parser.v2.NonValidatingParser.parseMarkupDecl(NonValidatingParser.java:843)
 at oracle.xml.parser.v2.NonValidatingParser.parseDoctypeDecl(NonValidatingParser.java:644)
 at oracle.xml.parser.v2.NonValidatingParser.parseProlog(NonValidatingParser.java:435)
 at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:393)
 at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:236)
Even though I’ve explicitly instructed my app to use Saxon library, obviously xml parser from oracle gets in the way, but why? It turns out that when you bring the oracle jdbc driver dependency via maven using Oracle's maven repo, it transitively gets other libraries which causes this problem when parsing the XMLs. I just excluded the transitive dependencies for the oracle driver and everything works just fine. I don't think those extra libs are necessary at all at runtime. If you have this in your pom:
1
2
3
4
5
<dependency>
    <groupid>com.oracle.jdbc</groupid>
    <artifactid>ojdbc7</artifactid>
    <version>12.1.0.2</version>
</dependency>
Just exclude the transitive dependencies for the oracle driver and everything works just fine.
1
2
3
4
5
6
7
8
9
10
11
<dependency>
    <groupid>com.oracle.jdbc</groupid>
    <artifactid>ojdbc7</artifactid>
    <version>12.1.0.2</version>
    <exclusions>
        <exclusion>
            <artifactid>xmlparserv2</artifactid>
            <groupid>com.oracle.jdbc</groupid>
        </exclusion>
    </exclusions>
</dependency>
This is the dependency tree by the way
  • ojdbc7 : 12.1.0.2
  • xdb6 : 12.1.0.2
  • orai18n : 12.1.0.2
  • xmlparserv2 : 12.1.0.2 -> obvious culprit
  • oraclepki : 12.1.0.2
  • osdt_cert : 12.1.0.2
  • osdt_core : 12.1.0.2

Happy coding!

Saturday, July 21, 2018

Maven error - Credentials cannot be used for NTLM authentication

I've been using CNTLM to access the resources on the internet through corporate proxy. Recently, I started getting the following error messages from maven.
  • WARNING: NEGOTIATE authentication error: No valid credentials provided (Mechanism level: No valid credentials provided (Mechanism level: Failed to find any Kerberos tgt))
  • WARNING: NTLM authentication error: Credentials cannot be used for NTLM authentication: org.apache.maven.wagon.providers.http.httpclient.auth.UsernamePasswordCredentials
After some investigation, I found out that wagon-http-lightweight artifact has to be overridden in maven configuration. I was able to do this by placing wagon-http-lightweight-2.2.jar file into $M2_HOME\lib\ext folder I'm using maven version number 3.5.2. I haven't checked it with other versions. This artifact can be downloaded from here

Wednesday, February 14, 2018

Shopify dashing - swiping jira issues widget

Based on Matt Snider's dashing widget and Swiper from iDangero.us

See it live here as part of a complete Agile Dashboard, with some cartoon sugar :)

Source code can be accessed here

Tuesday, February 6, 2018

Shopify dashing - How to avoid list widget flickering

Please note that the live demo cannot be viewed on IE because dashing does not support IE, either. Because basically Dashing relies on "Server Sent Events"



Original list widget in dashing flickers annoyingly, as also mentioned here. That's simply because the widget redraws the complete list every time there's an update from the server side.

See the problem here (Buzzwords widget flickers)

dashing demo

This widget, on the other hand, is an alternative and a drop-in replacement for the original list widget. It simply creates the list elements beforehand and updates the values inline so that the widget is rendered without any flickering.

view raw README.md hosted with ❤ by GitHub
class Dashing.List extends Dashing.Widget
onData: (data) ->
for value, index in data.items
$(@node).find('ul li:nth-child(' + (index+1).toString() + ')' + ' span.value').text(value.value)
$(@node).find('ul li:nth-child(' + (index+1).toString() + ')' + ' span.label').text(value.label)
view raw list.coffee hosted with ❤ by GitHub
<h1 class="title" data-bind="title"></h1>
<ul class="list-nostyle">
<li>
<span class="label"></span>
<span class="value"></span>
</li>
<li>
<span class="label"></span>
<span class="value"></span>
</li>
<li>
<span class="label"></span>
<span class="value"></span>
</li>
<li>
<span class="label"></span>
<span class="value"></span>
</li>
<li>
<span class="label"></span>
<span class="value"></span>
</li>
<li>
<span class="label"></span>
<span class="value"></span>
</li>
<li>
<span class="label"></span>
<span class="value"></span>
</li>
<li>
<span class="label"></span>
<span class="value"></span>
</li>
<li>
<span class="label"></span>
<span class="value"></span>
</li>
</ul>
<p class="more-info" data-bind="moreinfo"></p>
<p class="updated-at" data-bind="updatedAtMessage"></p>
view raw list.html hosted with ❤ by GitHub

How to convince MUnit Maven Plugin that you have an enterprise license

Let's say you have an enterprise license for Mule Runtime and you'd like to see the coverage report for your unit tests in a CI environment like Jenkins or Bamboo. You configured everything in your pom.xml as described in the documentation but you keep seeing the following message.

[INFO] [CoverageManager] Coverage feature runs over EE runtime only. Feature is shut down

OK, you need to convince the plugin that you're an enterprise customer but how?

Surprisingly very simple, but hard to find out unless you do some reverse engineering because this information is not documented, or let's say was not documented last time I checked.

just make sure that you don't have the following community artifact dependency in your pom.xml

<dependency>
  <groupId>org.mule</groupId>
  <artifactId>mule-core</artifactId>
  <version>${mule.version}</version>
  <scope>provided</scope>
</dependency>

and instead, you have this enterprise artifact dependency

<dependency>
  <groupId>com.mulesoft.muleesb</groupId>
  <artifactId>mule-core-ee</artifactId>
  <version>${mule.version}</version>
  <scope>provided</scope>
</dependency>

Tuesday, August 13, 2013

mapping XML to Java objects without XSD

There is a common misconception that JAXB requires an XML Schema

Until I read the following blog post, JAXB xjc Java Generation with DTD, I was also thinking that there was no binding solution for DTDs when you try to map XML content into Java objects. 

For that reason, while maintaining some legacy applications using DTD, I was being forced to write my own parser(using SAX generally) for each different XML structure.

Luckily, although not part of the JAXB specification, the XJC tool offers the ability to generate Java classes from a DTD.

Simply execute the following command in your console, 

1
"%JAVA_HOME%\bin\xjc" -dtd -d generatedsrc -p the.target.packagename sample.dtd
1
2
3
-d <dir>  : generated files will go into this directory
-p <pkg>  : specifies the target package
-dtd   : treat input as XML DTD


Sample DTD File : Product Catalog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!ENTITY AUTHOR "John Doe">
 
<!ENTITY COMPANY "JD Power Tools, Inc.">
 
<!ENTITY EMAIL "jd@jd-tools.com">
 
 
<!ELEMENT CATALOG (PRODUCT+)>
 
 
<!ELEMENT PRODUCT
 
(SPECIFICATIONS+,OPTIONS?,PRICE+,NOTES?)>
 
<!ATTLIST PRODUCT
 
NAME CDATA #IMPLIED
 
CATEGORY (HandTool|Table|Shop-Professional) "HandTool"
 
PARTNUM CDATA #IMPLIED
 
PLANT (Pittsburgh|Milwaukee|Chicago) "Chicago"
 
INVENTORY (InStock|Backordered|Discontinued) "InStock">
 
 
<!ELEMENT SPECIFICATIONS (#PCDATA)>
 
<!ATTLIST SPECIFICATIONS
 
WEIGHT CDATA #IMPLIED
 
POWER CDATA #IMPLIED>
 
 
<!ELEMENT OPTIONS (#PCDATA)>
 
<!ATTLIST OPTIONS
 
FINISH (Metal|Polished|Matte) "Matte"
 
ADAPTER (Included|Optional|NotApplicable) "Included"
 
CASE (HardShell|Soft|NotApplicable) "HardShell">
 
 
<!ELEMENT PRICE (#PCDATA)>
 
<!ATTLIST PRICE
 
MSRP CDATA #IMPLIED
 
WHOLESALE CDATA #IMPLIED
 
STREET CDATA #IMPLIED
 
SHIPPING CDATA #IMPLIED>
 
 
<!ELEMENT NOTES (#PCDATA)>
Running XJC and producing Java classes
1
2
3
4
5
6
7
8
9
xjc.exe -dtd -d generatedsrc -p com.example.product.catalog product_catalog.dtd
parsing a schema...
compiling a schema...
com\example\product\catalog\CATALOG.java
com\example\product\catalog\OPTIONS.java
com\example\product\catalog\ObjectFactory.java
com\example\product\catalog\PRICE.java
com\example\product\catalog\PRODUCT.java
com\example\product\catalog\SPECIFICATIONS.java
Product.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2013.11.02 at 02:15:25 PM VET
//
 
 
package com.example.product.catalog;
 
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
import javax.xml.bind.annotation.adapters.NormalizedStringAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 
 
/**
 *
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "specifications",
    "options",
    "price",
    "notes"
})
@XmlRootElement(name = "PRODUCT")
public class PRODUCT {
 
    @XmlAttribute(name = "NAME")
    @XmlJavaTypeAdapter(NormalizedStringAdapter.class)
    protected String name;
    @XmlAttribute(name = "CATEGORY")
    @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
    protected String category;
    @XmlAttribute(name = "PARTNUM")
    @XmlJavaTypeAdapter(NormalizedStringAdapter.class)
    protected String partnum;
    @XmlAttribute(name = "PLANT")
    @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
    protected String plant;
    @XmlAttribute(name = "INVENTORY")
    @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
    protected String inventory;
    @XmlElement(name = "SPECIFICATIONS", required = true)
    protected List<SPECIFICATIONS> specifications;
    @XmlElement(name = "OPTIONS")
    protected OPTIONS options;
    @XmlElement(name = "PRICE", required = true)
    protected List<PRICE> price;
    @XmlElement(name = "NOTES")
    protected String notes;
 
    /**
     * Gets the value of the name property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *    
     */
    public String getNAME() {
        return name;
    }
 
    /**
     * Sets the value of the name property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *    
     */
    public void setNAME(String value) {
        this.name = value;
    }
 
    /**
     * Gets the value of the category property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *    
     */
    public String getCATEGORY() {
        if (category == null) {
            return "HandTool";
        } else {
            return category;
        }
    }
 
    /**
     * Sets the value of the category property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *    
     */
    public void setCATEGORY(String value) {
        this.category = value;
    }
 
    /**
     * Gets the value of the partnum property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *    
     */
    public String getPARTNUM() {
        return partnum;
    }
 
    /**
     * Sets the value of the partnum property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *    
     */
    public void setPARTNUM(String value) {
        this.partnum = value;
    }
 
    /**
     * Gets the value of the plant property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *    
     */
    public String getPLANT() {
        if (plant == null) {
            return "Chicago";
        } else {
            return plant;
        }
    }
 
    /**
     * Sets the value of the plant property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *    
     */
    public void setPLANT(String value) {
        this.plant = value;
    }
 
    /**
     * Gets the value of the inventory property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *    
     */
    public String getINVENTORY() {
        if (inventory == null) {
            return "InStock";
        } else {
            return inventory;
        }
    }
 
    /**
     * Sets the value of the inventory property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *    
     */
    public void setINVENTORY(String value) {
        this.inventory = value;
    }
 
    /**
     * Gets the value of the specifications property.
     *
     * <p>
     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the JAXB object.
     * This is why there is not a <CODE>set</CODE> method for the specifications property.
     *
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     *    getSPECIFICATIONS().add(newItem);
     * </pre>
     *
     *
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {@link SPECIFICATIONS }
     *
     *
     */
    public List<SPECIFICATIONS> getSPECIFICATIONS() {
        if (specifications == null) {
            specifications = new ArrayList<SPECIFICATIONS>();
        }
        return this.specifications;
    }
 
    /**
     * Gets the value of the options property.
     *
     * @return
     *     possible object is
     *     {@link OPTIONS }
     *    
     */
    public OPTIONS getOPTIONS() {
        return options;
    }
 
    /**
     * Sets the value of the options property.
     *
     * @param value
     *     allowed object is
     *     {@link OPTIONS }
     *    
     */
    public void setOPTIONS(OPTIONS value) {
        this.options = value;
    }
 
    /**
     * Gets the value of the price property.
     *
     * <p>
     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the JAXB object.
     * This is why there is not a <CODE>set</CODE> method for the price property.
     *
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     *    getPRICE().add(newItem);
     * </pre>
     *
     *
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {@link PRICE }
     *
     *
     */
    public List<PRICE> getPRICE() {
        if (price == null) {
            price = new ArrayList<PRICE>();
        }
        return this.price;
    }
 
    /**
     * Gets the value of the notes property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *    
     */
    public String getNOTES() {
        return notes;
    }
 
    /**
     * Sets the value of the notes property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *    
     */
    public void setNOTES(String value) {
        this.notes = value;
    }
 
}