2016-04-11 8 views
2

Я использую следующий код для регистрации пользователя в WSO2 IS 5,1:Axisfault 302 при вызове WSO2 веб-службы

public static void main (String args[]){ 
    try { 
     UserInformationRecoveryServiceStub stub = new UserInformationRecoveryServiceStub("https://localhost:9443/UserInformationRecoveryService"); 
     RegisterUser user=new RegisterUser(); 
     UserIdentityClaimDTO claim=new UserIdentityClaimDTO(); 
     claim.setClaimUri("https://wso2.org/claims/emailaddress"); 
     claim.setClaimValue("[email protected]"); 
     UserIdentityClaimDTO[] claims=new UserIdentityClaimDTO[2]; 
     claims[0]=claim; 
     user.setUserName("user10"); 
     user.setPassword("123456"); 
     user.setProfile("default"); 
     user.setTenantDomain("carbon.super"); 
     user.setUserIdentityClaimDTOs(claims); 
     util.registerUser(user); 
    } catch (AxisFault e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (RemoteException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (UserInformationRecoveryServiceIdentityMgtServiceExceptionException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

И я получаю ниже AXIS ошибки

org.apache.axis2.AxisFault: Transport error: 302 Error: Found 

Когда я использую это через SOAP-клиент, такой как SOAPUI. Я могу успешно получить доступ к веб-сервису.

Когда я заглянул в это, увидел, что это может произойти, если WSDL внутренне использует HTTP и затем перенаправляет HTTPS.

Есть ли способ выяснить, что мне здесь не хватает?

+0

Привет, Althaf, не могли бы вы сообщить нам, как вы создали UserInformationRecoveryServiceStub? Также, если бы вы могли поделиться с нами созданной заглушкой и внедрением утилиты. – Charitha

ответ

0

В следующем примере кода я написал, чтобы зарегистрировать пользователя, используя UserInformationRecoveryService.

import org.apache.axis2.AxisFault; 
import org.apache.axis2.client.Options; 
import org.apache.axis2.client.ServiceClient; 
import org.apache.axis2.context.ConfigurationContext; 
import org.apache.axis2.context.ConfigurationContextFactory; 
import org.apache.axis2.transport.http.HttpTransportProperties; 
import org.wso2.carbon.identity.mgt.stub.UserInformationRecoveryServiceIdentityMgtServiceExceptionException; 
import org.wso2.carbon.identity.mgt.stub.UserInformationRecoveryServiceStub; 
import org.apache.axis2.transport.http.HTTPConstants; 

import java.io.File; 
import java.rmi.RemoteException; 
public class RegisterUserTest { 

    /** 
    * User Name to access WSO2 Carbon Server 
    */ 
    private static String USER_NAME = "admin"; 

    /** 
    * Password of the User who access the WSO2 Carbon Server 
    */ 
    private static String PASSWORD = "admin"; 

    /** 
    * Server url of the WSO2 Carbon Server 
    */ 
    private static String SEVER_URL = "https://localhost:9443/services/"; 

    public static void main(String args[]) { 

     /** 
     * trust store path. this must contains server's certificate or Server's CA chain 
     */ 
     String trustStore = System.getProperty("user.dir") + File.separator + 
       "src" + File.separator + "main" + File.separator + 
       "resources" + File.separator + "wso2carbon.jks"; 

     /** 
     * Call to https://localhost:9443/services/ uses HTTPS protocol. 
     * Therefore we to validate the server certificate or CA chain. The server certificate is looked up in the 
     * trust store. 
     * Following code sets what trust-store to look for and its JKs password. 
     */ 

     System.setProperty("javax.net.ssl.trustStore", trustStore); 

     System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon"); 

     /** 
     * Axis2 configuration context 
     */ 
     ConfigurationContext configContext; 

     try { 
      configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null); 
      String serviceEndPoint = SEVER_URL + "UserInformationRecoveryService"; 

      UserInformationRecoveryServiceStub stub = new UserInformationRecoveryServiceStub(configContext, serviceEndPoint); 
      ServiceClient client = stub._getServiceClient(); 
      Options option = client.getOptions(); 

      option.setProperty(HTTPConstants.COOKIE_STRING, null); 
      HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator(); 
      auth.setUsername(USER_NAME); 
      auth.setPassword(PASSWORD); 
      auth.setPreemptiveAuthentication(true); 
      option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth); 
      option.setManageSession(true); 

      stub.registerUser("fazlan", "Abcd123#", null, null, "carbon.super"); 

     } catch (AxisFault e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } catch (RemoteException e) { 
      e.printStackTrace(); 
     } catch (UserInformationRecoveryServiceIdentityMgtServiceExceptionException e) { 
      e.printStackTrace(); 
     } 
    } 
} 

Необходимо скопировать хранилище ключей сервера Identity в каталог ресурсов для назначения квитирования SSL.

Ниже приведено значение pom.xml Я использовал.

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>stack.overflow.is</groupId> 
    <artifactId>adminservice</artifactId> 
    <version>1.0-SNAPSHOT</version> 

    <repositories> 
     <repository> 
      <id>wso2-nexus</id> 
      <name>WSO2 internal Repository</name> 
      <url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url> 
      <releases> 
       <enabled>true</enabled> 
       <!--<updatePolicy>daily</updatePolicy> --> 
       <checksumPolicy>ignore</checksumPolicy> 
      </releases> 
     </repository> 
     <repository> 
      <id>wso2.releases</id> 
      <name>WSO2 internal Repository</name> 
      <url>http://maven.wso2.org/nexus/content/repositories/releases/</url> 
      <releases> 
       <enabled>true</enabled> 
       <!--<updatePolicy>daily</updatePolicy> --> 
       <checksumPolicy>ignore</checksumPolicy> 
      </releases> 
     </repository> 
    </repositories> 

    <dependencies> 
     <dependency> 
      <groupId>org.wso2.carbon.identity</groupId> 
      <artifactId>org.wso2.carbon.identity.mgt.stub</artifactId> 
      <version>5.0.7</version> 
     </dependency> 
    </dependencies> 

</project> 
0

Encounter этот сообщение тоже. Попробуйте получить доступ к webservice, но показывает: org.apache.axis2.AxisFault: Ошибка транспорта: 302 Ошибка: найдено.

Оказывается, причина в том, что я обращаюсь к неправильному доменному имени URL-адреса webservice. Так что я не могу получить правильный SSL-сертификат. Поэтому я думаю, что это что-то вроде SSL.