use of javax.xml.ws.handler.MessageContext in project camel by apache.
the class EchoServiceSessionImpl method echo.
public String echo(String text) {
// Find the HttpSession
MessageContext mc = context.getMessageContext();
HttpSession session = ((javax.servlet.http.HttpServletRequest) mc.get(MessageContext.SERVLET_REQUEST)).getSession();
if (session == null) {
throw new WebServiceException("No HTTP Session found");
}
if (session.getAttribute("foo") == null) {
session.setAttribute("foo", "bar");
return "New " + text;
}
return "Old " + text;
}
use of javax.xml.ws.handler.MessageContext in project camel by apache.
the class HeaderTesterImpl method addReplyOutOfBandHeader.
private void addReplyOutOfBandHeader() {
if (context != null) {
MessageContext ctx = context.getMessageContext();
if (ctx != null) {
try {
OutofBandHeader ob = new OutofBandHeader();
ob.setName("testOobReturnHeaderName");
ob.setValue("testOobReturnHeaderValue");
ob.setHdrAttribute("testReturnHdrAttribute");
JAXBElement<OutofBandHeader> job = new JAXBElement<OutofBandHeader>(new QName(Constants.TEST_HDR_NS, Constants.TEST_HDR_RESPONSE_ELEM), OutofBandHeader.class, null, ob);
Header hdr = new Header(new QName(Constants.TEST_HDR_NS, Constants.TEST_HDR_RESPONSE_ELEM), job, new JAXBDataBinding(ob.getClass()));
List<Header> hdrList = CastUtils.cast((List<?>) ctx.get(Header.HEADER_LIST));
hdrList.add(hdr);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
use of javax.xml.ws.handler.MessageContext in project camel by apache.
the class HeaderTesterWithInsertionImpl method validateOutOfBandHander.
@Override
protected boolean validateOutOfBandHander() {
MessageContext ctx = context == null ? null : context.getMessageContext();
if (!relayHeaders) {
if (ctx != null && !ctx.containsKey(Header.HEADER_LIST) || (ctx.containsKey(Header.HEADER_LIST) && ((List<?>) ctx.get(Header.HEADER_LIST)).size() == 0)) {
return true;
}
return false;
}
boolean success = false;
if (ctx != null && ctx.containsKey(Header.HEADER_LIST)) {
List<Header> oobHdr = CastUtils.cast((List<?>) ctx.get(Header.HEADER_LIST));
if (oobHdr.size() != 2) {
throw new RuntimeException("test failed expected 2 soap headers but found " + oobHdr.size());
}
verifyHeader(oobHdr.get(0), "testOobHeader", "testOobHeaderValue");
verifyHeader(oobHdr.get(1), "New_testOobHeader", "New_testOobHeaderValue");
oobHdr.clear();
success = true;
} else {
throw new RuntimeException("MessageContext is null or doesnot contain OOBHeaders");
}
return success;
}
use of javax.xml.ws.handler.MessageContext in project libresonic by Libresonic.
the class SonosService method getUsername.
private String getUsername() {
MessageContext messageContext = context.getMessageContext();
if (messageContext == null || !(messageContext instanceof WrappedMessageContext)) {
LOG.error("Message context is null or not an instance of WrappedMessageContext.");
return null;
}
Message message = ((WrappedMessageContext) messageContext).getWrappedMessage();
List<Header> headers = CastUtils.cast((List<?>) message.get(Header.HEADER_LIST));
if (headers != null) {
for (Header h : headers) {
Object o = h.getObject();
// Unwrap the node using JAXB
if (o instanceof Node) {
JAXBContext jaxbContext;
try {
// TODO: Check performance
jaxbContext = new JAXBDataBinding(Credentials.class).getContext();
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
o = unmarshaller.unmarshal((Node) o);
} catch (JAXBException e) {
// failed to get the credentials object from the headers
LOG.error("JAXB error trying to unwrap credentials", e);
}
}
if (o instanceof Credentials) {
Credentials c = (Credentials) o;
// Note: We're using the username as session ID.
String username = c.getSessionId();
if (username == null) {
LOG.debug("No session id in credentials object, get from login");
username = c.getLogin().getUsername();
}
return username;
} else {
LOG.error("No credentials object");
}
}
} else {
LOG.error("No headers found");
}
return null;
}
use of javax.xml.ws.handler.MessageContext in project tomee by apache.
the class JaxWsInvocationTest method testWsInvocations.
public void testWsInvocations() throws Exception {
System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
final ConfigurationFactory config = new ConfigurationFactory();
final Assembler assembler = new Assembler();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class, "PseudoSecurityService", null, "PseudoSecurityService", null));
assembler.createContainer(config.configureService(StatelessSessionContainerInfo.class));
final EjbJarInfo ejbJar = config.configureApplication(buildTestApp());
assembler.createApplication(ejbJar);
final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
final BeanContext beanContext = containerSystem.getBeanContext("EchoBean");
assertNotNull(beanContext);
assertEquals("ServiceEndpointInterface", EchoServiceEndpoint.class, beanContext.getServiceEndpointInterface());
// OK, Now let's fake a web serivce invocation coming from any random
// web service provider. The web serivce provider needs supply
// the MessageContext and an interceptor to do the marshalling as
// the arguments of the standard container.invoke signature.
// So let's create a fake message context.
final MessageContext messageContext = new FakeMessageContext();
// Now let's create a fake interceptor as would be supplied by the
// web service provider. Instead of writing "fake" marshalling
// code that would pull the arguments from the soap message, we'll
// just give it the argument values directly.
final Object wsProviderInterceptor = new FakeWsProviderInterceptor("Hello world");
// Ok, now we have the two arguments expected on a JAX-RPC Web Service
// invocation as per the OpenEJB-specific agreement between OpenEJB
// and the Web Service Provider
final Object[] args = new Object[] { messageContext, wsProviderInterceptor };
// Let's grab the container as the Web Service Provider would do and
// perform an invocation
final RpcContainer container = (RpcContainer) beanContext.getContainer();
final Method echoMethod = EchoServiceEndpoint.class.getMethod("echo", String.class);
final String value = (String) container.invoke("EchoBean", InterfaceType.SERVICE_ENDPOINT, echoMethod.getDeclaringClass(), echoMethod, args, null);
assertCalls(Call.values());
calls.clear();
assertEquals("Hello world", value);
}
Aggregations