3 Replies Latest reply: Jun 5, 2013 11:49 PM by Aver RSS

    Cannot authenticate to Web Service

    CInglez
      Hello all.

      I am following the tutorial on http://tardate.blogspot.com/2007/08/first-tests-of-11g-native-web-services.html. It generated an WSDL (http://scott:tiger@localhost:8080/orawsv/SCOTT/EMPCOUNT?wsdl):

      <definitions name="EMPCOUNT" targetNamespace="http://xmlns.oracle.com/orawsv/SCOTT/EMPCOUNT" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://xmlns.oracle.com/orawsv/SCOTT/EMPCOUNT" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
      <types>
      <xsd:schema targetNamespace="http://xmlns.oracle.com/orawsv/SCOTT/EMPCOUNT" elementFormDefault="qualified">
      <xsd:element name="SNUMBER-EMPCOUNTInput">
      <xsd:complexType>
      <xsd:sequence>
      </xsd:sequence>
      </xsd:complexType>
      </xsd:element>


      <xsd:element name="EMPCOUNTOutput">
      <xsd:complexType>
      <xsd:sequence>
      <xsd:element name="RETURN" type="xsd:double"/>
      </xsd:sequence>
      </xsd:complexType>
      </xsd:element>
      </xsd:schema>
      </types>

      <message name="EMPCOUNTInputMessage">
      <part name="parameters" element="tns:SNUMBER-EMPCOUNTInput"/>
      </message>

      <message name="EMPCOUNTOutputMessage">
      <part name="parameters" element="tns:EMPCOUNTOutput"/>
      </message>

      <portType name="EMPCOUNTPortType">
      <operation name="EMPCOUNT">
      <input message="tns:EMPCOUNTInputMessage"/>
      <output message="tns:EMPCOUNTOutputMessage"/>
      </operation>
      </portType>

      <binding name="EMPCOUNTBinding" type="tns:EMPCOUNTPortType">
      <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
      <operation name="EMPCOUNT">
      <soap:operation soapAction="EMPCOUNT"/>
      <input>
      <soap:body parts="parameters" use="literal"/>
      </input>
      <output>
      <soap:body parts="parameters" use="literal"/>
      </output>
      </operation>
      </binding>

      <service name="EMPCOUNTService">
      <documentation>Oracle Web Service</documentation>
      <port name="EMPCOUNTPort" binding="tns:EMPCOUNTBinding">
      <soap:address location="http://localhost:8080/orawsv/SCOTT/EMPCOUNT"/>
      </port>
      </service>

      </definitions>


      I created the following java client:



      import java.net.Authenticator;
      import java.net.PasswordAuthentication;
      import com.oracle.xmlns.orawsv.scott.empcount.EMPCOUNTService;
      import com.oracle.xmlns.orawsv.scott.empcount.EMPCOUNTPortType;
      import com.oracle.xmlns.orawsv.scott.empcount.SNUMBEREMPCOUNTInput;
      import com.oracle.xmlns.orawsv.scott.empcount.EMPCOUNTOutput;

      class EMPCOUNT_XDB {

      public class MyAuthenticator extends Authenticator {

      private String user;
      private String password;

      public MyAuthenticator(String user,String password) {
      this.user = user;
      this.password = password;
      }

      @Override
      protected PasswordAuthentication getPasswordAuthentication() {
      PasswordAuthentication auth = new PasswordAuthentication(user,password.toCharArray());
      return auth;
      }
      }

      public void empcountXDB(){

      try { // Call Web Service Operation


      EMPCOUNTService service = new EMPCOUNTService();
      EMPCOUNTPortType

      port = service.getEMPCOUNTPort();

      SNUMBEREMPCOUNTInput parameters = new SNUMBEREMPCOUNTInput();

      EMPCOUNTOutput result = port.empcount(parameters);

      MyAuthenticator myAuth = new MyAuthenticator("SCOTT","tiger");
      Authenticator.setDefault(myAuth);

      System.out.println("Result = "+result.toString());



      } catch (Throwable e1) {e1.printStackTrace();}

      }

      public static void main(String[] args) throws Exception {

      EMPCOUNT_XDB t = new EMPCOUNT_XDB();
      t.empcountXDB();
      System.out.println("Result = ABCDEFG");

      }



      }


      When I try to run:

      java -jar EMPCOUNT_XDB.jar, I always get:

      org.apache.axis2.AxisFault: Transport error: 401 Error: Unauthorized.

      What am I missing?

      Edited by: CInglez on May 2, 2011 5:29 PM