Friday, December 19, 2014

JBoss AS 7 not accepting remote connections

For those who use JBoss AS 7 and want to connect to your application using the IP or server name from a computer in the intranet, you need to do this:
This is for Dev Environments only!
The answer is... Change the 127.0.0.1 (localhost) to 0.0.0.0 in standalone.xml

Friday, November 7, 2014

Apex Component error: Element type "input" should be followed by either attribute specifications, ">" or "/>"

Not sure if you have faced this situation, but let's see what we're trying to accomplish.

Scenario Display 2 radio buttons, one unchecked and another one checked based on the value of a variable.

How was developed
For educational purposes I'll just show 1 radio button :)
Looks simple, however we got the weird error message listed as title of this post.

Solution
After thinking carefully and asking salesforce support, we end up with the same solution
In order to display 1 radio button only, we have to write code for 2 radio buttons!

I hope this saves you valuable time.

Monday, October 13, 2014

Invoke a SOAP API written in Salesforce using Axis

I had to consume an API written by someone else in Salesforce. I got the WSDL and the EndPoint.

Essentially what I had to do is to replace existing code I wrote a year ago to perform User Provisioning in Salesforce and rely on this API to perform that logic.

Now the interesting part is how to write my client, the obvious answer was to use WSDL2Java (Axis), because I don't want to write much code. And this is my final code: This is a simple Cooking recipe with the exception of these lines: Things to keep in mind (otherwise you'll get "INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session"):
  1. Open a session in Salesforce (that's how get permission to invoke the API)
  2. Populate SessionHeader object (with Salesforce sessionId)
  3. Set the Header to your Port before making your call

Tuesday, September 16, 2014

Querying a DATE field and a TIMESTAMP

When I was running a few reports, I faced a very interesting scenario.
(Because I'm lazy I wrote a Stored Proc with all my queries and used a scheduled Job to run it)

Anyway, the idea here is that I had to run my report for a certain window of time.
So I declared my start date and end date variables as DATE and wrote all my queries using: And when I ran for the first time my queries in the body of the Stored Proc I got a bunch of errors. Why???

After thinking seriously, that maybe I've lost my edge I just realized that in a few tables the created_on column was declared as DATE and in others as TIMESTAMP. Not the end of the world, I just decided to change the data type of my variables to TIMESTAMP and end of the story :)

Monday, August 25, 2014

Java Code Refactoring


I recently browsed again the excellent book Code Complete from Steve McConnell while in the middle of several Java code reviews. Although the book is nor specifically dedicated to Java code, I still found it quite useful and inspiring.

The chapter on refactoring in particular offers a very practical perspective that all programmer should have in mind when it comes to infuse a dose of evolution in the life cycle of their software.

What I found particularly valuable are the checklists that the author has put together: reasons to refactor, specific re-factorings (data level, statement level, routine-level, class-implementation, class-interface, system-level), refactoring safely, strategies, summary.

Since I do not have time to comment every item in these checklists, I decided to pick-up those that are not trivial or obvious and might bring the best return on your refactoring investment.

In a future post, I would like to illustrate some of these refactoring techniques with java code snippets, but that will be later :)


Checklist: Reasons to Refactor
  • Code is duplicate
  • A routine is too long
  • A loop is too long or too deeply nested
  • A class/interface/method has poor cohesion ⇐
  • A class interface does not provide a consistent level of abstraction ⇐
  • A parameter list has too many parameters ⇐
  • Changes within a class tend to be compartmentalized
  • Changes require parallel modifications to multiple classes ⇐
  • Inheritance hierarchies have to be modified in parallel
  • Related data items that are used together are not organized into classes ⇐
  • A routine uses more features of another class than of its own class
  • A primitive data type is overloaded
  • A class doesn't do very much
  • A chain of routines passes tramp data ⇐
  • A middle man object isn't doing anything
  • One class is overly intimate with another
  • A routine has a poor name
  • Data members are public
  • A subclass uses only a small percentage of its parents' routines
  • Comments are used to explain difficult code
  • Global variables are used
  • A routine uses setup code before a routine call or takedown code after a routine call
  • A program contains code that seems like it might be needed someday

Checklist: Summary of Refactorings
  • Data Level Refactoring
  • Replace a magic number with a named constant ⇐
  • Rename a variable with a clearer or more informative name
  • Move an expression inline
  • Replace an expression with a routine
  • Introduce an intermediate variable
  • Convert a multi-use variable to a multiple single-use variables ⇐
  • Use a local variable for local purposes rather than a parameter
  • Convert a data primitive to a class
  • Convert a set of type codes to a class
  • Convert a set of type codes to a class with subclasses
  • Change an array to an object
  • Encapsulate a collection ⇐
  • Replace a traditional record with a data class
  • Statement Level Refactorings
  • Decompose a boolean expression
  • Move a complex boolean expression into a well-named boolean function
  • Consolidate fragments that are duplicated within different parts of a conditional
  • Use break or return instead of a loop control variable
  • Return as soon as you know the answer instead of assigning a return value within nested if-then-else statements
  • Replace conditionals with polymorphism (especially repeated case statements) ⇐
  • Create and use null objects instead of testing for null values
  • Routine Level Refactorings
  • Extract a routine
  • Move a routine's code inline
  • Convert a long routine to a class
  • Substitute a simple algorithm for a complex algorithm
  • Add a parameter
  • Remove a parameter
  • Separate query operations from modification operations
  • Combine similar routines by parameterizing them
  • Separate routines whose behavior depends on parameters passed in ⇐
  • Pass a whole object rather than specific fields
  • Pass specific fields rather than a whole object
  • Encapsulate downcasting ⇐ 


Class Implementation Refactorings

  • Change value objects to reference objects
  • Change reference objects to value objects
  • Replace virtual routines with data initialization
  • Change member routine or data placement
  • Extract specialized code into a subclass ⇐
  • Combine similar code into a superclass
  • Class Interface Refactorings
  • Move a routine to another class
  • Convert one class to two
  • Eliminate a class
  • Hide a delegate ⇐
  • Replace inheritance with delegation
  • Replace delegation with inheritance
  • Remove a middle man ⇐
  • Introduce a foreign routine
  • Introduce a class extension
  • Encapsulate an exposed member variable
  • Remove Set() routines for fields that cannot be changed
  • Hide routines that are not intended to be used outside the class
  • Encapsulate unused routines ⇐
  • Collapse a superclass and subclass if their implementations are very similar
  • System Level Refactorings
  • Duplicate data you can't control ⇐
  • Change unidirectional class association to bidirectional class association
  • Change bidirectional class association to unidirectional class association
  • Provide a factory routine rather than a simple constructor
  • Replace error codes with exceptions or vice versa



Friday, July 18, 2014

Memory Settings on WebMethods - Windows Installation as Service

According to SoftwareAG, if you want to modify the memory settings of your WebMethods Installation (IS - Integration Server) you have to do it in one place:

setenv.bat
set JAVA_MIN_MEM=1024M
set JAVA_MAX_MEM=2048M
set JAVA_MAX_PERM_SIZE=512M

I'm not saying this is wrong, because is not if you start your IS using command line by invoking startup.bat (X:\SoftwareAG\IntegrationServer\bin)

However for us mortals (muggles) who have our installation configured as a Windows Service I found this that my service is started by executing an EXE file (which uses a config file named wrapper.conf):
X:\SoftwareAG\profiles\IS\configuration\wrapper.conf

Inside that file you'll find all sort of properties but no matter how many changes you perform in this file, you won't see any change reflected (no mater how many times you restart your service), unless you have checked at the end of this file where there is a commented line (leave it commented, no need to change anything) which actually includes an additional file custom_wrapper.conf (aha! That's the right spot!)

Feel free to modify this entries (those are the values I set to my DEV environment):
wrapper.java.additional.7=-Xms2048M
wrapper.java.additional.8=-Xmx2048M
wrapper.java.additional.9=-XX:MaxPermSize=512M 

If you want to add an additional property to your JVM (since the last property ends in 17), I added an additional property 18:
wrapper.java.additional.18=-Dcom.sun.management.jmxremote.port=7007 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false

Restart your IS Windows Service and you'll see your changes reflected.

Monday, June 23, 2014

How to configure webMethods JDBC Adapter to use Oracle RAC

If you have created a JDBC Adapter on WebMethods, it's a really straight forward process, but what happens when we have to connect to a Cluster

Try it and see what happens...

Now it's not that simple isn't?

Thankfully I have a workaround
  1. Leave blank serverName, databaseName and portNumber fields.
  2. In Other Properties enter your URL:
    url=jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=on)
    (ADDRESS=(PROTOCOL=TCP)(HOST=host1) (PORT=1521))
    (ADDRESS=(PROTOCOL=TCP)(HOST=host2) (PORT=1521))
    (CONNECT_DATA=(SERVICE_NAME=service)))
