Search in sources :

Example 21 with LoggingInInterceptor

use of org.apache.cxf.interceptor.LoggingInInterceptor in project midpoint by Evolveum.

the class AbstractWebserviceTest method createModelPort.

/**
     * Creates webservice client connecting to midpoint
     * */
protected static ModelPortType createModelPort(String username, String password, String passwordType) {
    String endpoint = ENDPOINT;
    if (System.getProperty("midpoint.endpoint") != null) {
        endpoint = System.getProperty("midpoint.endpoint");
    }
    LOGGER.info("Creating model client endpoint: {} , username={}, password={}", new Object[] { endpoint, username, password });
    ModelService modelService = new ModelService();
    ModelPortType modelPort = modelService.getModelPort();
    BindingProvider bp = (BindingProvider) modelPort;
    Map<String, Object> requestContext = bp.getRequestContext();
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
    org.apache.cxf.endpoint.Client client = ClientProxy.getClient(modelPort);
    org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();
    Map<String, Object> outProps = new HashMap<String, Object>();
    if (username != null) {
        outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
        outProps.put(WSHandlerConstants.USER, username);
        outProps.put(WSHandlerConstants.PASSWORD_TYPE, passwordType);
        ClientPasswordHandler.setPassword(password);
        outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordHandler.class.getName());
        WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
        cxfEndpoint.getOutInterceptors().add(wssOut);
    }
    cxfEndpoint.getInInterceptors().add(new LoggingInInterceptor());
    cxfEndpoint.getOutInterceptors().add(new LoggingOutInterceptor());
    return modelPort;
}
Also used : 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) LoggingOutInterceptor(org.apache.cxf.interceptor.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.interceptor.LoggingInInterceptor) WSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)

Example 22 with LoggingInInterceptor

use of org.apache.cxf.interceptor.LoggingInInterceptor in project camel by apache.

the class CXFWsdlOnlyPayloadModeNoSpringTest method testApplicationFault.

@Test
public void testApplicationFault() {
    URL wsdlURL = getClass().getClassLoader().getResource("person.wsdl");
    PersonService ss = new PersonService(wsdlURL, QName.valueOf(getServiceName()));
    Person client = ss.getSoap();
    ((BindingProvider) client).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + port1 + "/" + getClass().getSimpleName() + "/PersonService");
    Client c = ClientProxy.getClient(client);
    c.getInInterceptors().add(new LoggingInInterceptor());
    c.getOutInterceptors().add(new LoggingOutInterceptor());
    Holder<String> personId = new Holder<String>();
    personId.value = "";
    Holder<String> ssn = new Holder<String>();
    Holder<String> name = new Holder<String>();
    Throwable t = null;
    try {
        client.getPerson(personId, ssn, name);
        fail("expect UnknownPersonFault");
    } catch (UnknownPersonFault e) {
        t = e;
    }
    assertNotNull(t);
    assertTrue(t instanceof UnknownPersonFault);
}
Also used : UnknownPersonFault(org.apache.camel.wsdl_first.UnknownPersonFault) LoggingOutInterceptor(org.apache.cxf.interceptor.LoggingOutInterceptor) PersonService(org.apache.camel.wsdl_first.PersonService) Holder(javax.xml.ws.Holder) LoggingInInterceptor(org.apache.cxf.interceptor.LoggingInInterceptor) Client(org.apache.cxf.endpoint.Client) Person(org.apache.camel.wsdl_first.Person) URL(java.net.URL) Test(org.junit.Test)

Example 23 with LoggingInInterceptor

use of org.apache.cxf.interceptor.LoggingInInterceptor 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)

Example 24 with LoggingInInterceptor

use of org.apache.cxf.interceptor.LoggingInInterceptor in project ddf by codice.

the class AttributeQueryClaimsHandler method createDispatcher.

/**
     * Creates a dispatcher for dispatching requests.
     */
