use of javax.xml.ws.handler.MessageContext in project cxf by apache.
the class GreeterSessionImpl method greetMeOneWay.
public void greetMeOneWay(String me) {
LOG.info("Executing operation greetMeOneWay");
LOG.info("Message received: " + me);
MessageContext mc = context.getMessageContext();
HttpServletRequest req = (HttpServletRequest) mc.get(MessageContext.SERVLET_REQUEST);
HttpSession session = req.getSession();
if (session == null) {
throw new WebServiceException("No session in WebServiceContext");
}
String name = (String) session.getAttribute("name");
if (name == null) {
name = me;
LOG.info("Starting the Session");
}
session.setAttribute("name", me);
}
use of javax.xml.ws.handler.MessageContext in project tomee by apache.
the class EjbWsContext method getMessageContext.
@Override
public MessageContext getMessageContext() {
final ThreadContext threadContext = ThreadContext.getThreadContext();
final MessageContext messageContext = threadContext.get(MessageContext.class);
if (messageContext == null) {
throw new IllegalStateException("Only calls on the service-endpoint have a MessageContext.");
}
return messageContext;
}
use of javax.xml.ws.handler.MessageContext in project tomee by apache.
the class EjbWsContext method getMessageContext.
public MessageContext getMessageContext() {
final ThreadContext threadContext = ThreadContext.getThreadContext();
final MessageContext messageContext = threadContext.get(MessageContext.class);
if (messageContext == null) {
throw new IllegalStateException("Only calls on the service-endpoint have a MessageContext.");
}
return messageContext;
}
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);
}
use of javax.xml.ws.handler.MessageContext in project cxf by apache.
the class OOBHdrServiceImpl method checkContext.
private boolean checkContext() {
boolean success = false;
MessageContext ctx = context == null ? null : context.getMessageContext();
if (ctx.containsKey(Header.HEADER_LIST)) {
List<?> oobHdr = (List<?>) ctx.get(Header.HEADER_LIST);
Iterator<?> iter = oobHdr.iterator();
while (iter.hasNext()) {
Object hdr = iter.next();
if (hdr instanceof Header && ((Header) hdr).getObject() instanceof Node) {
Header hdr1 = (Header) hdr;
// System.out.println("Node conains : " + hdr1.getObject().toString());
try {
JAXBElement<?> job = (JAXBElement<?>) JAXBContext.newInstance(ObjectFactory.class).createUnmarshaller().unmarshal((Node) hdr1.getObject());
OutofBandHeader ob = (OutofBandHeader) job.getValue();
if ("testOobHeader".equals(ob.getName()) && "testOobHeaderValue".equals(ob.getValue())) {
if ("testHdrAttribute".equals(ob.getHdrAttribute())) {
success = true;
// mark it processed
iter.remove();
} else if ("dontProcess".equals(ob.getHdrAttribute())) {
// we won't remove it so we won't let the runtime know
// it's processed. It SHOULD throw an exception
// saying the mustunderstand wasn't processed
success = true;
}
} else {
throw new RuntimeException("test failed");
}
} catch (JAXBException ex) {
//
ex.printStackTrace();
}
}
}
} else {
throw new RuntimeException("MessageContext is null or doesnot contain OOBHeaders");
}
return success;
}
Aggregations