Search in sources :

Example 56 with BindingProvider

use of javax.xml.ws.BindingProvider in project midpoint by Evolveum.

the class RunScript method createModelPort.

public static ModelPortType createModelPort(CommandLine cmdLine) {
    String endpointUrl = cmdLine.getOptionValue(OPT_URL, DEFAULT_ENDPOINT_URL);
    String user = cmdLine.getOptionValue(OPT_USER, ADM_USERNAME);
    ClientPasswordHandler.setPassword(cmdLine.getOptionValue(OPT_PASSWORD, ADM_PASSWORD));
    System.out.println("Endpoint URL: " + endpointUrl);
    ModelService modelService = new ModelService();
    ModelPortType modelPort = modelService.getModelPort();
    BindingProvider bp = (BindingProvider) modelPort;
    Map<String, Object> requestContext = bp.getRequestContext();
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl);
    org.apache.cxf.endpoint.Client client = ClientProxy.getClient(modelPort);
    org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();
    Map<String, Object> outProps = new HashMap<>();
    outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
    outProps.put(WSHandlerConstants.USER, user);
    outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
    outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordHandler.class.getName());
    WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
    cxfEndpoint.getOutInterceptors().add(wssOut);
    return modelPort;
}
Also used : HashMap(java.util.HashMap) ModelPortType(com.evolveum.midpoint.xml.ns._public.model.model_3.ModelPortType) BindingProvider(javax.xml.ws.BindingProvider) ModelService(com.evolveum.midpoint.xml.ns._public.model.model_3.ModelService) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)

Example 57 with BindingProvider

use of javax.xml.ws.BindingProvider in project nhin-d by DirectProject.

the class DocumentRepositoryUtils method getDocumentRepositoryPortType.

/**
     * Construct a DocumentRepositoryPortType object using the provided
     * endpoint.
     * 
     * @param endpoint
     *            The XDR endpoint.
     * @param wsdlPath
     *            The path to the WSDL.
     * @return a DocumentRepositoryPortType object.
     * @throws Exception
     */
public static DocumentRepositoryPortType getDocumentRepositoryPortType(String endpoint, URL wsdlPath) throws Exception {
    QName qname = new QName("urn:ihe:iti:xds-b:2007", "DocumentRepository_Service");
    DocumentRepositoryService service = new DocumentRepositoryService(wsdlPath, qname);
    service.setHandlerResolver(new RepositoryHandlerResolver());
    DocumentRepositoryPortType port = service.getDocumentRepositoryPortSoap12(new MTOMFeature(true, 1));
    BindingProvider bp = (BindingProvider) port;
    SOAPBinding binding = (SOAPBinding) bp.getBinding();
    binding.setMTOMEnabled(true);
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
    return port;
}
Also used : DocumentRepositoryPortType(ihe.iti.xds_b._2007.DocumentRepositoryPortType) QName(javax.xml.namespace.QName) MTOMFeature(javax.xml.ws.soap.MTOMFeature) SOAPBinding(javax.xml.ws.soap.SOAPBinding) BindingProvider(javax.xml.ws.BindingProvider) DocumentRepositoryService(ihe.iti.xds_b._2007.DocumentRepositoryService)

Example 58 with BindingProvider

use of javax.xml.ws.BindingProvider in project midpoint by Evolveum.

the class AbstractWebServiceClient method createPort.

protected P createPort() throws Exception {
    String password = getDefaultPassword();
    String username = getDefaultUsername();
    String endpointUrl = getDefaultEndpointUrl();
    if (commandLine.hasOption('p')) {
        password = commandLine.getOptionValue('p');
    }
    if (commandLine.hasOption('u')) {
        username = commandLine.getOptionValue('u');
    }
    if (commandLine.hasOption('e')) {
        endpointUrl = commandLine.getOptionValue('e');
    }
    if (verbose) {
        System.out.println("Username: " + username);
        System.out.println("Password: <not shown>");
        System.out.println("Endpoint URL: " + endpointUrl);
    }
    // uncomment this if you want to use Fiddler or any other proxy
    //ProxySelector.setDefault(new MyProxySelector("127.0.0.1", 8888));
    P modelPort = createService().getPort(getPortClass());
    BindingProvider bp = (BindingProvider) modelPort;
    Map<String, Object> requestContext = bp.getRequestContext();
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl);
    org.apache.cxf.endpoint.Client client = ClientProxy.getClient(modelPort);
    org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();
    Map<String, Object> wssProps = new HashMap<String, Object>();
    if (!commandLine.hasOption('a') || (commandLine.hasOption('a') && WSHandlerConstants.USERNAME_TOKEN.equals(commandLine.getOptionValue('a')))) {
        wssProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
        wssProps.put(WSHandlerConstants.USER, username);
        wssProps.put(WSHandlerConstants.PASSWORD_TYPE, getPasswordType());
        wssProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordHandler.class.getName());
        ClientPasswordHandler.setPassword(password);
        WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(wssProps);
        cxfEndpoint.getOutInterceptors().add(wssOut);
    } else if (commandLine.hasOption('a') && "none".equals(commandLine.getOptionValue('a'))) {
    // Nothing to do
    } else {
        throw new IllegalArgumentException("Unknown authentication mechanism '" + commandLine.getOptionValue('a') + "'");
    }
    if (commandLine.hasOption('m')) {
        cxfEndpoint.getInInterceptors().add(new LoggingInInterceptor());
        cxfEndpoint.getOutInterceptors().add(new LoggingOutInterceptor());
    }
    return modelPort;
}
Also used : HashMap(java.util.HashMap) BindingProvider(javax.xml.ws.BindingProvider) LoggingOutInterceptor(org.apache.cxf.interceptor.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.interceptor.LoggingInInterceptor) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)

Aggregations

BindingProvider (javax.xml.ws.BindingProvider)58 URL (java.net.URL)40 Service (javax.xml.ws.Service)39 Test (org.junit.Test)31 WebServiceException (javax.xml.ws.WebServiceException)17 QName (javax.xml.namespace.QName)12 WSS4JOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)7 ModelPortType (com.evolveum.midpoint.xml.ns._public.model.model_3.ModelPortType)6 ModelService (com.evolveum.midpoint.xml.ns._public.model.model_3.ModelService)6 HashMap (java.util.HashMap)6 File (java.io.File)4 LoggingInInterceptor (org.apache.cxf.interceptor.LoggingInInterceptor)4 LoggingOutInterceptor (org.apache.cxf.interceptor.LoggingOutInterceptor)4 InvocationHandler (java.lang.reflect.InvocationHandler)3 MalformedURLException (java.net.MalformedURLException)3 List (java.util.List)3 DocumentRepositoryService (ihe.iti.xds_b._2007.DocumentRepositoryService)2 ArrayList (java.util.ArrayList)2 SOAPBinding (javax.xml.ws.soap.SOAPBinding)2 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)2