You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Andy Pahne <ap...@net22.de> on 2007/08/29 11:22:07 UTC

WS client // basic http authentication (Axis 1.3)

Hello,

I am currently having my first experiences with web services and axis, 
so this may be newbie questions.

I generated a client from WSDL that consumes one of our partner's web 
services. (I used EclipseWTP to do so, but that part was easy and 
succeeded, I think). EclipseWTP currently uses Axis 1, so the exact 
version is 1.3.0.

I was playing around with a unit test:

     public void testRawConnection_no_authentication() throws Exception {

         // get Service
         PartnerWebServiceLocator locator = new PartnerWebServiceLocator();
         PartnerWebServiceSoap service = locator.getPartnerWebServiceSoap();


         try {

             // Aufruf "under test"
             @SuppressWarnings("unused")
             ClsVacancy result =
                 service.getVacancy(rentalObjectID, checkIn, checkOut, 
ENVIRONMENT);

             fail("expected RemoteException was NOT thrown");

         } catch (RemoteException expected) {

             assertNotNull(expected);
             assertTrue(expected.getMessage().contains("Anonymous login 
not allowed"));

         }


     }





That test suceeds, because the Web Service is protected by basic http 
authentication. But at least I am confident that I succesfully connected 
to the service, because the recieved error message comes from the remote 
system and not from Axis itself.


Here are my questions:


1. Is it correct to obtain the service proxy like this:

         // get Service
         PartnerWebServiceLocator locator = new PartnerWebServiceLocator();
         PartnerWebServiceSoap service = locator.getPartnerWebServiceSoap();


   I think it is correct, but can you confirm?




2. And how do I use basic http authentication when I have a password and 
a username?
    I googled around and found a code snippet that used the Call class 
(Interface ?), but I am not sure if that is the correct direction. And 
the snippet also was not complete. I did not find anything apropriate in 
  the FAQ.


Thanks,
Andy Pahne





---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: WS client // basic http authentication (Axis 1.3)

Posted by Andy Pahne <ap...@net22.de>.
No, that does not work. The error message is still the same: "Anonymous 
login not allowed"

Here is how I tried:


     public void testRawConnection_OK() throws Exception {

         java.net.Authenticator.setDefault(
             new java.net.Authenticator(){

                 @Override
                 protected java.net.PasswordAuthentication 
getPasswordAuthentication(){
                     return new java.net.PasswordAuthentication(
                        USER_ID, PASSWORD.toCharArray());
                 }

             }
            );

         // get Service
         PartnerWebServiceLocator locator = new PartnerWebServiceLocator();
         PartnerWebServiceSoap service = locator.getPartnerWebServiceSoap();

         // Aufruf "under test"
         ClsVacancy result =
             service.getVacancy(rentalObjectID, checkIn, checkOut, 
ENVIRONMENT);

         // assert u. verify
         assertNotNull(result);

     }


Andrew Martin schrieb:
> I think you can supply the authentication username and password like this:
> java.net.Authenticator.setDefault(
>  new java.net.Authenticator()
>  {
>   protected java.net.PasswordAuthentication getPasswordAuthentication()
>   {
>    return new java.net.PasswordAuthentication(
>     "username", "password".toCharArray()); // Use your name/password
>   }
>  }
> );
> 
> I think that should work regardless of how you invoke the service (Call,
> proxy, etc.).
> 
> Andrew
> 
> Andy Pahne wrote:
>> I discovered the Users guide and the code examples. They all use Call.
>> But I find that a bit arkward, because then I'd have to deal with XSD
>> types, return types and such things.
>>
>> If I compare with
>>> ClsVacancy result =
>>>  service.getVacancy(rentalObjectID, checkIn, checkOut, ENVIRONMENT);
>> that seems very complicated.
>>
>> In the end, Axis generated all those objects like ClsVacancy for me and
>> I hoped not to have to deal with XML/XSD/SOAP details.
>>
>> Andy
>>
>>
>>
>>
>>
>>
>>
>> Andy Pahne schrieb:
>>> Hello,
>>>
>>> I am currently having my first experiences with web services and axis,
>>> so this may be newbie questions.
>>>
>>> I generated a client from WSDL that consumes one of our partner's web
>>> services. (I used EclipseWTP to do so, but that part was easy and
>>> succeeded, I think). EclipseWTP currently uses Axis 1, so the exact
>>> version is 1.3.0.
>>>
>>> I was playing around with a unit test:
>>>
>>>     public void testRawConnection_no_authentication() throws Exception {
>>>
>>>         // get Service
>>>         PartnerWebServiceLocator locator = new
>>> PartnerWebServiceLocator();
>>>         PartnerWebServiceSoap service =
>>> locator.getPartnerWebServiceSoap();
>>>
>>>
>>>         try {
>>>
>>>             // Aufruf "under test"
>>>             @SuppressWarnings("unused")
>>>             ClsVacancy result =
>>>                 service.getVacancy(rentalObjectID, checkIn, checkOut,
>>> ENVIRONMENT);
>>>
>>>             fail("expected RemoteException was NOT thrown");
>>>
>>>         } catch (RemoteException expected) {
>>>
>>>             assertNotNull(expected);
>>>             assertTrue(expected.getMessage().contains("Anonymous login
>>> not allowed"));
>>>
>>>         }
>>>
>>>
>>>     }
>>>
>>>
>>>
>>>
>>>
>>> That test suceeds, because the Web Service is protected by basic http
>>> authentication. But at least I am confident that I succesfully
>>> connected to the service, because the recieved error message comes
>>> from the remote system and not from Axis itself.
>>>
>>>
>>> Here are my questions:
>>>
>>>
>>> 1. Is it correct to obtain the service proxy like this:
>>>
>>>         // get Service
>>>         PartnerWebServiceLocator locator = new
>>> PartnerWebServiceLocator();
>>>         PartnerWebServiceSoap service =
>>> locator.getPartnerWebServiceSoap();
>>>
>>>
>>>   I think it is correct, but can you confirm?
>>>
>>>
>>>
>>>
>>> 2. And how do I use basic http authentication when I have a password
>>> and a username?
>>>    I googled around and found a code snippet that used the Call class
>>> (Interface ?), but I am not sure if that is the correct direction. And
>>> the snippet also was not complete. I did not find anything apropriate
>>> in  the FAQ.
>>>
>>>
>>> Thanks,
>>> Andy Pahne
>>>
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
>>> For additional commands, e-mail: axis-user-help@ws.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
>> For additional commands, e-mail: axis-user-help@ws.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: WS client // basic http authentication (Axis 1.3)

Posted by Andrew Martin <am...@regenstrief.org>.
I think you can supply the authentication username and password like this:
java.net.Authenticator.setDefault(
 new java.net.Authenticator()
 {
  protected java.net.PasswordAuthentication getPasswordAuthentication()
  {
   return new java.net.PasswordAuthentication(
    "username", "password".toCharArray()); // Use your name/password
  }
 }
);

I think that should work regardless of how you invoke the service (Call,
proxy, etc.).

Andrew

Andy Pahne wrote:
> 
> I discovered the Users guide and the code examples. They all use Call.
> But I find that a bit arkward, because then I'd have to deal with XSD
> types, return types and such things.
> 
> If I compare with
>>ClsVacancy result =
>>  service.getVacancy(rentalObjectID, checkIn, checkOut, ENVIRONMENT);
> that seems very complicated.
> 
> In the end, Axis generated all those objects like ClsVacancy for me and
> I hoped not to have to deal with XML/XSD/SOAP details.
> 
> Andy
> 
> 
> 
> 
> 
> 
> 
> Andy Pahne schrieb:
>>
>> Hello,
>>
>> I am currently having my first experiences with web services and axis,
>> so this may be newbie questions.
>>
>> I generated a client from WSDL that consumes one of our partner's web
>> services. (I used EclipseWTP to do so, but that part was easy and
>> succeeded, I think). EclipseWTP currently uses Axis 1, so the exact
>> version is 1.3.0.
>>
>> I was playing around with a unit test:
>>
>>     public void testRawConnection_no_authentication() throws Exception {
>>
>>         // get Service
>>         PartnerWebServiceLocator locator = new
>> PartnerWebServiceLocator();
>>         PartnerWebServiceSoap service =
>> locator.getPartnerWebServiceSoap();
>>
>>
>>         try {
>>
>>             // Aufruf "under test"
>>             @SuppressWarnings("unused")
>>             ClsVacancy result =
>>                 service.getVacancy(rentalObjectID, checkIn, checkOut,
>> ENVIRONMENT);
>>
>>             fail("expected RemoteException was NOT thrown");
>>
>>         } catch (RemoteException expected) {
>>
>>             assertNotNull(expected);
>>             assertTrue(expected.getMessage().contains("Anonymous login
>> not allowed"));
>>
>>         }
>>
>>
>>     }
>>
>>
>>
>>
>>
>> That test suceeds, because the Web Service is protected by basic http
>> authentication. But at least I am confident that I succesfully
>> connected to the service, because the recieved error message comes
>> from the remote system and not from Axis itself.
>>
>>
>> Here are my questions:
>>
>>
>> 1. Is it correct to obtain the service proxy like this:
>>
>>         // get Service
>>         PartnerWebServiceLocator locator = new
>> PartnerWebServiceLocator();
>>         PartnerWebServiceSoap service =
>> locator.getPartnerWebServiceSoap();
>>
>>
>>   I think it is correct, but can you confirm?
>>
>>
>>
>>
>> 2. And how do I use basic http authentication when I have a password
>> and a username?
>>    I googled around and found a code snippet that used the Call class
>> (Interface ?), but I am not sure if that is the correct direction. And
>> the snippet also was not complete. I did not find anything apropriate
>> in  the FAQ.
>>
>>
>> Thanks,
>> Andy Pahne
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
>> For additional commands, e-mail: axis-user-help@ws.apache.org
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org

-- 
Andrew Martin
Computer Programmer
Regenstrief Institute, Inc.
410 West 10th Street, Suite 2000
Indianapolis, IN 46202-3012
Phone: (317) 423-5542
Fax: (317) 423-5695
amartin@regenstrief.org


Confidentiality Notice: The contents of this message and any files
transmitted with it may contain confidential and/or privileged
information and are intended solely for the use of the named
addressee(s). Additionally, the information contained herein may have
been disclosed to you from medical records with confidentiality
protected by federal and state laws. Federal regulations and State laws
prohibit you from making further disclosure of such information without
the specific written consent of the person to whom the information
pertains or as otherwise permitted by such regulations. A general
authorization for the release of medical or other information is not
sufficient for this purpose.

If you have received this message in error, please notify the sender by
return e-mail and delete the original message. Any retention,
disclosure, copying, distribution or use of this information by anyone
other than the intended recipient is strictly prohibited.

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: WS client // basic http authentication (Axis 1.3)

Posted by Andy Pahne <ap...@net22.de>.
I discovered the Users guide and the code examples. They all use Call. 
But I find that a bit arkward, because then I'd have to deal with XSD 
types, return types and such things.

If I compare with
 >ClsVacancy result =
 >  service.getVacancy(rentalObjectID, checkIn, checkOut, ENVIRONMENT);
that seems very complicated.

In the end, Axis generated all those objects like ClsVacancy for me and 
I hoped not to have to deal with XML/XSD/SOAP details.

Andy







Andy Pahne schrieb:
> 
> Hello,
> 
> I am currently having my first experiences with web services and axis, 
> so this may be newbie questions.
> 
> I generated a client from WSDL that consumes one of our partner's web 
> services. (I used EclipseWTP to do so, but that part was easy and 
> succeeded, I think). EclipseWTP currently uses Axis 1, so the exact 
> version is 1.3.0.
> 
> I was playing around with a unit test:
> 
>     public void testRawConnection_no_authentication() throws Exception {
> 
>         // get Service
>         PartnerWebServiceLocator locator = new PartnerWebServiceLocator();
>         PartnerWebServiceSoap service = locator.getPartnerWebServiceSoap();
> 
> 
>         try {
> 
>             // Aufruf "under test"
>             @SuppressWarnings("unused")
>             ClsVacancy result =
>                 service.getVacancy(rentalObjectID, checkIn, checkOut, 
> ENVIRONMENT);
> 
>             fail("expected RemoteException was NOT thrown");
> 
>         } catch (RemoteException expected) {
> 
>             assertNotNull(expected);
>             assertTrue(expected.getMessage().contains("Anonymous login 
> not allowed"));
> 
>         }
> 
> 
>     }
> 
> 
> 
> 
> 
> That test suceeds, because the Web Service is protected by basic http 
> authentication. But at least I am confident that I succesfully connected 
> to the service, because the recieved error message comes from the remote 
> system and not from Axis itself.
> 
> 
> Here are my questions:
> 
> 
> 1. Is it correct to obtain the service proxy like this:
> 
>         // get Service
>         PartnerWebServiceLocator locator = new PartnerWebServiceLocator();
>         PartnerWebServiceSoap service = locator.getPartnerWebServiceSoap();
> 
> 
>   I think it is correct, but can you confirm?
> 
> 
> 
> 
> 2. And how do I use basic http authentication when I have a password and 
> a username?
>    I googled around and found a code snippet that used the Call class 
> (Interface ?), but I am not sure if that is the correct direction. And 
> the snippet also was not complete. I did not find anything apropriate in 
>  the FAQ.
> 
> 
> Thanks,
> Andy Pahne
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org