Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix proper jms message charset #200

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;

import javax.activation.DataSource;

Expand All @@ -45,7 +46,7 @@ public String getContentType() {
}

public InputStream getInputStream() throws IOException {
byte[] bytes = requestContent.getBytes("UTF-8");
byte[] bytes = requestContent.getBytes(StandardCharsets.UTF_8);
return new ByteArrayInputStream(bytes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
Expand Down Expand Up @@ -77,7 +78,7 @@ public boolean isRepeatable() {

public void writeTo(OutputStream arg0) throws IOException {
try {
arg0.write("\r\n".getBytes());
arg0.write("\r\n".getBytes(StandardCharsets.UTF_8));
((MimeMultipart) message.getContent()).writeTo(arg0);
} catch (Exception e) {
SoapUI.logError(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
Expand Down Expand Up @@ -94,7 +95,7 @@ public boolean isRepeatable() {

public void writeTo(OutputStream arg0) throws IOException {
try {
arg0.write("\r\n".getBytes());
arg0.write("\r\n".getBytes(StandardCharsets.UTF_8));
((MimeMultipart) message.getContent()).writeTo(arg0);
} catch (Exception e) {
SoapUI.logError(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;

/**
* DataSource for an existing WsdlMockResponse
Expand Down Expand Up @@ -59,7 +60,7 @@ public String getContentType() {
}

public InputStream getInputStream() throws IOException {
byte[] bytes = responseContent.getBytes("UTF-8");
byte[] bytes = responseContent.getBytes(StandardCharsets.UTF_8);
return new ByteArrayInputStream(bytes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;

import javax.activation.DataSource;

Expand All @@ -45,7 +46,7 @@ public String getContentType() {
}

public InputStream getInputStream() throws IOException {
byte[] bytes = requestContent.getBytes("UTF-8");
byte[] bytes = requestContent.getBytes(StandardCharsets.UTF_8);
return new ByteArrayInputStream(bytes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
Expand Down Expand Up @@ -77,7 +78,7 @@ public boolean isRepeatable() {

public void writeTo(OutputStream arg0) throws IOException {
try {
arg0.write("\r\n".getBytes());
arg0.write("\r\n".getBytes(StandardCharsets.UTF_8));
((MimeMultipart) message.getContent()).writeTo(arg0);
} catch (Exception e) {
SoapUI.logError(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;

import javax.activation.DataSource;

Expand Down Expand Up @@ -54,7 +55,7 @@ public String getContentType() {
}

public InputStream getInputStream() throws IOException {
byte[] bytes = requestContent.getBytes("UTF-8");
byte[] bytes = requestContent.getBytes(StandardCharsets.UTF_8);
return new ByteArrayInputStream(bytes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
Expand Down Expand Up @@ -92,7 +93,7 @@ public boolean isRepeatable() {
@Override
public void writeTo(OutputStream arg0) throws IOException {
try {
arg0.write("\r\n".getBytes());
arg0.write("\r\n".getBytes(StandardCharsets.UTF_8));
((MimeMultipart) message.getContent()).writeTo(arg0);
} catch (Exception e) {
SoapUI.logError(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;

import javax.activation.DataSource;

Expand Down Expand Up @@ -72,9 +73,9 @@ public InputStream getInputStream() throws IOException {
if (SchemaUtils.isInstanceOf(schemaType, XmlHexBinary.type)) {
return new ByteArrayInputStream(Hex.decodeHex(content.toCharArray()));
} else if (SchemaUtils.isInstanceOf(schemaType, XmlBase64Binary.type)) {
return new ByteArrayInputStream(Base64.decodeBase64(content.getBytes()));
return new ByteArrayInputStream(Base64.decodeBase64(content.getBytes(StandardCharsets.UTF_8)));
} else if (SchemaUtils.isAnyType(schemaType)) {
return new ByteArrayInputStream(content.getBytes());
return new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8));
} else {
throw new IOException("Invalid type for XOPPartDataSource; " + schemaType.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,14 @@ private String applyFilters(SubmitContext submitContext, Request request) {
private Message createBytesMessageFromText(SubmitContext submitContext, String requestContent, Session session)
throws JMSException {
BytesMessage bytesMessage = session.createBytesMessage();
bytesMessage.writeBytes(requestContent.getBytes());
final Request request = (Request) submitContext.getProperty(WSDL_REQUEST);
bytesMessage.writeBytes(JMSUtils.extractBytesFromString(requestContent, request));
return bytesMessage;
}

private Message createTextMessageFromAttachment(SubmitContext submitContext, Request request, Session session) {
try {
String content = convertStreamToString(request.getAttachments()[0].getInputStream());
String content = convertStreamToString(request.getAttachments()[0].getInputStream(), request);
TextMessage textMessageSend = session.createTextMessage();
String messageBody = PropertyExpander.expandProperties(submitContext, content);
textMessageSend.setText(messageBody);
Expand All @@ -341,14 +342,14 @@ private Message createTextMessageFromAttachment(SubmitContext submitContext, Req
return null;
}

private String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
private String convertStreamToString(InputStream is, Request request) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, JMSUtils.resolveCharset(request)));
StringBuilder sb = new StringBuilder();

String line = null;
String line;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
sb.append(line).append("\n");
}
} catch (IOException e) {
e.printStackTrace();
Expand Down Expand Up @@ -454,10 +455,10 @@ public void removeRequestFilter(RequestFilter filter) {

@Override
public void insertRequestFilter(RequestFilter filter, RequestFilter refFilter) {
int ix = filters.indexOf( refFilter );
if( ix == -1 )
filters.add( filter );
int ix = filters.indexOf(refFilter);
if (ix == -1)
filters.add(filter);
else
filters.add( ix, filter );
filters.add(ix, filter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.eviware.soapui.impl.wsdl.WsdlRequest;
import com.eviware.soapui.impl.wsdl.submit.transports.http.SSLInfo;
import com.eviware.soapui.impl.wsdl.submit.transports.http.WsdlResponse;
import com.eviware.soapui.impl.wsdl.submit.transports.jms.util.JMSUtils;
import com.eviware.soapui.model.iface.Attachment;
import com.eviware.soapui.model.iface.Request;
import com.eviware.soapui.support.types.StringToStringsMap;
Expand Down Expand Up @@ -118,15 +119,15 @@ public String[] getPropertyNames() {

public byte[] getRawRequestData() {
if (messageSend != null) {
return messageSend.toString().getBytes();
return JMSUtils.extractBytesFromString(messageSend.toString(), request);
} else {
return "".getBytes();
}
}

public byte[] getRawResponseData() {
if (messageReceive != null) {
return messageReceive.toString().getBytes();
return JMSUtils.extractBytesFromString(messageReceive.toString(), request);
} else {
return "".getBytes();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.eviware.soapui.impl.wsdl.submit.transports.jms.util;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Enumeration;

import javax.jms.BytesMessage;
Expand Down Expand Up @@ -108,4 +110,22 @@ public static byte[] extractByteArrayFromMessage(BytesMessage message) throws JM
message.readBytes(bytes);
return bytes;
}

public static byte[] extractBytesFromString(String source, Request request) {
if (source == null || source.isEmpty()) {
return new byte[0];
}
final Charset charset = resolveCharset(request);
return source.getBytes(charset);
}

public static Charset resolveCharset(Request request) {
final Charset charset;
if (request == null || request.getEncoding() == null || !Charset.isSupported(request.getEncoding())) {
charset = StandardCharsets.UTF_8;
} else {
charset = Charset.forName(request.getEncoding());
}
return charset;
}
}