0


My mission is to develop a web application using JSF2, EJB3 on a JBOSS7 application server.
The application is very simple, however I have to consume a web service developed by other people (soap / wsdl).
With the help of SOAPUI, the said web service works perfectly. The problem: when integrating into a Java code, the error message is displayed: " The server sent HTTP status code 404: null"
Can I have your advice?
Thank you

WSDL enter image description here
Test with SoapUi: enter image description here
Note: During the test phase with soapUi, you must manually integrate the endpoint URL and the soapaction value.

Class : ResponseHeader.java

package com.myproject.site;

public class ResponseHeader {
    private int code;
    public ResponseHeader() {
        super();
        // TODO Auto-generated constructor stub
    }

    public ResponseHeader(int code) {
        super();
        this.code = code;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

}

Interface SiteService.java:

package com.myproject.site;


import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

@WebService(targetNamespace = "http://www.monsite.com/webservices/app-homeSecurityValidation-ws", name = "app-homeSecurityValidation-ws")
public interface SiteService {

    @WebMethod
    public ResponseHeader HomeSecurityValidationRequest(
        @WebParam(name = "verif", targetNamespace = "")
        java.lang.String verif,
        @WebParam(name = "login", targetNamespace = "")
        java.lang.String account,
        @WebParam(name = "password", targetNamespace = "")
        java.lang.String password
    ) ;


}

class main Test.java:

package com.myproject.site;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Service;


public class Test {
public static void main(String[] args) throws SOAPException, IOException {

        try {           
            String soapEndpointUrl = "http://10.168.12.12:8080/homeSecurityValidation/app-homeSecurityValidation-ws";
            String soapAction = "homeSecurityValidation";

            URL url = new URL("http://10.168.12.12:8080/homeSecurityValidation/app-homeSecurityValidation-ws.wsdl"); 
            QName qName = new QName("http://www.monsite.com/webservices/app-homeSecurityValidation-ws",
                    "app-homeSecurityValidation-ws");

            /*********/
            MessageFactory messageFactory = MessageFactory.newInstance();
            SOAPMessage soapMessage = messageFactory.createMessage();


            MimeHeaders headers = soapMessage.getMimeHeaders();
            headers.addHeader("SOAPAction", soapAction);
            soapMessage.saveChanges();


            Service service = Service.create(url, qName);         

            SiteService hello = (SiteService) service.getPort(SiteService.class);

            BindingProvider bp = (BindingProvider) hello;
            bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, soapEndpointUrl);



            ResponseHeader r = hello.HomeSecurityValidationRequest("OK", 
                   "mylogin",
                   "mypassword");

              System.out.println("response: " + r.getCode()); 
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }


    }
}

Console Eclipse

Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 404: null
atcom.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.checkStatusCode(HttpTransportPipe.java:296)
    at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.createResponsePacket(HttpTransportPipe.java:245)
    at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:203)
    at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:122)
    at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:123)
    at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:626)
    at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:585)
    at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:570)
    at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:467)
    at com.sun.xml.internal.ws.client.Stub.process(Stub.java:308)
    at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:163)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:98)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
    at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:135)
    at com.sun.proxy.$Proxy10.homeSecurityValidationRequest(Unknown Source)
    at com.myproject.site.Test.main(Test.java:49)
Picked up JAVA_TOOL_OPTIONS: -Djava.vendor="Sun Microsystems Inc."
Anoir
  • 1
  • Tell me that, the request you made is what should be sent, check the docs again use postman to test if the api, are returning 200, before integrating into your java code – Declan Nnadozie Jun 25 '19 at 13:27
  • Why are you creating the code by hand? There are libraries/tools that generate the code for you based on the WSDL. That's the way you are supposed to implement a Soap WS. – Alexis Jun 25 '19 at 13:42
  • @DeclanNnadozie: I have already used the SOAPUI tool and the webservice responds correctly, my concern is to receive the same response of SOAPUI in my JAVA code. Is there a problem in my code? – Anoir Jun 25 '19 at 14:33
  • @Alexis: What are these libraries and tools ? you can give me an example please – Anoir Jun 25 '19 at 14:39
  • @Anoir https://stackoverflow.com/questions/25920799/consume-soap-webservice-in-java-only-wsdl-in-hand https://stackoverflow.com/questions/3588616/java-webservice-client-best-way?rq=1 [Google](https://www.google.com/search?client=opera&q=java+consuming+ws+from+wsdl&sourceid=opera&ie=UTF-8&oe=UTF-8) – Alexis Jun 25 '19 at 14:49

0 Answers0