package net.gicm.astral.test;
import java.io.IOException;
import java.util.Properties;
import javax.servlet.jsp.JspWriter;
import net.gicm.astral.client.handler.PasswordHandler;
import net.gicm.astral.metier.ArrayOfCompte;
import net.gicm.astral.patrimoine.jaxb.PatrimoineClient;
import net.gicm.astral.patrimoine.jaxb.PatrimoinePortType;
import net.gicm.astral.patrimoine.jaxb.ServiceException;
import org.apache.ws.security.handler.WSHandlerConstants;
import org.codehaus.xfire.client.Client;
import org.codehaus.xfire.security.wss4j.WSS4JInHandler;
import org.codehaus.xfire.security.wss4j.WSS4JOutHandler;
import org.codehaus.xfire.transport.http.CommonsHttpMessageSender;
import org.codehaus.xfire.util.dom.DOMInHandler;
import org.codehaus.xfire.util.dom.DOMOutHandler;
public class XfireTest {
/**
* @param args
*/
public void test(JspWriter out) {
try {
PatrimoinePortType portType = new PatrimoineClient()
.getPatrimoineHttpPort("http://localhost:8080/webservicexfire/services/Patrimoine");
Client client = org.codehaus.xfire.client.Client
.getInstance(portType);
client.setProperty(CommonsHttpMessageSender.HTTP_TIMEOUT, "3000");
// CONFIGURE OUTGOING SECURITY HERE (outProperties) <--
client.addOutHandler(new DOMOutHandler());
Properties outProperties = new Properties();
outProperties.setProperty(WSHandlerConstants.ACTION,
WSHandlerConstants.SIGNATURE);
// User in keystore
outProperties.setProperty(WSHandlerConstants.USER, "Client");
// This callback is used to specify password for given user for
// keystore
outProperties.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS,
PasswordHandler.class.getName());
// Configuration for accessing private key in keystore
outProperties.setProperty(WSHandlerConstants.SIG_PROP_FILE,
"client.properties");
outProperties.setProperty(WSHandlerConstants.SIG_KEY_ID,
"DirectReference");
client.addOutHandler(new WSS4JOutHandler(outProperties));
// CONFIGURE INCOMMING SECURITY HERE (inProperties) <--
client.addInHandler(new DOMInHandler());
Properties inProperties = new Properties();
inProperties.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.SIGNATURE);
// This callback is used to specify password for given user for keystore
inProperties.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS,
PasswordHandler.class.getName());
// Configuration for accessing private key in keystore
inProperties.setProperty(WSHandlerConstants.SIG_PROP_FILE,
"client.properties");
client.addInHandler(new WSS4JInHandler(inProperties));
ArrayOfCompte cpt = portType.rechercherPatrimoine("toto");
out.println(cpt.getCompte().get(0).getLibelle().getValue());
out.println("
");
out.println(cpt.getCompte().get(0).getSolde());
out.println("
");
out.println(cpt.getCompte().get(0).getContratSouscrit()
.getValue());
out.println("
");
out.println(cpt.getCompte().get(1).getLibelle().getValue());
out.println("
");
out.println(cpt.getCompte().get(1).getSolde());
out.println("
");
out.println(cpt.getCompte().get(1).getContratSouscrit()
.getValue());
out.println("
");
} catch (ServiceException e) {
try {
out.println(e.getMessage());
out.println("
");
out.println(e.getFaultInfo().getCodeProgramme());
out.println("
");
out.println(e.getFaultInfo().getCodeApplication());
out.println("
");
} catch (IOException e1) {
e1.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}