protected Dispatch<StreamSource> createDispatcher(Service service) {
    Dispatch<StreamSource> dispatch = null;
    if (service != null) {
        dispatch = service.createDispatch(QName.valueOf(portName), StreamSource.class, Service.Mode.MESSAGE);
        dispatch.getRequestContext().put(Dispatch.ENDPOINT_ADDRESS_PROPERTY, externalAttributeStoreUrl);
        dispatch.getRequestContext().put("ws-security.signature.properties", signatureProperties);
        dispatch.getRequestContext().put("ws-security.encryption.properties", encryptionProperties);
        ((DispatchImpl) dispatch).getClient().getBus().getOutInterceptors().add(new LoggingInInterceptor());
        ((DispatchImpl) dispatch).getClient().getBus().getOutInterceptors().add(new LoggingOutInterceptor());
    }
    return dispatch;
}
Also used : LoggingOutInterceptor(org.apache.cxf.interceptor.LoggingOutInterceptor) StreamSource(javax.xml.transform.stream.StreamSource) LoggingInInterceptor(org.apache.cxf.interceptor.LoggingInInterceptor)

Example 25 with LoggingInInterceptor

use of org.apache.cxf.interceptor.LoggingInInterceptor in project jbossws-cxf by jbossws.

the class FastInfosetTestCase method testInfosetUsingFeature.

@Test
@RunAsClient
@OperateOnDeployment(DEP1)
public void testInfosetUsingFeature() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ByteArrayOutputStream in = new ByteArrayOutputStream();
    PrintWriter pwIn = new PrintWriter(in);
    PrintWriter pwOut = new PrintWriter(out);
    Bus bus = BusFactory.newInstance().createBus();
    BusFactory.setThreadDefaultBus(bus);
    try {
        bus.getInInterceptors().add(new LoggingInInterceptor(pwIn));
        bus.getOutInterceptors().add(new LoggingOutInterceptor(pwOut));
        URL wsdlURL = new URL(baseURL + "HelloWorldService/HelloWorldFeatureImpl?wsdl");
        QName serviceName = new QName("http://org.jboss.ws/jaxws/cxf/fastinfoset", "HelloWorldFeatureService");
        Service service = Service.create(wsdlURL, serviceName, new UseThreadBusFeature());
        QName portQName = new QName("http://org.jboss.ws/jaxws/cxf/fastinfoset", "HelloWorldFeatureImplPort");
        HelloWorldFeature port = (HelloWorldFeature) service.getPort(portQName, HelloWorldFeature.class);
        assertEquals("helloworldFeature", port.echo("helloworldFeature"));
        assertTrue("request is expected fastinfoset", out.toString().indexOf("application/fastinfoset") > -1);
        assertTrue("response is expected fastinfoset", in.toString().indexOf("application/fastinfoset") > -1);
    } finally {
        bus.shutdown(true);
        pwOut.close();
        pwIn.close();
    }
}
Also used : Bus(org.apache.cxf.Bus) UseThreadBusFeature(org.jboss.wsf.stack.cxf.client.UseThreadBusFeature) LoggingOutInterceptor(org.apache.cxf.interceptor.LoggingOutInterceptor) QName(javax.xml.namespace.QName) LoggingInInterceptor(org.apache.cxf.interceptor.LoggingInInterceptor) Service(javax.xml.ws.Service) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URL(java.net.URL) PrintWriter(java.io.PrintWriter) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Aggregations

LoggingInInterceptor (org.apache.cxf.interceptor.LoggingInInterceptor)29 LoggingOutInterceptor (org.apache.cxf.interceptor.LoggingOutInterceptor)25 Test (org.junit.Test)12 URL (java.net.URL)9 Bus (org.apache.cxf.Bus)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 PrintWriter (java.io.PrintWriter)6 Service (javax.xml.ws.Service)6 Client (org.apache.cxf.endpoint.Client)6 UseThreadBusFeature (org.jboss.wsf.stack.cxf.client.UseThreadBusFeature)6 QName (javax.xml.namespace.QName)5 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)5 JBossWSTest (org.jboss.wsf.test.JBossWSTest)5 BindingProvider (javax.xml.ws.BindingProvider)4 Holder (javax.xml.ws.Holder)4 Person (org.apache.camel.wsdl_first.Person)4 PersonService (org.apache.camel.wsdl_first.PersonService)4 WSS4JOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)4 ModelPortType (com.evolveum.midpoint.xml.ns._public.model.model_3.ModelPortType)3 ModelService (com.evolveum.midpoint.xml.ns._public.model.model_3.ModelService)3