You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by John McCosker <J....@andronics.com> on 2004/08/05 15:13:08 UTC

NullPointerException returned from webservice

Hi I have an axis client which sends an image attachment to an axis
webservice, however I am returned with a null pointer exception,

this is my client,

[code]package chapter5;

import java.net.URL;

import org.apache.axis.client.Service;
import org.apache.axis.client.Call;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory;
import org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory;

import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.namespace.QName;

import javax.activation.DataHandler;
import javax.activation.FileDataSource;


public class AttachmentServiceClient{

public AttachmentServiceClient(){}

public static void main(String args[]){
try{
String filename = "D:\\images\\products\\r.jpg";
//create the data for the attached file
DataHandler dhSource = new DataHandler(new FileDataSource(filename)); 
String endpointURL =
"http://localhost:8080/axis/services/AttachmentService";
String methodName = "addImage";

Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(new URL(endpointURL));
call.setOperationName(new QName("AttachmentService",methodName));
call.addParameter("sku",XMLType.XSD_STRING,ParameterMode.PARAM_MODE_IN);
QName qname = new QName("AttachmentService","DataHandler");
call.addParameter("image",qname,ParameterMode.PARAM_MODE_IN);
//register the datahandler
call.registerTypeMapping(dhSource.getClass(),qname,JAFDataHandlerSerializerF
actory.class,JAFDataHandlerDeserializerFactory.class);
call.setReturnType(XMLType.XSD_STRING);

Object[] params = new Object[]{"SKU-111",dhSource};
String result = (String)call.invoke(params);

System.out.println("The response: "+result);
; }catch(Exception e){
System.err.println(e.toString());
}
}

}[/code]

this is my webservice,

[code]package chapter5;

import javax.activation.DataHandler;

import java.io.FileOutputStream;
import java.io.File;
import java.io.BufferedInputStream;

public class SparePartAttachmentService{

public SparePartAttachmentService(){}

public String addImage(String sku,DataHandler dataHandler){
System.out.println("trying");
try{
String filepath = "c:/wrox-axis/"+sku+"-image.jpg";
FileOutputStream fout = new FileOutputStream(new File(filepath));
BufferedInputStream in = new
BufferedInputStream(dataHandler.getInputStream());
while(in.available()!=0){
fout.write(in.read());
}
}catch(Exception e){
return e.toString();
}
return "Image: "+sku+" has been added successfully!!";
}

}[/code]

I did a test by stripping out the attachment being sent by the client and
just let it send the string,
then in the webservice I stripped out the lines for the attachment and just
returned the string and it worked ok, so it has been deployed correctly.

I have the Java Activation framework both in tomcat commons and my webapps
lib dir.

