Skip to main content

NullPointerException when reading properties file in BPEL client

1 reply [Last post]
cristinabotez
Offline
Joined: 2009-08-27
Points: 0

I have a Rest Service written in Java and a BPEL process and I want to invoke the process in the rest service. Here is the Java class I used:

import java.io.IOException;
import java.rmi.RemoteException;
import java.util.Map;
import java.util.Properties;
import org.apache.log4j.Logger;
import org.w3c.dom.Element;
import oracle.xml.parser.v2.XMLElement;
import com.oracle.bpel.client.Locator;
import com.oracle.bpel.client.ServerException;
import com.oracle.bpel.client.dispatch.IDeliveryService;
import com.oracle.bpel.client.NormalizedMessage;

public class SoapClientInvocation {

private static Logger log=Logger.getLogger("MyLog");

public String invokeBpelProcess(String senderNr, String receiverNr, String message) throws SoapClientException
{
String bpelResponse=null;
try{
Properties props=new java.util.Properties();
log.debug("PROPERTIES before reading: "+props);
java.net.URL url=ClassLoader.getSystemResource("context.properties");
log.debug("URL for properties"+url.getPath());
props.load(url.openStream());
log.debug("PROPERTIES: "+props);

String requestXml="" +
""+senderNr+"" +
""+receiverNr+"" +
""+message+"" +
"";
log.debug("PROCESS REQUEST XML: "+requestXml);

Locator locator=new Locator(props.getProperty("domain"),props.getProperty("java.naming.security.credentials"),props);
IDeliveryService deliveryService=(IDeliveryService)locator.lookupService(IDeliveryService.SERVICE_NAME);

NormalizedMessage nm=new NormalizedMessage();
nm.addPart("parameters",requestXml);

log.debug("requesting response from service... ");
NormalizedMessage response=deliveryService.request("TranslationRequestProcessor","process",nm);
Map payload=response.getPayload();

XMLElement xmlResponse=(XMLElement)payload.get("parameters");
Element partElement=(Element)xmlResponse.getChildrenByTagName("returnCode").item(0);
bpelResponse=partElement.getChildNodes().item(0).getNodeValue();

}catch (ServerException se){
log.error(se.getMessage());
throw new SoapClientException(se.getMessage());
} catch (RemoteException re) {
log.error(re.getMessage());
throw new SoapClientException(re.getMessage());
} catch (IOException ioe) {
log.error(ioe.getMessage());
throw new SoapClientException(ioe.getMessage());
}

log.debug("PROCESS RESPNONSE: "+bpelResponse);
String responseMessage=ReturnCode.getMessage(bpelResponse);
log.debug("["+bpelResponse+"]"+responseMessage);
return responseMessage;
}

}

and here is the context.properties file:

orabpel.platform=ias_10g
java.naming.factory.initial=com.evermind.server.rmi.RMIInitialContextFactory
java.naming.provider.url=opmn:ormi://127.0.0.1:6003:home/orabpel
java.naming.security.principal=oc4jadmin
java.naming.security.credentials=mirceaeliade0
dedicated.connection=true
domain=default

This WORKS if I run the Rest Service as a java application (having put context.properties in the src folder), but it does NOT WORK if I deploy the rest service with JBOSS (having put context.properties in C:\jboss-4.2.2.GA\bin). I get the following error when I run the rest service with SOAP UI:

- in SOAP UI:

java.lang.NullPointerException

- in JBOSS:

2009-08-29 01:50:35,984 DEBUG [com.arjuna.ats.arjuna.logging.arjLogger] Periodic recovery - first pass
2009-08-29 01:50:35,984 DEBUG [com.arjuna.ats.arjuna.logging.arjLogger] StatusModule: first pass
2009-08-29 01:50:35,984 DEBUG [com.arjuna.ats.txoj.logging.txojLoggerI18N] [com.arjuna.ats.internal.txoj.recovery.TORecoveryModule_3] - TORecoveryModule - first pass
2009-08-29 01:50:35,984 DEBUG [com.arjuna.ats.jta.logging.loggerI18N] [com.arjuna.ats.internal.jta.recovery.info.firstpass] Local XARecoveryModule - first pass
2009-08-29 01:50:43,812 ERROR [STDERR] 29.08.2009 01:50:43 org.apache.cxf.transport.servlet.CXFServlet updateContext
INFO: Load the bus with application context
2009-08-29 01:50:43,812 ERROR [STDERR] 29.08.2009 01:50:43 org.apache.cxf.bus.spring.BusApplicationContext getConfigResources
INFO: No cxf.xml configuration file detected, relying on defaults.
2009-08-29 01:50:43,828 ERROR [STDERR] 29.08.2009 01:50:43 org.apache.cxf.transport.servlet.AbstractCXFServlet replaceDestinationFactory
INFO: Servlet transport factory already registered
2009-08-29 01:50:45,281 ERROR [STDERR] 29.08.2009 01:50:45 org.apache.cxf.phase.PhaseInterceptorChain doIntercept
INFO: Application has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault
at org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:119)
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:107)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:109)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:63)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:56)
at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:92)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:78)
at org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:92)
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:283)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:128)
at org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:174)
at org.apache.cxf.transport.servlet.AbstractCXFServlet.doPost(AbstractCXFServlet.java:152)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.NullPointerException
at soapClient.SoapClientInvocation.invokeBpelProcess(SoapClientInvocation.java:30)
at restInterface.RestImplementation.sendSMS(RestImplementation.java:97)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:136)
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:82)
... 32 more

The error seems to appear at the following line:
log.debug("URL for properties"+url.getPath());

why isn't url initialized at this point:
java.net.URL url=ClassLoader.getSystemResource("context.properties"); ?

Any suggestions?

Thanks,
Cristina

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
cristinabotez
Offline
Joined: 2009-08-27
Points: 0

I solved the problem by using the following code for reading from the .properties file:

[b]Properties properties=new java.util.Properties();
FileInputStream in = new FileInputStream(new File("context.properties"));
properties.load(in);[/b]

[u](with this your class can access the .properties file if it is placed in the $JBOSS_HOME\bin folder, but it can't access the file if it is placed in the src folder of your project)[/u]

instead of:

[b]Properties props=new java.util.Properties();
java.net.URL url=ClassLoader.getSystemResource("context.properties");
props.load(url.openStream());[/b]

[u](with this your class can access the .properties file if it is placed in the src folder of your project, but it can't access the file if it is placed in the $JBOSS_HOME\bin folder)[/u]