- public class AppsImport {
- private static final BranchService BRANCH_SERVICE = MinasServiceLocator.getBranchService();
- private static final String token = TokenService.getToken();
- private static final String REPO_INTL = "intl";
- public static void main(String[] args) {
- InputStream in = ClassLoader.getSystemResourceAsStream("app_name.txt");
- BufferedReader bufferReader = new BufferedReader(new InputStreamReader(in));
- String tempString = null;
- try {
- tempString = bufferReader.readLine();
- String[] appNames = tempString.split(",");
- for (int i = 0; i < appNames.length; i++) {
- appNames[i] = appNames[i].substring(1, appNames[i].length() - 2);
- }
- bufferReader.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Thread.currendThread().getName()
这个可以返回线程对象的IDhttp://jira.codehaus.org/browse/XFIRE-1033
We have an intermittent bug that stops our webservice from accepting requests - it has occurred approx once a week thus far, i.e. unfortunately we can not reproduce it.
Basically something appears to trigger the processing of the XML to throw an nullpointerexception and then from there on all calls to that service fail. The first time it happened it stayed throwing nullpointer exceptions for 1 hour. The second time we were in the office - the only thing to stop it from failing was actually to query the WSDL, ie. ....Service?WSDL - This seemed to trigger a reset of the service - all calls worked properly afterwards.
This is the stack trace of the first exceptions we see in the logs when this happens (inside xerces code):
2007-06-11 15:28:33,859 ERROR http-80-4 org.codehaus.xfire.handler.DefaultFaultHandler - Fault occurred!
java.lang.NullPointerException
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1750)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipSpaces(XMLEntityScanner.java:1492)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$TrailingMiscDriver.next(XMLDocumentScannerImpl.java:1371)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:645)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:548)
at org.codehaus.xfire.soap.handler.ReadHeadersHandler.invoke(ReadHeadersHandler.java:44)
at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
at org.codehaus.xfire.transport.DefaultEndpoint.onReceive(DefaultEndpoint.java:64)
at org.codehaus.xfire.transport.AbstractChannel.receive(AbstractChannel.java:38)
at org.codehaus.xfire.transport.http.XFireServletController.invoke(XFireServletController.java:304)
at org.codehaus.xfire.transport.http.XFireServletController.doService(XFireServletController.java:129)
at org.codehaus.xfire.spring.remoting.XFireServletControllerAdapter.handleRequest(XFireServletControllerAdapter.java:67)
at org.codehaus.xfire.spring.remoting.XFireExporter.handleRequest(XFireExporter.java:48)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:45)
at ....Then all subsequent calls to the service fail with the following stack trace:
2007-06-11 15:28:47,734 ERROR http-80-14 org.codehaus.xfire.handler.DefaultFaultHandler - Fault occurred!
java.lang.NullPointerException
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.arrangeCapacity(XMLEntityScanner.java:1598)
at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipString(XMLEntityScanner.java:1684)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$XMLDeclDriver.next(XMLDocumentScannerImpl.java:785)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:645)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:548)
at org.codehaus.xfire.soap.handler.ReadHeadersHandler.invoke(ReadHeadersHandler.java:44)
at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
at org.codehaus.xfire.transport.DefaultEndpoint.onReceive(DefaultEndpoint.java:64)
at org.codehaus.xfire.transport.AbstractChannel.receive(AbstractChannel.java:38)
at org.codehaus.xfire.transport.http.XFireServletController.invoke(XFireServletController.java:304)
at org.codehaus.xfire.transport.http.XFireServletController.doService(XFireServletController.java:129)
at org.codehaus.xfire.spring.remoting.XFireServletControllerAdapter.handleRequest(XFireServletControllerAdapter.java:67)
at org.codehaus.xfire.spring.remoting.XFireExporter.handleRequest(XFireExporter.java:48)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:45)
.....Looking at the Xerces code the first failure appears to occur when accessing the 'fCurrentEntity' object, however two lines above it has already accessed this so it appears like a possible threading issue?
Anybody seen this before or know how we might look to resolve it?
I have attached our xfire-servlet.xml file - note the fault is occurring in our NovaWebService service (FYI The service NovaMaintWebservice uses a local custom type mapping registry in order to use the same POJOS but use annotations for NovaWebService & aegis mapping files for NovaMaintWebService).
Thanks,
Ted.============================
- http://old.uplook.cn/biancheng/139/1390236/
在多线程环境中,应每次new一个Unmarshaller对象实例保证线程安全,否则可以使用Unmarshaller的静态方法。
http://www.2cto.com/kf/201207/143011.html
- Jaxb2.0实现Java Object转换Xml转换Java Object.
- [java]
//测试类
[java]
<pre class="java" name="code">import com.toft.webservice.client.domino.DominoObject;
import com.toft.webservice.core.JaxbBinder;
public class JaxbTest {
private static final String DECLARATION = "<?xml version='1.0' encoding='utf-8'?><!DOCTYPE document SYSTEM 'xmlschemas/domino_7_0_1.dtd'>";
private static final String ENCODING = "UTF-8";
private DominoObject dominoObject = new DominoObject();
public static void main(String[] args){
}
/**
* 使用JAXB生成符合接口的XML.
* @return String
* @throws Exception
*/
private String getDominoXml() throws Exception {
try {
JaxbBinder binder = new JaxbBinder(DominoObject.class);
return binder.toXml(dominoObject, ENCODING, DECLARATION);
} catch (Exception e) {
throw e;
}
}
}
</pre><br>
<pre></pre>
<pre class="java" name="code"> </pre><pre class="java" name="code">//工具类</pre><pre class="java" name="code">import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
/**
* 使用Jaxb2.0实现XML<->Java Object的Binder.
*
* @author 孙祖强
*/
public class JaxbBinder {
//多线程安全的Context.
private JAXBContext jaxbContext;
/**
* @param types 所有需要序列化的Root对象的类型.
*/
public JaxbBinder(Class<?>... types) {
try {
jaxbContext = JAXBContext.newInstance(types);
} catch (JAXBException e) {
throw new RuntimeException(e);
}
}
/**
* Java Object->Xml.
*/
public String toXml(Object root) {
try {
StringWriter writer = new StringWriter();
createMarshaller("UTF-8", null, true).marshal(root, writer);
return writer.toString();
} catch (JAXBException e) {
throw new RuntimeException(e);
}
}
/**
* Java Object->Xml.
*/
public String toXml(Object root, String encoding) {
try {
StringWriter writer = new StringWriter();
createMarshaller(encoding, null, false).marshal(root, writer);
return writer.toString();
} catch (JAXBException e) {
throw new RuntimeException(e);
}
}
/**
* Java Object->Xml.
*/
public String toXml(Object root, String encoding, String declaration) {
try {
StringWriter writer = new StringWriter();
writer.append(declaration);
createMarshaller(encoding, declaration, false).marshal(root, writer);
return writer.toString();
} catch (JAXBException e) {
throw new RuntimeException(e);
}
}
/**
* Xml->Java Object.
*/
@SuppressWarnings("unchecked")
public <T> T fromXml(String xml) {
try {
StringReader reader = new StringReader(xml);
return (T) createUnmarshaller().unmarshal(reader);
} catch (JAXBException e) {
throw new RuntimeException(e);
}
}
/**
* 创建Marshaller, 设定encoding(可为Null), 设定declaration(可为Null).
*/
public Marshaller createMarshaller(String encoding, String declaration, Boolean formatted) {
try {
Marshaller marshaller = jaxbContext.createMarshaller();
//是否格式化XML
if (formatted) {
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
}
//设置编码方式
if (null != encoding && !"".equals(encoding)) {
marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding);
}
//设置XML声明
if (null != declaration && !"".equals(declaration)) {
marshaller.setProperty("com.sun.xml.bind.xmlDeclaration", Boolean.FALSE);
}
return marshaller;
} catch (JAXBException e) {
throw new RuntimeException(e);
}
}
/**
* 创建UnMarshaller.
*/ www.2cto.com
public Unmarshaller createUnmarshaller() {
try {
return jaxbContext.createUnmarshaller();
} catch (JAXBException e) {
throw new RuntimeException(e);
}
}
}
</pre><br>
作者:sunzuqiang- http://old.uplook.cn/biancheng/139/1390236/