This discussion is archived
3 Replies Latest reply: Feb 10, 2012 4:51 AM by gimbal2 RSS

[help] how to client a Web Services server which need authenticate?

843844 Newbie
Currently Being Moderated
I am programming a Web Services Client, and the Web Services need http basic authentication.

Most of codes are generated by Netbeans from a WSDL file, but the program return me a ClientTransportException: request requires HTTP authentication: Unauthorized.

How to write codes and where should I insert them?

printStackTrace as follow:
com.sun.xml.ws.client.ClientTransportException: request requires HTTP authentication: Unauthorized
com.sun.xml.ws.transport.http.client.HttpClientTransport.checkResponseCode(HttpClientTransport.java:232) 
com.sun.xml.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:151) 
com.sun.xml.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:88) 
com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:595) 
com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:554) 
com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:539) 
com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:436) 
com.sun.xml.ws.client.Stub.process(Stub.java:248) 
com.sun.xml.ws.client.sei.SEIStub.doProcess(SEIStub.java:134) 
com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:244) 
com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:224) 
com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:117) 
$Proxy27.zbjdaFmMd0H(Unknown Source) 
org.apache.jsp.index_jsp._jspService(index_jsp.java:94) 
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:803) 
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393) 
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320) 
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:803) 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390) 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263) 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584) 
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) 
java.lang.Thread.run(Thread.java:619)
and my page code as follow:
<%-- 
    Document   : index2
    Created on : 2008-10-13, 16:25:54
    Author     : Hawkeyes
--%>
 
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
 
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h2>Hello World!</h2>
 
    <%-- start web service invocation --%><hr/>
    <%
    try {
     com.heliteq.wsclient.client.ZBJDAFMMD0HV1_Service service
= new com.heliteq.wsclient.client.ZBJDAFMMD0HV1_Service();
     com.heliteq.wsclient.client.ZBJDAFMMD0HV1 port = service.getZBJDAFMMD0HV1();
      // TODO initialize WS operation arguments here
     javax.xml.ws.Holder<com.heliteq.wsclient.client.TableOfZbjdaTbMd0R> tabItab 
= new javax.xml.ws.Holder<com.heliteq.wsclient.client.TableOfZbjdaTbMd0R>();
     javax.xml.ws.Holder<com.heliteq.wsclient.client.Bapireturn> expReturn 
= new javax.xml.ws.Holder<com.heliteq.wsclient.client.Bapireturn>();
     port.zbjdaFmMd0H(tabItab, expReturn);
    } catch (Exception ex) {
     // TODO handle custom exceptions here
    }
    %>
    <%-- end web service invocation --%><hr/>
    </body>
</html>
Edited by: Winds on Oct 16, 2008 9:49 AM