use of org.apache.cxf.binding.soap.saaj.SAAJInInterceptor in project tomee by apache.
the class CalculatorTest method testCalculatorViaWsInterfaceWithTimestamp2ways.
public void testCalculatorViaWsInterfaceWithTimestamp2ways() throws Exception {
final Service calcService = Service.create(new URL("http://localhost:" + port + "/webservice-ws-security/CalculatorImplTimestamp2ways?wsdl"), new QName("http://superbiz.org/wsdl", "CalculatorWsService"));
assertNotNull(calcService);
// for debugging (ie. TCPMon)
calcService.addPort(new QName("http://superbiz.org/wsdl", "CalculatorWsService2"), SOAPBinding.SOAP12HTTP_BINDING, "http://127.0.0.1:8204/CalculatorImplTimestamp2ways");
// CalculatorWs calc = calcService.getPort(
// new QName("http://superbiz.org/wsdl", "CalculatorWsService2"),
// CalculatorWs.class);
final CalculatorWs calc = calcService.getPort(CalculatorWs.class);
final Client client = ClientProxy.getClient(calc);
final Endpoint endpoint = client.getEndpoint();
endpoint.getOutInterceptors().add(new SAAJOutInterceptor());
endpoint.getInInterceptors().add(new SAAJInInterceptor());
final Map<String, Object> outProps = new HashMap<String, Object>();
outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.TIMESTAMP);
final WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
endpoint.getOutInterceptors().add(wssOut);
final Map<String, Object> inProps = new HashMap<String, Object>();
inProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.TIMESTAMP);
final WSS4JInInterceptor wssIn = new WSS4JInInterceptor(inProps);
endpoint.getInInterceptors().add(wssIn);
assertEquals(12, calc.multiply(3, 4));
}
use of org.apache.cxf.binding.soap.saaj.SAAJInInterceptor in project cxf by apache.
the class SpringBeansTest method testClients.
@Test
public void testClients() throws Exception {
AbstractFactoryBeanDefinitionParser.setFactoriesAreAbstract(false);
ctx = new ClassPathXmlApplicationContext(new String[] { "/org/apache/cxf/frontend/spring/clients.xml" });
Object bean = ctx.getBean("client1.proxyFactory");
assertNotNull(bean);
ClientProxyFactoryBean cpfbean = (ClientProxyFactoryBean) bean;
BindingConfiguration bc = cpfbean.getBindingConfig();
assertTrue(bc instanceof SoapBindingConfiguration);
SoapBindingConfiguration sbc = (SoapBindingConfiguration) bc;
assertTrue(sbc.getVersion() instanceof Soap12);
HelloService greeter = (HelloService) ctx.getBean("client1");
assertNotNull(greeter);
Client client = ClientProxy.getClient(greeter);
assertNotNull("expected ConduitSelector", client.getConduitSelector());
assertTrue("unexpected ConduitSelector", client.getConduitSelector() instanceof NullConduitSelector);
List<Interceptor<? extends Message>> inInterceptors = client.getInInterceptors();
boolean saaj = false;
boolean logging = false;
for (Interceptor<? extends Message> i : inInterceptors) {
if (i instanceof SAAJInInterceptor) {
saaj = true;
} else if (i instanceof LoggingInInterceptor) {
logging = true;
}
}
assertTrue(saaj);
assertTrue(logging);
saaj = false;
logging = false;
for (Interceptor<?> i : client.getOutInterceptors()) {
if (i instanceof SAAJOutInterceptor) {
saaj = true;
} else if (i instanceof LoggingOutInterceptor) {
logging = true;
}
}
assertTrue(saaj);
assertTrue(logging);
ClientProxyFactoryBean clientProxyFactoryBean = (ClientProxyFactoryBean) ctx.getBean("client2.proxyFactory");
assertNotNull(clientProxyFactoryBean);
assertEquals("get the wrong transportId", clientProxyFactoryBean.getTransportId(), "http://cxf.apache.org/transports/local");
assertEquals("get the wrong bindingId", clientProxyFactoryBean.getBindingId(), "http://cxf.apache.org/bindings/xformat");
greeter = (HelloService) ctx.getBean("client2");
assertNotNull(greeter);
greeter = (HelloService) ctx.getBean("client3");
assertNotNull(greeter);
client = ClientProxy.getClient(greeter);
EndpointInfo epi = client.getEndpoint().getEndpointInfo();
AuthorizationPolicy ap = epi.getExtensor(AuthorizationPolicy.class);
assertNotNull("The AuthorizationPolicy instance should not be null", ap);
assertEquals("Get the wrong username", ap.getUserName(), "testUser");
assertEquals("Get the wrong password", ap.getPassword(), "password");
}
use of org.apache.cxf.binding.soap.saaj.SAAJInInterceptor in project cxf by apache.
the class WSS4JInOutTest method testOrder.
@Test
public void testOrder() throws Exception {
// make sure the interceptors get ordered correctly
SortedSet<Phase> phases = new TreeSet<>();
phases.add(new Phase(Phase.PRE_PROTOCOL, 1));
List<Interceptor<? extends Message>> lst = new ArrayList<>();
lst.add(new MustUnderstandInterceptor());
lst.add(new WSS4JInInterceptor());
lst.add(new SAAJInInterceptor());
PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);
chain.add(lst);
String output = chain.toString();
assertTrue(output.contains("MustUnderstandInterceptor, SAAJInInterceptor, WSS4JInInterceptor"));
}
use of org.apache.cxf.binding.soap.saaj.SAAJInInterceptor in project cxf by apache.
the class ClientMtomXopTest method testMtomXopProvider.
@Test
public void testMtomXopProvider() throws Exception {
TestMtom mtomPort = createPort(MTOM_SERVICE, MTOM_PORT_PROVIDER, TestMtom.class, true, true);
try {
Holder<DataHandler> param = new Holder<>();
Holder<String> name;
byte[] bytes;
InputStream in;
InputStream pre = this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl");
int fileSize = 0;
for (int i = pre.read(); i != -1; i = pre.read()) {
fileSize++;
}
int count = 50;
byte[] data = new byte[fileSize * count];
for (int x = 0; x < count; x++) {
this.getClass().getResourceAsStream("/wsdl/mtom_xop.wsdl").read(data, fileSize * x, fileSize);
}
Object[] validationTypes = new Object[] { Boolean.TRUE, SchemaValidationType.IN, SchemaValidationType.BOTH };
for (Object validationType : validationTypes) {
((BindingProvider) mtomPort).getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED, validationType);
param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
name = new Holder<>("call detail");
mtomPort.testXop(name, param);
assertEquals("name unchanged", "return detail + call detail", name.value);
assertNotNull(param.value);
in = param.value.getInputStream();
bytes = IOUtils.readBytesFromStream(in);
assertEquals(data.length, bytes.length);
in.close();
param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
name = new Holder<>("call detail");
mtomPort.testXop(name, param);
assertEquals("name unchanged", "return detail + call detail", name.value);
assertNotNull(param.value);
in = param.value.getInputStream();
bytes = IOUtils.readBytesFromStream(in);
assertEquals(data.length, bytes.length);
in.close();
}
validationTypes = new Object[] { Boolean.FALSE, SchemaValidationType.OUT, SchemaValidationType.NONE };
for (Object validationType : validationTypes) {
((BindingProvider) mtomPort).getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED, validationType);
SAAJOutInterceptor saajOut = new SAAJOutInterceptor();
SAAJInInterceptor saajIn = new SAAJInInterceptor();
param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
name = new Holder<>("call detail");
mtomPort.testXop(name, param);
assertEquals("name unchanged", "return detail + call detail", name.value);
assertNotNull(param.value);
in = param.value.getInputStream();
bytes = IOUtils.readBytesFromStream(in);
assertEquals(data.length, bytes.length);
in.close();
ClientProxy.getClient(mtomPort).getInInterceptors().add(saajIn);
ClientProxy.getClient(mtomPort).getInInterceptors().add(saajOut);
param.value = new DataHandler(new ByteArrayDataSource(data, "application/octet-stream"));
name = new Holder<>("call detail");
mtomPort.testXop(name, param);
assertEquals("name unchanged", "return detail + call detail", name.value);
assertNotNull(param.value);
in = param.value.getInputStream();
bytes = IOUtils.readBytesFromStream(in);
assertEquals(data.length, bytes.length);
in.close();
ClientProxy.getClient(mtomPort).getInInterceptors().remove(saajIn);
ClientProxy.getClient(mtomPort).getInInterceptors().remove(saajOut);
}
} catch (UndeclaredThrowableException ex) {
throw (Exception) ex.getCause();
} catch (Exception ex) {
System.out.println(System.getProperties());
throw ex;
}
}
use of org.apache.cxf.binding.soap.saaj.SAAJInInterceptor in project jbossws-cxf by jbossws.
the class JaspiClientOutInterceptor method handleMessage.
@Override
public void handleMessage(SoapMessage message) throws Fault {
if (message.getContent(SOAPMessage.class) == null) {
SAAJInInterceptor saajIn = new SAAJInInterceptor();
saajIn.handleMessage(message);
}
SOAPMessage soapMessage = message.getContent(SOAPMessage.class);
if (soapMessage == null) {
return;
}
SOAPMessage copyMessage = null;
try {
MessageFactory messageFactory = SAAJPreInInterceptor.INSTANCE.getFactory(message);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
soapMessage.writeTo(bout);
copyMessage = messageFactory.createMessage(soapMessage.getMimeHeaders(), new ByteArrayInputStream(bout.toByteArray()));
} catch (SOAPException e) {
throw new Fault(e);
} catch (IOException e) {
throw new Fault(e);
}
if (copyMessage != null) {
message.put(SOAPMessage.class, copyMessage);
}
try {
authManager.secureRequest(message);
} finally {
message.put(SOAPMessage.class, soapMessage);
}
}
Aggregations