Hi Conrad,

Thanks very much

That's very helpful

Freeman


Conrad O'Dea wrote:

On Thu, 2006-11-02 at 10:31 +0000, Conrad O'Dea wrote:
On Thu, 2006-11-02 at 17:41 +0800, Freeman Fang wrote:
If you can provide your test case, that would be great for us to write the test.
I'll put this together now...


Here's a really simple provider that attempts to set a test header.  The
main line GETs the message from the provider and checks if the header is
set.
------------------------------------------------------------------------

package test;

import java.io.StringReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.ws.BindingType;
import javax.xml.ws.Endpoint;
import javax.xml.ws.Provider;
import javax.xml.ws.Service;
import javax.xml.ws.ServiceMode;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.WebServiceProvider;
import javax.xml.ws.handler.MessageContext;

@WebServiceProvider()
@ServiceMode(value = Service.Mode.PAYLOAD)
//@BindingType(value = "http://cxf.apache.org/bindings/xformat";)
@BindingType(value = "http://celtix.objectweb.org/bindings/xmlformat";)
public class HeaderTest implements Provider<Source> {
public static final String TEST_HEADER_NAME = "Test"; @Resource WebServiceContext wsCtx; @SuppressWarnings("unchecked")
   public Source invoke(Source arg0) {
       MessageContext ctx = wsCtx.getMessageContext();

       List<String> hdr = new ArrayList<String>();
       hdr.add("test-value");
       Map<String, List<String>> hdrs = (Map<String, 
List<String>>)ctx.get(MessageContext.HTTP_RESPONSE_HEADERS);
if (hdrs != null) {
           hdrs.put(TEST_HEADER_NAME, hdr);
} return new StreamSource(new StringReader("<foo/>"));
   }

   public static void main(String[] args) throws Exception {
try { URL url = new URL("http://localhost:9999";);
           System.out.println("publishing endpoint");
           Endpoint.publish(url.toString(), new HeaderTest());
           System.out.println("server ready");
           HttpURLConnection conn = (HttpURLConnection)url.openConnection();

           conn.connect();
           boolean ok = false;
           Map<String, List<String>> hdrs = conn.getHeaderFields();
           for (String hdrName : hdrs.keySet()) {
               List<String> value = hdrs.get(hdrName);
               System.out.println(hdrName + ": " + value);
               if (TEST_HEADER_NAME.equals(hdrName)) {
                   ok = true;
               }
           }
           System.out.println("Test " + (ok ? "PASSED" : "FAILED"));
       } finally {
           System.exit(0);
       }
   }
}


--
Freeman Fang
Software Engineer

IONA Asia Pacific Software Development Center
No.2 Floor A Unit Information Center
Zhongguancun Software Park Haidian District,
Beijing, P.R.China

Tel.: +86-10-82825151 -  ex. 551
Fax: +86-10-8282-5210
[EMAIL PROTECTED]
-------------------------------------------------
Making Software Work Together TM



Reply via email to