I hope this will help you.

Friday, May 16, 2014

Built-In Services For Connections - WebMethods

Integration Server provides built‐in services that enable you to programmatically control connections.b You can use them to enable and disable a connection, and to return usage statistics and the current state (Enabled or Disabled) and error status for a connection. These services are located in the WmART package, in the pub.art.connection folder.

There are two built‐in services, setAdapterServiceNodeConnection and setPollingNotificationNodeConnection, that enable you to change the connection associated with an adapter service or notification respectively.

This is going to help you a lot and save you so much time if you haven't worked with this tool before.

Wednesday, April 23, 2014

Max number of values in IN clause

Somebody asked me about this a few days ago, and this person (really sure of what he was talking about) told me: "You can only pass a limit of 200 items in a IN clause (during a DELETE)"

I'm not an Expert DBA (know it all), but I do remember that you can pass up to 1000 elements. And that was my counter argument to this guy (as always if you don't believe me double check with your best friend or test it
In the past it used to be 256 elements, but that was in Oracle 8.

Tuesday, March 4, 2014

Add Token Based Authentication on Spring Security

Problem I have an application which has already implemented Basic Authentication using Spring Security.
Now as part of a new requirement I have to enable a Token based authentication as well.
My first task was to updgrade to Spring 3.0.7 and to Spring Security 3.1.3 among other dependicies that needed an update as well.
After that, let's go to the meaty part of this implementation :)
While researching I couldn't find any example, only pieces, that's why I'm publishing and sharing my findings with all the community:

