2010-06-01 14 views
6

Me estoy quedando sin ideas para tratar de conseguir realmente que un cliente se conecte al servicio SOAP que estoy ejecutando a través de axis2.ejecutando un cliente axis2 versión 1.5

Intenté dos métodos, uno era usar wsdl2java para compilar el stub y las clases laterales del cliente asociadas, y luego escribir una clase Client que crea los mensajes de las solicitudes y los envía a través del Stub. La otra forma era utilizar el ServiceClient para conectar ..

Ambos están fallando a su manera ..

Opción # 1, cada vez que se envía un mensaje a través del talón de recibo esto de vuelta:

org.apache.axis2.AxisFault: The input stream for an incoming message is null. 
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:87) 
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:67) 
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:354) 
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:417) 
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229) 
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165) 

Opción # 2, cada vez que lo ejecuto me sale esta excepción:

org.apache.axis2.deployment.DeploymentException: org.apache.axis2.transport.local.LocalTransportSender 

Opción # 2 fuente:

import javax.xml.stream.XMLStreamException; 
import org.apache.axiom.om.OMAbstractFactory; 
import org.apache.axiom.om.OMElement; 
import org.apache.axiom.om.OMFactory; 
import org.apache.axiom.om.OMNamespace; 
import org.apache.axis2.addressing.EndpointReference; 
import org.apache.axis2.client.Options; 
import org.apache.axis2.Constants; 
import org.apache.axis2.client.ServiceClient; 

public class loyaltyClient { 

    private static EndpointReference targetEPR = 
     new EndpointReference(
      "http://localhost:8080/axis2/services/service"); 

    public static OMElement verifyCustomer(String customer_id) { 
     OMFactory fac = OMAbstractFactory.getOMFactory(); 
     OMNamespace omNs = fac.createOMNamespace(
       "http://localhost/", "service"); 
     OMElement method = fac.createOMElement("VerifyCustomer", omNs); 
     OMElement value1 = fac.createOMElement("customer_id",omNs); 
     OMElement value2 = fac.createOMElement("source_id",omNs); 
     OMElement value3 = fac.createOMElement("source_password",omNs); 
     OMElement value4 = fac.createOMElement("source_txnid",omNs); 
     OMElement value5 = fac.createOMElement("timestamp",omNs); 

value1.addChild(fac.createOMText(value1, customer_id)); 
value2.addChild(fac.createOMText(value2, "source")); 
value3.addChild(fac.createOMText(value3, "1234")); 
value4.addChild(fac.createOMText(value4, "123")); 
value5.addChild(fac.createOMText(value5, "06-01-2010 12:01:01")); 
     method.addChild(value1); 
     method.addChild(value2); 
     method.addChild(value3); 
     method.addChild(value4); 
     method.addChild(value5); 
     return method; 
    } 

    public static void main(String[] args) { 
     try { 
      OMElement vctest = loyaltyClient.verifyCustomer("6177740603"); 
      Options options = new Options(); 
      options.setTo(targetEPR); 

options.setTransportInProtocol(Constants.TRANSPORT_HTTP); 

      ServiceClient sender = new ServiceClient(); 
      sender.setOptions(options); 
      OMElement result = sender.sendReceive(vctest); 

      String response = result.getFirstElement().getText(); 
      System.out.println(response); 

     } catch (Exception e) { //(XMLStreamException e) { 
      System.out.println(e.toString()); 
     } 
    } 

}

+0

¿Ha encontrado el problema con la Opción n. ° 1, tengo el mismo problema. – metdos

Respuesta

3

Con la advertencia de que Axis2 es un buggy pile of crap, recientemente he tenido que escribir un cliente Axis2, y se encontró que el uso del constructor por defecto ServiceClient() no funcionaba bien - tuve que crear manualmente una ConfigurationContext, etc. Encontré que al usar ServiceClient.getOptions() en lugar de crear new Options() conservaba algunos datos predeterminados. También recomendaría dejar el options.setTransportInProtocol(...) a menos que realmente lo necesite; todo debería funcionar bien a través de HTTP sin esto. Además, es posible que necesite establecer options.setAction(...) para que se corresponda con la "operación" en su WSDL.

He incluido la mayor parte de mi cliente (con información confidencial eliminada), con la esperanza de que ayude. Probablemente pueda ignorar las partes relacionadas con el direccionamiento a menos que planee usar WS-Addressing.

ConfigurationContext cfgCtx = null; 

try { 
    /* Passing null to both params causes an AxisConfiguration to be created that uses 
    * the default axis2.xml file, which is included in the axis2 distribution jar. 
    * This is ideal for our case, since we cannot pass a full file path (relative 
    * paths are not allowed) because we do not know where the customer will deploy 
    * the application. This also allows engaging modules from the classpath. */ 
    cfgCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null , null); 
} catch (AxisFault e) { 
    // Bubble up the error 
} 

ServiceClient svcClient = null; 
try { 
    svcClient = new ServiceClient(cfgCtx, null); 
} catch (AxisFault e) { 
    // Bubble up the error 
} 

try { 
    /* This will work with the above ConfigurationContext as long as the module 
    * (addressing-1.5.1.mar) is on the classpath, e.g. in shared/lib. */ 
    svcClient.engageModule("addressing"); 
} catch (AxisFault e) { 
    // Bubble up the error 
} 

Options opts = svcClient.getOptions(); 
opts.setTo(new EndpointReference("http://myservername:8080/axis2/services/MyService")); 
opts.setAction("urn:doSomething"); // Corresponds to the "operation" in MyService's WSDL 
opts.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI); // Set output to SOAP 1.2 

SOAPFactory factory = OMAbstractFactory.getSOAP12Factory(); 
svcClient.addHeader(createSOAPSecurityHeader(factory, response)); // CreateSOAPHeader just creates an OMElement 

try { 
    svcClient.sendReceive(createSOAPBody(factory, response)); // CreateSOAPBody just creates an OMElement 
} catch (AxisFault e) { 
    throw new ResponseDeliveryException(1, "Error sending SOAP payload.", e); 
} 
+2

+1 para axis2 es una pila con errores de mierda – idursun

+0

También es compatible con esa afirmación. Obviamente, la gente ha tenido éxito, pero yo personalmente pasé a Apache CXF en medio de mis problemas anteriores y no veo razón para mirar hacia atrás. – Rich

5

también he encontrado el error "El flujo de entrada de un mensaje entrante es nulo", mientras que el uso de Axis para conectarse a un proveedor de servicios .Net.

El problema es que .Net no es compatible con una característica llamada "codificación fragmentada", por defecto Axis romperá su encabezado de solicitud en fragmentos que se supone que es una cosa que cumple HTTP 1.1.

De todos modos, se puede desactivar esta función en el Eje de la siguiente manera:

// Turn off the Axsis Chunked feature, some service providers (like .Net) don't support chunked headers. 
Options options = serviceClient.getOptions(); 
options.setProperty(HTTPConstants.CHUNKED, Constants.VALUE_FALSE); 
serviceClient.setOptions(options);    

Esto funcionó para mí. Otra cosa de la que debe asegurarse al tratar con servicios .Net es poder especificar el nombre del puerto y asegurarse de que la carga útil del mensaje tenga el prefijo de espacio de nombre para cada elemento.

Espero que esta información ayude a alguien.

Saludos, DC

1

Como dijo por Danmar,

tratar el siguiente código: valor establecido en true ...

Options options = serviceClient.getOptions(); 
options.setProperty(HTTPConstants.CHUNKED, Constants.VALUE_TRUE); 
serviceClient.setOptions(options); 

espero que funcione ...

Gracias

Cuestiones relacionadas