Salesforce wsc hacking: yet another Open Source encounter?

As I wrote in an earlier post I’ve volunteered to become a committer to the wsc tool and are in the progress of making minor tweaks and enhancements for a coming release 23.

My plan was that this release should be no more than a “maintenance” release covering most of the relevant issues. And I do have a number of ideas for major changes for a possible release 24, e.g.:

  • Fixing issue 51 – or at least provide a usable implementation hopefully inspired by input from Martin Haynes
  • Reworking/reimplementing the wsdlc tool and templating mechanism
  • Reworking infrastructure parts, possibly using JAXB/JAX-WS
  • Mavenize the build, divide build tools and infrastructure, 2 perhaps 3 artifacts
  • Adding unit tests

I stopped further developments on the “23 branch” when I realized that there apparently already was a “fork” on github.
Continue reading

Posted in Java, Open Source, Salesforce | Tagged , | Leave a comment

Salesforce wsc hacking: new committer

Ok, things change rapidly sometimes.

The short story is that I wrote directly to the Owners of the WSC tool in order to get some information about when changes could be expected.

The response was basically that they no longer maintain the WSC tool and if I was interested I could become a committer. I was and now I am ๐Ÿ™‚

Currently working on wsc-23 to be released soon – probably by the end of January 2013.

Contains most of the stuff already discussed here and probably some other enhancements regarding the wsdlc tool.

Update 2013-01-31: There appear to be some confusion about the proper version/codebase of the wsc tool. I will not make a new formal release until I get some definitive answers… We might need to fork ๐Ÿ™‚

Posted in Personal, Salesforce | Tagged , , | Leave a comment

Salesforce wsc hacking: getting rid of SessionTimedOutException

The SoapConnection java class sports a private static inner Exception, the SessionTimedOutException. This Exception is used internally only to quickly pass control from the parseDetail() method back to the send() method.

This is bad practice, using an Exception to control flow of execution. And in this case the infrastructure is doing exception handling in the first place… There has to be a better way.

Continue reading

Posted in Java, Salesforce | Tagged , , , | Leave a comment

Salesforce wsc hacking: adding RequestTimedOutException

I have a number of situations where a RequestTimedOutException would be appropriate instead of just a ConnectionException when SoapConnection.send() encounters a SocketTimeoutException.

This would ease retry implementations (related to timeouts) in that they would only have to consider a special type of exception and does not have to revert to parsing exception messages.

If a RequestTimedOutException extends ConnectionException the handling of SocketTimeoutException in the SoapConnection class can be done without changing the api. It is a simple matter of changing the type of exception thrown as response to SocketTimeoutExceptions.

E.g. in SoapConnection:

112
113
114
115
116
117
        } catch (SocketTimeoutException e) {
            long timeTaken = System.currentTimeMillis() - startTime;
            throw new RequestTimedOutException("Request to " + url + " timed out. TimeTaken=" + timeTaken +
                    " ConnectionTimeout=" + config.getConnectionTimeout() + " ReadTimeout=" + 
                    config.getReadTimeout(), e);
        }

And the RequestTimedOutException, e.g. at the bottom of SoapConnection:

    public static class RequestTimedOutException extends ConnectionException {
        private static final long serialVersionUID = 1L;
 
        private RequestTimedOutException(String message, Exception e) {
            super(message, e);
        }
    }

WSC issue 67.

Posted in Java, Salesforce | Tagged , , , | Leave a comment

Salesforce wsc hacking: removing compiler warnings

I hate compiler warnings. These little yellow warning signs in Eclipse annoys me. I will go far to avoid compiler warnings in my own code.

But what about generated code? Actually generated code is the worst as it does not make sense to correct the code to remove the warnings โ€“ they will reappear when the code is regenerated. And it demonstrates sloppiness in the code generation tool.

In this article I will work through and demonstrate how to remove the compiler warnings from the wsc generated code, and some of the infrastructure code as well.

Continue reading

Posted in Java, Salesforce | Tagged , , , | Leave a comment

Unit-testing time/timing dependent components

I’m often faced with developing components that are depending on time or timing, one way or the other.

An example can be a query that returns all “active” rows, given current date/time and where the rows have effective and expiry columns. Or components that report different state depending on time T, T+n, T+m etc.

Unit-testing components like these can be a nuisance, unless “current time” is part of the interface in the first place, and with some sleep() and stuff in the second situation. Not ideal.
Continue reading

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

SimpleDateFormat instances are not thread-safe

It comes as a surprise to many developers that SimpleDateFormat instances are not thread-safe. Sometimes I encounter utility classes like below:

public class DateUtil {
	public static final SimpleDateFormat ISO_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
	public static final SimpleDateFormat SQL_TIMESTAMP_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
	// etc...
	public static Date parse(String date) throws ParseException {
		return ISO_DATE_FORMAT.parse(date);
	}
	public static String format(Date date) {
		return ISO_DATE_FORMAT.format(date);
	}
	// etc...
}

Looks innocent, but it will get you into trouble sooner or later if accessed by more than one thread at a time. And the problems are hard to find and debug, from strange dates in different application layers to strange exceptions where you’d expect none in a healthy system. And errors that only occurs very rare and more often when the system is under load…

Then what to do?
Continue reading

Posted in Java | Tagged | 5 Comments

Salesforce JAXB: Using wsimport to generate client artifacts

The Salesforce developer documentation provides JAVA examples based on WSC. WSC is a nice tool that makes interfacing to SFDC simple and easy, providing an EnterpriseConnection hiding all the details in calling SFDC.

But, WSC might not be for you:

  • Proprietary, not standards based
  • You might not be allowed to add third-party libraries to your application stack; or the process is too cumbersome…
  • Support, maintenance?

Unfortunately the wsimport tool that comes with the JDK does not “out of the box” like the Enterprise WSDL generated from Salesforce. Running it on the Enterprise WSDL from my test setup gives below output:

[jesper@linux3 ~]$ wsimport -keep enterprise.wsdl
parsing WSDL...
 
[WARNING] src-resolve: Cannot resolve the name 'tns:ID' to a(n) 'type definition' component.
  line 31 of file:/home/jesper/enterprise.wsdl#types?schema1
 
[ERROR] A class/interface with the same name "com.sforce.soap.enterprise.DescribeLayout" is already in use. Use a class customization to resolve this conflict.
  line 5952 of file:/home/jesper/enterprise.wsdl
 
[ERROR] (Relevant to above error) another "DescribeLayout" is generated from here.
  line 5620 of file:/home/jesper/enterprise.wsdl
 
[ERROR] Two declarations cause a collision in the ObjectFactory class.
  line 5952 of file:/home/jesper/enterprise.wsdl
 
[ERROR] (Related to above error) This is the other declaration.
  line 5620 of file:/home/jesper/enterprise.wsdl

Continue reading

Posted in Java, Salesforce | Tagged , , , | 2 Comments

Salesforce wsc: upsert null fields

 

The salesforce upsert() callย  is brilliant for interfacing legacy systems with Salesforce, especially if the data you are going to replicate into already contains some sort of unique identification.

  • It will create records that does not exist, and update records that does exist, given the unique id.
  • It allows updating up to 200 records in one batch returning create-/update status for each individual item.
  • It’s fast – can easily push more than 100,000 records/hour, depending on object type.

Basically the upsert() operation is nice and easy to use; it will happily set or change almost any field in your Salesforce based CRM solution.

But, how do you null (or “blank”) previously set fields?

Continue reading

Posted in Java, Salesforce | Tagged , , , | Leave a comment

Salesforce wsc: ConnectionException should have been Fault

This is the first article where I discuss details or issues using wsc (JAVA) on an Oracle WebLogic platform to integrate Customer Legacy systems with Salesforce CRM.

In some environments (specifically the WLS 10.3.5 used as production environment at my current Customer) the wsc infrastructure throws a ConnectionException (com.sforce.ws.ConnectionException: Unexpected element) in situations where it should actually return a Fault (com.sforce.soap.enterprise.fault.ApiFault).

I have tried to mock a similar environment in order to demonstrate the problem to no avail.

But, I have discovered why the problem arises – it has to do with the infrastructure related to the Transport.isSuccessful().
Continue reading

Posted in Java, Salesforce | Tagged , , , , , | 2 Comments