• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NullPointerException returned from webservice

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,

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,JAFDataHandlerSerializerFactory.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());
}
}

}

this is my webservice,

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!!";
}

}

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){

any help would be greatly appreciated,
thank you,
JP.
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to Javaranch John.
Can you post the full error starting with "Null pointer exception"
Also did you traced the SOAP message using soapmonitor or TCPIP monitor.
Also double check the WSDD file and check whether the you have defined serializer for file attachments.
 
John McCosker
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry, this is the full stack trace,

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

this is my service deployment descriptor,

<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 ataHandler" 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>

this is my server-config.wsdd

<?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 rg.apache.axis.handlers.JWSHandler"/>
</requestFlow>
</globalConfiguration>
<handler name="LocalResponder" type="java rg.apache.axis.transport.local.LocalResponder"/>
<handler name="URLMapper" type="java rg.apache.axis.handlers.http.URLMapper"/>
<handler name="RPCDispatcher" type="java rg.apache.axis.providers.java.RPCProvider"/>
<handler name="Authenticate" type="java rg.apache.axis.handlers.SimpleAuthenticationHandler"/>
<handler name="MsgDispatcher" type="java rg.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 rg.apache.axis.handlers.http.HTTPAuthHandler"/>
</requestFlow>
</transport>
<transport name="local">
<responseFlow>
<handler type="java rg.apache.axis.transport.local.LocalResponder"/>
</responseFlow>
</transport>
<typeMapping deserializer="org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" qname="ns1 ataHandler" serializer="org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory" type="java:javax.activation.DataHandler" xmlns:ns1="AttachmentService"/>
</deployment>

I'll have a look into TCP monitor
 
John McCosker
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just ran tcp monitor,

request in 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

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>

response

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>
reply
    Bookmark Topic Watch Topic
  • New Topic