# How to add data from java(java6 jax-ws)

**URL:** <https://techcommunity.softwareag.com/t/how-to-add-data-from-java-java6-jax-ws/90319>\
**Category:** Forum\
**Tags:** Adabas-Natural, Adabas, Adabas-Add-on-Products, Other-Adabas-add-on-products, Adabas-SOA-Gateway\
**Created:** [June 2, 2009, 10:34am UTC](https://techcommunity.softwareag.com/t/how-to-add-data-from-java-java6-jax-ws/90319 "2009-06-02T10:34:39Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tamino\_man](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/tamino_man/32/98_2.png) [@tamino\_man](https://techcommunity.softwareag.com/u/tamino_man)\
**Post date:** [June 2, 2009, 10:34am UTC](https://techcommunity.softwareag.com/t/how-to-add-data-from-java-java6-jax-ws/90319/1 "2009-06-02T10:34:39Z")

</div>

Hi.

I use Adabas SOA Gateway ver 2.4.  
I want to access it by JavaProgram.  
I can get a data (:source1),But I can’t add data(:source2).

Please help me.

\*The JavaProgram is made by “wsimport” command.(Java6 JAX-WS)  
\*This WebService is made according to “Adabas Tutorials”.  
[http://techcommunity.softwareag.com/ecosystem/documentation/adabas/asg241/tutorials/lobs\_prepare.htm#lobs\_prepare](http://techcommunity.softwareag.com/ecosystem/documentation/adabas/asg241/tutorials/lobs_prepare.htm#lobs_prepare)

* * *

[:source1]

AdaBlobsRootService service = new AdaBlobsRootService();  
AdaBlobsRootPortType port = service.getAdaBlobsRootport();  
System.out.println(port.toString());  
AdaBlobsGroupPrimaryKeyType keys = new AdaBlobsGroupPrimaryKeyType();  
keys.setAA(“99880000”);

AdaBlobsRootElementType result = null;  
try {  
//_get_  
result = port.get(keys);  
} catch (Fault e1) {  
e1.printStackTrace();  
}  
AdaBlobsGroupType type = result.getAdaBlobsRoot().getAdaBlobsGroup()  
.get(0);

## OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(“foo.jpg”)); out.write(type.getLB().getValue()); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (out != null) { out.flush(); out.close(); } } catch (Exception e) { e.printStackTrace(); } }

[:source2]

AdaBlobsRootService service = new AdaBlobsRootService();  
AdaBlobsRootPortType port = service.getAdaBlobsRootport();  
System.out.println(port.toString());

AdaBlobsGroupType type = new AdaBlobsGroupType();  
type.setAA(“99880004”);  
type.setLM(“”);

// BLOB data  
Base64Binary lobdata = new Base64Binary();  
lobdata.setContentType(“image/jpeg”);  
InputStream is = null;  
ByteArrayOutputStream bo = null;  
try {  
is = new BufferedInputStream(new FileInputStream(“input/test.jpg”));  
bo = new ByteArrayOutputStream();  
byte b = new byte[1024];  
while (is.read(b) \> 0) {  
bo.write(b);  
}  
bo.close();  
is.close();  
lobdata.setValue(bo.toByteArray());  
type.setLB(lobdata);

AdaBlobsRootType root = new AdaBlobsRootType();  
root.getAdaBlobsGroup().add(type);

//_add_  
port.add(root);

} catch (FileNotFoundException e) {  
e.printStackTrace();  
} catch (IOException e) {  
e.printStackTrace();  
} catch (Fault e) {  
e.printStackTrace();  
} finally{  
if(bo != null){  
try {  
bo.close();  
} catch (IOException e) {  
e.printStackTrace();  
}  
if(is != null){  
try {  
is.close();  
} catch (IOException e) {  
e.printStackTrace();  
}  
}  
}  
}

* * *

[:source2 error]

Exception in thread “main” com.sun.xml.internal.ws.streaming.XMLStreamReaderException: XML reader error: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]  
Message: Premature end of file.  
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.wrapException(XMLStreamReaderUtil.java:242)  
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.next(XMLStreamReaderUtil.java:70)  
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.nextContent(XMLStreamReaderUtil.java:85)  
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.nextElementContent(XMLStreamReaderUtil.java:75)  
at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:167)  
at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:149)  
at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:121)  
at com.sun.xml.internal.ws.encoding.SOAPBindingCodec.decode(SOAPBindingCodec.java:280)  
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:158)  
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:74)  
at com.sun.xml.internal.ws.API.pipe.Fiber.\_\_doRun(Fiber.java:581)  
at com.sun.xml.internal.ws.API.pipe.Fiber.\_doRun(Fiber.java:540)  
at com.sun.xml.internal.ws.API.pipe.Fiber.doRun(Fiber.java:525)  
at com.sun.xml.internal.ws.API.pipe.Fiber.runSync(Fiber.java:422)  
at com.sun.xml.internal.ws.client.Stub.process(Stub.java:235)  
at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:120)  
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:230)  
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:210)  
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:103)  
at $Proxy34.add(Unknown Source)  
at soaptest.HelloMainAdd.main(HelloMainAdd.java:61)  
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]  
Message: Premature end of file.  
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:588)  
at com.sun.xml.internal.ws.util.xml.XMLStreamReaderFilter.next(XMLStreamReaderFilter.java:78)  
at com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil.next(XMLStreamReaderUtil.java:51)  
… 19 more

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [June 2, 2009, 8:20pm UTC](https://techcommunity.softwareag.com/t/how-to-add-data-from-java-java6-jax-ws/90319/2 "2009-06-02T20:20:50Z")

</div>

First of all, the following is required to turn on MTOM attachments:

```auto
SOAPBinding binding = (SOAPBinding)((BindingProvider)port).getBinding();
binding.setMTOMEnabled(true);
```

However, there seems to be a problem with JAX-WS not sending the attachments across properly, although the Content-type indicates xop+xml the SOAP:Body does NOT send an Xop:Include :roll:

I will investigate this further and get back with the solution asap !

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [June 3, 2009, 12:35am UTC](https://techcommunity.softwareag.com/t/how-to-add-data-from-java-java6-jax-ws/90319/3 "2009-06-03T00:35:53Z")

</div>

I got this to work by upgrading from J6u12 (includes JAX-WS RI 2.1.1) to j6u14 (includes JAX-WS RI 2.1.6).

```auto
setMTOMEnabled(true)
```

still required !

---

<div class="post-metadata">

**Author:** ![tamino\_man](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/tamino_man/32/98_2.png) [@tamino\_man](https://techcommunity.softwareag.com/u/tamino_man)\
**Post date:** [June 3, 2009, 7:33am UTC](https://techcommunity.softwareag.com/t/how-to-add-data-from-java-java6-jax-ws/90319/4 "2009-06-03T07:33:17Z")

</div>

Thank you for your reply.

I upgrade j6u14 (includes JAX-WS RI 2.1.6).  
and I add a code (turn on MTOM attachments)

```auto

SOAPBinding binding = (SOAPBinding)((BindingProvider)port).getBinding(); 
binding.setMTOMEnabled(true);
```

But error occured.  
I want to add a LOBdata by JavaProgram.  
If JAX-WS is not support sending the attachments,  
is there other methods?

[:source3]

```auto

package soaptest;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import javax.xml.ws.BindingProvider;
import javax.xml.ws.soap.SOAPBinding;

import org.w3._2005._05.xmlmime.Base64Binary;

import uri.localhost._56000.ada_blobs.AdaBlobsRootPortType;
import uri.localhost._56000.ada_blobs.AdaBlobsRootService;
import uri.localhost._56000.ada_blobs.Fault;

import com.risaris.namespaces.ada_blobs.AdaBlobsGroupType;
import com.risaris.namespaces.ada_blobs.AdaBlobsRootType;

public class HelloMainAdd {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		AdaBlobsRootService service = new AdaBlobsRootService();
		AdaBlobsRootPortType port = service.getAdaBlobsRootport();
		System.out.println(port.toString());

		// *enable MTOM*
		SOAPBinding binding = (SOAPBinding) ((BindingProvider) port)
				.getBinding();
		binding.setMTOMEnabled(true);

		AdaBlobsGroupType type = new AdaBlobsGroupType();
		type.setAA("99880004");
		type.setLM("");

		// BLOB data
		Base64Binary lobdata = new Base64Binary();
		lobdata.setContentType("image/jpeg");
		InputStream is = null;
		ByteArrayOutputStream bo = null;
		try {
			is = new BufferedInputStream(new FileInputStream("input/test.jpg"));
			bo = new ByteArrayOutputStream();
			byte[] b = new byte[1024];
			while (is.read(b) > 0) {
				bo.write(b);
			}
			bo.close();
			is.close();
			lobdata.setValue(bo.toByteArray());
			type.setLB(lobdata);

			AdaBlobsRootType root = new AdaBlobsRootType();
			root.getAdaBlobsGroup().add(type);

			// *add*
			port.add(root);

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Fault e) {
			e.printStackTrace();
		} finally {
			if (bo != null) {
				try {
					bo.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (is != null) {
					try {
						is.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
		}

	}

}

```

[:source3 error]

```auto

JAX-WS RI 2.1.6 in JDK 6: Stub for http://localhost:56000/ada_blobs
Exception in thread "main" com.sun.xml.internal.ws.server.UnsupportedMediaException: Unsupported Content-Type: text/plain Supported ones are: [text/xml]
	at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:284)
	at com.sun.xml.internal.ws.encoding.StreamSOAPCodec.decode(StreamSOAPCodec.java:118)
	at com.sun.xml.internal.ws.encoding.SOAPBindingCodec.decode(SOAPBindingCodec.java:278)
	at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:180)
	at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:83)
	at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:105)
	at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:587)
	at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:546)
	at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:531)
	at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:428)
	at com.sun.xml.internal.ws.client.Stub.process(Stub.java:211)
	at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:124)
	at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:98)
	at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
	at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107)
	at $Proxy33.add(Unknown Source)
	at soaptest.HelloMainAdd.main(HelloMainAdd.java:63)

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [June 3, 2009, 12:08pm UTC](https://techcommunity.softwareag.com/t/how-to-add-data-from-java-java6-jax-ws/90319/5 "2009-06-03T12:08:59Z")

</div>

Please check your database, the ADD WORKED 😉

This exception occurs when JAX-WS receives the “add successful” response, but your data has been added.

I am currently investigating why this exception occurs, but you can safely ignore it.  
I’ll get back with more information asap.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [June 4, 2009, 1:29am UTC](https://techcommunity.softwareag.com/t/how-to-add-data-from-java-java6-jax-ws/90319/6 "2009-06-04T01:29:33Z")

</div>

The problem here is that the xml header comes across to the SOA Gateway server from JAX-WS as

```auto
[?xml version="1.0" ?]
```

But the server determines the encoding from that header and if it isn’t specified as in

```auto
[?xml version="1.0" encoding="UTF-8"?]
```

the content type is currently sent, as observed, as text/plain instead of text/xml.

Note: less-than and greater-than signs replaced by square brackets in the above code snippets because the forum filters those away …

This has been fixed and a service pack will be released asap, meanwhile this can be circumvented by forcing JAX-WS to send the encoding= on the XML header, unfortunately I haven’t found a way of doing this so far :roll:

If you find out, please let me know, I’ll continue to investigate from my end as well.

---

<div class="post-metadata">

**Author:** ![tamino\_man](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/tamino_man/32/98_2.png) [@tamino\_man](https://techcommunity.softwareag.com/u/tamino_man)\
**Post date:** [June 4, 2009, 6:23am UTC](https://techcommunity.softwareag.com/t/how-to-add-data-from-java-java6-jax-ws/90319/7 "2009-06-04T06:23:49Z")

</div>

Thank you for your reply.

I checked my database, when this exception occurs , But data is added as you say.

> If you find out, please let me know, I’ll continue to investigate from my end as well.  
> OK.  
> Me,too.I’ll investigate.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 2:57pm UTC](https://techcommunity.softwareag.com/t/how-to-add-data-from-java-java6-jax-ws/90319/8 "2021-04-02T14:57:06Z")

</div>


