The Artima Developer Community
Sponsored Link

Java Answers Forum
java.lang.NullPointerException returned from webservice

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
John McCosker

Posts: 1
Nickname: jpmac
Registered: Aug, 2004

java.lang.NullPointerException returned from webservice Posted: Aug 5, 2004 2:23 AM
Reply to this message Reply
Advertisement
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_STR ING,ParameterMode.PARAM_MODE_IN);
QName qname = new QName("AttachmentService","DataHandler");
call.addParameter("image",qname,Param eterMode.PARAM_MODE_IN);
//register the datahandler
call.registerTypeMapping(dhSource.getClass(),qname,JAFDataHandlerSe rializerFactory.class,JAFDataHandlerDeserializerFactory.class);
call.setReturnTy pe(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){
fo ut.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){

I f need to supply more information let me know,

any help would be greatly appreciated,
thank you,
JP.

Topic: plz help!!! Previous Topic   Next Topic Topic: Transaction Handling(in  EJB)

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use