[jboss-user] [JBossWS] - Re: Using WSSecurityHandlerOutbound in a DII client
acxjbertr
do-not-reply at jboss.com
Tue Aug 1 16:45:19 EDT 2006
I got it working. Here is the DII code:
package com.mycompany.client.test.ws;
|
| import java.net.MalformedURLException;
| import java.net.URL;
| import java.rmi.RemoteException;
| import java.util.ArrayList;
| import java.util.List;
|
| import javax.xml.namespace.QName;
| import javax.xml.rpc.ServiceException;
| import javax.xml.rpc.handler.HandlerInfo;
|
| import junit.framework.TestCase;
|
| import org.jboss.ws.jaxrpc.ServiceExt;
| import org.jboss.ws.jaxrpc.ServiceFactoryImpl;
| import org.jboss.ws.jaxrpc.ServiceImpl;
| import org.jboss.ws.wsse.WSSecurityHandlerOutbound;
|
| import ...
|
| public class WSTestCase extends TestCase {
| private static final String SERVICE_NAMESPACE = "http://client.mycompany.com/clientstuff/1.0";
|
| private String testDescription = null;
|
| // Possible Outputs
| private String exceptionThrown = null;
|
| public void testPlanStep1() throws MalformedURLException, ServiceException {
| go(getInput());
| }
|
| private void go(Echo request) throws ServiceException, MalformedURLException {
| System.out.println("\n" + this.testDescription + "\n");
| displayTestInput(request);
|
| String expectedOutput = determineExpectedOutput();
| try {
| ClientServiceEndpoint clientServiceEndpoint = getEndpoint();
| EchoResponse echoResponse = clientServiceEndpoint.echo(request);
|
| ClientServiceReply clientServiceReply = echoResponse.getResult();
| System.out.println(clientServiceReply.getAuditId());
|
| } catch (Exception e) {
| String exceptionThrown = e.getClass().getName();
| displayOutput(expectedOutput, exceptionThrown);
| displayResult(exceptionThrown.equals(expectedOutput));
| e.printStackTrace();
| assertTrue(false);
| }
| }
|
| private ClientServiceEndpoint getEndpoint() throws MalformedURLException, ServiceException, InvalidRequestException, SystemUnavailableException, RemoteException {
| ServiceFactoryImpl factory = new ServiceFactoryImpl();
| ClassLoader cl = Thread.currentThread().getContextClassLoader();
| URL wsdlLocation = new URL("http://localhost:8080/clientService/ClientService?wsdl");
| URL mappingLocation = cl.getResource("client-mapping.xml");
| URL securityLocation = cl.getResource("jboss-wsse-client.xml");
| QName serviceName = new QName(SERVICE_NAMESPACE, "ClientService");
| ServiceImpl service = (ServiceImpl) factory.createService(wsdlLocation, serviceName, mappingLocation, securityLocation);
| setupWSSecurityHandler(service);
| return (ClientServiceEndpoint) service.getPort(ClientServiceEndpoint.class);
| }
|
| private Echo getInput() {
| Echo echoInput = new Echo();
| ClientServiceRequest clientServiceRequest = new ClientServiceRequest();
| clientServiceRequest.setAuditId("eggie");
| echoInput.setClientServiceRequest_1(clientServiceRequest);
|
| return echoInput;
| }
|
| private void setupWSSecurityHandler(ServiceExt service) {
| List<HandlerInfo> clientHandlerChain = new ArrayList<HandlerInfo>();
| HandlerInfo handler = new HandlerInfo();
| handler.setHandlerClass(WSSecurityHandlerOutbound.class);
| clientHandlerChain.add(handler);
| QName securityName = new QName(SERVICE_NAMESPACE, "ClientStuffEndpointPort");
| service.getDynamicHandlerRegistry().setHandlerChain(securityName, clientHandlerChain);
| }
| }
|
|
Notice the use of the jboss-wsse-client.xml file as input to the createService method.
Here is my jboss-wsse-client.xml:
<?xml version="1.0" encoding="UTF-8"?>
| <jboss-ws-security xmlns="http://www.jboss.com/ws-security/config"
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
| xsi:schemaLocation="http://www.jboss.com/ws-security/config http://www.jboss.com/ws-security/schema/jboss-ws-security_1_0.xsd">
| <key-store-file>wsse.keystore</key-store-file>
| <key-store-password>jbossws</key-store-password>
| <trust-store-file>wsse.truststore</trust-store-file>
| <trust-store-password>jbossws</trust-store-password>
| <config>
| <sign type="x509v3" alias="wsse" />
| <requires>
| <signature />
| </requires>
| </config>
| </jboss-ws-security>
Of course, I used the keystore and truststore from the JBossWS 1.0.2 sample archive.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3962284#3962284
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3962284
More information about the jboss-user
mailing list