At least I knew that I had to implement another Authentication Provider (that's why I needed to Upgrade my App) and something to catch the event of login and tell Spring to perform another authentication (like a Filter, maybe?)

This is my implementation: Spring's config
PingIdentityTokenValidatorImpl (Validates Given token)
KaplanOAuth2UserDetailsService (Performs Authentication, generates user following spring security standards)
KaplanCustomOncePerRequestFilterFilter (This filter does the trick) Just add it to your security configuration in the right place of the chain of execution and you're set Although, my original approach was to extend from AbstractAuthenticationProcessingFilter, however I saw it being invoked multiple times per request (it didn't bother me), but that wasn't good enough for me, also it was more complex :P

Friday, February 14, 2014

Previously initiated loading for a different type with name "javax/management/MBeanServer"

When I was doing a migration / upgrade to Spring 3.1, I faced a really weird Error.

My App was using Jetty to run deploy my WAR file.


Short story / Long Story

Although I was not using MX4J library in my project, I remembered that:
"Jetty defaults to overriding the normal J2SE class loader delegation model  (which calls for delegating to the parent)."

Therefore, this could be fixed by using this System Property:


-Dorg.mortbay.jetty.webapp.parentLoaderPriority=true



This is how you should do it in your pom:


And that error will go away.


Friday, January 3, 2014

JSONProvider builds wrong String

Looking at my backlog I found a very interesting ticket:

As a consumer of JSON web services, I would like the services to render fields with consistent types regardless of the content. When postal codes begin with zero, they are rendered as strings. When they begin with a non-zero character, they are rendered as numbers. This makes handling the JSON responses very cumbersome and causes hard to track down bugs in our code. 

It would be better if the conversion checked the type in the xsd (in the case of postal codes, string) and rendered it accordingly. 


Weird, isn't it? Then I realize, I wasn't the only one with this issue, a found a few other clueless developers with the same problem (look here and here), so that, I wasn't alone.

But so far no one had an answer, until I checked the code of my JSONProvider, this one: org.apache.cxf.jaxrs.provider.JSONProvider

My conclusion was simple, depending on the value of the string passed to the Converter, it will be casted to Boolean, String or Number.

There are 2 choices: Create my own custom JSONProvider extending from the original (and try to fix the world) or implement another which really worked as expected.

In a few words, I chose JacksonJsonProvider, however I had to customize it a little bit, because I needed to fix the issue and not create a new one (i needed the same output), and so far this is the result:

This is the original output

This is my implementation
And my new output I still have something to fix-customize because that "ArrayList" looks ugly though, but code and areCode now make sense, because they match my XSD and Pojo as well.