Hi,

After hours of research and testing I've got a solution.
I don't know if my solution is the 'right'-one, but it works. Maybe you could 
explain how to do things better?
The follwing C/S Code shows how to send and recieve custom HTTP-Header and 
custom SOAP-Header.

Configuration:
- Axis 1.4
- Eclipse Galileo
- Tomcat 6

Development-steps:
- Install Eclipse and bind Tomcat into Eclipse
- Build new Dynamic Web-Project (Server)
- Add Axis libs
- Create POJO
- Use Eclipse to generate the Webservice in the same Project
- Use Eclipse to generate the Client (another Project)
- Configure the Eclipse TCP-Monitor
- Configure the generated endpoints for TCP-Monitoring
- Run Server as Webapplication in Tomcat
- Run Client as Application

Note that the follwing webservice is a little bit different to the Post before! 
(I created a new Test-Environment)


// Service
System.out.println("Server: Start");
        try{
                MessageContext mc = MessageContext.getCurrentContext();
                mc.setMaintainSession(true); // enable axis session
                
                /**
                 * Read properties
                 */
            Iterator i = mc.getAllPropertyNames();
            while (i.hasNext()){
                  System.out.println("Server: found Property -> "+i.next());
            }
                System.out.println("Server: found Username -> 
"+mc.getUsername());
                System.out.println("Server: found Pasword -> 
"+mc.getPassword());
                System.out.println("Server: found Cookie -> 
"+mc.getProperty(HTTPConstants.HEADER_COOKIE));
            
            HttpServletRequest request = 
(HttpServletRequest)mc.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
            String testProperty = (String) request.getHeader("testProperty");
            System.out.println("Server: found testProperty on HTTP-Header -> 
"+testProperty);

                
                /**
                 * Read Session
                 */
                System.out.println("Server: MaintainSession -> 
"+mc.getMaintainSession());
            System.out.println("Server: Session ID -> "+mc.getSession());
            
           
            /**
             * Set properties
             */
            HttpServletResponse response = 
(HttpServletResponse)mc.getProperty(HTTPConstants.MC_HTTP_SERVLETRESPONSE);
                        response.addHeader("testProperty2", 
"testvalue123fromserver");
                        mc.setProperty(HTTPConstants.MC_HTTP_SERVLETRESPONSE, 
response);
           
            /**
             * Set Session properties
             */
            mc.getSession().set("testServerSessionProperty", "11234test");
            
            /**
             * Set SOAP-Header
             */
                        SOAPEnvelope env = 
mc.getResponseMessage().getSOAPEnvelope();
                SOAPHeaderElement headerElement = new 
org.apache.axis.message.SOAPHeaderElement("http://webservice.cuba/headers";, 
"myHeader", "test12346");
                env.addHeader(headerElement);
                
                /**
                 * Read SOAP-Header (source 
https://svn.apache.org/repos/asf/webservices/rampart/scratch/java/test-module/modules/chamanthi-jar/src/main/java/org/apache/rampart/chamanthi/handler/Receiver.java)
                 */
                env = mc.getRequestMessage().getSOAPEnvelope(); 
            SOAPHeaderElement header = 
env.getHeaderByName("http://webservice.cuba/headers";, "myHeader");
            if (header != null)
                System.out.println("Server: SOAP-header -> "+header.getValue());
                
        } catch (Exception e) {
            e.printStackTrace(); // error output
        }
        System.out.println("Server: Finished");
        return true; // WS return true


// Client 1 (for HTTP-Header)
System.out.println("Client: Start");
        try {
                /**
                 * Simple WS-Call (source: 
http://ws.apache.org/axis/java/user-guide.html#ConsumingWebServicesWithAxis)
                 * + set http-Header
                 * + read http-Header
                 */
                String endpoint = 
"http://localhost:80/CubaDummyServer/services/CubaAxisTestService";;
            Service  service = new Service();
            service.setMaintainSession(true); // Enable Session-support
            Call     call    = (Call) service.createCall();
            call.setTargetEndpointAddress( new java.net.URL(endpoint) );
            call.setOperationName(new QName("http://webservice.cuba";, 
"doSomething") );

            // set http-Header
            MessageContext msgContext = call.getMessageContext();
            Hashtable userHeaderTable = (Hashtable) 
msgContext.getProperty(HTTPConstants.REQUEST_HEADERS);
                        if (userHeaderTable == null)
                        {
                                 userHeaderTable = new Hashtable();
                        }
                        userHeaderTable.put("testProperty", "testvalue123");
                        call.setProperty(HTTPConstants.REQUEST_HEADERS, 
userHeaderTable);
                        
                        String ret = (String) call.invoke( new Object[] { } ); 
// call with no params

                        // read http-Header (source: 
http://www.5341.com/msg/196651.html)
                        String[] testProperty = 
call.getMessageContext().getResponseMessage().getMimeHeaders().getHeader("testproperty2");
                        System.out.println("Client: found testProperty2 on 
HTTP-Header -> " + testProperty[0]);

                        System.out.println("Client: Server returned: "+ret);
        } catch (Exception e) {
                 e.printStackTrace(); // DEBUG output
        }
                System.out.println("Client: End");


// Client 2 (for SOAP-Header)
System.out.println("Client: Start");
        try {
                /**
                 * Simple WS-Call (source: 
http://ws.apache.org/axis/java/user-guide.html#ConsumingWebServicesWithAxis)
                 * + set SOAP-Header
                 * + read SOAP-Header
                 */
              String endpoint = 
"http://localhost:80/CubaDummyServer/services/CubaAxisTestService";;
              Service  service = new Service();
              service.setMaintainSession(true); // enable axis session-support
              CubaAxisTestServiceServiceLocator locator = new 
CubaAxisTestServiceServiceLocator();
              Call     call    = (Call) service.createCall();
              call.setTargetEndpointAddress( new java.net.URL(endpoint) );
              call.setOperationName(new QName("http://webservice.cuba";, 
"doSomething") );
              
              // set soap-header
              SOAPHeaderElement header = new 
SOAPHeaderElement("http://webservice.cuba/headers";, "myHeader");
              header.setValue("myHeader");
              call.addHeader(header);
              
              String ret = (String) call.invoke( new Object[] { } ); // call 
service
              
              // read soap-header
              SOAPEnvelope env = call.getResponseMessage().getSOAPEnvelope(); 
              header = env.getHeaderByName("http://webservice.cuba/headers";, 
"myHeader"); 
              
              System.out.println("Client: Server returned -> "+ret);
              System.out.println("Client: SOAP-header returned -> 
"+header.getValue());
         } catch (Exception e) {
             e.printStackTrace(); // DEBUG output
         }

                System.out.println("Client: End");


The monitored results:
request with SOAP-Header
POST /CubaDummyServer/services/CubaAxisTestService HTTP/1.0
Content-Type: text/xml; charset=utf-8
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: Axis/1.4
Host: localhost:80
Cache-Control: no-cache
Pragma: no-cache
SOAPAction: ""
Content-Length: 663

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";><soapenv:Header><ns1:myHeader
 soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"; 
soapenv:mustUnderstand="0" xsi:type="soapenc:string" 
xmlns:ns1="http://webservice.cuba/headers"; 
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/";>myHeader</ns1:myHeader></soapenv:Header><soapenv:Body><ns2:doSomething
 soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"; 
xmlns:ns2="http://webservice.cuba"/></soapenv:Body></soapenv:Envelope>

response with SOAP-Header
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
testProperty2: testvalue123fromserver
Set-Cookie: JSESSIONID=B13B1B3BA3A2AC1549DCA663CEE72BD7; Path=/CubaDummyServer
Content-Type: text/xml;charset=utf-8
Date: Wed, 23 Dec 2009 13:08:30 GMT
Connection: close

<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";><soapenv:Header><ns1:myHeader
 soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"; 
soapenv:mustUnderstand="0" 
xmlns:ns1="http://webservice.cuba/headers";>test12346</ns1:myHeader></soapenv:Header><soapenv:Body><doSomethingResponse
 
xmlns="http://webservice.cuba";><doSomethingReturn>true</doSomethingReturn></doSomethingResponse></soapenv:Body></soapenv:Envelope>


request with HTTP-Header
POST /CubaDummyServer/services/CubaAxisTestService HTTP/1.0
Content-Type: text/xml; charset=utf-8
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: Axis/1.4
Host: localhost:80
Cache-Control: no-cache
Pragma: no-cache
SOAPAction: ""
Content-Length: 380
testProperty: testvalue123

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";><soapenv:Body><ns1:doSomething
 soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"; 
xmlns:ns1="http://webservice.cuba"/></soapenv:Body></soapenv:Envelope>

response with HTTP-Header
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
testProperty2: testvalue123fromserver
Set-Cookie: JSESSIONID=2B9B1B4DBE7411434A9DCFE83554B434; Path=/CubaDummyServer
Content-Type: text/xml;charset=utf-8
Date: Wed, 23 Dec 2009 13:08:08 GMT
Connection: close

<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";><soapenv:Header><ns1:myHeader
 soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"; 
soapenv:mustUnderstand="0" 
xmlns:ns1="http://webservice.cuba/headers";>test12346</ns1:myHeader></soapenv:Header><soapenv:Body><doSomethingResponse
 
xmlns="http://webservice.cuba";><doSomethingReturn>true</doSomethingReturn></doSomethingResponse></soapenv:Body></soapenv:Envelope>
___________________________________________________________
Preisknaller: WEB.DE DSL Flatrate für nur 16,99 Euro/mtl.! 
http://produkte.web.de/go/02/

Reply via email to