KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > webservice > header > ImplicitHeaderEndpointImpl


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * 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.test.webservice.header;
23
24 import org.jboss.logging.Logger;
25
26 import javax.xml.rpc.ServiceException JavaDoc;
27 import javax.xml.rpc.handler.soap.SOAPMessageContext JavaDoc;
28 import javax.xml.rpc.server.ServiceLifecycle JavaDoc;
29 import javax.xml.rpc.server.ServletEndpointContext JavaDoc;
30 import javax.xml.soap.Name JavaDoc;
31 import javax.xml.soap.SOAPElement JavaDoc;
32 import javax.xml.soap.SOAPException JavaDoc;
33 import javax.xml.soap.SOAPFactory JavaDoc;
34 import javax.xml.soap.SOAPHeader JavaDoc;
35 import javax.xml.soap.SOAPHeaderElement JavaDoc;
36 import javax.xml.soap.SOAPMessage JavaDoc;
37 import java.rmi.RemoteException JavaDoc;
38 import java.util.Iterator JavaDoc;
39
40 /**
41  * @author Thomas.Diesler@jboss.org
42  * @since 26-Nov-2004
43  */

44 public class ImplicitHeaderEndpointImpl implements ImplicitHeaderEndpoint, ServiceLifecycle JavaDoc
45 {
46    // provide logging
47
private final Logger log = Logger.getLogger(ImplicitHeaderEndpointImpl.class);
48
49    private static final String JavaDoc NAMESPACE_URI = ImplicitHeaderEndpoint.NAMESPACE_URI;
50    private static final String JavaDoc PREFIX = ImplicitHeaderEndpoint.PREFIX;
51
52    private ServletEndpointContext JavaDoc context;
53
54    public boolean doStuff(String JavaDoc parameter) throws RemoteException JavaDoc
55    {
56       if (parameter == null)
57          throw new IllegalArgumentException JavaDoc("Null parameter");
58
59       try
60       {
61          SOAPFactory JavaDoc factory = SOAPFactory.newInstance();
62
63          SOAPMessageContext JavaDoc msgContext = (SOAPMessageContext JavaDoc)context.getMessageContext();
64          SOAPMessage JavaDoc soapMessage = msgContext.getMessage();
65          SOAPHeader JavaDoc soapHeader = soapMessage.getSOAPHeader();
66          Iterator JavaDoc it = soapHeader.extractAllHeaderElements();
67          if (it.hasNext() == false)
68             throw new IllegalArgumentException JavaDoc("No header elements");
69
70          SOAPHeaderElement JavaDoc headerElement = (SOAPHeaderElement JavaDoc)it.next();
71          Name JavaDoc usernameName = factory.createName("username", PREFIX, NAMESPACE_URI);
72          SOAPElement JavaDoc usrElement = (SOAPElement JavaDoc)headerElement.getChildElements(usernameName).next();
73          String JavaDoc username = usrElement.getValue();
74
75          Name JavaDoc sessionIDName = factory.createName("sessionID", PREFIX, NAMESPACE_URI);
76          SOAPElement JavaDoc seElement = (SOAPElement JavaDoc)headerElement.getChildElements(sessionIDName).next();
77          String JavaDoc sessionID = seElement.getValue();
78
79          log.info("username: " + username);
80          log.info("sessionID: " + sessionID);
81
82          return true;
83       }
84       catch (SOAPException JavaDoc e)
85       {
86          log.error(e);
87          return false;
88       }
89    }
90
91    public void init(Object JavaDoc context) throws ServiceException JavaDoc
92    {
93       log.info("init: " + context);
94       this.context = (ServletEndpointContext JavaDoc)context;
95    }
96
97    public void destroy()
98    {
99       log.info("destroy: " + context);
100    }
101 }
102
Popular Tags