use of org.apache.cxf.message.Message in project tesb-rt-se by Talend.
the class FlowIdProducerTest method flowIdProducerOut2Test.
@Test
public void flowIdProducerOut2Test() {
FlowIdProducerOut<Message> flowIdProducerOut = new FlowIdProducerOut<Message>();
Message message = new MessageImpl();
Exchange exchange = new ExchangeImpl();
Message inMessage = new MessageImpl();
exchange.setInMessage(inMessage);
message.setExchange(exchange);
WeakReference<Message> wrPreviousMessage = EasyMock.createMock(WeakReference.class);
EasyMock.expect(wrPreviousMessage.get()).andReturn(message);
EasyMock.replay(wrPreviousMessage);
message.put(PhaseInterceptorChain.PREVIOUS_MESSAGE, wrPreviousMessage);
message.put(Message.REQUESTOR_ROLE, true);
String flowId = FlowIdHelper.getFlowId(message);
Assert.assertNull("FlowId should be null before FlowIdProducerOut handleMessage()", flowId);
flowIdProducerOut.handleMessage(message);
flowId = FlowIdHelper.getFlowId(message);
Assert.assertNotNull("FlowId should not be null after FlowIdProducerOut handleMessage()", flowId);
}
use of org.apache.cxf.message.Message in project tesb-rt-se by Talend.
the class FlowIdProducerTest method flowIdProducerOutTest.
@Test
public void flowIdProducerOutTest() {
FlowIdProducerOut<Message> flowIdProducerOut = new FlowIdProducerOut<Message>();
Message message = new MessageImpl();
Exchange exchange = new ExchangeImpl();
Message inMessage = new MessageImpl();
exchange.setInMessage(inMessage);
message.setExchange(exchange);
String flowId = FlowIdHelper.getFlowId(message);
Assert.assertNull("FlowId should be null before FlowIdProducerOut handleMessage()", flowId);
flowIdProducerOut.handleMessage(message);
flowId = FlowIdHelper.getFlowId(message);
Assert.assertNotNull("FlowId should not be null after FlowIdProducerOut handleMessage()", flowId);
}
use of org.apache.cxf.message.Message in project tesb-rt-se by Talend.
the class WireTapIn method handleMessage.
/* (non-Javadoc)
* @see org.apache.cxf.interceptor.Interceptor#handleMessage(org.apache.cxf.message.Message)
*/
@Override
public void handleMessage(final Message message) throws Fault {
final InputStream is = message.getContent(InputStream.class);
if (logMessageContent) {
if (null == is) {
Reader reader = message.getContent(Reader.class);
if (null != reader) {
String encoding = (String) message.get(Message.ENCODING);
if (encoding == null) {
encoding = "UTF-8";
}
try {
final CachedOutputStream cos = new CachedOutputStream();
final Writer writer = new OutputStreamWriter(cos, encoding);
IOUtils.copy(reader, writer, 1024);
reader.reset();
writer.flush();
message.setContent(InputStream.class, cos.getInputStream());
message.setContent(Reader.class, null);
message.setContent(CachedOutputStream.class, cos);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
try {
reader.reset();
} catch (IOException e) {
}
}
}
} else {
try {
final CachedOutputStream cos = new CachedOutputStream();
// TODO: We should try to make this streaming
// WireTapInputStream wtis = new WireTapInputStream(is, cos);
// message.setContent(InputStream.class, wtis);
IOUtils.copyAndCloseInput(is, cos);
message.setContent(InputStream.class, cos.getInputStream());
message.setContent(CachedOutputStream.class, cos);
message.getInterceptorChain().add(new AbstractPhaseInterceptor<Message>(Phase.POST_INVOKE) {
@Override
public void handleMessage(Message message) throws Fault {
if (cos != null) {
try {
cos.close();
} catch (IOException e) {
}
}
}
});
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
use of org.apache.cxf.message.Message in project tesb-rt-se by Talend.
the class SecurityContextFilter method filter.
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
Message message = JAXRSUtils.getCurrentMessage();
SecurityContext sc = message.get(SecurityContext.class);
if (sc != null) {
Principal principal = sc.getUserPrincipal();
if (principal != null) {
String accountName = principal.getName();
UserAccount account = accounts.getAccount(accountName);
if (account == null) {
account = accounts.getAccountWithAlias(accountName);
}
if (account == null) {
requestContext.abortWith(createFaultResponse());
} else {
setNewSecurityContext(message, account.getName());
}
return;
}
}
List<String> authValues = headers.getRequestHeader("Authorization");
if (authValues == null || authValues.size() != 1) {
requestContext.abortWith(createFaultResponse());
return;
}
String[] values = authValues.get(0).split(" ");
if (values.length != 2 || !"Basic".equals(values[0])) {
requestContext.abortWith(createFaultResponse());
return;
}
String decodedValue = null;
try {
decodedValue = new String(Base64Utility.decode(values[1]));
} catch (Base64Exception ex) {
requestContext.abortWith(createFaultResponse());
return;
}
String[] namePassword = decodedValue.split(":");
if (namePassword.length != 2) {
requestContext.abortWith(createFaultResponse());
return;
}
final UserAccount account = accounts.getAccount(namePassword[0]);
if (account == null || !account.getPassword().equals(namePassword[1])) {
requestContext.abortWith(createFaultResponse());
return;
}
setNewSecurityContext(message, account.getName());
}
use of org.apache.cxf.message.Message in project tesb-rt-se by Talend.
the class SecurityContextFilter method filter.
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
Message message = JAXRSUtils.getCurrentMessage();
if (ui.getAbsolutePath().toString().endsWith(userRegistrationPath)) {
return;
}
List<String> authValues = headers.getRequestHeader("Authorization");
if (authValues.size() != 1) {
requestContext.abortWith(createFaultResponse());
return;
}
String[] values = authValues.get(0).split(" ");
if (values.length != 2 || !"Basic".equals(values[0])) {
requestContext.abortWith(createFaultResponse());
return;
}
String decodedValue = null;
try {
decodedValue = new String(Base64Utility.decode(values[1]));
} catch (Base64Exception ex) {
requestContext.abortWith(createFaultResponse());
return;
}
String[] namePassword = decodedValue.split(":");
if (namePassword.length != 2) {
requestContext.abortWith(createFaultResponse());
return;
}
final UserAccount account = accounts.getAccount(namePassword[0]);
if (account == null || !account.getPassword().equals(namePassword[1])) {
requestContext.abortWith(createFaultResponse());
return;
}
final SecurityContext sc = new SecurityContext() {
public Principal getUserPrincipal() {
return new SimplePrincipal(account.getName());
}
public boolean isUserInRole(String arg0) {
return false;
}
};
message.put(SecurityContext.class, sc);
}
Aggregations