Skip to Content
0

Calling Graphical mapping via Java mapping in sap pi 7.31

Aug 23, 2017 at 05:57 AM

131

avatar image

Hi Experts,

I need to call a graphical mapping via Java mapping and get the graphical output in java mapping.

If it is possible, Please help me on this

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Muniyappan Marasamy Aug 23, 2017 at 08:17 AM
0

As Evgeniy said this is not possible to call graphical map from java map.

But you can achieve this using below blog.

https://blogs.sap.com/2014/11/24/message-and-java-mappings-together/

Show 3 Share
10 |10000 characters needed characters left characters exceeded

Hi Muni,

Thanks for sharing the blog.

I'm stuck up with the below errors.

com.sap.xi.tf._MM_mapping_.TransformationOutputImpl is not abstract and does not override abstract method getOutputAttachments() in com.sap.aii.mapping.api.TransformationOutput class TransformationOutputImpl extends TransformationOutput {

capture.png

capture.png (10.0 kB)
0

I tried using java map first and calling message map. it is working. you need to implement your login in method "YourExtBussLogicMethod"

i put the trace to verify this. it is working.

This is the code i am using in method "Attributes and Methods". converting inputstread to by ByteArrayOutputStream can be done in many ways. google search and use the best approach.


       InputAttachments inputAttachments;
	InputHeader inputHeader;
	InputParameters inputParameters;
	DynamicConfiguration dynamicConfiguration;
	OutputAttachments outputAttachments;
	OutputHeader outputHeader;
	OutputParameters outputParameters;


	public void transform(TransformationInput in, TransformationOutput out)
			throws StreamTransformationException {


getTrace().addInfo("Java Map start");
		try {
			dynamicConfiguration = in.getDynamicConfiguration();
			inputAttachments = in.getInputAttachments();
			inputHeader = in.getInputHeader();
			inputParameters = in.getInputParameters();
			outputAttachments = out.getOutputAttachments();
			outputHeader = out.getOutputHeader();
			outputParameters = out.getOutputParameters();
			InputStream is = (InputStream) in.getInputPayload()
					.getInputStream();
			/*
			 * **************************** GuideLines for Java Mapping
			 * *********
			 * *********************************************************** You
			 * can have java mapping code INLINE if it is few lines. And if it
			 * is a big and complex code, then I recommend to isolate java
			 * mapping logic and develop it separately as a NORMAL java program.
			 * Import it as 'imported archive' and refer it in graphical mapping
			 * And then call the externally developed public method here
			 * Recommendation for external method signature: public
			 * ByteArrayOutputStream YourExtBussLogicMethod(InputStream is, ...)
			 * *
			 * *****************************************************************
			 * ****************************************************************
			 */
			/*
			 * BEGIN ************************************************* PATTERN 1
			 * (JM - GM) *************************************************
			 */
			// Java Mapping: YourExtBussLogicMethod(is) code is nothing but your
			// java mapping logic. You can also have INLINE code here
			ByteArrayOutputStream baos = YourExtBussLogicMethod(is);
			InputStream newInputStream = new ByteArrayInputStream(baos
					.toByteArray());
			InputPayloadImpl payloadInObj = new InputPayloadImpl(newInputStream);
			TransformationInputImpl transformInObj = new TransformationInputImpl(
					payloadInObj);
			// Graphical mapping called here
			super.transform(transformInObj, out);
		} catch (Exception e) {
			throw new StreamTransformationException(e.getMessage());
		}
	}


	class InputPayloadImpl extends InputPayload {
		InputStream in;


		public InputPayloadImpl(InputStream in) {
			this.in = in;
		}


		@Override
		public InputStream getInputStream() {
			return in;
		}
	}


	class TransformationInputImpl extends TransformationInput {
		InputPayload payload;


		public DynamicConfiguration getDynamicConfiguration() {
			return dynamicConfiguration;
		}


		public TransformationInputImpl(InputPayload payload) {
			this.payload = payload;
		}


		@Override
		public InputAttachments getInputAttachments() {
			return inputAttachments;
		}


		@Override
		public InputHeader getInputHeader() {
			return inputHeader;
		}


		@Override
		public InputParameters getInputParameters() {
			return inputParameters;
		}


		@Override
		public InputPayload getInputPayload() {
			return payload;
		}
	}


	class OutPayloadImpl extends OutputPayload {
		OutputStream ou;


		public OutPayloadImpl(OutputStream ou) {
			this.ou = ou;
		}


		@Override
		public OutputStream getOutputStream() {
			return ou;
		}
	}


	class TransformationOutputImpl extends TransformationOutput {
		OutputPayload payload;


		public TransformationOutputImpl(OutputPayload payload) {
			this.payload = payload;
		}


		@Override
		public void copyInputAttachments() {
		}


		@Override
		public OutputAttachments getOutputAttachments() {
			return outputAttachments;
		}


		@Override
		public OutputHeader getOutputHeader() {
			return outputHeader;
		}


		@Override
		public OutputParameters getOutputParameters() {
			return outputParameters;
		}


		@Override
		public OutputPayload getOutputPayload() {
			return payload;
		}
	}
	
public ByteArrayOutputStream YourExtBussLogicMethod(InputStream is)
			throws Exception {




	String in = null;
		BufferedReader br = new BufferedReader(new InputStreamReader(is));
		StringBuilder sbr = new StringBuilder();
		while(( in =br.readLine())!=null){
			sbr.append(in);
		}
				
		String outputmessage = sbr.toString();
		getTrace().addInfo(outputmessage);
		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
		DataOutputStream out = new DataOutputStream(byteArrayOutputStream);
		out.write(outputmessage.getBytes());
		byteArrayOutputStream.flush();
		byteArrayOutputStream.close();
		
		return byteArrayOutputStream;


	}




i used below udf in one of the message mapping field.

container.getTrace().addInfo("This is from Message map UDF"); return var1;

my mapping output

mapping.jpg

mapping.jpg (44.0 kB)
0

Thanks Muni.

Solved my problem.

0
Evgeniy Kolmakov Aug 23, 2017 at 06:59 AM
0

Hi Vinoth!

I guess it's not possible. And why do you have such a strange requirement?

Regards, Evgeniy.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi Evgeniy,

I have a graphical mapping which is not mapped for handle multiple details record. So Now I have a requirement to process multiple records.

If I execute with multiple records, I'm getting context issue.

So, I'm planning to loop a graphical mapping with single record via java mapping.

Thanks

Vinoth S

0
Raghuraman S Aug 23, 2017 at 07:47 AM
0

Hello Vinoth,

Why your calling Graphical in java mapping.

Instead sequence it in operation mapping like first java mapping then graphical mapping

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi Raghu,

I designed multi mapping in OM. that is 0..unbound scenario and my graphical mapping doesn't build for handle unbound scenario. So I want to execute graphical mapping for each message separately and club it in java mapping and then send to target.

0

Hello vinoth,

Requirment is not clear.

Your trying to merge messages using Java mapping?

0