axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kiran Hoke <kiran_h...@persistent.co.in>
Subject Axis2: Facing proxy issue
Date Thu, 23 Aug 2012 14:12:57 GMT
Hi,

Please find below Client.java.
I am using axis2 1.5.2 libraries and  eutil_axis2.jar.
Client is an example program(http://www.ncbi.nlm.nih.gov/books/NBK55696/), which I am trying
to execute. I have following step mention in "Using Eclipse for development" section, but
it is giving below error
org.apache.axis2.AxisFault: Connection timed out: connect
       at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
       at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:203)
       at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:76)
       at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:400)
       at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:225)
       at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:435)
       at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:402)
       at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
       at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
       at gov.nih.nlm.ncbi.www.soap.eutils.EUtilsServiceStub.run_eSearch(EUtilsServiceStub.java:253)
       at gov.nih.nlm.ncbi.www.soap.eutils.Client.main(Client.java:49)


I set proxy arguments as jvm arguments(-Dhttp.proxySet=true -Dhttp.proxyHost=myhost -Dhttp.proxyPort=8080
-Dhttp.proxyUser=username -Dhttp.proxyPassword=password), but it gives below error:
before run_eSearch
org.apache.axis2.AxisFault: Transport error: 407 Error: Proxy Authentication Required ( The
ISA Server requires authorization to fulfill the request. Access to the Web Proxy filter is
denied.  )
       at org.apache.axis2.transport.http.HTTPSender.handleResponse(HTTPSender.java:310)
       at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:200)
       at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:76)
       at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:400)
       at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:225)
       at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:435)
       at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:402)
       at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
       at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
       at gov.nih.nlm.ncbi.www.soap.eutils.EUtilsServiceStub.run_eSearch(EUtilsServiceStub.java:253)
       at gov.nih.nlm.ncbi.www.soap.eutils.Client.main(Client.java:49)

I am getting above error when I try to set proxy settings into System properties as below:
System.setProperty("http.proxySet", "true");
                System.setProperty("http.proxyHost", "");
                System.setProperty("http.proxyPort", "8080");
                System.setProperty("http.proxyUser", "username");
                System.setProperty("http.proxyPassword", "password");

                Authenticator.setDefault(new Authenticator() {
                                  protected PasswordAuthentication getPasswordAuthentication()
{
                                        return new PasswordAuthentication("DOMAIN"+"\\"+"username",
"password".toCharArray());
                                 }
                 });

I tried to search solution for it and found below one:

private static void test(ServiceClient client){
       final String proxyUser = "username";
              final String proxyPassword = "password";
              //Authenticator.setDefault(new ProxyAuthenticator(proxyUser, proxyPassword));
              Authenticator.setDefault(new Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
                      return new PasswordAuthentication("DOMAIN"+"\\"+proxyUser, proxyPassword.toCharArray());
                      }
                    });
                      Properties props = System.getProperties();
                      String proxyHost = "Hostname";
                           props.put("http.proxyHost", proxyHost);
                      String proxyPort = "8080";
                           props.put("http.proxyPort", proxyPort);
                      props.put("http.proxyUser", proxyUser);
                      props.put("http.proxyPassword", proxyPassword);
                      props.put("https.proxyHost", proxyHost);
                      props.put("https.proxyPort", proxyPort);
                      props.put("https.proxyUser", proxyUser);
                      props.put("https.proxyPassword", proxyPassword);
                      /*-*/
                      HttpTransportProperties.Authenticator authentication = new
                      HttpTransportProperties.Authenticator();
                      authentication.setUsername(proxyUser);
                      authentication.setPassword(proxyPassword);
                      authentication.setHost(proxyHost);
                      authentication.setPort(Integer.parseInt(proxyPort));
                      /*-*/
                      HttpTransportProperties.ProxyProperties proxyProperties = new
                      HttpTransportProperties.ProxyProperties();
                      proxyProperties.setProxyName(proxyHost);
                      proxyProperties.setProxyPort(Integer.parseInt(proxyPort));
                      proxyProperties.setUserName(proxyUser);
                      proxyProperties.setPassWord(proxyPassword);
                      /*-*/
                      /*ServiceClient client = new ServiceClient();
                      client = new ReportingServiceStub(address)._getServiceClient();*/
                      /*-*/
                      Options options1 = new Options();
                      options1 = client.getOptions();
                      options1.setProperty(HTTPConstants.PROXY, proxyProperties);
                      options1.setProperty(HTTPConstants.HTTP_PROTOCOL_VERSION,
                      HTTPConstants.HEADER_PROTOCOL_10);
                      options1.setProperty(HTTPConstants.AUTHENTICATE, authentication);
                      options1.setProperty(AuthPolicy.AUTH_SCHEME_PRIORITY,
                      AuthPolicy.NTLM);
                      client.setOptions(options1);
                      /*-*/
                      Options options2 = new Options();
                      //options2.setTo(new EndpointReference(address));
                      options2.setAction("urn:getReportingData");
                      client.setOptions(options2);
                      /*-*/
                     /* OMElement res = client.sendReceive(createPayLoad());
                      System.out.println(res.toString());*/
    }

