Sunday, November 5, 2017

ORABPEL-05250 Error - JDeveloper Part2

ORABPEL-05250 Error - JDeveloper Part2

I was facing a strange issue while deploying the composite to the server but The composite was successfully build in JDeveloper but during deployment to the server received the following exception.

[02:02:37 PM] Sending archive - sca_SuppressSelectionFailure_rev1.0.jar
[02:02:49 PM] Received HTTP response from the server, response code=500
[02:02:49 PM] Error deploying archive sca_SuppressSelectionFailure_rev1.0.jar to partition "default" on server AdminServer [http://inkaban3ua-eai05:8000]
[02:02:49 PM] HTTP error code returned [500]
[02:02:49 PM] Error message from server:
There was an error deploying the composite on AdminServer: Error occurred during deployment of component: SuppressSelectionFailure to service engine: implementation.bpel, for composite: SuppressSelectionFailure: ORABPEL-05250

Error deploying BPEL suitcase.
error while attempting to deploy the BPEL component file "/fmw/config/admin/domains/SOACoreDomain/servers/AdminServer/dc/soa_1b6f358e-8947-4572-a573-e036770c0591"; the exception reported is: java.lang.Exception: BPEL 1.1 compilation failed

This error contained an exception thrown by the underlying deployment module.
Verify the exception trace in the log (with logging level set to debug mode).
.

[02:02:49 PM] Check server log for more details.
[02:02:49 PM] Error deploying archive sca_SuppressSelectionFailure_rev1.0.jar to partition "default" on server AdminServer [http://localhost:8000]
[02:02:49 PM] ####  Deployment incomplete.  ####
[02:02:49 PM] Error deploying archive file:/C:/JDeveloper/mywork/Application1/SuppressSelectionFailure/deploy/sca_SuppressSelectionFailure_rev1.0.jar
 (oracle.tip.tools.ide.fabric.deploy.common.SOARemoteDeployer)


java.lang.ClassCastException for the same class com.sample.test.Test cannot be cast to com.sample.test.Test - Adobe Experience Manager(AEM)

java.lang.ClassCastException for the same class com.sample.test.Test cannot be cast to com.sample.test.Test - Adobe Experience Manager(AEM)

We were facing a strange ClassCastException - ClassCastException pointing to the same class in Adobe Experience Manager(AEM)

java.lang.ClassCastException: com.sample.test.Test cannot be cast to com.sample.test.Test

While analyzing through depfinder - http://localhost:4502/system/console/depfinder, there is two version of the same class available from two different packages.

But this class is only defined in one of the package and referred in the other package, after analyzing the Sling class loading is little different - If one of the class com.sample.test.Test is referred from different package, Sling copies the classes locally to the target package and if the target package export the same package(<Export-Package>) -  com.sample.* then Sling export the classes copied from other package that matches the export pattern, in this case our target package is already exporting com.sample.* so two version of same class is available now. This will lead to the ClassCastException specified above.

To fix this issue, we can change the target package pom.xml file to restrict the export of referred classes from other package.

<Export-Package>com.sample.*,!com.sample.test</Export-Package>

Please make sure the restricted package - !com.sample.test is kept after the wider package - com.sample.*

Now only one version of the class from source package is available for reference.


Wednesday, July 5, 2017

Exposing the AEM resources through OAuth - Adobe Experience Manager(AEM)

Exposing the AEM resources through OAuth - Adobe Experience Manager(AEM)

This post will explain the approach to expose the resources through OAuth in Adobe Experience Manager(AEM).

Refer https://www.albinsblog.com/2017/05/how-to-get-basic-profile-details-of-user-through-oauth.html for the basic configurations to expose the the resources thorough OAuth.

Exposing /etc/designs/geometrixx/static.css through OAuth

Configure the "Allowed Scope" as "/etc/designs/geometrixx"(based on the resource that should be exposed) in "Adobe Granite OAuth Resource Server"


The OAuth Authentication handler is not enabled by default and it looks to be an product defect.




Monday, May 29, 2017

How to expose Regex based rest service in Adobe Experience Manager( AEM)

How to expose Regex based rest service in Adobe Experience Manager(AEM)

This post will explain the approach to expose the regex based rest service in Adobe Experience Manager(AEM). By default OSGI will not support exposing regex based rest services and it will only support the services based on the specified Path or Resource Type.

Install OSGI JAX-RS connector:

Install(/system/console/bundles) jersey-all, publisher, provider-security and other required bundles e.g. provider-gson for JSON support and make sure the bundles are in Active state.

The bundles(jar) can be downloaded from following URL - http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.eclipsesource.jaxrs%22

com.eclipsesource.jaxrs-bundles

Develop the Servlet with required path mapping:

>=AEM 6.2

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import org.osgi.service.component.annotations.Component;

@Component(service = RegexServlet.class)
@Path("/{catagroy}/{title}/p/{code : \\d{5}}")
public class RegexServlet {

  @GET
  @Produces({MediaType.TEXT_PLAIN})
  public String getProductDetails(@Context HttpServletRequest request, @Context HttpServletResponse response,@PathParam("catagroy") String catagroy,@PathParam("title") String title,@PathParam("code") String code) {

    return "code="+code+";catagroy="+catagroy+";title="+title;

    }
}

< AEM 6.2

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import javax.ws.rs.Path;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Service(RegexServlet.class)
@Component(metatype = false)
@Path("/{catagroy}/{title}/p/{code : \\d{5}}")
public class RegexServlet {

 @GET
 @Produces({MediaType.TEXT_PLAIN})
public String getProductDetails(@Context HttpServletRequest request, @Context HttpServletResponse response,@PathParam("catagroy") String catagroy,@PathParam("title") String title,@PathParam("code") String code) {

   return "code="+code+";catagroy="+catagroy+";title="+title;

    }
}

Add the following dependency in POM.xml

<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
    <version>2.0</version>
</dependency>

Install the package and make sure the core bundle status is active.

Verify whether the RegexServlet service is registered in system console

JAX-RS_Servlet

The servlet will accept the request with matching pattern - the servlet path should be starting with /services

The Path Regex pattern specified in the servlet will match for the following URL  - localhost:4502/services/categoryTest/Sampletitle/p/12345 (Code should be 5 digit)

Download the sample code -https://gitlab.com/albinsblog-data/RegexServlet/tree/master (Refer com.regex.servlet.core.RegexServlet.java in core module)
The sample code is tested in AEM 6.3 but it should be working in 6.2


Friday, May 19, 2017

Java PayPal API integration through proxy server

Java PayPal API integration through proxy server

Getting the below exception while integrating PayPal API with Java, based on the analysis the direct communication to the API is not enabled from the server and the communication should be directed via Proxy server.

09:10:50.525 [main] ERROR com.paypal.base.HttpConnection -  Retry  No : 1...
09:11:54.577 [main] ERROR com.paypal.base.HttpConnection - Caught exception while handling error response java.net.ConnectException: Connection timed out
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.7.0_67]

Setting the proxy server in the API:

 HashMap<String,String> config=new HashMap<String,String>();
config.put("http.UseProxy", "true");
config.put("http.ProxyPort", "80");
config.put("http.ProxyHost", "proxy.server.com");
config.put("http.ProxyUserName", null);
config.put("http.ProxyPassword", null);

APIContext context = new APIContext(clientId, clientSecret, "sandbox",config);

Change the values of  ProxyHost,  ProxyPort, ProxyUserName and ProxyPassword accordingly.

The communication will be success after this.