【问题标题】:Axisfault 302 when calling wso2 web services调用 wso2 Web 服务时出现 Axisfault 302
【发布时间】:2016-04-11 09:24:03
【问题描述】:

我正在使用以下代码在 wso2 IS 5.1 中注册用户:

  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("althaf.ashraf@gmail.com");
        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 

当我通过像 SOAPUI 这样的 SOAP 客户端使用它时,我能够成功访问 Web 服务。

当我对此进行研究时发现,如果 WSDL 在内部使用 HTTP 然后重定向到 HTTPS,则可能会发生这种情况。

有没有办法弄清楚我在这里遗漏了什么?

【问题讨论】:

  • 嗨,Althaf,您能否告诉我们您生成 UserInformationRecoveryServiceStub 的方式?如果可以请与我们分享生成的存根和实用程序实现。

标签: wso2 axis2 axis wso2is


【解决方案1】:

请找到以下我为使用 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();
        }
    }
}

您需要将身份服务器密钥库复制到资源目录以进行 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>

【讨论】:

    【解决方案2】:

    也遇到这种消息。 尝试访问网络服务,但显示: org.apache.axis2.AxisFault:传输错误:302 错误:找到。

    原来原因是我访问了错误的Web服务URL域名。所以我无法获得正确的SSL证书。所以我猜这与SSL有关。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-07
      • 2013-05-15
      • 1970-01-01
      • 2013-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多