use of org.apache.cxf.io.CachedOutputStream in project tesb-rt-se by Talend.
the class MessageToEventMapperTest method getTestMessage.
private Message getTestMessage() throws IOException, EndpointException {
Message message = new MessageImpl();
ExchangeImpl exchange = new ExchangeImpl();
ServiceInfo serviceInfo = new ServiceInfo();
InterfaceInfo interfaceInfo = new InterfaceInfo(serviceInfo, new QName("interfaceNs", "interfaceName"));
serviceInfo.setInterface(interfaceInfo);
SoapBindingInfo bInfo = new SoapBindingInfo(serviceInfo, WSDLConstants.NS_SOAP12);
bInfo.setTransportURI(TransportType);
OperationInfo opInfo = new OperationInfo();
opInfo.setName(new QName("namespace", "opName"));
BindingOperationInfo bindingOpInfo = new BindingOperationInfo(bInfo, opInfo);
exchange.put(BindingOperationInfo.class, bindingOpInfo);
SoapBinding binding = new SoapBinding(bInfo);
exchange.put(Binding.class, binding);
String ns = "ns";
EndpointInfo ei = new EndpointInfo(serviceInfo, ns);
ei.setAddress(Address);
Service service = new ServiceImpl();
Bus bus = BusFactory.getThreadDefaultBus();
Endpoint endpoint = new EndpointImpl(bus, service, ei);
exchange.put(Endpoint.class, endpoint);
message.setExchange(exchange);
FlowIdHelper.setFlowId(message, FlowID);
Principal principal = new X500Principal(PrincipalString);
SecurityContext sc = new DefaultSecurityContext(principal, new Subject());
message.put(SecurityContext.class, sc);
CachedOutputStream cos = new CachedOutputStream();
InputStream is = new ByteArrayInputStream(TESTCONTENT.getBytes("UTF-8"));
IOUtils.copy(is, cos);
message.setContent(CachedOutputStream.class, cos);
CustomInfo customInfo = CustomInfo.getOrCreateCustomInfo(message);
customInfo.put("key1", "value1");
return message;
}
use of org.apache.cxf.io.CachedOutputStream in project tesb-rt-se by Talend.
the class CompressionInInterceptor method decompressMessage.
public void decompressMessage(Message message) throws Fault {
if (isGET(message)) {
return;
}
final CachedOutputStream cache = new CachedOutputStream();
final CachedOutputStream decompressedSoapMessage = new CachedOutputStream();
try {
LOG.fine("Uncompressing response");
// Original stream with compressed body
InputStream is = message.getContent(InputStream.class);
if (is == null) {
return;
}
// Loading content of original InputStream to cache
IOUtils.copyAndCloseInput(is, cache);
// Loading SOAP body content to separate stream
CachedOutputStream soapBodyContent = new CachedOutputStream();
Scanner scanner = new Scanner(cache.getInputStream());
MatchResult bodyPosition = null;
try {
bodyPosition = CompressionHelper.loadSoapBodyContent(soapBodyContent, scanner, CompressionConstants.COMPRESSED_SOAP_BODY_PATTERN);
} catch (XMLStreamException e) {
throw new Fault("Can not read compressed SOAP Body", LOG, e, e.getMessage());
}
if (bodyPosition == null) {
// compressed SOAP body content is not found
// skipping decompression
message.setContent(InputStream.class, cache.getInputStream());
} else {
// compressed SOAP body content is found
// apply Base64 decoding for encoded soap body content
final byte[] base64DecodedSoapBody = (new Base64()).decode(soapBodyContent.getBytes());
// uncompress soap body
GZIPInputStream decompressedBody = new GZIPInputStream(new ByteArrayInputStream(base64DecodedSoapBody));
// replace original soap body by compressed one
CompressionHelper.replaceBodyInSOAP(cache.getBytes(), bodyPosition, decompressedBody, decompressedSoapMessage, null, null, true);
message.setContent(InputStream.class, decompressedSoapMessage.getInputStream());
}
if (message.getInterceptorChain() != null) {
message.getInterceptorChain().add(new AbstractPhaseInterceptor<Message>(Phase.POST_INVOKE) {
@Override
public void handleMessage(Message message) throws Fault {
closeCacheStreams(cache, decompressedSoapMessage);
}
});
}
} catch (Exception ex) {
closeCacheStreams(cache, decompressedSoapMessage);
throw new Fault("SOAP Body decompression failed", LOG, ex);
}
}
use of org.apache.cxf.io.CachedOutputStream in project tesb-rt-se by Talend.
the class CompressionHelperTest method testSoapBodyIsNotFound.
@Test
public void testSoapBodyIsNotFound() throws Exception {
// Loading SOAP body content to separate stream
CachedOutputStream soapBodyContent = new CachedOutputStream();
CachedOutputStream cache = new CachedOutputStream();
cache.write("1".getBytes());
Scanner scanner = new Scanner(cache.getInputStream());
try {
CompressionHelper.loadSoapBodyContent(soapBodyContent, scanner, "(\\d)(a)*");
} catch (XMLStreamException e) {
// TODO Auto-generated catch block
fail("XMLStreamException is not expected");
} catch (RuntimeException ex) {
return;
} finally {
cache.close();
}
fail("No exception is not expected");
}
use of org.apache.cxf.io.CachedOutputStream in project tesb-rt-se by Talend.
the class CompressionHelperTest method testNullScaner.
@Test
public void testNullScaner() throws Exception {
// Loading SOAP body content to separate stream
CachedOutputStream soapBodyContent = new CachedOutputStream();
CachedOutputStream cache = new CachedOutputStream();
cache.write("1".getBytes());
try {
CompressionHelper.loadSoapBodyContent(soapBodyContent, null, "(\\d)(a)*");
} catch (XMLStreamException e) {
// TODO Auto-generated catch block
fail("XMLStreamException is not expected");
} catch (RuntimeException ex) {
return;
} finally {
cache.close();
}
fail("No exception is not expected");
}
use of org.apache.cxf.io.CachedOutputStream in project tesb-rt-se by Talend.
the class CompressionOutInterceptorTest method handleRuntimeException2.
@Test
public void handleRuntimeException2() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
map.put(Message.HTTP_REQUEST_METHOD, "GET");
Message message = CompressionCommonTest.getMessageStub(null, map);
ByteArrayOutputStream os = new ByteArrayOutputStream();
CompressionCachedOutputStreamCallback callback = new CompressionCachedOutputStreamCallback(os, 1024, message);
CachedOutputStream wrapper = new CachedOutputStream();
try {
callback.onClose(wrapper);
} catch (RuntimeException ex) {
return;
}
fail("No exception is not expected");
}
Aggregations