security - Invoking Secure .asmx webservice from Java -


i have webservice url this:

http://pc212323/adminservice/helloworldservice.asmx?wsdl 

now when hit service soapui asks username, password in saperate popup window. done before soapui loads request structure. again have pass username , password in request properties present on left of soapui tool. gives me output.

now want hit asmx sevice through java unable figure out how invoke service passing username , password.

in short want replicate behaviour of soapui through java code

looking forward answers. in advance.

i invoking above service code of mine:

import javax.xml.namespace.qname; import org.apache.axiom.om.omabstractfactory; import org.apache.axiom.om.omelement; import org.apache.axiom.om.omfactory; import org.apache.axiom.om.omnamespace; import org.apache.axis2.axisfault; import org.apache.axis2.addressing.endpointreference; import org.apache.axis2.client.options; import org.apache.axis2.client.serviceclient; import org.apache.axis2.context.messagecontext; import org.apache.axis2.transport.http.httpconstants; import org.apache.commons.httpclient.httpclient; import org.apache.commons.httpclient.multithreadedhttpconnectionmanager; import org.apache.commons.httpclient.params.httpconnectionmanagerparams;   public class helloworldsecurity {                  public static void main(string[] args) {                                 helloworldsecurity helloworldsecurity = new helloworldsecurity ();                                 helloworldsecurity.service_code();                 }                  public serviceclient configuration()                 {                                                               system.out.println("configuration");                                 serviceclient stclient = null;                                 try{                                                 org.apache.axis2.context.configurationcontext configurationcontext = org.apache.axis2.context.configurationcontextfactory.createconfigurationcontextfromfilesystem(null,null);                                                 multithreadedhttpconnectionmanager multithreadedhttpconnectionmanager = new multithreadedhttpconnectionmanager();                                                 httpconnectionmanagerparams params = new httpconnectionmanagerparams();                                                 params.setdefaultmaxconnectionsperhost(2);                                                 multithreadedhttpconnectionmanager.setparams(params);                                                 httpclient httpclient = new       httpclient(multithreadedhttpconnectionmanager);                                                 configurationcontext.setproperty(httpconstants.cached_http_client,httpclient);                                                 stclient = new serviceclient(configurationcontext , null);                                                 options options = new options();                                                 endpointreference targetepr = new endpointreference("http://pc212323/adminservice/helloworldservice.asmx");                                                 options.setto(targetepr);                                                 options.setaction("http://tempuri.org/helloworld");                                                 options.setusername("kevin");                                                 options.setpassword("password-1");                                                 stclient.setoptions(options);                                 }                                 catch(exception e)                                 {                                                 e.printstacktrace();                                 }                                 return stclient;                 }                  public void service_code(){                                 omfactory fac = omabstractfactory.getomfactory();                                 omnamespace ns = fac.createomnamespace("http://tempuri.org", "ns1");                                 omelement result = null;                                 omelement payloadelement = fac.createomelement("helloworld", ns);                                 serviceclient client = configuration();                                 try {                                      result = client.sendreceive(payloadelement);                                 } catch (axisfault e) {                                                 e.printstacktrace();                                 }                 }  } 

but getting error as:

org.apache.axis2.axisfault: transport error: 401 error: unauthorized     @ org.apache.axis2.transport.http.httpsender.handleresponse(httpsender.java:310)     @ org.apache.axis2.transport.http.httpsender.sendviapost(httpsender.java:194)     @ org.apache.axis2.transport.http.httpsender.send(httpsender.java:75)     @ org.apache.axis2.transport.http.commonshttptransportsender.writemessagewithcommons(commonshttptransportsender.java:404)     @ org.apache.axis2.transport.http.commonshttptransportsender.invoke(commonshttptransportsender.java:231)     @ org.apache.axis2.engine.axisengine.send(axisengine.java:443)     @ org.apache.axis2.description.outinaxisoperationclient.send(outinaxisoperation.java:406)     @ org.apache.axis2.description.outinaxisoperationclient.executeimpl(outinaxisoperation.java:229)     @ org.apache.axis2.client.operationclient.execute(operationclient.java:165)     @ org.apache.axis2.client.serviceclient.sendreceive(serviceclient.java:555)     @ org.apache.axis2.client.serviceclient.sendreceive(serviceclient.java:531)     @ helloworldsecurity.service_code(helloworldsecurity.java:63)     @ helloworldsecurity.main(helloworldsecurity.java:22) 


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -