01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.ejb3.test.jaxws;
23:
24: // $Id: EndpointEJB.java 1874 2007-01-09 14:28:41Z thomas.diesler@jboss.com $
25:
26: import javax.annotation.Resource;
27: import javax.ejb.SessionContext;
28: import javax.ejb.Stateless;
29: import javax.jws.WebService;
30: import javax.xml.soap.SOAPElement;
31: import javax.xml.soap.SOAPException;
32: import javax.xml.soap.SOAPMessage;
33: import javax.xml.ws.WebServiceContext;
34: import javax.xml.ws.WebServiceException;
35:
36: import org.jboss.ws.annotation.WebContext;
37:
38: @WebService(endpointInterface="org.jboss.ejb3.test.jaxws.EndpointInterface",serviceName="TestService",targetNamespace="http://org.jboss.ws/jaxws/context")
39: @WebContext(contextRoot="jaxws-context",urlPattern="/*")
40: @Stateless
41: public class EndpointEJB {
42: @Resource
43: WebServiceContext wsCtx;
44:
45: @Resource
46: SessionContext ejbCtx;
47:
48: public String echoWS(String input) {
49: try {
50: String retValue = getValueJAXWS();
51: return retValue;
52: } catch (SOAPException ex) {
53: throw new WebServiceException(ex);
54: }
55: }
56:
57: public String echoRPC(String input) {
58: try {
59: String retValue = getValueJAXRPC();
60: return retValue;
61: } catch (SOAPException ex) {
62: throw new WebServiceException(ex);
63: }
64: }
65:
66: private String getValueJAXWS() throws SOAPException {
67: if (wsCtx == null)
68: throw new IllegalStateException("wsCtx was not injected");
69: javax.xml.ws.handler.soap.SOAPMessageContext jaxwsContext = (javax.xml.ws.handler.soap.SOAPMessageContext) wsCtx
70: .getMessageContext();
71: SOAPMessage soapMessage = jaxwsContext.getMessage();
72: SOAPElement soapElement = (SOAPElement) soapMessage
73: .getSOAPBody().getChildElements().next();
74: soapElement = (SOAPElement) soapElement.getChildElements()
75: .next();
76: return soapElement.getValue();
77: }
78:
79: private String getValueJAXRPC() throws SOAPException {
80: if (ejbCtx == null)
81: throw new IllegalStateException("ejbCtx was not injected");
82: javax.xml.rpc.handler.soap.SOAPMessageContext jaxrpcContext = (javax.xml.rpc.handler.soap.SOAPMessageContext) ejbCtx
83: .getMessageContext();
84: SOAPMessage soapMessage = jaxrpcContext.getMessage();
85: SOAPElement soapElement = (SOAPElement) soapMessage
86: .getSOAPBody().getChildElements().next();
87: soapElement = (SOAPElement) soapElement.getChildElements()
88: .next();
89: return soapElement.getValue();
90: }
91: }
|