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

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


[: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

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

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 !

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

setMTOMEnabled(true)

still required !

Thank you for your reply.

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


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]


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]


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)

Please check your database, the ADD WORKED :wink:

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.

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

[?xml version="1.0" ?]

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

[?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.

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.