But it gives below exception:
java.lang.NullPointerException
       at gov.nih.nlm.ncbi.www.soap.eutils.EUtilsServiceStub.run_eSearch(EUtilsServiceStub.java:316)
       at gov.nih.nlm.ncbi.www.soap.eutils.Client.main(Client.java:52)


Client.java:

ackage gov.nih.nlm.ncbi.www.soap.eutils;

import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.util.Properties;

import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.transport.http.HttpTransportProperties;
import org.apache.commons.httpclient.auth.AuthPolicy;

public class Client{
    public static void main(String[] args) throws Exception {

        // search in PubMed Central for stem cells in free fulltext articles

        Try {
              /*
System.setProperty("http.proxySet", "true");
              System.setProperty("http.proxyHost", "Hostname");
              System.setProperty("http.proxyPort", "8080");
              System.setProperty("http.proxyUser", "username");
              System.setProperty("http.proxyPassword", "password");

              Authenticator.setDefault(new Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
                      return new PasswordAuthentication("DOMAIN"+"\\"+"username", "password".toCharArray());
                      }
                    });
              */

            EUtilsServiceStub service = new EUtilsServiceStub();
            ServiceClient client = service._getServiceClient();
            test(client);
            // call NCBI ESearch utility

            // NOTE: search term should be URL encoded

            EUtilsServiceStub.ESearchRequest req = new EUtilsServiceStub.ESearchRequest();
            req.setDb("pmc");
            req.setTerm("stem+cells+AND+free+fulltext[filter]");
            req.setRetMax("15");
            System.out.println("before run_eSearch");
            EUtilsServiceStub.ESearchResult res = service.run_eSearch(req);
            System.out.println("after run_eSearch");
            // results output

            System.out.println("Original query: stem cells AND free fulltext[filter]");
            System.out.println("Found ids: " + res.getCount());
            System.out.print("First " + res.getRetMax() + " ids: ");
            for (int i = 0; i < res.getIdList().getId().length; i++) {
                System.out.print(res.getIdList().getId()[i] + " ");
            }
            System.out.println();
        }
       catch (Exception e) { System.out.println(e.toString());
        e.printStackTrace();}
    }
}

Can anyone please help me to resolve this problem?


Thanks and Regards,
Kiran


DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the property of Persistent
Systems Ltd. It is intended only for the use of the individual or entity to which it is addressed.
If you are not the intended recipient, you are not authorized to read, retain, copy, print,
distribute or use this message. If you have received this communication in error, please notify
the sender and delete all copies of this message. Persistent Systems Ltd. does not accept
any liability for virus infected mails.

Mime
View raw message