简体   繁体   English

调用wso2 Web服务时的Axisfault 302

[英]Axisfault 302 when calling wso2 web services

I am using the below code to register a user in wso2 IS 5.1: 我正在使用以下代码在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();
    }

And I am getting the below AXIS error 我收到以下AXIS错误

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

When I use it through a SOAP client like SOAPUI I am able to access the web service successfully. 通过像SOAPUI这样的SOAP客户端使用它时,我能够成功访问Web服务。

When I looked into this have seen that this might happen if the WSDL internally uses HTTP and then redirect to HTTPS. 当我查看此内容时,已经看到如果WSDL内部使用HTTP,然后重定向到HTTPS,则可能会发生这种情况。

Is there a way to figure out what I am missing here? 有没有办法找出我在这里想念的东西?

Please find the following example code I wrote to register a user using UserInformationRecoveryService . 请找到以下我编写的使用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();
        }
    }
}

You need to copy the Identity server keystore into the resources directory for SSL handshake purpose. 您需要将身份服务器密钥库复制到资源目录中,以进行SSL握手。

Following is the pom.xml I used. 以下是我使用的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>

Encounter this kind of message too. 也遇到这种消息。 Try to access webservice but shows: org.apache.axis2.AxisFault: Transport error: 302 Error: Found. 尝试访问Web服务,但显示:org.apache.axis2.AxisFault:传输错误:302错误:找到。

Turns out that the reason is that I access wrong domain name of webservice URL.So I can not get right SSL certificate.So I guess it is something about SSL. 原来原因是我访问了Web服务URL的域名错误,所以我无法获得正确的SSL证书,所以我猜想这与SSL有关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM