0

код выдаёт ошибку на SOAPConnectionFactory soapFactory = SOAPConnectionFactory.newInstance(); самое начало функции. Ошибка: javax.xml.soap.SOAPException: Unable to create SOAP connection factory: Provider com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnectionFactory not found

Файл build.gradle

plugins {
    id 'com.android.application'
}

android {
    compileSdk 32
    defaultConfig {
        applicationId "com.ddev.advanced_post_tracker"
        minSdk 23
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    packagingOptions {
        resources.excludes.add("META-INF/*")
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    implementation fileTree(dir: 'C:\\Java\\libraries\\OkHttp', include: ['*.aar', '*.jar'], exclude: [])
    implementation fileTree(dir: 'C:\\Java\\libraries\\Jackson-DataBind', include: ['*.aar', '*.jar'], exclude: [])
    implementation 'org.jsoup:jsoup:1.13.1'
    implementation 'javax.xml.soap:javax.xml.soap-api:1.4.0'
    implementation 'com.sun.xml.messaging.saaj:saaj-impl:2.0.1'
    implementation 'com.sun.xml.messaging.saaj:metro-saaj:2.0.1'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

сама функция:

    private String Request(String trackNumber) {
        try{
            //Создание соединения
            SOAPConnectionFactory soapFactory = SOAPConnectionFactory.newInstance();
            SOAPConnection connection = soapFactory.createConnection();
            String url = "https://tracking.russianpost.ru/rtm34";

            //Содание сообщения
            MessageFactory messageFactory = MessageFactory.newInstance("SOAP 1.2 Protocol");
            SOAPMessage message = messageFactory.createMessage();

            //Создание компонентов сообщения
            SOAPPart soapPart = message.getSOAPPart();
            SOAPEnvelope envelope = soapPart.getEnvelope();
            envelope.addNamespaceDeclaration("soap","http://www.w3.org/2003/05/soap-envelope");
            envelope.addNamespaceDeclaration("oper","http://russianpost.org/operationhistory");
            envelope.addNamespaceDeclaration("data","http://russianpost.org/operationhistory/data");
            envelope.addNamespaceDeclaration("soapenv","http://schemas.xmlsoap.org/soap/envelope/");

            SOAPBody body = envelope.getBody();
            SOAPElement operationElement = body.addChildElement("getOperationHistory", "oper");
            SOAPElement dataElement = operationElement.addChildElement("OperationHistoryRequest", "data");
            SOAPElement barcode = dataElement.addChildElement("Barcode", "data");
            SOAPElement messageType = dataElement.addChildElement("MessageType", "data");


            //Заполнение сообщения
            barcode.addTextNode(trackNumber);
            messageType.addTextNode("0");

            //Сохранение изменений
            message.saveChanges();

            //Запрос и получение ответа
            SOAPMessage soapResponse = connection.call(message, url);
            Source sourceContent = soapResponse.getSOAPPart().getContent();
            try{
                Transformer t = TransformerFactory.newInstance().newTransformer();
                t.setOutputProperty(OutputKeys.METHOD, "xml");
                t.setOutputProperty(OutputKeys.INDENT, "yes");
                try {
                    StreamResult result = new StreamResult(System.out);
                    t.transform(sourceContent, result);
                    return result.toString();
                }
                catch (TransformerException e) {e.printStackTrace();}
            }
            catch ( TransformerConfigurationException e) {e.printStackTrace();}

        }
        catch (SOAPException e){
            e.printStackTrace();
        }
        return "чёт не то";
    }

1 ответ 1

0

Мне помогла установка этих jar файлов вместо maven библиотек

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.