Submit HTML form using AngularJS

The payment gateway I’m integrating with requires a post from a form to navigate to their payment page. Some of the information I need to post is dependent on the results from a call to my back end server.

My first attempt was to invoke my controller from a regular JavaScript function called in onsubmit. However, as all $http calls in AngularJS are asynchronous there was no way to wait for the result of my back end server call before either allowing or blocking submission of the form.

The approach that worked was to create the form without an action or method. When the ‘submit’ button is clicked, the controller function (createPaymentAndNavigate) is called. This does the call to the back end, in the success callback sets the action and method on the form, and then submits the form.

HTML

<form id="bookingForm" name="bookingForm" novalidate >
...
<button class="btn btn-success btn-lg pull-right" ng-click="createPaymentAndNavigate(bookingForm.$valid)">Payment</button>
...
</form>

Success callback in AngularJS controller

var bookingForm = document.getElementById('bookingForm')
bookingForm.action = "https://www.example.com/xyz/process.trans";
bookingForm.method = "POST";
bookingForm.submit();

Posted in Programming | Tagged , | Leave a comment

Xamarin View Fails To Bind To Model

MvxBind:Warning: 9.81 Unable to bind: source property source not found Property:SomeObject on null-object

One of the causes of the above error is mixing up the order of base.OnCreate and SetContentView calls in the Views OnCreate method.

Below is an example of the correct order.

protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);
    SetContentView(Resource.Layout.MyLayout);
}

Posted in Programming | Tagged , | Leave a comment

5 Minute NLog Wrapper: Limiting The Number Of Emails Sent

If you’re using an Email target to send notifications when an error occurs, it may be useful to limit the frequency of those emails. One way of achieving this is to wrap your target that sends email in a Wrapper target. This custom target will intercept calls to the Email target and, based on the time since the last email was sent, either pass on the log event to the wrapped target or swallow it.

[Target("FrequencyWrapper", IsWrapper = true)]
public class NLogFrequencyWrapper : WrapperTargetBase
{
    private DateTime _lastLogEventOccurredAt = DateTime.MinValue;
 
    protected override void Write(AsyncLogEventInfo logEvent)
    {
        if ((DateTime.Now - _lastLogEventOccurredAt).TotalMinutes >= MinLogIntervalInMinutes)
        {
            _lastLogEventOccurredAt = DateTime.Now;
            this.WrappedTarget.WriteAsyncLogEvent(logEvent);
        }
        else
        {
            logEvent.Continuation(null);
        }
    }
 
    [DefaultValue(30)]
    public int MinLogIntervalInMinutes { get; set; }
}
<extensions>
  <add assembly="MyAssembly"/>
</extensions>
 
<target name="limitedEmail" type="FrequencyWrapper" minLogIntervalInMinutes="40">
  <target name="email" xsi:type="Mail"
      ...
  />
</target>

Posted in Programming | Tagged , | 3 Comments

JEE7 Launch with Arun Gupta

The Jozi JUG is hosting Arun Gupta on 26 August for the launch of JEE7. You can RSVP on Meetup. See you there!

Arun Gupta will be flying in (not to Waterkloof) to give a presentation to the Jozi JUG on all the new goodness in JEE7. It’s not often we get international speakers, let alone of this caliber, so this one is not to be missed!

About the speaker:
Arun Gupta is a Java EE & GlassFish Evangelist working at Oracle. Arun has over 14 years of experience in software industry working in various distributed computing technologies, Java(TM) platform, and several web-related technologies. In his current role, he works very closely to create and foster the community around Java EE & GlassFish and related technologies.

To find out more about Arun, head over to https://blogs.oracle.com/arungupta/

Duke says... thumbs up to Arun!

Duke says... thumbs up to Arun!

Posted in Uncategorized | Leave a comment

Unit Testing WebMethods Services With JUnit

Unit tests are ubiquitous (or at least should be) amongst software projects. Some environments are easier to unit test than others, and WebMethods is somewhere in the middle. As the services run on a server and the tests in your IDE, we need to connect to the server to run tests. Strictly speaking it’s integration testing, but as the server is really an extension of your IDE I’m going to call it unit testing.

Step 1: Setup your dependencies

I’m using Maven. Set up instructions for the client jar dependencies can be found here.

Step 2: Create your tests

I’ve included setup and teardown methods that are invoked once to create and destroy the expensive Context variable through which all services are called.

package example;
 
import com.wm.app.b2b.client.Context;
import com.wm.app.b2b.client.ServiceException;
import com.wm.data.IData;
import com.wm.data.IDataCursor;
import com.wm.data.IDataFactory;
import com.wm.data.IDataUtil;
import org.junit.AfterClass;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.BeforeClass;
 
/**
 *
 * @author Michael.Williams
 *
 */
public class TestWMString {
    private static final String INPUT_LABEL = "inString";//Input variable name matching the service
    private static final String OUTPUT_LABEL = "value";//Output variable name matching the service
 
    //The Context is the variable we will connect to the server with and invoke services through.
    private static Context context = new Context();
 
    public TestWMString() {
    }
 
    /**
     * The Context is expensive to create and so is done through a method annotated @BeforClass.
     * 
     * @throws ServiceException 
     */
    @BeforeClass
    public static void setup() throws ServiceException {
        String server = "localhost:5555";
        String username = "Administrator";
        String password = "manage";
 
        context.connect(server, username, password);
    }
 
    /**
     * We must remember to disconnect the Context from the server once we have completed our unit tests.
     * 
     * @throws ServiceException 
     */
    @AfterClass
    public static void teardown() throws ServiceException {
        context.disconnect();
    }
 
    /**
     * This method handles the details of calling the service.
     * 
     * @param inputString
     * @return
     * @throws ServiceException 
     */
    private int invokeStringLengthService(String inputString) throws ServiceException {
        IData input = IDataFactory.create();//IData objects are data structures used to store input and output variables for service invocation.
        IDataCursor cursor = input.getCursor();//The cursor is used to traverse and manipulate an IData object.
        IDataUtil.put(cursor, INPUT_LABEL, inputString);//IDataUtil makes it easy to manipulate add and find variables in an IData object. Here we're adding an input variable called 'inString'
 
        IData output = context.invoke("pub.string", "length", input);//This invokes the service on the server. We pass in the package and name of the service as well as our input variables.
 
        IDataCursor outputCursor = output.getCursor();
        return IDataUtil.getInt(outputCursor, OUTPUT_LABEL, -1);//We retrieve the output variable from the IData object as an int. Various convenience methods are available to get other types of objects.
    }
 
    /**
     * Our unit test that double checks Software AG's math.
     * 
     * @throws ServiceException 
     */
    @Test
    public void testStringLength() throws ServiceException {
        int length = invokeStringLengthService("12345");
        assertEquals(5, length);
    }
}

Posted in Programming, Software AG | Tagged , , , | 1 Comment

WebMethods Client – java.lang.NoClassDefFoundError: iaik/x509/X509Certificate

If you’re calling a WebMethods service from a client and you get the error below, you need to add the enttoolkit jar to your classpath. It can be found under the Software AG installation directory on the server: \common\lib\ext\enttoolkit.jar

java.lang.NoClassDefFoundError: iaik/x509/X509Certificate
	at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
	at com.wm.net.HttpURLConnection.getHttpURLConnection(HttpURLConnection.java:105)
	at com.wm.app.b2b.client.BaseContext.getURLConnection(BaseContext.java:456)
	at com.wm.app.b2b.client.Context.invoke(Context.java:950)
	at com.wm.app.b2b.client.Context.invoke(Context.java:900)
	at com.wm.app.b2b.client.Context.connect(Context.java:541)
	at com.wm.app.b2b.client.Context.connect(Context.java:495)

Posted in Programming, Software AG | Tagged , | Leave a comment

WebMethods Client – NoClassDefFoundError: javax/mail/internet/ParseException

If you’re calling a WebMethods service from a client and you get the error below, you need to add the java mail jar to your classpath.

java.lang.NoClassDefFoundError: javax/mail/internet/ParseException
	at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
	at com.wm.util.Base64.encode(Base64.java:77)
	at com.wm.app.b2b.client.BaseContext.setAuthentication(BaseContext.java:598)
	at com.wm.app.b2b.client.Context.connect(Context.java:492)

Posted in Programming, Software AG | Tagged , | Leave a comment

WebMethods Client Maven Dependencies For 8.2.2.0

If you’re invoking WebMethods services from a Java client, you need 3 jars, two of which are specific to Software AG.

Step 1: Add dependencies to pom

<!-- Software AG specific dependencies-->
<dependency>
    <groupId>com.softwareag</groupId>
    <artifactId>wm-isclient</artifactId>
    <version>8.2.2.0</version>
</dependency>
<dependency>
    <groupId>com.softwareag</groupId>
    <artifactId>enttoolkit</artifactId>
    <version>8.2.2.0</version>
</dependency>
<!-- Java Mail dependency-->
<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.4.7</version>
</dependency>

Step 2: Finding the jars

The jars can be found under the Software AG installation directory on the server.
\common\lib\wm-isclient.jar
\common\lib\ext\enttoolkit.jar

Step 3: Add jars manually to local repository

mvn install:install-file -DgroupId=com.softwareag -DartifactId=wm-isclient -Dversion=8.2.2.0 -Dpackaging=jar -Dfile=wm-isclient.jar
mvn install:install-file -DgroupId=com.softwareag -DartifactId=enttoolkit -Dversion=8.2.2.0 -Dpackaging=jar -Dfile=enttoolkit.jar

Posted in Programming | Tagged , , | 1 Comment

Joburg GDG BarCamp – 11 May

The Johannesburg Google Developer Groups BarCamp is on this Saturday from 09:30 at the Jozi Hub in 44 Stanley Avenue, Milpark.

These kind of events are a great networking, learning and teaching opportunity with something for everyone. So if you’re interested in any Google related technology, this is the place to be.

We are planning a GDG BarCamp for the 11th May 2013. There will be talks in the morning but most of the day will be set aside for lightning talks in an un-conference format.

Topics to be covered

  • Android development
  • Google APIs
  • PhoneGap
  • Building back-end services with Drupal

For more details and to RSVP checkout the Meetup page.

 

Africa GDG

Africa GDG

Posted in Event | Tagged , , , | Leave a comment

WebMethods Throws NullPointerException When Calling Flow Service In Debug Mode

When debugging a flow service, on calling another flow service an error dialog popped up stating a null pointer exception had occurred. No other information was displayed. On dismissing the dialog, the debugging session terminated.

This did not occur when running the same flow service, nor did it occur on all flow service calls.

While trying to debug the problem, I selected ‘Validate Input’ on the flow service being called, then saved the service. The call to the flow service ceased throwing the error. I then deselected ‘Validate Input’, and saved the file. The error did not come back.

I’m still trying to figure out what caused the issue, but if you experience the problem, try editing the flow service and saving it.

Posted in Programming | Tagged , | Leave a comment