use of org.apache.cxf.service.Service in project cxf by apache.
the class ClientMtomXopTest method createPort.
private <T> T createPort(QName serviceName, QName portName, Class<T> serviceEndpointInterface, boolean enableMTOM, boolean installInterceptors) throws Exception {
ReflectionServiceFactoryBean serviceFactory = new JaxWsServiceFactoryBean();
Bus bus = getStaticBus();
LoggingFeature lf = new LoggingFeature();
lf.setPrettyLogging(false);
lf.setLogBinary(false);
lf.setLogMultipart(true);
bus.getFeatures().add(lf);
serviceFactory.setBus(bus);
serviceFactory.setServiceName(serviceName);
serviceFactory.setServiceClass(serviceEndpointInterface);
serviceFactory.setWsdlURL(ClientMtomXopTest.class.getResource("/wsdl/mtom_xop.wsdl"));
Service service = serviceFactory.create();
EndpointInfo ei = service.getEndpointInfo(portName);
JaxWsEndpointImpl jaxwsEndpoint = new JaxWsEndpointImpl(bus, service, ei);
SOAPBinding jaxWsSoapBinding = new SOAPBindingImpl(ei.getBinding(), jaxwsEndpoint);
jaxWsSoapBinding.setMTOMEnabled(enableMTOM);
if (installInterceptors) {
// jaxwsEndpoint.getBinding().getInInterceptors().add(new TestMultipartMessageInterceptor());
jaxwsEndpoint.getBinding().getOutInterceptors().add(new TestAttachmentOutInterceptor());
}
jaxwsEndpoint.getBinding().getInInterceptors().add(new LoggingInInterceptor());
jaxwsEndpoint.getBinding().getOutInterceptors().add(new LoggingOutInterceptor());
Client client = new ClientImpl(bus, jaxwsEndpoint);
InvocationHandler ih = new JaxWsClientProxy(client, jaxwsEndpoint.getJaxwsBinding());
Object obj = Proxy.newProxyInstance(serviceEndpointInterface.getClassLoader(), new Class[] { serviceEndpointInterface, BindingProvider.class }, ih);
updateAddressPort(obj, PORT);
return serviceEndpointInterface.cast(obj);
}
use of org.apache.cxf.service.Service in project cxf by apache.
the class MAPAggregatorTest method setUpMessage.
private Message setUpMessage(SetupMessageArgs args) throws Exception {
Message message = getMessage();
Exchange exchange = getExchange();
setUpOutbound(message, exchange, args.outbound, args.fault);
setUpMessageProperty(message, REQUESTOR_ROLE, Boolean.valueOf(args.requestor));
if (args.outbound && args.requestor) {
if (args.usingAddressing) {
setUpConduit(message, exchange);
}
setUpUsingAddressing(message, exchange, args.usingAddressing);
if (args.usingAddressing) {
setUpRequestor(message, exchange, args.oneway, args.mapsInContext, args.decoupled, args.zeroLengthAction);
}
} else if (!args.requestor) {
SetupResponderArgs srArgs = new SetupResponderArgs();
srArgs.oneway = args.oneway;
srArgs.outbound = args.outbound;
srArgs.decoupled = args.decoupled;
srArgs.zeroLengthAction = args.zeroLengthAction;
srArgs.fault = args.fault;
srArgs.noMessageId = args.noMessageId;
Endpoint endpoint = control.createMock(Endpoint.class);
exchange.getEndpoint();
EasyMock.expectLastCall().andReturn(endpoint).anyTimes();
setUpResponder(message, exchange, srArgs, endpoint);
endpoint.getOutInterceptors();
EasyMock.expectLastCall().andReturn(new ArrayList<Interceptor<? extends Message>>()).anyTimes();
Service serv = control.createMock(Service.class);
endpoint.getService();
EasyMock.expectLastCall().andReturn(serv).anyTimes();
serv.getOutInterceptors();
EasyMock.expectLastCall().andReturn(new ArrayList<Interceptor<? extends Message>>()).anyTimes();
}
control.replay();
return message;
}
use of org.apache.cxf.service.Service in project cxf by apache.
the class DOMToStaxRoundTripTest method testEncryptSignature.
@Test
public void testEncryptSignature() throws Exception {
// Create + configure service
Service service = createService();
WSSSecurityProperties inProperties = new WSSSecurityProperties();
inProperties.setCallbackHandler(new TestPwdCallback());
Properties cryptoProperties = CryptoFactory.getProperties("insecurity.properties", this.getClass().getClassLoader());
inProperties.setSignatureVerificationCryptoProperties(cryptoProperties);
inProperties.setDecryptionCryptoProperties(cryptoProperties);
WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
service.getInInterceptors().add(inhandler);
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
Map<String, Object> properties = new HashMap<>();
properties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SIGNATURE + " " + ConfigurationConstants.ENCRYPTION);
properties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
properties.put(ConfigurationConstants.SIG_PROP_FILE, "outsecurity.properties");
properties.put(ConfigurationConstants.ENC_PROP_FILE, "outsecurity.properties");
properties.put(ConfigurationConstants.USER, "myalias");
WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
}
use of org.apache.cxf.service.Service in project cxf by apache.
the class DOMToStaxRoundTripTest method testUsernameTokenText.
@Test
public void testUsernameTokenText() throws Exception {
// Create + configure service
Service service = createService();
WSSSecurityProperties inProperties = new WSSSecurityProperties();
inProperties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_TEXT);
inProperties.setCallbackHandler(new TestPwdCallback());
WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
service.getInInterceptors().add(inhandler);
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
Map<String, Object> properties = new HashMap<>();
properties.put(ConfigurationConstants.ACTION, ConfigurationConstants.USERNAME_TOKEN);
properties.put(ConfigurationConstants.PASSWORD_TYPE, WSS4JConstants.PW_TEXT);
properties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
properties.put(ConfigurationConstants.USER, "username");
WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
// Negative test for wrong password type
service.getInInterceptors().remove(inhandler);
inProperties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST);
inhandler = new WSS4JStaxInInterceptor(inProperties);
service.getInInterceptors().add(inhandler);
service.put(SecurityConstants.RETURN_SECURITY_ERROR, true);
try {
echo.echo("test");
fail("Failure expected on the wrong password type");
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
// expected
String error = "The security token could not be authenticated or authorized";
assertTrue(ex.getMessage().contains(error));
}
}
use of org.apache.cxf.service.Service in project cxf by apache.
the class DOMToStaxRoundTripTest method testSignaturePKI.
@Test
public void testSignaturePKI() throws Exception {
// Create + configure service
Service service = createService();
WSSSecurityProperties inProperties = new WSSSecurityProperties();
inProperties.setCallbackHandler(new TestPwdCallback());
Properties cryptoProperties = CryptoFactory.getProperties("cxfca.properties", this.getClass().getClassLoader());
inProperties.setSignatureVerificationCryptoProperties(cryptoProperties);
WSS4JStaxInInterceptor inhandler = new WSS4JStaxInInterceptor(inProperties);
service.getInInterceptors().add(inhandler);
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
Map<String, Object> properties = new HashMap<>();
properties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SIGNATURE);
properties.put(ConfigurationConstants.PW_CALLBACK_REF, new KeystorePasswordCallback());
properties.put(ConfigurationConstants.SIG_PROP_FILE, "alice.properties");
properties.put(ConfigurationConstants.USER, "alice");
properties.put(ConfigurationConstants.USE_SINGLE_CERTIFICATE, "true");
properties.put(ConfigurationConstants.SIG_KEY_ID, "DirectReference");
WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
}
Aggregations