title: Consuming SOAP Webservice - Java VS PHP
body: <p>a general question:</p>
  
  <p>We are launching a new ITSM Toolsuite in our company called ServiceNow.
  ServiceNow offers a lot of nice out-of-the-box Webservices.
  Currenty we are implementing some interfaces to other interal systems and we use these Webservices to consume data of Servicenow.</p>
  
  <p>How we did it in <strong>PHP</strong>:</p>
  
  <pre><code>&lt;?php
  $credentials = array('login'=&gt;'user', 'password'=&gt;'pass');
  $client = new SoapClient("https://blah.com/incident.do?WSDL", $credentials);
  $params = array('param1' =&gt; 'value1', 'param1' =&gt; 'value1');
  $result = $client-&gt;__soapCall('getRecords', array('parameters' =&gt; $params));
  // result array stored in $result-&gt;getRecordsResult
  ?&gt;
  </code></pre>
  
  <p>And thats it! 5 minutes of work, Beautiful and simple - from my point of view.</p>
  
  <p>Ok and now the same in <strong>Java</strong>:</p>
  
  <p>I did some research and it seems everbody is using Apache Axis2 for consuming Webservices in Java. So I decided to go down that road.</p>
  
  <ol>
  <li>Install Apache Axis</li>
  <li><p>open cygwin or cmd and generate Classes from WSDL.. WTF? what for?</p>
  
  <p><code>$ ./wsdl2java.sh -uri https://blah.com/incident.do?WSDL</code></p></li>
  <li><p>copy generated classes to Java Project in Eclipse.</p></li>
  <li>Use this classes:</li>
  </ol>
  
  <pre class="lang-java prettyprint-override"><code>ServiceNow_incidentStub proxy = new ServiceNow_incidentStub();
  
  proxy._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);
  ServiceNow_incidentStub.GetRecords defectsGetRecords = new ServiceNow_incidentStub.GetRecords();
  ServiceNow_incidentStub.GetRecordsResponse defectsResult = new ServiceNow_incidentStub.GetRecordsResponse();
  proxy._getServiceClient().getOptions().setManageSession(true);
  HttpTransportProperties.Authenticator basicAuthentication = new HttpTransportProperties.Authenticator();
  basicAuthentication.setUsername("user");
  basicAuthentication.setPassword("pass");
  proxy._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, basicAuthentication);
  defectsResult = proxy.getRecords(defectsGetRecords);
  com.service_now.www.ServiceNow_incidentStub.GetRecordsResult_type0[] defects = defectsResult.getGetRecordsResult();
  
  for (int j=0; j &lt; defects.length; j++) {
      // do something
  }
  </code></pre>
  
  <p>Its working but I think this way is very complicated..
  everytime something in the wsdl changes - i must recompile them with axis.
  There is no way to configure something globally like Soap-endpoint or something like that.</p>
  
  <p>Is there an easier way in Java to consume SOAP with a WSDL??</p>