Boa Noite a todos,
Eu estou querendo fazer uma autenticação básica no Axis, mas ao tentar acessar o serviço eu recebo a mensagem
[code] <?xml version="1.0" encoding="UTF-8" ?>
- <soapenv:Envelope xmlns:soapenv=“http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsd=“http://www.w3.org/2001/XMLSchema” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”>
- soapenv:Body
-
soapenv:Fault
soapenv:MustUnderstand
Did not understand “MustUnderstand” header(s):{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}Security - PC006 [/code]
A minha classe para acessar o WS é a seguinte
public AccessWs {
private String user = null;
private Call call = null;
public static void main(String[] args) throws ServiceException {
AccessWs access = new AccessWs();
access.setUser("teste");
String result = access.callService("http://localhost:8080/teste/services/ProjectWs", "getProject");
System.out.println(result);
}
private void auth(String user) {
if (user != null) {
call.setProperty(UsernameToken.PASSWORD_TYPE, WSConstants.PASSWORD_TEXT);
call.setProperty(WSHandlerConstants.USER, user);
call.setProperty(WSHandlerConstants.MUST_UNDERSTAND, "false");
call.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
}
}
public String callService(String endPoint, String operation) {
String retorno = "";
try {
call = (Call) new Service().createCall();
call.setTargetEndpointAddress(endPoint);
call.setOperationName(operation);
this.auth(this.user);
retorno = (String) call.invoke(new Object[] {});
} catch (ServiceException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
return retorno;
}
}
O arquivo wsdd que eu faço o deploy é o seguinte:
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<globalConfiguration>
<parameter name="sendMultiRefs" value="true" />
<parameter name="disablePrettyXML" value="true" />
<parameter name="adminPassword" value="admin" />
<parameter name="dotNetSoapEncFix" value="true" />
<parameter name="enableNamespacePrefixOptimization" value="false" />
<parameter name="sendXMLDeclaration" value="true" />
<parameter name="sendXsiTypes" value="true" />
<requestFlow>
<handler type="java:org.apache.ws.axis.security.WSDoAllSender">
<parameter name="action" value="UsernameToken" />
<parameter name="user" value="teste" />
<parameter name="passwordType" value="PasswordText" />
<parameter name="passwordCallbackClass" value="br.com.teste.security.AuthCallback" />
</handler>
</requestFlow>
</globalConfiguration>
<service name="LoginWs" provider="java:RPC">
<parameter name="className" value="br.com.teste.ws.LoginWs" />
<parameter name="allowedMethods" value="doLogin" />
</service>
<service name="ProjectWs" provider="java:RPC">
<parameter name="className" value="br.com.teste.ws.ProjectWs" />
<parameter name="allowedMethods" value="getProject,getProjects" />
</service>
</deployment>
O Handler abaixo:
public class AuthCallback implements CallbackHandler {
private static final byte[] key = { (byte) 0x31, (byte) 0xfd, (byte) 0xcb, (byte) 0xda, (byte) 0xfb, (byte) 0xcd, (byte) 0x6b, (byte) 0xa8, (byte) 0xe6, (byte) 0x19, (byte) 0xa7, (byte) 0xbf,
(byte) 0x51, (byte) 0xf7, (byte) 0xc7, (byte) 0x3e, (byte) 0x80, (byte) 0xae, (byte) 0x98, (byte) 0x51, (byte) 0xc8, (byte) 0x51, (byte) 0x34, (byte) 0x04, };
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback call : callbacks) {
if (call instanceof WSPasswordCallback) {
WSPasswordCallback callback = (WSPasswordCallback) call;
if ((callback.getIdentifier().equals("teste"))) {
callback.setKey(key);
callback.setPassword("teste");
} else {
throw new UnsupportedCallbackException(call, "Unrecognized callback");
}
}
}
}
}
Eu procurei no GUJ, JavaRanch,Google e etc… mas não consegui detectar o problema. O link mais próximo que eu cheguei foi este:
[link]http://wso2.org/library/tutorials/understand-famous-did-not-understand-mustunderstand-header-s-error#error_causes[/link].
Realmente não está sendo criado o Envelope com o Header e o Body, mas eu também não estou conseguindo cria-los, isto se for este o problema…
Desde já muito obrigado!