Pessoal, eu tenho um webservice simples, que pode ter o WSDL acessado da seguinte forma:
http://scott:tiger@localhost:8080/orawsv/SCOTT/EMPCOUNT?wsdl. O WSDL é:
<xsd:element name="EMPCOUNTOutput">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="RETURN" type="xsd:double"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Para isso, criei o seguinte client java:
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");
}
}
Mas sempre acabo com o erro:
org.apache.axis2.AxisFault: Transport error: 401 Error: Unauthorized.
Algo errado com a minha autenticação. O que pode ser?
Obrigado