在android中使用REST API创建用户组

时间:2017-05-23 08:14:25

标签: android rest api xmpp openfire

我无法创建用户组。我已经尝试过使用名册,但却无法创建用户组。我还尝试了从git hub获取的rest api示例但是收到错误“找不到MediaBodyWriter的媒体类型= application / xml,type = class org.igniterealtime.restclient.entity.UserEntity,genericType = class org.igniterealtime.restclient.entity。 UserEntity。“我正在使用“compile('org.igniterealtime:rest-api-client:1.1.3')”来依赖gradle。任何建议将不胜感激。这是创建用户组的代码

            RestApiClient restApiClient = new RestApiClient("<serverName>", 9090, authToken);
            UserEntity userEntity = new UserEntity("tester9", "Tester9", "test@gmail.com", "12345");

            UserProperty userProperty = new UserProperty();
            userProperty.setKey("Content-Type");
            userProperty.setValue("application/xml");
            List<UserProperty> list = new ArrayList<>();
            list.add(userProperty);
            userEntity.setProperties(list);
            GroupEntity groupEntity = new GroupEntity();
            groupEntity.setName("Test");
            restApiClient.createUser(userEntity);
            restApiClient.createGroup(groupEntity);

Logcat:

I/LoggingFilter: 1 * Sending client request on thread AsyncTask #3
                 1 > POST https://90.0.0.166:9090/plugins/restapi/v1/users
                 1 > Authorization: aPQ1n9khu384OUri
                 1 > Content-Type: application/xml
E/iterInterceptorExecutor: MessageBodyWriter not found for media type=application/xml, type=class org.igniterealtime.restclient.entity.UserEntity, genericType=class org.igniterealtime.restclient.entity.UserEntity.
E/ClientRequest: Error while committing the request output stream.
                 javax.net.ssl.SSLHandshakeException: Handshake failed
                     at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:396)
                     at com.android.okhttp.internal.http.SocketConnector.connectTls(SocketConnector.java:103)
                     at com.android.okhttp.Connection.connect(Connection.java:143)
                     at com.android.okhttp.Connection.connectAndSetOwner(Connection.java:185)
                     at com.android.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:128)
                     at com.android.okhttp.internal.http.HttpEngine.nextConnection(HttpEngine.java:341)
                     at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:330)
                     at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)
                     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:433)
                     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:114)
                     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:245)
                     at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
                     at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java)
                     at org.glassfish.jersey.client.internal.HttpUrlConnector$4.getOutputStream(HttpUrlConnector.java:385)
                     at org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:200)
                     at org.glassfish.jersey.message.internal.CommittingOutputStream.commitStream(CommittingOutputStream.java:194)
                     at org.glassfish.jersey.message.internal.CommittingOutputStream.commit(CommittingOutputStream.java:262)
                     at org.glassfish.jersey.message.internal.OutboundMessageContext.commitStream(OutboundMessageContext.java:816)
                     at org.glassfish.jersey.client.ClientRequest.writeEntity(ClientRequest.java:545)
                     at org.glassfish.jersey.client.internal.HttpUrlConnector._apply(HttpUrlConnector.java:388)
                     at org.glassfish.jersey.client.internal.HttpUrlConnector.apply(HttpUrlConnector.java:285)
                     at org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:255)
                     at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:700)
                     at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
                     at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
                     at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
                     at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:444)
                     at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:696)
                     at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:448)
                     at org.igniterealtime.restclient.RestClient.call(RestClient.java:145)
                     at org.igniterealtime.restclient.RestClient.post(RestClient.java:91)
                     at org.igniterealtime.restclient.RestApiClient.createUser(RestApiClient.java:92)
                     at com.marothiatechs.mchat.LoginActivity$CreateNewAccount.doInBackground(LoginActivity.java:456)
                     at com.marothiatechs.mchat.LoginActivity$CreateNewAccount.doInBackground(LoginActivity.java:389)
                     at android.os.AsyncTask$2.call(AsyncTask.java:295)
                     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                     at java.lang.Thread.run(Thread.java:818)
                    Suppressed: javax.net.ssl.SSLHandshakeException: Handshake failed
                        ... 40 more
                        Suppressed: javax.net.ssl.SSLHandshakeException: Handshake failed
                            ... 40 more
                        Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0xaabbbb40: Failure in SSL library, usually a protocol error
                 error:100bd10c:SSL routines:ssl3_get_record:WRONG_VERSION_NUMBER (external/boringssl/src/ssl/s3_pkt.c:311 0xab4bbd97:0x00000000)
                     at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
                            at com.android.org.conscrypt.OpenSSLSocketImp

UserEntity.class

package org.igniterealtime.restclient.entity;

import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

/**
 * The Class UserEntity.
 */
@XmlRootElement(name = "user")
@XmlType(propOrder = { "username", "name", "email", "password", "properties" })
public class UserEntity {

    /** The username. */
    private String username;

    /** The name. */
    private String name;

    /** The email. */
    private String email;

    /** The password. */
    private String password;

    /** The properties. */
    private List<UserProperty> properties;

    /**
     * Instantiates a new user entity.
     */
    public UserEntity() {

    }

    /**
     * Instantiates a new user entity.
     *
     * @param username            the username
     * @param name            the name
     * @param email            the email
     * @param password the password
     */
    public UserEntity(String username, String name, String email, String password) {
        this.username = username;
        this.name = name;
        this.email = email;
        this.password = password;
    }

    /**
     * Gets the username.
     *
     * @return the username
     */
    @XmlElement
    public String getUsername() {
        return username;
    }

    /**
     * Sets the username.
     *
     * @param username
     *            the new username
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * Gets the name.
     *
     * @return the name
     */
    @XmlElement
    public String getName() {
        return name;
    }

    /**
     * Sets the name.
     *
     * @param name
     *            the new name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Gets the email.
     *
     * @return the email
     */
    @XmlElement
    public String getEmail() {
        return email;
    }

    /**
     * Sets the email.
     *
     * @param email
     *            the new email
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * Gets the password.
     *
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * Sets the password.
     *
     * @param password
     *            the new password
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * Gets the properties.
     *
     * @return the properties
     */
    @XmlElement(name = "property")
    @XmlElementWrapper(name = "properties")
    public List<UserProperty> getProperties() {
        return properties;
    }

    /**
     * Sets the properties.
     *
     * @param properties
     *            the new properties
     */
    public void setProperties(List<UserProperty> properties) {
        this.properties = properties;
    }
}

1 个答案:

答案 0 :(得分:0)

看起来框架会记录您的异常并将其抛出到您的客户端代码中。可能要么无法抑制它,要么(如果通过日志记录API记录),您可以使用适当的日志记录级别配置来控制它。