Fork me on Github s

Posts Tagged maven

Connecting to Magento Web Services with Java

I was in the unenviable position of needing to connect to Magento, a PHP ecommerce platform, web services using Java.  It was kind of difficult to get the classes generated from the WSDL so I figured I would throw the results up on my github account for any other poor sap in a similar position.

First, pull down the project using git:

git clone git://github.com/webdevwilson/magento-java.git

and build it with maven:

mvn install

Here is a quick example of how to pull an order using the generated classes:

MagentoServiceLocator serviceLocator = new MagentoServiceLocator();
String url = "http://domain.com/index.php/api/v2_soap";
Mage_Api_Model_Server_V2_HandlerPortType port = serviceLocator.getMage_Api_Model_Server_V2_HandlerPort(url);
String sessionId = port.login("username", "key");
SalesOrderEntity salesOrder = port.salesOrderInfo(sessionId, orderId);

I also have some wrapper code in there that makes it a little easier to call the API.

Checkout the project at https://github.com/webdevwilson/magento-java

There is another option. it’s called Magja and it is located at google code.

Tags: , , , ,

No Comments

Absent Code attribute in method that is not native or abstract

I got the following, quite puzzling error today when running a unit test:

java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/http/Cookie

A google search found this post, which explains that it is caused by having an interface in the classpath, and not an actual implementation.

In this case it’s the java-ee interface. To fix this I added the jetty servlet api implementation to my pom:

    
        jetty
        javax.servlet
        test
    

Piece of cake. I have run in to this before, so I figured I would capture the fix here in case I run in to it again.

Tags: ,

1 Comment

Using Cucumber tests with Maven and Java

Want to jump right in? I have zipped up a working project, with examples. You can download it here.

What’s that? You like using Cucumber and want to use it with your Java project but your company ecosystem is not hip to JRuby?  Enter the cukes4duke project, which allows you to run cucumber with most JVM-based languages.  I am focusing on running it with the Maven plugin. This tutorial assumes you have maven installed, and Java knowledge.

Before you start, you must run the following goal. It will install JRuby and the gems to your .m2 repository.

mvn -Dcucumber.installGems=true cuke4duke:cucumber

Then add the following to your pom:

    
        
            codehaus
            http://repository.codehaus.org
        
        
            cukes
            http://cukes.info/maven
        
    

    
        
            cukes
            http://cukes.info/maven
        
    

    
        0.3.2
    

    
        
            cuke4duke
            cuke4duke
            ${cuke4duke.version}
            test
        
        
            org.picocontainer
            picocontainer
            2.8.3
            test
        
        
            junit
            junit
            4.8.1
            test
        
    

    
        
            
                cuke4duke
                cuke4duke-maven-plugin
                ${cuke4duke.version}
                
                    
                        
                  -Dcuke4duke.objectFactory=cuke4duke.internal.jvmclass.PicoFactory
                        
                        ${cucumber.debug}
                    
                    
                        ${basedir}/target/test-classes
                        --tags ~@wip
                    
                    
                        install cuke4duke --version ${cuke4duke.version}
                    
                
                
                    
                        run-features
                        integration-test
                        
                            cucumber
                        
                    
                
            
            
                org.apache.maven.plugins
                maven-compiler-plugin
                2.0.2
                
                    1.6
                    1.6
                
            
        
    

Next, create a feature file under the ‘features’ directory (at the root of your project).

features/example.feature:

Feature: Example of a feature file
  As some aspiring cuke4duke user
  I want an example of how it works
  So that I can easily setup my project to use it
  
  # This should pass
  Scenario: A simple passing scenario
    Given the letter 'A'
    When I check the letter
    Then the letter should be 'A'

Then, create a ‘step’ class under src/test/java/cukes:

src/test/java/cukes/CukeSteps.java:

package cukes;

import cuke4duke.annotation.I18n.EN.Given;
import cuke4duke.annotation.I18n.EN.Then;
import cuke4duke.annotation.I18n.EN.When;

import static org.junit.Assert.assertThat;
import static org.hamcrest.CoreMatchers.is;

public class CukeSteps {

    private char theLetter;

    @Given("^the letter '([A-Za-z])'$")
    public void gimmeALetter(final char theLetter) {
        this.theLetter = theLetter;
    }

    @When("^I check the letter(?:s)?$")
    public void checkThem() {
        // just a stub
    }

    @Then("^the letter should be '([A-Za-z])'$")
    public void checkTheLetter(final char aLetter) {
        assertThat(theLetter, is(aLetter));
    }
}

Now, run that test using:

mvn integration-test

I have zipped up an example project with more example steps. It is located here.

Tags: , ,

36 Comments

Does Your Build Suck?

I have come up with a few questions you should ask yourself if your build is up to snuff. 

  • Does it take longer than 10 minutes to setup a new computer to build a project?
  • Are there only a one or two people who know how to completely setup a new computer?
  • Do builds sometimes fail on the integration server when they are passing on your development machine?
  • Do you often make cross-repository commits?
  • Does building a subproject force you to build several other subprojects?
  • Does it take longer than 2 minutes to checkout a new project and build it successfully?
  • Is it possible for other developers (or other external factors) to break your development build without checking in code?
  • Can you use any IDE with your project?

If you answered yes to any of these questions, perhaps you should spend some time refactoring your build and/or project structure.  A nasty build can be very frustrating for developers yet is an oft overlooked part of development.

Tags: , , , , , ,

1 Comment