Client java ( ADD LLIBRARY D:\IBM\SDP\runtimes\base_v61_stub\runtimes\com.ibm.jaxws.thinclient_6.1.0.jar )
package com.service.test;
import java.util.Map;
import com.ibm.websphere.wssecurity.wssapi.WSSException;
import com.ibm.websphere.wssecurity.wssapi.WSSFactory;
import com.ibm.websphere.wssecurity.wssapi.WSSGenerationContext;
import com.ibm.websphere.wssecurity.wssapi.token.SecurityToken;
import com.ibm.websphere.wssecurity.wssapi.token.UsernameToken;
import javax.xml.ws.BindingProvider;
import com.service.OperacionesServiceDelegate;
import com.service.OperacionesServiceService;
/**
* @author DiegoCastaneda
*
*/
public class Test {
public static void main(String[] args) {
OperacionesServiceService serv= new OperacionesServiceService();
OperacionesServiceDelegate del=serv.getOperacionesServicePort();
// use BindingProvider to hook into message context
BindingProvider bp = (BindingProvider) del;
Map<String,Object> requestContext = bp.getRequestContext();
WSSFactory wssfactory=null;
try
{
wssfactory = WSSFactory.getInstance();
WSSGenerationContext generationContext = wssfactory.newWSSGenerationContext();
//manda el username y el password.
com.ibm.websphere.wssecurity.callbackhandler.UNTGenerateCallbackHandler untCallback=new com.ibm.websphere.wssecurity.callbackhandler.UNTGenerateCallbackHandler("adminTraslados","12345",true,true);
SecurityToken unt=null;
unt = wssfactory.newSecurityToken(UsernameToken.class,
untCallback);
generationContext.add(unt);
//procesa el encabezado.
generationContext.process(requestContext);
} catch (WSSException e) {
// TODO Bloque catch generado automáticamente
e.printStackTrace();
}
System.out.println("Resultado "+del.sumar(3,4));
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
WEB client (( ADD LLIBRARY D:\IBM\SDP\runtimes\base_v61_stub\runtimes\com.ibm.jaxws.thinclient_6.1.0.jar )
public String consultarServicio()
{
System.out.println("LLamando servicio");
OperacionesServicePortProxy proxy;
try {
proxy = new OperacionesServicePortProxy(
new URL(endpointURL + "?wsdl"),
new QName("http://service.com/", "operacionesServiceService"));
OperacionesServiceDelegate del=proxy._getDescriptor().getProxy();
// use BindingProvider to hook into message context
BindingProvider bp = (BindingProvider) del;
Map<String,Object> requestContext = bp.getRequestContext();
WSSFactory wssfactory=null;
wssfactory = WSSFactory.getInstance();
WSSGenerationContext generationContext = wssfactory.newWSSGenerationContext();
//manda el username y el password.
com.ibm.websphere.wssecurity.callbackhandler.UNTGenerateCallbackHandler untCallback=new com.ibm.websphere.wssecurity.callbackhandler.UNTGenerateCallbackHandler("adminTraslados","12345",true,true);
SecurityToken unt=null;
unt = wssfactory.newSecurityToken(UsernameToken.class,
untCallback);
generationContext.add(unt);
//procesa el encabezado.
generationContext.process(requestContext);
System.out.println("Resultado 3+4 = "+del.sumar(3,4));
} catch (WSSException e) {
e.printStackTrace();
}
catch (MalformedURLException e) {
e.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
System.out.println("Fin Llamar Servicio ");
}
return null;
}