lank81
lank81

Reputation: 49

Consuming Soap Service - JDK11 - Webservice Transportation Exception

Error I'm getting: "Error: org.springframework.ws.client.WebServiceTransportException: Not Found [404]"

I was getting quite a bit of JaxB errors but was able to get around those. I've been able to call the Soap Service via SoapUI but when it tries to do the MarshalSendAndReceive I'm getting the 404 error. Most of what I'm doing is a re-write/re-use of what we had in JDK 8 and Maven.

We're now using JDK11 and Gradle.

MyServiceConfig.java:

package com.mytest.config;

import com.mytest.webservice.GetSummaryRequestType;
import com.mytest.webservice.GetSummaryResponseType;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;

@Configuration
public class MyServiceConfig {

@Bean(name="myMarshaller")
public Jaxb2Marshaller myMarshaller() {
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setClassesToBeBound(GetSummaryRequestType.class, GetSummaryResponseType.class);
    return marshaller;
}

MyService.java:

package com.mytest.service

import javax.xml.bind.JAXBElement;

import com.mytest.webservice.KeyType;
import com.mytest.webservice.GetSummaryRequestType;
import com.mytest.webservice.GetSummaryResponseType;
import com.mytest.webservice.ObjectFactory;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.stereotype.Service;
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
import org.springframework.ws.soap.client.core.SoapActionCallback;

import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

@Slf4j
@Service
public class MyService extends WebServiceGatewaySupport {

    @Autowired
    @Qualifier("myMarshaller")
    Jaxb2Marshaller marshaller;

    @Value("${soapws.url:http://localhost/soapService}")
    String wsUrl;

    @Getter
    private ObjectFactory myServiceObjectFactory = new ObjectFactory();

    public GetSummaryResponseType getSummary(int number, String todaysDate, String id, String startTime) throws Exception {

        try {
            this.setDefaultUri(wsUrl);

            keyType objKey = getMyServiceObjectFactory().createKeyType();
            objKey.setNumber(number);
            XMLGregorianCalendar calDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(todaysDate);
            objKey.setDate(calDate);
            objKey.setScannerId(id);
            objKey.setStartTime(startTime);

            GetSummaryRequestType request = getMyServiceObjectFactory().createGetSummaryRequestType();
            request.getKeyType().add(objKey);

            getWebServiceTemplate().setMarshaller(marshaller);
            getWebServiceTemplate().setUnmarshaller(marshaller);

            JAXBElement<?> responseElement = null;

            SoapActionCallback soapActionCallback = new SoapActionCallback("getSummary");
            responseElement = (JAXBElement<?>) getWebServiceTemplate().marshalSendAndReceive(
                    request, soapActionCallback);

            GetSummaryResponseType response = (GetSummaryResponseType)responseElement.getValue();

            return response;
        } catch (Exception e) {
            log.info("Error: " + e);
            throw new Exception("My Service is unavailable while fetching the summary information", e);
        }
    }
}

build.gradle:

JAXB/Jakarta Relevant dependencies

implementation 'jakarta.xml.bind:jakarta.xml.bind-api:4.0.1'
implementation 'jakarta.xml.ws:jakarta.xml.ws-api:4.0.1'
implementation 'org.glassfish.jaxb:jaxb-runtime:4.0.4'
implementation 'jakarta.jws:jakarta.jws-api:3.0.0'
implementation 'javax.xml.bind:jaxb-api:2.3.1'
implementation 'com.sun.xml.bind:jaxb-impl:2.3.4'
implementation 'com.sun.xml.ws:jaxws-tools:4.0.2'
implementation 'one.gfw:jakarta.activation-api:2.1.1'

Upvotes: 0

Views: 93

Answers (0)

Related Questions