Axis2 Problem: leeres Array?

Status
Nicht offen für weitere Antworten.

trivium

Neues Mitglied
Hallo, ich habe ein Problem bei meinem Web-Sevice für Axis2. Ich will von meinem Client aus ein Double-Array übergeben und mir dann von meinem Service die Länge des Arrays zurückgeben lassen. Ich bekomme aber immer 0.0 zurück.

Mein Service Code:

Java:
package de.matlabservice;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;


public class MatlabService {
	
	Socket sock = null;
	PrintWriter out = null;
	BufferedReader in = null;
	String sendRequest = "";
	String fromServer = "";
	
	public void init(org.apache.axis2.context.ServiceContext serviceContext){
		
		
		//Verbindung aufbauen
		try{
			sock = new Socket( "localhost", 4444 );
		    out = new PrintWriter( sock.getOutputStream(), true );
		    in = new BufferedReader( new InputStreamReader( sock.getInputStream()) );
		}
		catch(UnknownHostException e){
			System.err.println("no localhost");
			System.exit(1);
		} 
		catch(IOException e){
			System.err.println( e );
			System.exit(1);
		}
	}
	
	public void destroy(org.apache.axis2.context.ServiceContext serviceContext){
		
		out.close();
	    try {
			in.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	    try {
			sock.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	public double getMedian(double[] array){
		
		
		//Array in String wandeln
		//Form: x = [1;2;3];
		
		/*
		String stringArray = "x = [";
				
		for(int i = 0; i < array.length; i++){
			stringArray = stringArray + array[i];
			if(i<(array.length-1)){
				stringArray = stringArray + ";";
			}
		}
		
		stringArray = stringArray + "];";
		
		//Request absetzen
		String sendRequest = stringArray;
		//Array x
		out.println(sendRequest);
		//Median berechnen lassen
		out.println("median(x)");
		//Antwort einlesen
		String rez = "";
		int c;
		try {
			while((c = in.read()) != 13){
				rez = rez + ((char)c);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		*/
		//Antwort in double umwandeln
		
		return (double)array.length; 
	}
}

Mein Client Code:

Java:
package client;

import javax.xml.namespace.QName;

import org.apache.axiom.om.OMElement;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.databinding.utils.BeanUtil;
import org.apache.axis2.engine.DefaultObjectSupplier;


public class AxisMatlabClient {
	
	public static void main(String[] args2) throws AxisFault{
		
		ServiceClient sender = new ServiceClient();
		Options options = sender.getOptions();
		EndpointReference targetEPR = new EndpointReference("http://localhost:8081/axis2/services/Axis2Matlab");
		options.setTo(targetEPR);
		
		// die Operation "getMedian" soll aufgerufen werden
		QName opGetMedian = new QName("http://matlabservice.de", "getMedian");
		
		// Parameter für die Operation "getMedian" definieren
		double[] zahlen = { 0.0 , 1.0 , 5.0 };
		
		System.out.println(zahlen[1]);
		
		Object[] opArgs = new Object[] { zahlen };
		
		
		// OMElement mit der Request-Nachricht erzeugen
		OMElement request = BeanUtil.getOMElement(opGetMedian,opArgs, null, false, null);
		
		// Request an den Service schicken... der Aufruf erfolgt
		
		// synchron mit dem Kommunikationsmuster IN-OUT
		OMElement response = sender.sendReceive(request);
		
	
		System.out.println(response.toString());
		
		
		// diese Typen sollte der Web Service zurückliefern...
		Class<?>[] returnTypes = new Class[] { Double.class };
		
		
		// Antwort mit Hilfsroutine in ein Objekt-Array überführen
		Object[] result = BeanUtil.deserialize(response, returnTypes, new DefaultObjectSupplier());
		
		// Median ausgeben
		double median = (Double) result[0];
		
		System.out.println("Der Median ist:" + median);
		
		
	}
}

Meine services.xml:

[XML]<service>
<description>MatlabJavaService</description>
<parameter name="ServiceClass">
de.matlabservice.MatlabService
</parameter>
<operation name="getMedian">
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</operation>
</service>[/XML]

Meine services.wsdl:

[XML]<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd"
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:xsd="http://matlabservice.de" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://matlabservice.de">
<wsdl:types>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified"
targetNamespace="http://matlabservice.de">
<xs:element name="getMedian">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="array" type="xs:double"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getMedianResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:double"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="getMedianRequest">
<wsdl:part name="parameters" element="xsd:getMedian"/>
</wsdl:message>
<wsdl:message name="getMedianResponse">
<wsdl:part name="parameters" element="xsd:getMedianResponse"/>
</wsdl:message>
<wsdl:portType name="MatlabServicePortType">
<wsdl:eek:peration name="getMedian">
<wsdl:input message="xsd:getMedianRequest" wsaw:Action="urn:getMedian"/>
<wsdl:eek:utput message="xsd:getMedianResponse" wsaw:Action="urn:getMedianResponse"/>
</wsdl:eek:peration>
</wsdl:portType>
<wsdl:binding name="MatlabServiceSoap11Binding" type="xsd:MatlabServicePortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:eek:peration name="getMedian">
<soap:eek:peration soapAction="urn:getMedian" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:eek:utput>
<soap:body use="literal"/>
</wsdl:eek:utput>
</wsdl:eek:peration>
</wsdl:binding>
<wsdl:binding name="MatlabServiceSoap12Binding" type="xsd:MatlabServicePortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:eek:peration name="getMedian">
<soap12:eek:peration soapAction="urn:getMedian" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:eek:utput>
<soap12:body use="literal"/>
</wsdl:eek:utput>
</wsdl:eek:peration>
</wsdl:binding>
<wsdl:binding name="MatlabServiceHttpBinding" type="xsd:MatlabServicePortType">
<http:binding verb="POST"/>
<wsdl:eek:peration name="getMedian">
<http:eek:peration location="MatlabService/getMedian"/>
<wsdl:input>
<mime:content type="text/xml" part="getMedian"/>
</wsdl:input>
<wsdl:eek:utput>
<mime:content type="text/xml" part="getMedian"/>
</wsdl:eek:utput>
</wsdl:eek:peration>
</wsdl:binding>
<wsdl:service name="MatlabService">
<wsdl:port name="MatlabServiceHttpSoap11Endpoint" binding="xsd:MatlabServiceSoap11Binding">
<soap:address location="http://localhost:8080/axis2/services/MatlabService"/>
</wsdl:port>
<wsdl:port name="MatlabServiceHttpSoap12Endpoint" binding="xsd:MatlabServiceSoap12Binding">
<soap12:address location="http://localhost:8080/axis2/services/MatlabService"/>
</wsdl:port>
<wsdl:port name="MatlabServiceHttpEndpoint" binding="xsd:MatlabServiceHttpBinding">
<http:address location="http://localhost:8080/axis2/services/MatlabService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
[/XML]

Die services.xml habe ich selbst erstellt und die services.xml habe ich mir vom Axis2 Codegernerator erstellen lassen.
 
Zuletzt bearbeitet von einem Moderator:

Keo

Mitglied
benutzt doch für die Client-Implementierung die generierten Sourcen. Das wäre einfacher:

Java:
sender.getMedian(zahlen)

die Rückgabe müsste wahrscheinlich auch schon das double besitzen.
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
S Axis2 MustUnderstand problem mit Boolean SOA 9
S Axis2 Dateien lesen und schreiben - Pfade SOA 1
L [AXIS2] OutOfMemory Exception bei Übertragung von größerer Datei via Webservice SOA 3
C SSL in Tomcat mit Axis2 SOA 4
K Axis2 SOAP Logging via Client SOA 2
T Verwendung von Eclipse Projekten im Axis2 Webservice SOA 8
S AXIS2 Webservice: Umgang mit komplexen Datentypen SOA 5
S Axis2 Fault - Wie im Client auslesen? SOA 6
S Axis2 / Rampart - XML-Datei verschlüsseln & versenden SOA 14
J Axis2 und wiederverwenden der Serverobjekte SOA 3
B Axis2 Cipher Suite und Protocol einschränken SOA 2
H Axis2 dynamische URL zu WSDL SOA 2
H Axis2: XML<->DB SOA 2
F Axis2 große Strings streamen SOA 3
A Axis2 oder 1 Ntlm Authentification SOA 5
J Axis2 und Tomcat SOA 4
T Hat AXIS2 noch Zukunft und wie REST implementieren? SOA 6
R AXIS2 u. Eclipse (Galileo) Fehler bei Serverstart SOA 2
G Stub generieren (WSDL=Axis1.4) (WSDL2JAVA=Axis2) SOA 11
H Axis2 Deployment SOA 5
R SOAP Nachrichtenaustausch zwischen Axis2-WSs SOA 5
S Exception in axis2 java2wsdl ant Task SOA 1
N Request-XML-String -> AXIS2 -> WSDL-Check -> Respon SOA 2
G Axis2 Properties SOA 6
N Axis2: Binärdateien übertragen mit JWS/RPC SOA 2
M Axis2 vs XFire vs JAX-WS SOA 4
N Axis2 - hibernate.cfg.xml - wohin? SOA 6
K Axis2 Service / deploying to Tomcat 5.5.25 / web.xml SOA 5
F Axis2 und Listen SOA 3
I Axis2 mit SSL verschlüsseln SOA 4
N Axis2 - Cliententwicklung SOA 3
G axis2 rampart 1.3 SOA 1
K Webservices mit Axis2 SOA 2
M problem mit großem SOAP Response SOA 3
H Problem beim Aufruf meines Webservices SOA 0
F Client Problem gegen Webservice SOA 3
D Problem CXF und Tomcat 6 SOA 2
N JAX-WS Client Timeout Problem SOA 4
C Problem mit digitalen Signaturen auf Web Service Seite SOA 3
C Problem mit Java Webservice - SOAPBinding.Style - Wrapper class fehlt SOA 1
F nach wsimport neues problem -> nicht gefundener import SOA 3
G Problem bei Zugriff auf .Net Web Service SOA 3
L WebService TestClient Problem SOA 2

Ähnliche Java Themen

Neue Themen


Oben