I'm pretty sure the error is being thrown here,
public String addImage(String sku,DataHandler dataHandler){

this is the stack trace of the error,

C:\wrox-axis>java chapter5.AttachmentServiceClient
java.lang.NullPointerException
at org.apache.axis.AxisFault.makeFault(Unknown Source)
at org.apache.axis.SOAPPart.getAsString(Unknown Source)
at org.apache.axis.SOAPPart.getAsBytes(Unknown Source)
at org.apache.axis.Message.getContentLength(Unknown Source)
at org.apache.axis.transport.http.HTTPSender.invoke(Unknown Source)
at org.apache.axis.strategies.InvocationStrategy.visit(Unknown Source)
at org.apache.axis.SimpleChain.doVisiting(Unknown Source)
at org.apache.axis.SimpleChain.invoke(Unknown Source)
at org.apache.axis.client.AxisClient.invoke(Unknown Source)
at org.apache.axis.client.Call.invoke(Unknown Source)
at org.apache.axis.client.Call.invoke(Unknown Source)
at org.apache.axis.client.Call.invoke(Unknown Source)
at org.apache.axis.client.Call.invoke(Unknown Source)
at chapter5.AttachmentServiceClient.main(AttachmentServiceClient.java:45
)
Caused by: java.lang.NullPointerException
at org.apache.axis.encoding.ser.JAFDataHandlerSerializer.serialize(Unkno
wn Source)
at org.apache.axis.encoding.SerializationContextImpl.serializeActual(Unk
nown Source)
at org.apache.axis.encoding.SerializationContextImpl.serialize(Unknown S
ource)
at org.apache.axis.encoding.SerializationContextImpl.outputMultiRefs(Unk
nown Source)
at org.apache.axis.message.SOAPEnvelope.outputImpl(Unknown Source)
at org.apache.axis.message.MessageElement.output(Unknown Source)
... 13 more

deployment descriptor,

[code]<deployment xmlns="http://xml.apache.org/axis/wsdd/"
	
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
			
	<service name="AttachmentService" provider="java:RPC">
		<parameter name="className"
value="chapter5.SparePartAttachmentService"/>
		<parameter name="allowedMethods" value="addImage"/>
	</service>
	
	<typeMapping qname="ns1:DataHandler" xmlns:ns1="AttachmentService" 
		languageSpecificType="java:javax.activation.DataHandler"
	
serializer="org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory"
	
deserializer="org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory
"
		encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
			
</deployment>[/code]

server-config file looks like this,

[code]<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
 <globalConfiguration>
  <parameter name="adminPassword" value="admin"/>
  <parameter name="attachments.Directory"
value="C:\tomcat\jakarta-tomcat-4.1.27\webapps\axis\WEB-INF\attachments"/>
  <parameter name="attachments.implementation"
value="org.apache.axis.attachments.AttachmentsImpl"/>
  <parameter name="sendXsiTypes" value="true"/>
  <parameter name="sendMultiRefs" value="true"/>
  <parameter name="sendXMLDeclaration" value="true"/>
  <requestFlow>
   <handler type="java:org.apache.axis.handlers.JWSHandler"/>
  </requestFlow>
 </globalConfiguration>
 <handler name="LocalResponder"
type="java:org.apache.axis.transport.local.LocalResponder"/>
 <handler name="URLMapper"
type="java:org.apache.axis.handlers.http.URLMapper"/>
 <handler name="RPCDispatcher"
type="java:org.apache.axis.providers.java.RPCProvider"/>
 <handler name="Authenticate"
type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>
 <handler name="MsgDispatcher"
type="java:org.apache.axis.providers.java.MsgProvider"/>
 <service name="AttachmentService" provider="java:RPC">
  <parameter name="allowedMethods" value="addImage"/>
  <parameter name="className" value="chapter5.SparePartAttachmentService"/>
 </service>
 <service name="AdminService" provider="java:MSG">
  <parameter name="allowedMethods" value="AdminService"/>
  <parameter name="enableRemoteAdmin" value="false"/>
  <parameter name="className" value="org.apache.axis.utils.Admin"/>
  <namespace>http://xml.apache.org/axis/wsdd/</namespace>
 </service>
 <service name="Version" provider="java:RPC">
  <parameter name="allowedMethods" value="getVersion"/>
  <parameter name="className" value="org.apache.axis.Version"/>
 </service>
 <transport name="http">
  <requestFlow>
   <handler type="URLMapper"/>
   <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>
  </requestFlow>
 </transport>
 <transport name="local">
  <responseFlow>
   <handler type="java:org.apache.axis.transport.local.LocalResponder"/>
  </responseFlow>
 </transport>
 <typeMapping
deserializer="org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory
" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
qname="ns1:DataHandler"
serializer="org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory"
type="java:javax.activation.DataHandler" xmlns:ns1="AttachmentService"/>
</deployment>[/code]


ran tcp monitor,

request window is blank,

response gives,

java.net.SocketException: Connection reset at
java.net.SocketInputStream.read(SocketInputStream.java:168) at
org.apache.axis.utils.tcpmon$Connection.run(Unknown Source)

I also tested tcp on another webservice and it worked correctly,

request

[code]POST /axis/services/SparePartDetails HTTP/1.0Content-Length: 774Host:
localhostContent-Type: text/xml; charset=utf-8SOAPAction: ""<?xml
version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:addSparePart xmlns:ns1="SparePartDetails">
<SparePart href="#id0"/>
</ns1:addSparePart>
<multiRef id="id0" SOAP-ENC:root="0" xsi:type="ns2:SparePartBean"
xmlns:ns2="SparePartDetails">
<sku xsi:type="xsd:string">SKU-333</sku>
<price xsi:type="xsd:float">50.0</price>
<description xsi:type="xsd:string">Air filter model: 12345</description>
</multiRef>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>[/code]

response

[code]HTTP/1.1 200 OKContent-Type: text/xml; charset=utf-8Content-Length:
550Date: Thu, 05 Aug 2004 10:46:39 GMTServer: Apache Coyote/1.0Connection:
close<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<ns1:addSparePartResponse
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns1="SparePartDetails">
<addSparePartResult xsi:type="xsd:string">SparePart with SKU: SKU-333 has
been added successfully!</addSparePartResult>
</ns1:addSparePartResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>[/code]


If I just pass a string in the webservice and remove the attachment, its
works fine returning the passed string, so the service seems to be deployed
ok.

I am using IBM Eclipse to build my projects, and it reports no errors at
build time.
I also downloaded the code for Apress as a final resort compiled and
redeployed everything after un-deploying mine, but still the exact same
problem.

If some assistance into clues what is causing the webservice to flake would
be greatly appreciated.


any help would be greatly appreciated,
thank you,

Respectfully,

John McCosker ( Web Applications Architect ) 
Andronics Data Global Communications Ltd, 
20 Balliniska Road, 
Springtown Industrial Estate,
Londonderry, 
Co.Londonderry, 
N.Ireland,
BT48 0LY,

Tel	+44 (0)28 7127 3100
Fax	+44 (0)28 7127 3101